A simple websocket test client for python

A friend sent it, I haven't been able to find it on the Internet before, remember it first

 

#!/usr/bin/env python

import asyncio
import websockets
import json

async def test_ws_quote():
    async with websockets.connect('ws://192.168.0.205:8888/quote/quote') as websocket:
        req = {"protocol":"history_req",'code':'XAGODS','type':'MINUTE','start_pos':'0','pos_num':'10'}
        await websocket.send(json.dumps(req))
   
        while True:
            quote = await websocket.recv()
            print(quote)

asyncio.get_event_loop().run_until_complete(test_ws_quote())

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325119650&siteId=291194637