Open MoeQatoum opened 2 years ago
working with this library is becoming exhausting and frustrating, its not well maintained you have to go through the library and debug its issues, this is distracting and a wast of time, I recommend migrating to unicorn-binance-websocket-api , its well maintained and very easy to use. or use binance-ru and port it to your python code. which is easier than looking at and debugging 1000s of code lines! I will keep this issue open for others who might be willing to fix this issue ...
I can confirm this bug. Same problem with #1174 . Have found a quick fix there, but no promise since I don't use threaded socket.
hi @halfelf, thanks for your reply, your suggestion actually fixed the issue.
TO FIX THIS ISSUE:
at threaded_stream.py
modify self._loop
as below
class ThreadedApiManager(threading.Thread):
def __init__(
self,
api_key: Optional[str] = None,
api_secret: Optional[str] = None,
requests_params: Optional[Dict[str, str]] = None,
tld: str = "com",
testnet: bool = False,
):
"""Initialise the BinanceSocketManager"""
super().__init__()
#self._loop: asyncio.AbstractEventLoop = asyncio.new_event_loop()
self._loop: asyncio.AbstractEventLoop = asyncio.get_event_loop()
self._client: Optional[AsyncClient] = None
self._running: bool = True
self._socket_running: Dict[str, bool] = {}
self._client_params = {
"api_key": api_key,
"api_secret": api_secret,
"requests_params": requests_params,
"tld": tld,
"testnet": testnet,
}
tried @halfelf solution but when running two sockets got another problem
self.tdcm = ThreadedDepthCacheManager()
self.twsm= ThreadedWebsocketManager()
self.twsm.start()
self.tdcm.start()
RuntimeError: This event loop is already running
any work around?
I can confirm the fix from @MoeQatoum here worked for me.
there is compatibility issues with python 3.10 connection closes after a few seconds for some reason. also looking at debug logs Kline stream did not connect.
EDIT: after further investigation , I found out the program is stuck in an infinite loop in
start_listener
ln 42 atthreaded_stream.py
. the exception is catchingasyncio.TimeoutError
but doing nothing.this the function code:
It works perfectly with python 3.9, websokets 10.2, python-binance 1.0.15.
To Reproduce
Environment:
DEBUG LOG