Last active
January 25, 2019 02:36
-
-
Save icehongssii/d702782a30d84a95180b77a5125999d5 to your computer and use it in GitHub Desktop.
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
# PRECISION = "s" | |
# MEASUREMENT = "candlesticks" | |
# EXCHANGE = "bitmex" | |
# | |
# SUBSCRIPTION_DICT = {"op":"subscribe", "args":'tradeBin1m:{}'} | |
# PAIR_URL = "https://www.bitmex.com/api/v1/instrument/active" | |
# WEBSOCK_URL = "wss://www.bitmex.com/realtime?subscribe=tradeBin1m:XBTUSD" | |
# TYPE = "SPOT" | |
import websocket | |
def on_message(ws, message): | |
print(message) | |
def on_error(ws, error): | |
print(error) | |
ws.on_close(ws) | |
def on_close(ws): | |
print("### closed ###") | |
ws.close() | |
def on_open(ws): | |
print("### open ###") | |
def run(endpoint): | |
websocket.enableTrace(True) | |
ws = websocket.WebSocketApp(endpoint, | |
on_open = on_open, | |
on_message = on_message, | |
on_error = on_error, | |
on_close = on_close) | |
ws.run_forever() | |
if __name__ == "__main__": | |
command = 'subscribe=tradeBin1m:XBTUSD' | |
endpoint = 'wss://www.bitmex.com/realtime?'+command | |
run(endpoint) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment