我正试图从Oandas的V20休息api中获得stream the price一种乐器,但没有取得多大成功。我正在使用python请求,因为它适用于常规获取请求。这是我需要的地方:
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 :(得分:1)
您的网址无效(请参阅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绑定: https://github.com/search?utf8=%E2%9C%93&q=v20&type=
检查这些存储库中的示例代码,例如: https://github.com/hootnot/oandapyV20-examples
答案 1 :(得分:0)
使用默认的OANDA curl
示例,验证您的访问凭据:
curl \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <AUTHENTICATION TOKEN>" \
"https://api-fxtrade.oanda.com/v3/accounts/<ACCOUNT>/pricing?instruments=EUR_USD%2CUSD_CAD"
CASE isERR:前往OANDA支持,以解决无效凭据问题。
CASE wasOK:继续第1步。
curl
调用语法AS-IS CASE isERR:审核您的一次性python代码,以便以1:1的比例满足工作OANDA规范,已经证明在步骤0中工作。
curl
审核OANDA服务状态:curl http://api-status.oanda.com/api/v1/services
CASE wasOK:继续第2步。
然而,请记住,不要超越OANDA规定的每日最大请求数量和类似的限制性限制,这些限制应该谨慎处理。
CASE isERR:使用下面的curl
审核OANDA服务状态,并报告可能的错误详情:
curl http://api-status.oanda.com/api/v1/services
CASE wasOK:恭喜,您的定价来源的端到端工作符合规格。
405方法不允许
当客户端尝试使用不支持的HTTP方法访问API端点时,可能会从v20 REST API返回“405 Method Not Allowed”响应。响应Content-Type将是application / json并具有以下模式:
{
#
# The code of the error that has occurred. This field may not be returned
# for some errors.
#
errorCode : (string),
#
# The human-readable description of the error that has occurred.
#
errorMessage : (string, required)
}