gpt4 book ai didi

python - 使用 python 请求从 oanda V20 Rest api 流式定价

转载 作者:太空宇宙 更新时间:2023-11-03 15:29:57 25 4
gpt4 key购买 nike

我正在尝试stream the price来自 Oandas V20 Rest api 的仪器,但没有取得太大成功。我正在使用 python requests,因为它适用于常规 get 请求。这是我必须要做的:

import requests
url = 'https://stream-fxpractice.oanda.com/v3/accounts/MY_ACCOUNT_ID/pricing?instruments=EUR_USD'
head = {'Content-type':"application/json",
'Accept-Datetime-Format':"RFC3339",
'Authorization':"Bearer MY_ACCESS8TOKEN"}


r = requests.get(url, headers=head, stream=True)
print(r)

for line in r.iter_lines():

if line:
decoded_line = line.decode('utf-8')
print(json.loads(decoded_line))

响应错误代码为 405,表示不支持该方法。我做错了什么?

最佳答案

您的网址无效(请参阅 developer.oanda.com/rest-live-v20/pricing-ep/ ),
应该是:

url_OK = 'https://stream-fxpractice.oanda.com/v3/accounts/MY_ACCOUNT_ID/pricing/stream?instruments=EUR_USD'

而不是:

urlNOT = 'https://stream-fxpractice.oanda.com/v3/accounts/MY_ACCOUNT_ID/pricing?instruments=EUR_USD'
// |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||vvvvvvvv
// _OK = 'https://stream-fxpractice.oanda.com/v3/accounts/MY_ACCOUNT_ID/pricing/stream?instruments=EUR_USD'

如果您不想构造 URL 的麻烦,您可以使用 V20 绑定(bind)之一: https://github.com/search?utf8=%E2%9C%93&q=v20&type=

检查这些存储库中的示例代码,例如: https://github.com/hootnot/oandapyV20-examples

关于python - 使用 python 请求从 oanda V20 Rest api 流式定价,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42959165/

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