json - How to access Oanda's API in Python -
i'm looking current rate oanda's api. how in python? have following credentials , have tried far has been bust. streaming rates not work cannot parse correctly. here appreciated.
curl -x "https://api-fxpractice.oanda.com/v1/instruments?accountid=12345&instruments=eur_usd"
under normal circumstances work, however, require "token" passed call , have no idea how implement that. here have in documentation:
curl -h "authorization: bearer 12345678900987654321-abc34135acde13f13530" https://api-fxtrade.oanda.com/v1/accounts
(not access token way, on site)
any great!
in addition here of streaming code have tried adapt:
import requests import json optparse import optionparser def connect_to_stream(): """ environment <domain> fxtrade stream-fxtrade.oanda.com fxtrade practice stream-fxpractice.oanda.com sandbox stream-sandbox.oanda.com """ # replace following variables personal ones domain = 'stream-fxpractice.oanda.com' access_token = 'xxxxxxxxx' account_id = 'xxxxxx' instruments = "eur_usd" try: s = requests.session() url = "https://" + domain + "/v1/prices?instruments=eur_usd" headers = {'authorization' : 'bearer ' + access_token, # 'x-accept-datetime-format' : 'unix' } params = {'instruments' : instruments, 'accountid' : account_id} req = requests.request('get', url, headers = headers, params = params) pre = req.prepare() resp = s.send(pre, stream = true, verify = false) return resp except exception e: s.close() print "caught exception when connecting stream\n" + str(e) print resp
for looking answer in future, found can access api using oanda's python wrapper..
Comments
Post a Comment