Closed lr2bmail closed 9 months 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
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/********"}
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
===============================================================================================
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]
Hello @bobwng and @lr2bmail
Thank you for reporting this issue!
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!)
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?
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.
Do you use UnicornFy? What happens if you deactivate it?
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
does anyone still have this problem?
I'll close, if the problem should still exist please just report back here!
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
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)
here is data from one stream after it stop showing updates
here is data from the same stream after it stop showing updates (after 5 min )
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
and thank you very much for the excellent library