Last active
August 2, 2019 18:29
-
-
Save coinscious-io/c1a1dadca71d013adfc787106fb68ace to your computer and use it in GitHub Desktop.
Subscribing to live stream trade history data
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
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