python3 通过websockets发送wss请求的例子
作者:互联网
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)))
标签:websocket,wss,api,python3,msg,import,response,websockets 来源: https://blog.csdn.net/qq_23114283/article/details/121633346