0

i create a local orderbook using websockets on mexc

message = {"method": "SUBSCRIPTION",
               "params": [f"spot@public.increase.depth.v3.api@BTCUSDT"]}

    try:
        async with websockets.connect("wss://wbs.mexc.com/ws", ping_interval=None) as ws:
            await ws.send(json.dumps(message))
            i = 0
            while True:
                i += 1
                message = json.loads(await ws.recv())
                print(message)
                if i % 30 == 0:
                    output = json.dumps({"method": "PING"})
                    await ws.send(output)
                    i = 0
    except Exception as err:
        print(err)

the documentation says about ping frame. because i had an error websockets.exceptions.ConnectionClosedError: sent 1011 (unexpected error) keepalive ping timeout; no close frame received, i disabled network checking ping_interval=None, and in addition, to avoid being disabled by the server, i send this ping frame. how do i understand what causes this problem, and how to get rid of it?

i tried without disabling network checking, and without sending ping frame, the error still occurs sooner or later. my first version looks like this

async with websockets.connect("wss://wbs.mexc.com/ws",ping_interval=None) as ws:
            await ws.send(json.dumps(message))
            while True:
                message = json.loads(await ws.recv())
                print(message)

but it also causes this problem. i have no any idea about it

budick
  • 1
  • 2

0 Answers0