Skip to content

Instantly share code, notes, and snippets.

@drpancake
Last active November 17, 2016 03:26
Show Gist options
  • Save drpancake/9605830 to your computer and use it in GitHub Desktop.
Save drpancake/9605830 to your computer and use it in GitHub Desktop.
Manually long-polling the Atlas ATS API (Bayeux protocol)
# Requires the 'requests' module: http://docs.python-requests.org/en/latest/
import json
import requests
URL = 'https://data.atlasats.com:4000/api'
def bayeux_call(data):
headers = {'content-type': 'application/json'}
res = requests.post(URL, data=json.dumps(data), headers=headers, verify=False) # no SSL cert check
return json.loads(res.text)
# Handshake
handshake_obj = bayeux_call({
"channel": "/meta/handshake",
"supportedConnectionTypes": ["long-polling"],
"version": "1.0"
})[0]
client_id = handshake_obj['clientId']
print 'Got client ID: %s' % client_id
# Subscribe
subscription_obj = bayeux_call({
"channel": "/meta/subscribe",
'subscription': '/trades',
'clientId': client_id
})[0]
print 'SUBSCRIPTION:'
print subscription_obj
# Poll
while 1:
print 'Polling...'
connect_obj = bayeux_call({
"channel": "/meta/connect",
'connectionType': 'long-polling',
'clientId': client_id
})
print 'Response:'
print connect_obj
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment