Skip to content

Instantly share code, notes, and snippets.

@icehongssii
Last active January 25, 2019 02:36
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 icehongssii/d702782a30d84a95180b77a5125999d5 to your computer and use it in GitHub Desktop.
Save icehongssii/d702782a30d84a95180b77a5125999d5 to your computer and use it in GitHub Desktop.
# 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