Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem in modify existing order #2

Open
learnereveryday opened this issue Jul 5, 2016 · 1 comment
Open

Problem in modify existing order #2

learnereveryday opened this issue Jul 5, 2016 · 1 comment

Comments

@learnereveryday
Copy link

Thank you for building the code.

I have one problem using your code to modify an existing order. It seems httpOPTIONS is not the function to make PATCH request. Could you please advise what I did wrong or revise the code? Thanks! The following is the error message I have got:

                                                                                 Server 
                                                                    "openresty/1.7.0.1" 
                                                                                   Date 
                                                        "Tue, 05 Jul 2016 02:35:26 GMT" 
                                                                           Content-Type 
                                                                     "application/json" 
                                                                         Content-Length 
                                                                                    "0" 
                                                                             Connection 
                                                                           "keep-alive" 
                                                           Access-Control-Allow-Headers 

"Accept, Authorization, Content-Type, Origin, X-Accept-DateTime-Format, X-HTTP-Method-Override"
Access-Control-Allow-Methods
"GET, PATCH, DELETE, OPTIONS"
Access-Control-Max-Age
"86400"
status
"204"
statusMessage
"NO_CONTENT\r\n"
Warning messages:
1: In mapCurlOptNames(names(.els), asNames = TRUE) :
Unrecognized CURL options: .params
2: In mapCurlOptNames(names(.els), asNames = TRUE) :
Unrecognized CURL options: .params

@learnereveryday learnereveryday changed the title Problem is modify existing order Problem in modify existing order Jul 9, 2016
@IFFranciscoME
Copy link
Owner

I have been trying to fix this but i cant, i found that with httr package there is the PATCH() function that we need although i just couldn't make it work, i took the advice from Oanda's Trouble Shooting for POST and PATCH Requests and reviewed the Modify an existing order. I am stuck here. So far this is the code i have for that particular function. The error i get so far is the following:

Response [https://api-fxpractice.oanda.com/v1/accounts/1742531/orders/10406990195]
  Date: 2016-08-08 02:14
  Status: 401
  Content-Type: application/json
  Size: 169 B
{
    "code" : 4,
    "message" : "The access token provided does not allow this request to be made",
    "moreInfo" : "http:\/\/developer.oanda.com\/docs\/v1\/auth\/#overview"
> 

Obviously i have double and triple check for the Token and authentication methods, for the rest of the functions that requires it there is no problem, so i have no idea here. The code I have so far is this

ModifyTrade <- function(AccountType, AccountID, Token, 
                        TradeID, StopLoss, TakeProfit, TrailingStop)
{
  if(AccountType == "practice") {
    httpaccount <- "https://api-fxpractice.oanda.com"
  } else 
  if(AccountType == "live") {
      httpaccount <- "https://api-fxtrade.oanda.com"
  } else print("Account type error. Must be practice or live")

  Queryhttp  <- paste(httpaccount,"/v1/accounts/", sep = "")
  Queryhttp1 <- paste(Queryhttp,AccountID, sep = "")
  Queryhttp2 <- paste(Queryhttp1,"/orders/", sep = "")
  Queryhttp3 <- paste(Queryhttp2,TradeID, sep = "")

  auth   <- c(Authorization = paste("Authorization: Bearer",Token, sep=" "))
  params <- list(stopLoss=StopLoss, takeProfit=TakeProfit, trailingStop=TrailingStop)
  DataReturn <- PATCH(Queryhttp3, add_headers(auth),body = params)

return(DataReturn)
}

I will momentarily leave it that way, so if any of the readers/followers get the answer to this i will include it. Or make a push request.

There are a couple of on line tools to troubleshoot this, i have used them unsuccessfully but maybe i am missing something simple that anybody would not. Here they are:

  • To make HTTP Requests: HURL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants