Last active
December 5, 2016 15:57
-
-
Save wckd/a1132a95cc5066ed0487bd69bbc82f79 to your computer and use it in GitHub Desktop.
OSE/OAX websocket
This file contains 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
#!/usr/bin/python | |
import websocket | |
try: | |
import _thread as thread | |
except ImportError: | |
import thread | |
import json | |
import pprint | |
def on_message(ws, message): | |
message = json.loads(message) | |
msgtype = message.get('type') | |
#if 'status:update' in msgtype: | |
# data = message.get('data') | |
pp.pprint(message) | |
def on_error(ws, error): | |
print(error) | |
ws.close() | |
def on_close(ws): | |
print("Closed for business") | |
def on_open(ws): | |
print("Open for business") | |
OSE = "subscribe?type=ranking&cutoffAtZero=false&ranking=%2BLONG_NAME&columns=ITEM%2C+ITEM_SECTOR%2C+LONG_NAME%2C+CHANGE_PCT%2C+BID%2C+ASK%2C+LAST%2C+VOLUME&limit=9999&offset=0&filter=&source=feed.ose.quotes.EQUITIES&channel=1" | |
OAX = "subscribe?type=ranking&cutoffAtZero=false&ranking=%2BLONG_NAME&columns=ITEM%2C+ITEM_SECTOR%2C+LONG_NAME%2C+CHANGE_PCT%2C+BID%2C+ASK%2C+LAST%2C+VOLUME&limit=9999&offset=0&filter=&source=feed.oax.quotes.EQUITIES&channel=2" | |
ws.send(OSE) | |
ws.send(OAX) | |
if __name__ == "__main__": | |
DEBUG = False | |
pp = pprint.PrettyPrinter(indent=4) | |
websocket.enableTrace(DEBUG) | |
ws = websocket.WebSocketApp("wss://bors.e24.no/server/components", | |
on_message = on_message, | |
on_error = on_error, | |
on_close = on_close, | |
on_open = on_open ) | |
while True: | |
try: | |
ws.run_forever() | |
except: | |
ws.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment