Skip to content

Instantly share code, notes, and snippets.

@AdamSBarnes
Created December 6, 2019 04:44
Show Gist options
  • Save AdamSBarnes/6e6bbf5a0aa2b9f21eb6574bfc156c29 to your computer and use it in GitHub Desktop.
Save AdamSBarnes/6e6bbf5a0aa2b9f21eb6574bfc156c29 to your computer and use it in GitHub Desktop.
Oanda stream API
import requests
import json
config = {
'token' : '#',
'account' : '#'
}
headers = {
"Content-Type": "application/json",
"Authorization": "Bearer " + config['token']
}
url = 'https://stream-fxpractice.oanda.com/v3/accounts/{0}/pricing/stream?instruments=AUD_USD'.format(config['account'])
while True:
r = requests.get(url, headers=headers, stream=True)
for line in r.iter_lines():
if line:
decoded_line = line.decode('utf-8')
line_dict = json.loads(decoded_line)
if line_dict['type'] == 'PRICE':
print(line_dict)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment