Skip to content

Instantly share code, notes, and snippets.

@nagadomi
Created April 26, 2018 12:51
Show Gist options
  • Save nagadomi/670408b58ef6b1caab80ee160eb9e73d to your computer and use it in GitHub Desktop.
Save nagadomi/670408b58ef6b1caab80ee160eb9e73d to your computer and use it in GitHub Desktop.
import websocket
import json
from pprint import pprint
def on_message(ws, message):
message = json.loads(message)
pprint(message)
def on_error(ws, error):
print(error)
def on_close(ws):
print("### closed ###")
def on_open(ws):
ws.send(json.dumps({"method": "subscribe", "params": {"channel": "lightning_executions_FX_BTC_JPY"}}))
ws.send(json.dumps({"method": "subscribe", "params": {"channel": "lightning_ticker_FX_BTC_JPY"}}))
if __name__ == "__main__":
#websocket.enableTrace(True)
ws = websocket.WebSocketApp("wss://ws.lightstream.bitflyer.com/json-rpc",
on_message = on_message,
on_error = on_error,
on_close = on_close)
ws.on_open = on_open
ws.run_forever()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment