ccxt: [binance] future websocket error: connection closed by remote server
- OS: centos7
- Programming Language version: NodeJS
- CCXT version: ccxt.pro@0.3.55
We have been trading binance future with ccxt.pro and it has been working fine most of the times. However, every once in a while we receive the following errors:
connection closed by remote server, closing code 1006Connection to wss://fstream.binance.com/ws timed out due to a ping-pong keepalive missing on time.
We suspect the code that cause the problem is the watchOrderBook method, but not 100% sure. Here is the full log for the first error.
NetworkError: connection closed by remote server, closing code 1006
at WsClient.onClose (/myProject/node_modules/ccxt.pro/js/base/Client.js:225:25)
at WebSocket.onClose (/myProject/node_modules/ccxt.pro/node_modules/ws/lib/event-target.js:129:16)
at WebSocket.emit (events.js:311:20)
at WebSocket.EventEmitter.emit (domain.js:482:12)
at WebSocket.emitClose (/myProject/node_modules/ccxt.pro/node_modules/ws/lib/websocket.js:191:10)
at TLSSocket.socketOnClose (/myProject/node_modules/ccxt.pro/node_modules/ws/lib/websocket.js:858:15)
at TLSSocket.emit (events.js:323:22)
at TLSSocket.EventEmitter.emit (domain.js:482:12)
at net.js:668:12
at TCP.done (_tls_wrap.js:556:7) {
constructor: [Function: NetworkError],
name: 'NetworkError'
}
About this issue
- Original URL
- State: open
- Created 4 years ago
- Comments: 24 (5 by maintainers)
The latest ccxt is still experiencing the same issue , although the bug fix suggested by @FakePsyho is already added to
cache.py. Is there any updates on this issue? Thanks!@FakePsyho thanks for finding this bug, I’ve used your code to fix it just now
@kroitor I figured that it’s easier for me to find the bug than to file a proper report. Since I can’t reference the code (different repo) I’ll explain the problem.
In cache.py
ArrayCacheBySymbolById.append()has a bug.by_idpoints toself.hashmap[item['symbol']]. When the data structure is full and you’re removing an element, you’re trying to remove it from the ‘by_id’, but this will fail if removed element uses different symbol than the one just added.This:
Could be this:
I’m surprised that this bug exist, as I’d imagine this is exchange-agnostic and this bug probably crashes every exchange after placing
ordersLimitorders when using watch* method that populates self.ordersNoting that we too have had the second error on Binance spot occasionally.
Connection to wss://stream.binance.com:9443/ws/... timed out due to a ping-pong keepalive missing on time.Perhaps the ping-pong is not implemented according to what Binance wants, or there is a problem on the server side. Not sure if it’s related or will help, but this error also tends to pop up around when the ping-pong error does:Exception in callback FastClient.receive_loop.<locals>.handler() at ...\Python\Python38\site-packages\ccxtpro\base\fast_client.py:19 handle: <Handle FastClient.receive_loop.<locals>.handler() at ...\Python\Python38\site-packages\ccxtpro\base\fast_client.py:19> Traceback (most recent call last): File "C:\Program Files (x86)\Python38-32\lib\asyncio\events.py", line 81, in _run self._context.run(self._callback, *self._args) File "...\Python\Python38\site-packages\ccxtpro\base\fast_client.py", line 23, in handler self.handle_message(message) File "...\Python\Python38\site-packages\ccxtpro\base\aiohttp_client.py", line 32, in handle_message self.handle_text_or_binary_message(message.data) File "...\Python\Python38\site-packages\ccxtpro\base\aiohttp_client.py", line 27, in handle_text_or_binary_message self.on_message_callback(self, decoded) File "...\Python\Python38\site-packages\ccxtpro\binance.py", line 739, in handle_message return method(client, message) File "...\Python\Python38\site-packages\ccxtpro\binance.py", line 718, in handle_order orders.append(parsed) File "...\Python\Python38\site-packages\ccxtpro\base\cache.py", line 75, in append del by_id[delete_reference['id']] KeyError: '2026130'Im still experience this issue even though i use exchange.close() anyone solved this?