How to generate your API access token
Before you can access your account on OANDA’s REST v20 API, you must first generate a personal access token. To do this, follow these steps:
-
Log in to your live or demo account in the HUB.
-
On the top, click on Tools and then on API.
-
Click on Generate.
-
Below ‘Your key to OANDA’s API’, a combination of letters and numbers will appear. This is your API access token. Copy the entire line of text and use it to authenticate your account on the REST v20 API application.
-
To revoke access to the current token, click on Revoke. If you have added any additional sub-accounts to your REST v20 API account, you will also need to revoke and generate a new token to access them through the REST v20 API.
‘Insufficient authorization to perform request’ error message
The most common reason for this error message is that you may have used the incorrect endpoint for your request.
If you are using a live account, use the following endpoint: https://api-fxtrade.oanda.com.
If you are using a demo account, use the following endpoint: https://api-fxpractice.oanda.com.
‘Insufficient authorization to perform request’ error message when using REST-V20 API Java Wrapper
When your JAR files for dependent libraries are out of date, you may receive this error while executing Java code. This can be independent of the fact that your accountID and token are still working with the REST v20 API curl commands.
The solution is to:
-
Upgrade all libraries
-
Delete the external JAR files
-
Reload them from the internet.
The following list shows current libraries you may refer to:
-
common-logging-1.1.1.jar
-
gson-2.6.2.jar
-
httpclient-4.0-alpha4.jar
-
httpclient-4.3.5.jar
-
httpcore-4.3.2.jar
-
v20-3.0.21.jar
-
JRE System Library
-
Maven Dependencies (junit-3.8.1.jar)
‘Insufficient authorization to perform request’ error message when using oandapyv20
oandapyV20 is a third-party wrapper, not supported by OANDA.
We have a v20 Python wrapper available on the developer website for our API clients.
You will need to confirm that the following information is correct:
-
The URL provided to the curl command is correct. If you are using a live account, confirm that you are using https://api-fxtrade.oanda.com.
In your sample code, the default for environment is set to demo. You should confirm that you have changed it to live. You will need to edit the following code:
client = oandapyV20.API(access_token=access_token,environment="live")
-
Ensure the authentication token is valid and has been added as a bearer token in the HTTP authorization header.
‘The provided request was forbidden’ error message
The most common reason for this error is that you have used an invalid accountID in your request. To locate your correct accountID, follow these steps:
-
Log in to your live or demo account in the HUB.
-
From the left navigation bar, click on Accounts.
-
Click on the desired account
-
The number in the format of xxx-xxx-xxxxxxx-xxx next to v20 Account Number is your accountID.
Why is historical data different from live data?
OANDA’s historical data differs from live data as we offer different pricing segments and account types. For this reason, the live pricing feed of the API could be different from the historical data retrieved from the API.
This is because the ‘candle’ endpoint used to retrieve historical data only provides base-price group candlestick data. The price polling and streaming endpoints are used to retrieve live data, which uses your account_id to provides live data based on your specific pricing group.
Using ‘get - /v3/accounts/{accountID}/orders’ returns an empty order list
Because an order is changed to a trade once it is filled, using get - /v3/accounts/{accountID}/orders may return an empty order list.
Changing the default condition of orderstatefilter to all will allow you to use get /v3/accounts/{accountID}/orders even when the orders have been filled.
The values used for
OrderAn instruction to buy or sell an instrument under the specified conditions State Filter
are available on our
API documentation.
Why can’t I construct open-high-low-close (OHLC) candlesticks using REST v20 Stream endpoint?
You cannot create OHLC candlestick data using the REST v20 Stream endpoint, since open, high, low, and close data of the period are not guaranteed to be returned in the response packets. The instrument/candles endpoint probes the server to receive data once a bar is closed. The candle endpoint can thus be used to create accurate candle data with all the bar's activity.
If you need technical support, email api@oanda.com providing:
-
Your complete request and
-
Your server response logs, as well as
-
Other relevant information.