I've connected to the Deribit websocket for option data, but the following code snippet only gets one valid response of data, and then stops updating, but says it's still running.
The website recommends using the asyncio module, but was able to pull data using below code snippet. I would like to be able to stream data continuously.
import json
import websocket
def on_open(ws):
msg = {
"jsonrpc" : "2.0",
"id" : 8106,
"method" : "public/ticker",
"params" : {
"instrument_name" : "BTC-28JAN22-45000-C",
"depth" : 1
}
}
ws.send(json.dumps(msg))
print('opened')
def on_error(ws, msg):
print('error')
print(msg)
def on_message(ws, msg):
d = json.loads(msg)
print(d)
def on_close(ws):
print("closed connection")
socket='wss://www.deribit.com/ws/api/v2/public/get_order_book'
ws = websocket.WebSocketApp(
socket,
on_error=on_error,
on_open=on_open,
on_message=on_message,
on_close=on_close)
ws.run_forever()