Я пытаюсь опубликовать тестовый заказ в Oanda и не могу заставить аутентификацию работать.
require(RCurl)
require(jsonlite)
NewOrder <- function(AccountType,AccountID,Token,OrderType,Instrument,Units,Side) {
httpaccount <- "https://api-fxpractice.oanda.com"
auth <- c(Authorization = paste("Bearer",Token,sep=" "))
Queryhttp <- paste(httpaccount,"/v3/accounts/",sep="")
Queryhttp1 <- paste(Queryhttp,AccountID,sep="")
Queryhttp2 <- paste(Queryhttp1,"/orders",sep="")
Param <- c(instrument=Instrument, units=Units, side=Side, type=OrderType)
PF <- postForm(Queryhttp2, style="POST", .params=Param,
.opts=list(httpheader=auth))
InstJson <- fromJSON(PF, simplifyDataFrame = TRUE)
return(InstJson)
}
Когда я запускаю функцию, я получаю следующее сообщение Error: Bad Request
Возвращаясь к ошибке, я вижу, что именно эта аутентификация и вызывает проблему.
4. stop(err)
3. stop.if.HTTP.error(http.header)
2. postForm(Queryhttp2, style = "POST", .params = Param, .opts = list(httpheader = auth))
1. NewOrder(AccountType, AccountID = AccountID, Token = Token, OrderType = "market",
Instrument = "EUR_USD", Units = 20, Side = "buy")
Я следовал документации API, но не могу заставить ее работать - пример документации Oanda:
body=$(cat << EOF
{
"order": {
"price": "1.2000",
"timeInForce": "GTC",
"instrument": "EUR_CAD",
"units": "10000",
"clientExtensions": {
"comment": "New idea for trading",
"tag": "strategy_9",
"id": "my_order_100"
},
"type": "MARKET_IF_TOUCHED",
"positionFill": "DEFAULT"
}
}
EOF
)
curl \
-X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <AUTHENTICATION TOKEN>" \
-d "$body" \
"https://api-fxtrade.oanda.com/v3/accounts/<ACCOUNT>/orders"
Кто-нибудь знает, что я делаю не так?