我正在尝试从Oandas的v20restapi中提取一个工具,但是没有成功。我使用python请求,因为它适用于常规的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,表示不支持该方法。 我做错什么了?在
步骤0.:验证您的访问凭据:
使用默认OANDA
curl
示例,验证您的访问凭据:CASE iser:继续OANDA支持,以修复使用无效凭据的问题。在
案例正常:继续步骤1。
步骤1:在一个一次性python中复制
curl
调用语法AS-IS没有增加,没有排除。应提供与步骤0相同的结果。在
CASE isERR:检查一下您的一次性python代码,以满足1:1的OANDA规范,该规范已经在步骤0中被证明是有效的。在
curl
查看OANDA服务状态:curl http://api-status.oanda.com/api/v1/services
案例正常:继续步骤2。
步骤2:扩展python代码,以便请求和处理响应
但是,请记住,不要超过OANDA规定的每天请求的最大数量和类似的限制性限制,这些限制应该小心处理。在
CASE iser:使用下面的
^{pr2}$curl
和可能报告的错误详细信息检查OANDA服务状态:案例没问题:恭喜你,你的定价来源按照规范进行了端到端的工作。在
错误405不是“不支持”服务,而是“不允许”
您的URL无效(请参见developer.oanda.com/rest-live-v20/pricing-ep/),
它应该是:
而不是:
^{pr2}$如果你不想麻烦你构造网址, 您可以使用V20绑定之一: https://github.com/search?utf8=%E2%9C%93&q=v20&type=
检查这些存储库中的示例代码,例如: https://github.com/hootnot/oandapyV20-examples
相关问题 更多 >
编程相关推荐