Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending an order to oanda

I want to send an order to oanda to make a transaction,I use ipython notebook to compile my code,this is my code:

import oandapy

trade_expire=datetime.now()+timedelta(days=1)
trade_expire=trade_expire.isoformat("T")+"Z"
oanda=oandapy.API(environment='practice',access_token='XXXX....')
account_id=xxxxxxx

response=oanda.create_order(account_id,instrument='USD_EUR',units=1000,side='buy',/
type='limit',price=1.105,expire=trade_expire)

But the error is:

OandaError: OANDA API returned error code 4 (The access token provided does
            not allow this request to be made)

How can I solve this problem?

like image 363
taylor Avatar asked Nov 09 '22 03:11

taylor


1 Answers

I had the same problem, but when sending orders via curl commands.

The problem has to do with which API you are using from which account.

I notice in your python it says "practice," so you'll want to make sure the API token you generated is from within your practice account. Live accounts and practice accounts each use their own API tokens, and your commands will need to match.

You might also look elsewhere in your python, where it actually pings OandA's server.

For example, when using curl, a live account uses

"https://api-fxtrade.oanda.com/v3/accounts/<ACCOUNT>/orders"

and a practice account uses

"https://api-fxpractice.oanda.com/v3/accounts/<ACCOUNT>/orders"

Using your API token generated on your live account in a practice account will produce the error you're asking about.

like image 159
Matt Zabojnik Avatar answered Nov 14 '22 21:11

Matt Zabojnik