CyberPunkMetalHead / Binance-volatility-trading-bot

This is a fully functioning Binance trading bot that measures the volatility of every coin on Binance and places trades with the highest gaining coins If you like this project consider donating though the Brave browser to allow me to continuously improve the script.
MIT License
3.41k stars 777 forks source link

get_all_tickers Connection Error #20

Closed goodlifeinc closed 3 years ago

goodlifeinc commented 3 years ago

Hello,

when the bot is left running for some time very often an error is received deep into python request libraries:

Traceback (most recent call last): File "C:\Users\Evgeni\Desktop\crypto\Binance-volatility-trading-bot\Binance Detect Moonings.py", line 323, in orders, last_price, volume = buy() File "C:\Users\Evgeni\Desktop\crypto\Binance-volatility-trading-bot\Binance Detect Moonings.py", line 190, in buy volume, last_price = convert_volume() File "C:\Users\Evgeni\Desktop\crypto\Binance-volatility-trading-bot\Binance Detect Moonings.py", line 154, in convert_volume volatile_coins, number_of_coins, last_price = wait_for_price() File "C:\Users\Evgeni\Desktop\crypto\Binance-volatility-trading-bot\Binance Detect Moonings.py", line 132, in wait_for_price last_price = get_price() File "C:\Users\Evgeni\Desktop\crypto\Binance-volatility-trading-bot\Binance Detect Moonings.py", line 107, in get_price prices = client.get_all_tickers() File "C:\Users\Evgeni\AppData\Local\Programs\Python\Python39\lib\site-packages\binance\client.py", line 568, in get_all_tickers return self._get('ticker/price', version=self.PRIVATE_API_VERSION) File "C:\Users\Evgeni\AppData\Local\Programs\Python\Python39\lib\site-packages\binance\client.py", line 365, in _get return self._request_api('get', path, signed, version, kwargs) File "C:\Users\Evgeni\AppData\Local\Programs\Python\Python39\lib\site-packages\binance\client.py", line 328, in _request_api return self._request(method, uri, signed, kwargs) File "C:\Users\Evgeni\AppData\Local\Programs\Python\Python39\lib\site-packages\binance\client.py", line 308, in _request self.response = getattr(self.session, method)(uri, kwargs) File "C:\Users\Evgeni\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\sessions.py", line 555, in get return self.request('GET', url, kwargs) File "C:\Users\Evgeni\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\sessions.py", line 542, in request resp = self.send(prep, send_kwargs) File "C:\Users\Evgeni\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\sessions.py", line 655, in send r = adapter.send(request, kwargs) File "C:\Users\Evgeni\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\adapters.py", line 498, in send raise ConnectionError(err, request=request) requests.exceptions.ConnectionError: ('Connection aborted.', ConnectionResetError(10054, 'An existing connection was forcibly closed by the remote host', None, 10054, None))

In such occasions the bot must be manually started again. Perhaps there can be a try/catch or something smarter to handle it :)

jsbots commented 3 years ago

The same error occurred for me when i used TIME_DIFFERENCE = 4, but when i used 3 or 5, it worked well.

DJeler commented 3 years ago

I have the same issue. And I think it has something to do with the binance API connection being timed out after a certain amount of time. I think the way to fix it would be to ping it like every minute or so using client.ping() to keep the connection active. I have yet to test this though.

When I loaded the bot into the interpreter and manually ran client.get_all_tickers(), it would work until I waited like 5 or so minutes in between and then it would give the error. If you run it again right after the error though, it works again. So I think a try/catch solution would also work here and just make it run client.get_all_tickers() twice.

getsec commented 3 years ago

this should be fixed. Closing this now, if it happens again please open a new ticket with stack traces, config, and all error text. Thanks.