import asyncio
import websockets
import json
msg = \
{
"method" : "SUBSCRIBE",
"id" : 9344,
"params" : "public/get_book_summary_by_currency",
"params" : {
"currency" : "BTC",
"kind" : "future"
}
}
async def call_api(msg):
async with websockets.connect('wss://test.deribit.com/ws/api/v2') as websocket:
await websocket.send(msg)
while websocket.open:
response = await websocket.recv()
# do something with the response...
print(response)
asyncio.get_event_loop().run_until_complete(call_api(json.dumps(msg)))