I am testing websocket by binance-connector-python.
this app connected websocket and got aggtrade streaming.
but cannot restart the websocket.
import time
import logging
from binance.lib.utils import config_logging
from binance.websocket.spot.websocket_client import SpotWebsocketClient as Client
config_logging(logging, logging.DEBUG)
def message_handler(message):
print(message)
my_client = Client()
my_client.start()
my_client.agg_trade(
symbol="btcusdt",
id=1,
callback=message_handler,
)
time.sleep(2)
logging.debug("closing ws connection")
my_client.stop()
time.sleep(3)
my_client.start() ## ←error
Error Message is here.
File "/usr/local/Cellar/python@3.9/3.9.9/Frameworks/Python.framework/Versions/3.9/lib/python3.9/threading.py", line 887, in start
raise RuntimeError("threads can only be started once")
RuntimeError: threads can only be started once
In the future, we want to add an “unsubscribe” feature to maintain the connection instead of “.stop” so that we can subscribe again to start receiving the data again, although there’s no ETA for this yet.
Unfortunately you can’t “restart” websocket once you’ve close it with “my_client.stop()” within same process, so if you want to use the websocket again,
OK. I I cannnot restart by “binance-connector-python”, but I have re-run by “websocket.WebSocketApp”
so that we can subscribe again to start receiving the data again,
OK. we wait your update.