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

I tested the API but error #135

Closed 5harever closed 5 years ago

5harever commented 5 years ago

Please help me fix the problem. I tried below code

get a list of trades

from oandapyV20 import API import oandapyV20.endpoints.trades as trades

api = API(access_token="blah blah blah") accountID = "001-011-1926632-001"

r = trades.TradesList(accountID)

show the endpoint as it is constructed for this call

print("REQUEST:{}".format(r)) rv = api.request(r) print("RESPONSE:\n{}".format(json.dumps(rv, indent=2)))

And I got this error message.

REQUEST:v3/accounts/001-011-1926632-001/trades

V20Error Traceback (most recent call last)

in () 9 # show the endpoint as it is constructed for this call 10 print("REQUEST:{}".format(r)) ---> 11 rv = api.request(r) 12 print("RESPONSE:\n{}".format(json.dumps(rv, indent=2))) ~\Anaconda3\lib\site-packages\oandapyV20\oandapyV20.py in request(self, endpoint) 304 305 response = self.__request(method, url, --> 306 request_args, headers=headers) 307 content = response.content.decode('utf-8') 308 content = json.loads(content) ~\Anaconda3\lib\site-packages\oandapyV20\oandapyV20.py in __request(self, method, url, request_args, headers, stream) 241 response.content.decode('utf-8')) 242 raise V20Error(response.status_code, --> 243 response.content.decode('utf-8')) 244 return response 245 V20Error: {"errorMessage":"Insufficient authorization to perform request."}
hootnot commented 5 years ago

Hi @5harever , the error is very clear: V20Error: {"errorMessage":"Insufficient authorization to perform request."}, make sure that you use a correct token. Maybe just revoke it and generate a new one.

If you have both a live and a practice account make sure you don't mix up

5harever commented 5 years ago

I already revoked and copy and paste again. It was still same error. I never created the practice version.

Or I have to define below? class oandapyV20.API(access_token, environment='live', headers=None, request_params=None)

hootnot commented 5 years ago

if you want to use a live account AND you have a token for live, the code from your first message should be:

api = API(access_token="blah blah blah", environment='live')

By default the client works on the practice environment. So if you passed a token for a live-account that V20 authorization error was logical.

I would strongly advise you to work on the practice environment first.

5harever commented 5 years ago

Oh this one is crystal clear. Thank you very much.

Best Regards,

Mr. Patchara Wattanadheerakul (Share)

On Oct 25, 2018, at 00:03, Feite Brekeveld notifications@github.com wrote:

if you want to use a live account AND you have a token for live, the code from your first message should be:

api = API(access_token="blah blah blah", environment='live')

By default the client works on the practice environment. So if you passed a token for a live-account that V20 authorization error was logical.

I would strongly advise you to work on the practice environment first.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.