hootnot / oanda-api-v20

OANDA REST-V20 API wrapper. Easy access to OANDA's REST v20 API with oandapyV20 package. Checkout the Jupyter notebooks!
MIT License
397 stars 107 forks source link

Insufficient authorization to perform request #129

Closed saeedesmaili closed 6 years ago

saeedesmaili commented 6 years ago

I've cloned this jupyter notebook file, but running the following snippet leads to an error:

import configparser

# v20 OANDA API - 3rd party
import json
from oandapyV20 import API    # the client
import oandapyV20.endpoints.trades as trades

config = configparser.ConfigParser()
config.read('oanda.cfg')

client = API(environment='practice',access_token=config['oanda']['access_token'])

import datetime
from dateutil import parser
import oandapyV20.endpoints.instruments as instruments

params={"from": parser.parse("2016-12-07 18:00:00 EDT").strftime('%s'),
        "to": parser.parse("2016-12-10 00:000:00 EDT").strftime('%s'),
        "granularity":'M1',
        "price":'A'}
r = instruments.InstrumentsCandles(instrument="EUR_USD",params=params)
data = client.request(r)
print(json.dumps(data, indent=2))    # <----- add this line to show the data

V20Error: {"errorMessage":"Insufficient authorization to perform request."}

My access token is correct and works fine with v1 api.

hootnot commented 6 years ago

your v1 account looks like: 1234567, the v20 account looks like: 123-456-123456.

If you did use the correct account then you should revoke the token and generate a new one. If you don't have a v20 test account, get one ... and regenerate that token right away .

Then try again.

... this piece of code works fine. You definitely must seek it in your account/token, just as the V20 error suggests. Therefore I will close this issue.

hootnot commented 6 years ago

@saeedesmaili by coincidence I saw you also opened the same issue at https://github.com/benjaminchodroff/oandamomentum/issues/3, which was actually the right place since it concerns his repo. Pls. close that issue since there is no need to waste someones time on an already resolved issue. Next time pls. only open an issue once.

saeedesmaili commented 6 years ago

Thanks for your help and advice. I closed that issue.