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

multi userData streams (20) stop reading data after 1-2 days uptime #342

Closed lr2bmail closed 4 months ago

lr2bmail commented 1 year ago

Version of this library.

1.47.1

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

Hardware?

VPS or other cloud hosting

Operating System?

Linux

Python version?

Python3.8

Installed packages

No response

Logging output

2023-05-19 17:17:20,624 [DEBUG   ] 2034979 139969535952640 manager: BinanceWebSocketApiManager.is_stop_as_crash_request(09e890e5cb09-27d4-8fa0-0859-8dfaf699)
2023-05-19 17:17:20,624 [DEBUG   ] 2034979 139969535952640 manager: BinanceWebSocketApiManager.set_heartbeat(09e890e5cb09-27d4-8fa0-0859-8dfaf699)
2023-05-19 17:17:20,625 [DEBUG   ] 2034979 139969535952640 manager: BinanceWebSocketApiManager.is_stop_request(09e890e5cb09-27d4-8fa0-0859-8dfaf699)
2023-05-19 17:17:20,626 [DEBUG   ] 2034979 139969812911872 sockets: BinanceWebSocketApiSocket.start_socket(ed0937684636-57c7-f2bc-c433-91a37d4a, ['arr'], ['!userData'] - Received inner asyncio.TimeoutError (This is no ERROR, its exactly what we want!)
2023-05-19 17:17:20,626 [DEBUG   ] 2034979 139969812911872 manager: BinanceWebSocketApiManager.is_stop_request(ed0937684636-57c7-f2bc-c433-91a37d4a)
2023-05-19 17:17:20,626 [DEBUG   ] 2034979 139969812911872 manager: BinanceWebSocketApiManager.is_stop_as_crash_request(ed0937684636-57c7-f2bc-c433-91a37d4a)
2023-05-19 17:17:20,627 [DEBUG   ] 2034979 139969812911872 manager: BinanceWebSocketApiManager.set_heartbeat(ed0937684636-57c7-f2bc-c433-91a37d4a)
2023-05-19 17:17:20,627 [DEBUG   ] 2034979 139969812911872 manager: BinanceWebSocketApiManager.is_stop_request(ed0937684636-57c7-f2bc-c433-91a37d4a)
2023-05-19 17:17:20,744 [DEBUG   ] 2034979 139969888446208 sockets: BinanceWebSocketApiSocket.start_socket(f48e636bc084-3329-8d92-6eb3-64a2a62d, ['arr'], ['!userData'] - Received inner asyncio.TimeoutError (This is no ERROR, its exactly what we want!)
2023-05-19 17:17:20,745 [DEBUG   ] 2034979 139969661843200 sockets: BinanceWebSocketApiSocket.start_socket(44488f5e5540-ca66-33e9-629e-17844b33, ['arr'], ['!userData'] - Received inner asyncio.TimeoutError (This is no ERROR, its exactly what we want!)
2023-05-19 17:17:20,745 [DEBUG   ] 2034979 139969888446208 manager: BinanceWebSocketApiManager.is_stop_request(f48e636bc084-3329-8d92-6eb3-64a2a62d)
2023-05-19 17:17:20,745 [DEBUG   ] 2034979 139969661843200 manager: BinanceWebSocketApiManager.is_stop_request(44488f5e5540-ca66-33e9-629e-17844b33)
2023-05-19 17:17:20,746 [DEBUG   ] 2034979 139969888446208 manager: BinanceWebSocketApiManager.is_stop_as_crash_request(f48e636bc084-3329-8d92-6eb3-64a2a62d)
2023-05-19 17:17:20,747 [DEBUG   ] 2034979 139969888446208 manager: BinanceWebSocketApiManager.set_heartbeat(f48e636bc084-3329-8d92-6eb3-64a2a62d)
2023-05-19 17:17:20,747 [DEBUG   ] 2034979 139969888446208 manager: BinanceWebSocketApiManager.is_stop_request(f48e636bc084-3329-8d92-6eb3-64a2a62d)
2023-05-19 17:17:20,746 [DEBUG   ] 2034979 139969661843200 manager: BinanceWebSocketApiManager.is_stop_as_crash_request(44488f5e5540-ca66-33e9-629e-17844b33)
2023-05-19 17:17:20,748 [DEBUG   ] 2034979 139969661843200 manager: BinanceWebSocketApiManager.set_heartbeat(44488f5e5540-ca66-33e9-629e-17844b33)
2023-05-19 17:17:20,748 [DEBUG   ] 2034979 139969661843200 manager: BinanceWebSocketApiManager.is_stop_request(44488f5e5540-ca66-33e9-629e-17844b33)
2023-05-19 17:17:20,775 [DEBUG   ] 2034979 139969687021312 sockets: BinanceWebSocketApiSocket.start_socket(410d2c901ae4-df12-e2dd-afe7-f537c711, ['arr'], ['!userData'] - Received inner asyncio.TimeoutError (This is no ERROR, its exactly what we want!)
2023-05-19 17:17:20,776 [DEBUG   ] 2034979 139969687021312 manager: BinanceWebSocketApiManager.is_stop_request(410d2c901ae4-df12-e2dd-afe7-f537c711)
2023-05-19 17:17:20,777 [DEBUG   ] 2034979 139969863268096 sockets: BinanceWebSocketApiSocket.start_socket(26b37e0bf2da-3481-b699-d2e1-526d6862, ['arr'], ['!userData'] - Received inner asyncio.TimeoutError (This is no ERROR, its exactly what we want!)
2023-05-19 17:17:20,777 [DEBUG   ] 2034979 139969687021312 manager: BinanceWebSocketApiManager.is_stop_as_crash_request(410d2c901ae4-df12-e2dd-afe7-f537c711)
2023-05-19 17:17:20,778 [DEBUG   ] 2034979 139969863268096 manager: BinanceWebSocketApiManager.is_stop_request(26b37e0bf2da-3481-b699-d2e1-526d6862)
2023-05-19 17:17:20,778 [DEBUG   ] 2034979 139969687021312 manager: BinanceWebSocketApiManager.set_heartbeat(410d2c901ae4-df12-e2dd-afe7-f537c711)
2023-05-19 17:17:20,778 [DEBUG   ] 2034979 139969863268096 manager: BinanceWebSocketApiManager.is_stop_as_crash_request(26b37e0bf2da-3481-b699-d2e1-526d6862)
2023-05-19 17:17:20,779 [DEBUG   ] 2034979 139969687021312 manager: BinanceWebSocketApiManager.is_stop_request(410d2c901ae4-df12-e2dd-afe7-f537c711)
2023-05-19 17:17:20,779 [DEBUG   ] 2034979 139969863268096 manager: BinanceWebSocketApiManager.set_heartbeat(26b37e0bf2da-3481-b699-d2e1-526d6862)
2023-05-19 17:17:20,780 [DEBUG   ] 2034979 139969863268096 manager: BinanceWebSocketApiManager.is_stop_request(26b37e0bf2da-3481-b699-d2e1-526d6862)
2023-05-19 17:17:20,834 [DEBUG   ] 2034979 139970014336768 sockets: BinanceWebSocketApiSocket.start_socket(213080244ea6-1d25-7a1b-c27f-ee370986, ['arr'], ['!userData'] - Received inner asyncio.TimeoutError (This is no ERROR, its exactly what we want!)

Processing method?

stream_buffer

Used endpoint?

concerns all

Issue

In my app, I connect +20 streams (userData) and initially everything works smoothly. However, after the app has been running for a 1-2 days, I notice that the streams gradually stop receiving data, even though they still appear to be active. To test the streams, I have been opening orders in the accounts every 2 hours vi python-binance .

this what i see after 1d:18h (0 recon)

====================== unicorn-binance-websocket-api_1.46.1-python_3.8.10 =====================
 exchange: binance.com
 uptime: 1d:18h:10m:13s since 2023-05-17, 21:22:20 UTC
 streams: 21
 active_streams: 21
 subscriptions: 21
 stream_buffer_stored_items: 787
 stream_buffer_byte_size: 304204 (297.07 kB)
 current_receiving_speed: 0 B/s
 average_receiving_speed: 4.565218294075404 B/s (per day 0.0 gB)
 highest_receiving_speed: 18.37 kB/s (reached at 2023-05-17, 22:15:15 UTC)
 total_receives: 1793
 total_received_bytes: 693060 (676.82 kB)
 total_transmitted_payloads: 0
 stream_buffer_maxlen: None
 binance_api_status: used_weight=40, status_code=200 (last update 2023-05-19, 15:28:28 UTC)
 process_ressource_usage: cpu=21.7%, memory=82.28 mB, threads=86
 ---------------------------------------------------------------------------------------------
               stream_id              |   stream_label  |  last  |  average  |  peak  | recon
 ---------------------------------------------------------------------------------------------
 2cc6c5e20210-6180-d842-fd43-97109878 | d99e1fcc03      |      0 |       0.0 |      2 |      0
 f5e8ddbf905f-a931-437c-217f-6ec7dd8b | d1a0151a4d      |      0 |       0.0 |      0 |      0
 213080244ea6-1d25-7a1b-c27f-ee370986 | e6a887562c      |      0 |       0.0 |      2 |      0
 83246ce31aff-f17b-fb04-f15e-826717ec | 9fb39f34e5      |      0 |       0.0 |      6 |      0
 b79094ed4e39-e264-9bd6-1f99-f35f7a3f | ea56ff452c      |      0 |       0.0 |      7 |      0
 f48e636bc084-3329-8d92-6eb3-64a2a62d | 1f2f0ae09b      |      0 |       0.0 |      5 |      0
 26b37e0bf2da-3481-b699-d2e1-526d6862 | 5f8e16bfb9      |      0 |       0.0 |     18 |      0
 036b1d7f78aa-d010-f830-6e5f-4aeea0de | ef6db165a8      |      0 |       0.0 |      5 |      0
 ed0937684636-57c7-f2bc-c433-91a37d4a | 38c7cee5dd      |      0 |       0.0 |      5 |      0
 b4611fdeae31-e5b5-cf74-8857-a9d24da1 | f1b9fbce3b      |      0 |       0.0 |      6 |      0
 2ae9abef2cf6-c6d8-5c09-b143-5df261ff | 6d88d712cc      |      0 |       0.0 |      3 |      0
 f4ecc56c8518-6da2-5c3d-a0e3-85e3ce86 | 1610a71d02      |      0 |       0.0 |      4 |      0
 410d2c901ae4-df12-e2dd-afe7-f537c711 | 050df55d0f      |      0 |       0.0 |      5 |      0
 44488f5e5540-ca66-33e9-629e-17844b33 | 74712ac118      |      0 |       0.0 |      2 |      0
 f5d82b02193d-a3c4-c1bb-ccd7-593ede4e | eed7ce9e33      |      0 |       0.0 |      5 |      0
 453c46847d91-50bc-3323-2209-13f2dea4 | e55614abdc      |      0 |       0.0 |      5 |      0
 964dd80f6ffa-9b34-b51a-0975-3cb3c06e | 3c91778dfb      |      0 |       0.0 |      5 |      0
 4d55979e88b1-9c9e-1b43-7b83-aa789412 | 798f59082d      |      0 |       0.0 |      5 |      0
 09e890e5cb09-27d4-8fa0-0859-8dfaf699 | c06a301e4f      |      0 |       0.0 |      4 |      0
 9753509b1bd2-c942-b618-bdca-3545893d | 9d1fc4bed2      |      0 |       0.0 |      5 |      0
 cb52442c9555-20d4-71d9-829c-c6e5318d | ff1cd1da41      |      0 |       0.0 |      3 |      0
 ---------------------------------------------------------------------------------------------
 all_streams                                            |      0 |       0.0 |     46 |      0
===============================================================================================

here is data from one stream after it stop showing updates


{'exchange': 'binance.com', 'stream_id': '2cc6c5e20210-6180-d842-fd43-97109878',
 'recent_socket_id': UUID('bbd0443f-1b62-4440-ae55-764026fb8eaf'), 'channels': ['arr'], 'markets': ['!userData'],
 'stream_label': 'd99e1fcc03', 'stream_buffer_name': '2cc6c5e20210-6180-d842-fd43-97109878',
 'stream_buffer_maxlen': None, 'symbols': False, 'output': 'raw_data', 'subscriptions': 1, 'payload': [], 'api': False,
 'api_key': 'xxxxxxxxxxx',
 'api_secret': 'xxxxxx', 'dex_user_address': False,
 'ping_interval': 5, 'ping_timeout': 10, 'close_timeout': 1, 'status': 'running', 'start_time': 1684358540.5338664,
 'processed_receives_total': 14,
 'receives_statistic_last_second': {'most_receives_per_second': 2, 'entries': {1684436200: 2, 1684446656: 2}},
 'seconds_to_last_heartbeat': None, 'last_heartbeat': 1684510534.311881, 'stop_request': None, 'crash_request': None,
 'kill_request': None, 'seconds_since_has_stopped': None, 'has_stopped': False, 'reconnects': 0,
 'last_stream_signal': 'CONNECT', 'logged_reconnects': [], 'processed_transmitted_total': 0,
 'last_static_ping_listen_key': 1684510003.442101,
 'listen_key': 'xxxxxx', 'listen_key_cache_time': 600,
 'last_received_data_record': '{"e":"outboundAccountPosition","E":1684446656258,"u":1684446656257,"B":[{"a":"BNB","f":"0.04265220","l":"20.43000000"}]}',
 'processed_receives_statistic': {},
 'transfer_rate_per_second': {'bytes': {1684436200: 302, 1684446656: 302}, 'speed': 302},
 'websocket_uri': 'wss://stream.binance.com:9443/ws/xxxxxx'}

here is data from the same stream after it stop showing updates (after 5 min )

{'exchange': 'binance.com', 'stream_id': '2cc6c5e20210-6180-d842-fd43-97109878',
 'recent_socket_id': UUID('bbd0443f-1b62-4440-ae55-764026fb8eaf'), 'channels': ['arr'], 'markets': ['!userData'],
 'stream_label': 'd99e1fcc03', 'stream_buffer_name': '2cc6c5e20210-6180-d842-fd43-97109878',
 'stream_buffer_maxlen': None, 'symbols': False, 'output': 'raw_data', 'subscriptions': 1, 'payload': [], 'api': False,
 'api_key': 'xxxxxx',
 'api_secret': 'xxxxxx', 'dex_user_address': False,
 'ping_interval': 5, 'ping_timeout': 10, 'close_timeout': 1, 'status': 'running', 'start_time': 1684358540.5338664,
 'processed_receives_total': 14,
 'receives_statistic_last_second': {'most_receives_per_second': 2, 'entries': {1684436200: 2, 1684446656: 2}},
 'seconds_to_last_heartbeat': None, 'last_heartbeat': 1684510895.3435338, 'stop_request': None, 'crash_request': None,
 'kill_request': None, 'seconds_since_has_stopped': None, 'has_stopped': False, 'reconnects': 0,
 'last_stream_signal': 'CONNECT', 'logged_reconnects': [], 'processed_transmitted_total': 0,
 'last_static_ping_listen_key': 1684510604.6786826,
 'listen_key': 'xxxxxx', 'listen_key_cache_time': 600,
 'last_received_data_record': '{"e":"outboundAccountPosition","E":1684446656258,"u":1684446656257,"B":[{"a":"BNB","f":"0.04265220","l":"20.43000000"}]}',
 'processed_receives_statistic': {},
 'transfer_rate_per_second': {'bytes': {1684436200: 302, 1684446656: 302}, 'speed': 302},
 'websocket_uri': 'wss://stream.binance.com:9443/ws/xxxxxx'}

I don't think Binance is blocking the IP since the app works fine when I restart it every 20 hours. The CPU usage is around 20-30%. I'm unsure if this is a bug or if I'm doing something incorrectly.

and here app 18 min after restart it

====================== unicorn-binance-websocket-api_1.46.1-python_3.8.10 =====================
 exchange: binance.com
 uptime: 15m:54s since 2023-05-19, 15:43:31 UTC
 streams: 21
 active_streams: 21
 subscriptions: 21
 current_receiving_speed: 0 B/s
 average_receiving_speed: 0.7983083089588786 B/s (per day 0.0 gB)
 highest_receiving_speed: 762 B/s (reached at 2023-05-19, 15:43:54 UTC)
 total_receives: 2
 total_received_bytes: 762 (762 B)
 total_transmitted_payloads: 0
 stream_buffer_maxlen: None
 binance_api_status: used_weight=36, status_code=200 (last update 2023-05-19, 15:54:19 UTC)
 process_ressource_usage: cpu=15.8%, memory=77.25 mB, threads=77

and thank you very much for the excellent library

lr2bmail commented 1 year ago

update Over the past 2-3 days, I have been running 21 scripts simultaneously, each handling one userdata stream. Everything has been functioning properly in this setup and it reconnect 2 time in 58 hours .

it we be great to have 21 streams in one script and will save a lot of ram 21 stream in one script need 80-100 mb ram (don't reconnect ) 21 scripts 700mb-800mb (work great )

====================== unicorn-binance-websocket-api_1.46.1-python_3.8.10 =====================
 exchange: binance.com-testnet
 uptime: 2d:9h:15m:0s since 2023-05-23, 12:49:59 UTC
 streams: 1
 active_streams: 1
 subscriptions: 1
 current_receiving_speed: 0 B/s
 average_receiving_speed: 0.041964920958257705 B/s (per day 0.0 gB)
 highest_receiving_speed: 1.26 kB/s (reached at 2023-05-25, 19:20:08 UTC)
 total_receives: 22
 total_received_bytes: 8649 (8.45 kB)
 total_transmitted_payloads: 0
 stream_buffer_maxlen: None
 binance_api_status: used_weight=6, status_code=200 (last update 2023-05-25, 21:55:58 UTC)
 process_ressource_usage: cpu=11.6%, memory=23.29 mB, threads=6
 ---------------------------------------------------------------------------------------------
               stream_id              |   stream_label  |  last  |  average  |  peak  | recon
 ---------------------------------------------------------------------------------------------
 8955fc7c0c6a-542b-1f7c-f865-3c22451c | ffba13f2f8      |      0 |       0.0 |      3 |      2
 ---------------------------------------------------------------------------------------------
 all_streams                                            |      0 |       0.0 |      3 |      2
lr2bmail commented 1 year ago

here two scripts that showing "status" = running but the first one is dead for 2 days last_heartbeat is updated but last_static_ping_listen_key was not in the dead one should the stream re-connect if last_static_ping_listen_key is 2 days ago and don't show running ?

 {"exchange": "binance.com", "stream_id": "7d8064b3abfe-03ef-9f93-2347-e4b2fc2a",
     "recent_socket_id": "53f141bf-7423-4c7c-be87-b58752e870a4", "channels": ["arr"], "markets": ["!userData"],
     "stream_label": "dfbc3b5247", "stream_buffer_name": False, "stream_buffer_maxlen": None, "symbols": False,
     "output": "raw_data", "subscriptions": 1, "payload": [], "api": False,
     "api_key": "*******************",
     "api_secret": "*******************", "dex_user_address": False,
     "ping_interval": 5, "ping_timeout": 10, "close_timeout": 1, "status": "running", "start_time": 1687867153.2648451,
     "processed_receives_total": 16, "receives_statistic_last_second": {"most_receives_per_second": 2,
                                                                        "entries": {"1687872204": 2, "1687872205": 2,
                                                                                    "1687872644": 2}},
     "seconds_to_last_heartbeat": 0.5373742580413818, "last_heartbeat": 1688079419.1499472, "stop_request": None,
     "crash_request": None, "kill_request": None, "seconds_since_has_stopped": None, "has_stopped": False,
     "reconnects": 0, "last_stream_signal": "CONNECT", "logged_reconnects": [], "processed_transmitted_total": 0,
     "last_static_ping_listen_key": 1687947696.3234684,
     "listen_key": "*******************", "listen_key_cache_time": 600,
     "last_received_data_record": "{\"e\":\"outboundAccountPosition\",\"E\":1687872644175,\"u\":1687872644172,\"B\":[{\"a\":\"BNB\",\"f\":\"0.00038563\",\"l\":\"0.00000000\"},{\"a\":\"USDT\",\"f\":\"99.96600000\",\"l\":\"0.00000000\"}]}",
     "processed_receives_statistic": {"stream_receives_per_second": 7.57090194473728e-05,
                                      "stream_receives_per_minute": 0.004542541166842369,
                                      "stream_receives_per_hour": 0.2725524700105421,
                                      "stream_receives_per_day": 6.54125928025301, "stream_receives_per_month": 0,
                                      "stream_receives_per_year": 0, "uptime": 211335.45404219627},
     "transfer_rate_per_second": {"bytes": {"1687872204": 772, "1687872205": 753, "1687872644": 779}, "speed": 0},
     "websocket_uri": "wss://stream.binance.com:9443/ws/*********************"}

{"exchange": "binance.com", "stream_id": "4817e64c9cd6-4312-b86d-64be-7e9479ad",
     "recent_socket_id": "88137f03-77a2-41d2-9d8a-4ac74e1e5849", "channels": ["arr"], "markets": ["!userData"],
     "stream_label": "a7fc361a81", "stream_buffer_name": False, "stream_buffer_maxlen": None, "symbols": False,
     "output": "raw_data", "subscriptions": 1, "payload": [], "api": False,
     "api_key": "*******************",
     "api_secret": "*******************", "dex_user_address": False,
     "ping_interval": 5, "ping_timeout": 10, "close_timeout": 1, "status": "running", "start_time": 1687867153.6230206,
     "processed_receives_total": 20, "receives_statistic_last_second": {"most_receives_per_second": 2,
                                                                        "entries": {"1687872644": 2, "1688079107": 2,
                                                                                    "1688079131": 2, "1688079366": 2,
                                                                                    "1688079384": 2}},
     "seconds_to_last_heartbeat": 0.4426445960998535, "last_heartbeat": 1688079419.9090648, "stop_request": None,
     "crash_request": None, "kill_request": None, "seconds_since_has_stopped": None, "has_stopped": False,
     "reconnects": 0, "last_stream_signal": "CONNECT", "logged_reconnects": [], "processed_transmitted_total": 0,
     "last_static_ping_listen_key": 1688079326.648718,
     "listen_key": "*******************", "listen_key_cache_time": 600,
     "last_received_data_record": "{\"e\":\"outboundAccountPosition\",\"E\":1688079384730,\"u\":1688079384730,\"B\":[{\"a\":\"BNB\",\"f\":\"0.00038563\",\"l\":\"0.00000000\"},{\"a\":\"USDT\",\"f\":\"99.96600000\",\"l\":\"0.00000000\"}]}",
     "processed_receives_statistic": {"stream_receives_per_second": 5.678168037610828e-05,
                                      "stream_receives_per_minute": 0.0034069008225664967,
                                      "stream_receives_per_hour": 0.2044140493539898,
                                      "stream_receives_per_day": 4.905937184495755, "stream_receives_per_month": 0,
                                      "stream_receives_per_year": 0, "uptime": 211335.76746082306},
     "transfer_rate_per_second": {
         "bytes": {"1687872644": 779, "1688079107": 749, "1688079131": 781, "1688079366": 749, "1688079384": 781},
         "speed": 781},
     "websocket_uri": "wss://stream.binance.com:9443/ws/********"}
bobwng commented 6 months ago

I met the similar simulation.

I'm running two userData streams currently, one is for futures' userData, another one for spot's userData.

Interesting thing is, the stream for futures' is good, only the stream for spot's will stop to receive latest event after some minutes(maybe 10+ or 20+).

here is the streaminfo printed, you can find looks like everything's OK:

======================unicorn-binance-websocket-api_1.46.2-python_3.8.11 ======================
 exchange: binance.com
 stream_id: 5076dc14aca9-07dc-d3d1-4a3e-463445cf
 stream_label: spot user data
 stream_buffer_maxlen: None
 api: False
 channels (1): ['arr']
 markets (1): ['!userData']
 websocket_uri: wss://stream.binance.com:9443/ws/***
 subscriptions: 1
 status: running
 ping_interval: 5 seconds
 ping_timeout: 10 seconds
 close_timeout: 1 seconds
 start_time: 1702352125.066748
 uptime: 2h:45m:57s since 2023-12-12, 03:35:25 UTC
 reconnects: 0
 last_heartbeat: 1702362385.883665
 seconds_to_last_heartbeat: 0.8950097560882568
 kill_request: None
 stop_request: None
 has_stopped: False
 seconds_since_has_stopped: None
 current_receiving_speed: 0 B/s
 processed_receives: 11
 transmitted_payloads: 0
 stream_most_receives_per_second: 6
 stream_receives_per_second: 0.001
 stream_receives_per_minute: 0.066
 stream_receives_per_hour: 3.977
 stream_receives_per_day: 0
===============================================================================================
bobwng commented 6 months ago

I met the similar simulation.

I'm running two userData streams currently, one is for futures' userData, another one for spot's userData. And meanwhile

Interesting thing is, the stream for futures' is good, only the stream for spot's will stop to receive latest event after some minutes(maybe 10+ or 20+).

here is the streaminfo printed, you can find looks like everything's OK:

Enabled the debug log, and then I found that there is only below log related to userData:

2023-12-13 11:15:38,629 [DEBUG   ] 25558 281457944752624 sockets: BinanceWebSocketApiSocket.start_socket(d4916cad375c-2e7f-8049-4238-59617dd8, ['arr'], ['!userData'] - Received inner asyncio.TimeoutError (This is no ERROR, its exactly what we want!)

Meanwhile, streaminfo is still okay with it:

======================unicorn-binance-websocket-api_1.46.2-python_3.8.11 ======================
 exchange: binance.com
 stream_id: 0636d0dd9dda-6eaa-eb2e-9dd1-93788b5b
 stream_label: spot user data
 stream_buffer_maxlen: None
 api: False
 channels (1): ['arr']
 markets (1): ['!userData']
 websocket_uri: wss://stream.binance.com:9443/ws/***
 subscriptions: 1
 status: running
 ping_interval: 5 seconds
 ping_timeout: 10 seconds
 close_timeout: 1 seconds
 start_time: 1702436681.657233
 uptime: 5m:7s since 2023-12-13, 03:04:41 UTC
 reconnects: 0
 last_heartbeat: 1702437289.7080026
 seconds_to_last_heartbeat: 0.11040663719177246
 kill_request: None
 stop_request: None
 has_stopped: False
 seconds_since_has_stopped: None
 current_receiving_speed: 0 B/s
 processed_receives: 11
 transmitted_payloads: 0
 stream_most_receives_per_second: 7
 stream_receives_per_second: 0.036
 stream_receives_per_minute: 2.146
 stream_receives_per_hour: 0
 stream_receives_per_day: 0
===============================================================================================

Was I blocked by Binance? I don't think so, because I can still receive market data like below in that time(after I can't get the userData event):

2023-12-13 03:15:38,926 [DEBUG   ] 25558 281457992790512 protocol: < TEXT '{"stream":"ethusdt@miniTicker","data":{"e":"24h...","q":"6822062885.20"}}' [187 bytes]
oliver-zehentleitner commented 6 months ago

Hello @bobwng and @lr2bmail

Thank you for reporting this issue!

  1. @bobwng This is realy fine, its a timeout how long we wait for a receive till we break the loop. this enables us to stop streams with no receiving data.
2023-12-13 11:15:38,629 [DEBUG   ] 25558 281457944752624 sockets: BinanceWebSocketApiSocket.start_socket(d4916cad375c-2e7f-8049-4238-59617dd8, ['arr'], ['!userData'] - Received inner asyncio.TimeoutError (This is no ERROR, its exactly what we want!)
  1. @lr2bmail

Are you saying that if 1 userdata stream is running per script everything works, but as soon as several different ones are running in one script there are problems?

  1. I have revised the keep listen_key alive procedure and the UBRA implementation in the latest versions. Which versions of UBWA are you currently using?

It is also important to know that you only ever receive one listen key from Binance. It is always the same until it expires. If you have two processes with one ubwa instance each and both execute a userData stream for the same API key pair, the following problem usually arises: If script A stops, then the list key is deleted and script B tries to ping a deleted list key. Here you can firstly tell UBWA not to delete the list key. Secondly, UBWA should learn to request a new list key and perform a restart with updated parameters.

  1. Do you use UnicornFy? What happens if you deactivate it?

  2. So that I can really understand what is going wrong, I need logs at DEBUG level. Please add this to your code and send me the created LOG file:

    import logging
    logging.getLogger("unicorn_binance_websocket_api")
    logging.basicConfig(level=logging.DEBUG,
                    filename=os.path.basename(__file__) + '.log',
                    format="{asctime} [{levelname:8}] {process} {thread} {module}: {message}",
                    style="{")

Since the logs contain sensitive data in this case, you are welcome to send them to me privately via Telegram or via our chat: https://www.lucit.tech/get-support.html

oliver-zehentleitner commented 4 months ago

does anyone still have this problem?

oliver-zehentleitner commented 4 months ago

I'll close, if the problem should still exist please just report back here!