Reputation: 99
I'm trying to create a code to automatic execute orders in OANDA API
This is the code of my order:
class Execution(object):
def __init__(self, domain, access_token, account_id):
self.domain = domain
self.access_token = access_token
self.account_id = account_id
self.conn = self.obtain_connection()
def obtain_connection(self):
return httplib.HTTPSConnection(self.domain)
def execute_order(self, instrument, units, order_type, side):
headers = {
"Content-Type": "application/x-www-form-urlencoded",
"Authorization": "Bearer " + self.access_token
}
params = urllib.urlencode({
"instrument": instrument,
"units": units,
"type": order_type,
"side": side
})
self.conn.request(
"POST",
"/v1/accounts/%s/orders" % str(self.account_id),
params, headers
)
response = self.conn.getresponse().read()
print response
When I try to execute the order I obtain a strange error that I'm not able to solve:
{"code" : 52,
"message" : "Invalid or malformed resource identifier: accountId",
"moreInfo" : "http:\/\/developer.oanda.com\/docs\/v1\/troubleshooting\/#errors"
}
Did someone ever face this kind of problem? I'm asking because in the tutorial of OANDA related to the errors (http://developer.oanda.com/rest-live/troubleshooting-errors/) there is no mention about the code 52.
Is it a problem of connection or a problem about the creation of the order?
Upvotes: 0
Views: 1953
Reputation: 23
I received that error several times, it was bugging me because I could not figure it out, both access token and account id were correct. Then I realized I added the sub account AFTER creating my access token. You will be able to get historical prices because those are not account specific, but it wont let you in the account. So i had to revoke and regenerate my token, and it worked just fine. I know this is old, but I had this problem today.
Upvotes: 1
Reputation: 2403
Although code 52 is not specified in the troubleshooting errors, I'm pretty sure you got a 400 status code from your request:
400 Bad Request Invalid or malformed argument: [arg] The argument specified is not properly formatted or is an unaccepted value
double check your accountId
http://developer.oanda.com/rest-live/troubleshooting-errors/
please note that:
"code" : [OANDA error code, may or may not be the same as the HTTP status code],
Try "debugging" or passing your vars for the following section:
import requests
aTok = 'acess token'
header = {'Authorization': 'Bearer '+aTok}
account_id = "your account id"
uri = 'https://api-fxpractice.oanda.com' #or non-practice api-fxtrade.oanda.com
resp = requests.get(uri+'/v1/accounts/{0}/orders'.format(account_id), headers=header)
response = resp.text
print(response)
Upvotes: 0