如何让ondapyV20完成授权?

Sha*_*ley 2 python algorithm finance forex

这是我的代码:

from oandapyV20 import API
import oandapyV20.endpoints.trades as trades
api = API(access_token="xxx")
accountID = "xxx-xxx-xxxxxxx-xxx"
r = trades.TradesList(accountID)
print("REQUEST:{}".format(r))
rv = api.request(r)
print("RESPONSE:\n{}".format(json.dumps(rv, indent=2)))
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

Traceback (most recent call last):
  File "C:\Users\Administrator\Desktop\oanda tester.py", line 10, in <module>
    rv = api.request(r)
  File "C:\Python37\lib\site-packages\oandapyV20\oandapyV20.py", line 306, in request
    request_args, headers=headers)
  File "C:\Python37\lib\site-packages\oandapyV20\oandapyV20.py", line 243, in __request
    response.content.decode('utf-8'))
oandapyV20.exceptions.V20Error: {"errorMessage":"Insufficient authorization to perform request."}
Run Code Online (Sandbox Code Playgroud)

我的令牌和帐户信息是正确的。

该代码是直接从文档复制的。

我在这里错过了什么吗?

小智 5

试试这个:

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

access_token="xxx"
accountID = "xxxx"
client= API(access_token=access_token,environment="live" or "practice")

r = trades.TradesList(accountID)
print("REQUEST:{}".format(r))
rv = client.request(r)
print("RESPONSE:\n{}".format(json.dumps(rv, indent=2)))
Run Code Online (Sandbox Code Playgroud)