gpt4 book ai didi

python - 向 oanda 发送订单

转载 作者:行者123 更新时间:2023-12-02 19:49:46 24 4
gpt4 key购买 nike

我想向oanda发送订单进行交易,我使用ipython笔记本来编译我的代码,这是我的代码:

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)

但错误是:

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

如何解决这个问题?

最佳答案

我遇到了同样的问题,但是当通过curl命令发送订单时。

问题与您从哪个帐户使用哪个 API 有关。

我注意到你的Python中写着“练习”,所以你需要确保你生成的API token 来自你的练习帐户。真实帐户和练习帐户各自使用自己的 API token ,并且您的命令需要匹配。

您还可以查看 Python 中的其他位置,它实际上 ping OandA 的服务器。

例如,当使用curl时,真实账户使用

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

练习帐户使用

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

在练习帐户中使用真实帐户生成的 API token 将会产生您所询问的错误。

关于python - 向 oanda 发送订单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41443556/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com