LUCIT-Systems-and-Development / unicorn-binance-websocket-api

A Python SDK by LUCIT to use the Binance Websocket API`s (com+testnet, com-margin+testnet, com-isolated_margin+testnet, com-futures+testnet, com-coin_futures, us, tr, dex/chain+testnet) in a simple, fast, flexible, robust and fully-featured way.
https://unicorn-binance-websocket-api.docs.lucit.tech/
Other
677 stars 166 forks source link

websocket error #269

Closed reasondk closed 2 years ago

reasondk commented 2 years ago

Version of this library.

1.34.1

Solution to Issue cannot be found in the documentation or other Issues and also occurs in the latest version of this library.

Hardware?

Local server/workstation

Operating System?

macOS

Python version?

Python3.9

Installed packages

No response

Logging output

No response

Processing method?

stream_buffer

Used endpoint?

binance.com

Issue

Hi, when i have used websockt to get the live data and found some problems.

  1. Used a local server to connect wss via VPN, which can capable of simulating network interrupts. VPN connected, wss can be connected. In this progress, It can get the data successfully. A few moments later, If manually disconnect the VPN. The program has an exception。Log is here:

{"stream":"btcusdt@trade","data":{"e":"trade","E":1650359173412,"s":"BTCUSDT","t":1329338364,"p":"40734.63000000","q":"0.02427000","b":10231885572,"a":10231883927,"T":1650359173411,"m":false,"M":true}} {"stream":"btcusdt@trade","data":{"e":"trade","E":1650359173424,"s":"BTCUSDT","t":1329338365,"p":"40734.62000000","q":"0.00121000","b":10231884834,"a":10231885575,"T":1650359173423,"m":true,"M":true}} CRITICAL:root:BinanceWebSocketApiSocket.start_socket(35abfb0e-7c39-4906-8c76-9ffec5a3806a, ['trade', 'kline_1m'], ['btcusdt']) - Exception ConnectionClosed - error_msg: sent 1011 (unexpected error) keepalive ping timeout; no close frame received CRITICAL:root:BinanceWebSocketApiManager.stream_is_crashing(35abfb0e-7c39-4906-8c76-9ffec5a3806a) ERROR:root:BinanceWebSocketApiConnection.await._conn.aenter(35abfb0e-7c39-4906-8c76-9ffec5a3806a, ['trade', 'kline_1m'], ['btcusdt']) - ConnectionResetError - error_msg: [Errno 54] Connection reset by peer ERROR:root:BinanceWebSocketApiConnection.send(35abfb0e-7c39-4906-8c76-9ffec5a3806a, ['trade', 'kline_1m'], ['btcusdt']) - Exception ConnectionClosed - error_msg: sent 1011 (unexpected error) keepalive ping timeout; no close frame received CRITICAL:root:BinanceWebSocketApiManager.stream_is_crashing(35abfb0e-7c39-4906-8c76-9ffec5a3806a) ERROR:root:BinanceWebSocketApiConnection.aexit(*args, kwargs): AttributeError - 'Connect' object has no attribute 'protocol' ERROR:root:BinanceWebSocketApiConnection.await._conn.aenter(35abfb0e-7c39-4906-8c76-9ffec5a3806a, ['trade', 'kline_1m'], ['btcusdt']) - ConnectionResetError - error_msg: [Errno 54] Connection reset by peer ERROR:root:BinanceWebSocketApiConnection.send(35abfb0e-7c39-4906-8c76-9ffec5a3806a, ['trade', 'kline_1m'], ['btcusdt']) - Exception ConnectionClosed - error_msg: sent 1011 (unexpected error) keepalive ping timeout; no close frame received CRITICAL:root:BinanceWebSocketApiManager.stream_is_crashing(35abfb0e-7c39-4906-8c76-9ffec5a3806a) ERROR:root:BinanceWebSocketApiConnection.aexit(*args, *kwargs): AttributeError - 'Connect' object has no attribute 'protocol' ERROR:root:BinanceWebSocketApiConnection.await._conn.aenter(35abfb0e-7c39-4906-8c76-9ffec5a3806a, ['trade', 'kline_1m'], ['btcusdt']) - ConnectionResetError - error_msg: [Errno 54] Connection reset by peer ERROR:root:BinanceWebSocketApiConnection.send(35abfb0e-7c39-4906-8c76-9ffec5a3806a, ['trade', 'kline_1m'], ['btcusdt']) - Exception ConnectionClosed - error_msg: sent 1011 (unexpected error) keepalive ping timeout; no close frame received CRITICAL:root:BinanceWebSocketApiManager.stream_is_crashing(35abfb0e-7c39-4906-8c76-9ffec5a3806a) ERROR:root:BinanceWebSocketApiConnection.aexit(args, kwargs): AttributeError - 'Connect' object has no attribute 'protocol' ERROR:root:BinanceWebSocketApiConnection.await._conn.aenter(35abfb0e-7c39-4906-8c76-9ffec5a3806a, ['trade', 'kline_1m'], ['btcusdt']) - ConnectionResetError - error_msg: [Errno 54] Connection reset by peer ERROR:root:BinanceWebSocketApiConnection.send(35abfb0e-7c39-4906-8c76-9ffec5a3806a, ['trade', 'kline_1m'], ['btcusdt']) - Exception ConnectionClosed - error_msg: sent 1011 (unexpected error) keepalive ping timeout; no close frame received CRITICAL:root:BinanceWebSocketApiManager.stream_is_crashing(35abfb0e-7c39-4906-8c76-9ffec5a3806a) ERROR:root:BinanceWebSocketApiConnection.aexit(*args, *kwargs): AttributeError - 'Connect' object has no attribute 'protocol' ERROR:root:BinanceWebSocketApiConnection.await._conn.aenter(35abfb0e-7c39-4906-8c76-9ffec5a3806a, ['trade', 'kline_1m'], ['btcusdt']) - ConnectionResetError - error_msg: [Errno 54] Connection reset by peer ERROR:root:BinanceWebSocketApiConnection.send(35abfb0e-7c39-4906-8c76-9ffec5a3806a, ['trade', 'kline_1m'], ['btcusdt']) - Exception ConnectionClosed - error_msg: sent 1011 (unexpected error) keepalive ping timeout; no close frame received CRITICAL:root:BinanceWebSocketApiManager.stream_is_crashing(35abfb0e-7c39-4906-8c76-9ffec5a3806a) ERROR:root:BinanceWebSocketApiConnection.aexit(args, **kwargs): AttributeError - 'Connect' object has no attribute 'protocol'

  1. If reconnected the VPN manually. Another error message appears。

Exception in thread Thread-30: Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/websockets/legacy/client.py", line 653, in __await_impl__ transport, protocol = await self._create_connection() File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/base_events.py", line 1041, in create_connection sock = await self._connect_sock( File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/base_events.py", line 955, in _connect_sock await self.sock_connect(sock, address) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/selector_events.py", line 502, in sock_connect return await fut asyncio.exceptions.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/tasks.py", line 492, in wait_for fut.result() asyncio.exceptions.CancelledError

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/threading.py", line 973, in _bootstrap_inner self.run() File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/threading.py", line 910, in run self._target(*self._args, **self._kwargs) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/unicorn_binance_websocket_api/unicorn_binance_websocket_api_manager.py", line 473, in _create_stream_thread loop.run_until_complete(socket.start_socket()) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete return future.result() File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/unicorn_binance_websocket_api/unicorn_binance_websocket_api_socket.py", line 63, in start_socket async with BinanceWebSocketApiConnection(self.manager, File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/unicorn_binance_websocket_api/unicorn_binance_websocket_api_connection.py", line 144, in aenter self.manager.websocket_list[self.stream_id] = await self._conn.aenter() File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/websockets/legacy/client.py", line 632, in aenter return await self File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/websockets/legacy/client.py", line 649, in await_impl_timeout return await asyncio.wait_for(self.await_impl(), self.open_timeout) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/tasks.py", line 494, in wait_for raise exceptions.TimeoutError() from exc asyncio.exceptions.TimeoutError Exception in thread Thread-32: Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/websockets/legacy/client.py", line 653, in await_impl transport, protocol = await self._create_connection() File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/base_events.py", line 1041, in create_connection sock = await self._connect_sock( File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/base_events.py", line 955, in _connect_sock await self.sock_connect(sock, address) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/selector_events.py", line 502, in sock_connect return await fut asyncio.exceptions.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/tasks.py", line 492, in wait_for fut.result() asyncio.exceptions.CancelledError

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/threading.py", line 973, in _bootstrap_inner self.run() File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/threading.py", line 910, in run self._target(*self._args, **self._kwargs) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/unicorn_binance_websocket_api/unicorn_binance_websocket_api_manager.py", line 473, in _create_stream_thread loop.run_until_complete(socket.start_socket()) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete return future.result() File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/unicorn_binance_websocket_api/unicorn_binance_websocket_api_socket.py", line 63, in start_socket async with BinanceWebSocketApiConnection(self.manager, File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/unicorn_binance_websocket_api/unicorn_binance_websocket_api_connection.py", line 144, in aenter self.manager.websocket_list[self.stream_id] = await self._conn.aenter() File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/websockets/legacy/client.py", line 632, in aenter return await self File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/websockets/legacy/client.py", line 649, in await_impl_timeout return await asyncio.wait_for(self.__await_impl__(), self.open_timeout) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/tasks.py", line 494, in wait_for raise exceptions.TimeoutError() from exc asyncio.exceptions.TimeoutError

oliver-zehentleitner commented 2 years ago

This issue is already reported and should be fixed in the latest version.

Please reopen if the issue remains!