From afc45a8e16b78eede2293ec4613aaafebfa4441a Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Thu, 19 Jan 2023 10:35:39 -0500 Subject: [PATCH] `binance`: same thing, only unsub when connected --- piker/brokers/binance.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/piker/brokers/binance.py b/piker/brokers/binance.py index 5ea7860a..0c177db8 100644 --- a/piker/brokers/binance.py +++ b/piker/brokers/binance.py @@ -519,14 +519,15 @@ async def stream_quotes( subs.append("{sym}@bookTicker") # unsub from all pairs on teardown - await ws.send_msg({ - "method": "UNSUBSCRIBE", - "params": subs, - "id": uid, - }) + if ws.connected(): + await ws.send_msg({ + "method": "UNSUBSCRIBE", + "params": subs, + "id": uid, + }) - # XXX: do we need to ack the unsub? - # await ws.recv_msg() + # XXX: do we need to ack the unsub? + # await ws.recv_msg() async with open_autorecon_ws( 'wss://stream.binance.com/ws',