Skip to content

Instantly share code, notes, and snippets.

@coinscious-io
Last active August 2, 2019 18:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coinscious-io/5b58c0cacbf362f5342e310333396ced to your computer and use it in GitHub Desktop.
Save coinscious-io/5b58c0cacbf362f5342e310333396ced to your computer and use it in GitHub Desktop.
Subscribing to live stream order book data
import websocket
try:
import
thread
except ImportError:
import _thread as thread
import time
def on_message(ws, message):
print(message)
def on_error(ws, error):
print(error)
def on_close(ws):
print("closed")
def on_open(ws):
print("onopen")
def
run(*args):
ws.send("{\"subscribe\":\"trade\",\"msg\":{\"exchange\":\"binance\",\"pair\":\"btc_usdt\"}}")
while True:
time.sleep(1)
ws.close()
thread.start_new_thread(run,())
if __name__ == "__main__":
websocket.enableTrace(True)
ws = websocket.WebSocketApp("wss://livestream.coinscious.org/live",
header = {"Authorization:Bearer <token>"},
on_message = on_message,
on_error = on_error,
on_close = on_close)
ws.on_open = on_open
ws.run_forever(ping_interval=60)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment