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
678 stars 166 forks source link

Failed to establish a new connection: [Errno 110] Connection timed out #200

Closed Twister7 closed 2 years ago

Twister7 commented 2 years ago

Check this or we will delete your issue. (fill in the checkbox with an X like so: [x])

Select one:

Environment

What kind of internet connection do you have?

Up to 5 Gigabit (AWS Network)

Average system load (CPU)

less than 20%

Hardware specification

EC2 T4g.medium (2 vcpu 4gb Ram )

Operating System? (include version)

Options

Which endpoint do you connect?

binance.com-futures

Python Version Requirement

Exact Python Version?

Python 3.8.10

Pip Version?

pip 21.1.3 from /usr/local/lib/python3.8/site-packages/pip (python 3.8)

Dependencies

Run pip list > pip_list.txt and upload the file.

UNICORN Binance WebSocket API Version?

Did you upgrade to the latest release version with `pip install unicorn-binance-websocket-api --upgrade`? No, current version 1.30

Description of your issue

Hi I've developed a Crypto bot running for 5 month without any issue,
But recently (from 1 week ago) I've get and error from WS API and after that connection will be Expired.

I've don't touched any line of code. the error I get from docker log is:

CRITICAL:root:BinanceWebSocketApiRestclient._request() - error_msg: HTTPSConnectionPool(host='fapi.binance.com',
port=443): Max retries exceeded with url: /fapi/v1/listenKey (Caused by
NewConnectionError('<urllib3.connection.HTTPSConnection object at 0xffff8046af70>: 
Failed to establish a new connection: [Errno 110] Connection timed out'))

 and after this I get:

 {'e': 'listenKeyExpired', 'E': 1632180531342}

 Unfortunately, I don't have any more logs (recently I've added INFO level of log if it happened again I will posting here)
 Is there any Idea, How to fix this issue?

 Possible solution:
 Returning an exception could be very helpful or raising a signal to know connection is disconnected.
 Also, It would be great to have retry mechanism to retry request couple of minutes later but based on the Binance Doc:
 No more user data event will be updated after listenKeyExpired event received until a new valid listenKey used.
 so if I'm right any retry should happened before this Event.

 Meta Data:
 I've running this bot in a container and for 5 user, which mean for each user I've standalone container.
  My first doubt was its because of too many request to Binance server,
  but it's less likely because for day there was no signal and trade and I've figure out its happening again.
oliver-zehentleitner commented 2 years ago

You receive {'e': 'listenKeyExpired', 'E': 1632180531342} as last data record via websocket and get disconnected?

Actually I would expect that the userdata stream reconnects then, but this does not happen?

How many times has CRITICAL:root:BinanceWebSocketApiRestclient._request() - error_msg: HTTPSConnectionPool(host='fapi.binance.com', port=443): Max retries exceeded with url: /fapi/v1/listenKey (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0xffff8046af70>: Failed to establish a new connection: [Errno 110] Connection timed out')) been reported to you?

A log file would help me please!

Twister7 commented 2 years ago

Thanks Oliver,

You receive {'e': 'listenKeyExpired', 'E': 1632180531342} as last data record via websocket and get disconnected?

Yes

Actually I would expect that the userdata stream reconnects then, but this does not happen?

No, I should restart docker so ListenKey will change and its start receiving data again

How many times has CRITICAL:root:BinanceWebSocketApiRestclient._request() - error_msg: HTTPSConnectionPool(host='fapi.binance.com', port=443): Max retries exceeded with url: /fapi/v1/listenKey (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0xffff8046af70>: Failed to establish a new connection: [Errno 110] Connection timed out')) been reported to you?

more than 5 times for different user during this week. The sequence is like this : I get above error then after afew minutes I get listenKeyExpired.

A log file would help me please!

I set the log, As soon as it happening again I will update this issue.

BTW, I setup a new server with fresh IP and it happened again, So my first assumption was wrong and it's not about too many request from my IP.

oliver-zehentleitner commented 2 years ago

requesting a new listenkey costs 1 weight and you can use 1000 per minute... i dont think thats the reason.

I wait for your log file.

oliver-zehentleitner commented 2 years ago

https://github.com/oliver-zehentleitner/unicorn-binance-websocket-api/commit/a44fb410689e5b680efa03b580f03093567279dc#diff-593fd8b0b38c29d2630eab6801d345013356080186dff9eb6da84312d2d2213b

i have improved the logging in the affected area, can you please install this version: pip install https://github.com/oliver-zehentleitner/unicorn-binance-websocket-api/tarball/master --upgrade

and post the new error message if it happens again.

This patch will be included in the next release.

oliver-zehentleitner commented 2 years ago

From Telegram: "It was DigitalOcean for me, they had a day+ of network outages"

I close this. If this happens again, please open with the new error log (> ubwa 1.34.1)!

Thanks!