-
-
Save zph/3e0fa3e0a4644def5a65df066668fa9f to your computer and use it in GitHub Desktop.
Manually long-polling the Atlas ATS API (Bayeux protocol)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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