python3.x - oanda를 사용하여 Python의 시뮬레이션된 거래 API에서 json을 얻는 방법에 대한 두 번째 질문
迷茫
迷茫 2017-05-18 10:55:43
0
2
653

첫 번째 질문에서는 oanda의 시뮬레이션 거래 API를 연결하여 EUR_USD의 즉각적인 환율을 얻을 수 있도록 해결되었습니다. 열정적인 도움을 주신 @prolifes에게 다시 한 번 감사드립니다. 절차는 다음과 같습니다.
import 요청
import json
url = "https://api-fxpractice.oanda.com/v1/prices"
instruments = 'EUR_USD'
account_id = 'cawa11'
params = {'instruments':instruments,'accountId':account_id}
access_token = 'a554db3a48ac8180a6996a5547ba1663 -ac5947e64456 cc5842a34f4ce05e4380'
headers = {'Authorization ':'Bearer '+access_token} # Bearer 뒤에 공백이 있습니다
r = 요청.get(url, 헤더 = 헤더, params=params)
print(r.json() )
결과 json은 다음과 같습니다.
{'price': [{'bid': 1.0926, 'time': '2017-05-03T05:45:25.737018Z', 'ask': 1.09274, 'instrument': 'EUR_USD '}]}
이제 EUR_USD와 USD_CAD를 모두 가져오고 싶습니다. 실시간 환율은 다음 형식의 json으로 가져옵니다.
{'prices': [{'instrument': 'EUR_USD', 'ask': 1.09324 , '시간': '2017-05-03T04:44:38.200174Z', ' bid': 1.09311},{'instrument': 'USD_CAD', 'ask': 1.37270, 'time': '2017-05-03T04 :44:38.200174Z', '입찰가': 1.37251}]}

迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

모든 응답(2)
大家讲道理

问题已解决,谢谢各位关注:
가져오기 요청
import json

url = "https://api-fxpractice.oanda.com/v1/prices"
instruments = 'EUR_USD,USD_CAD'
account_id = 'cawa11'
params = {'instruments':instruments,'accountId':account_id}
access_token = 'a554db3a48ac8180a6996a5547ba1663-ac5947e64456cc5842a34f4ce05e4380'
headers = {'연결': 'Keep-Alive','Accept-Encoding': 'gzip,deflate','Authorization':'Bearer '+access _token}
r = 요청.get (url,headers = headers, params=params)
price = r.json()
print(r.json())
print(price'prices'['instrument'].replace('_','/' ),':',round((price'prices'['ask']+price'prices'['bid'])/2,4),' ',price'prices'['time'])
인쇄 (price'prices'['instrument'].replace('_','/'),':',round((price'prices'['ask']+price'prices'['bid'])/ 2,4),' ',가격'가격'['시간'])

输출:
{'price': [{'bid': 1.09171, 'ask': 1.09184, 'instrument': 'EUR_USD', 'time': '2017-05-03T06:44:19.750556Z'}, { '입찰가': 1.37203, '요청': 1.37219, '수단': 'USD_CAD', '시간': '2017-05-03T06:44:19.738338Z'}]}
EUR/USD : 1.0918 2017-05-03T06 :44:19.750556Z
USD/CAD : 1.3721 2017-05-03T06:44:19.738338Z

漂亮男人

이것은 더 이상 기술적인 문제가 아닙니다. 해당 API가 동시에 두 개를 얻는 기능을 제공하지 않으면 별도로 얻은 다음 함께 병합할 수 있습니다.

최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!