CyberPunkMetalHead / binance-trading-bot-new-coins

This Binance trading bot detects new coins as soon as they are listed on the Binance exchange and automatically places sell and buy orders. It comes with trailing stop loss and other features. If you like this project please consider donating via Brave.
MIT License
1.46k stars 268 forks source link

Cascading crash caused by API timeout #7

Open vmajor opened 3 years ago

vmajor commented 3 years ago

Traceback (most recent call last): File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 421, in _make_request six.raise_from(e, None) File "", line 3, in raise_from File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 416, in _make_request httplib_response = conn.getresponse() File "/usr/lib/python3.8/http/client.py", line 1344, in getresponse response.begin() File "/usr/lib/python3.8/http/client.py", line 307, in begin version, status, reason = self._read_status() File "/usr/lib/python3.8/http/client.py", line 268, in _read_status line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1") File "/usr/lib/python3.8/socket.py", line 669, in readinto return self._sock.recv_into(b) File "/usr/lib/python3/dist-packages/urllib3/contrib/pyopenssl.py", line 326, in recv_into raise timeout("The read operation timed out") socket.timeout: The read operation timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/usr/lib/python3/dist-packages/requests/adapters.py", line 439, in send resp = conn.urlopen( File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 719, in urlopen retries = retries.increment( File "/usr/lib/python3/dist-packages/urllib3/util/retry.py", line 400, in increment raise six.reraise(type(error), error, _stacktrace) File "/usr/lib/python3/dist-packages/six.py", line 703, in reraise raise value File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 665, in urlopen httplib_response = self._make_request( File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 423, in _make_request self._raise_timeout(err=e, url=url, timeout_value=read_timeout) File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 330, in _raise_timeout raise ReadTimeoutError( urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='api.binance.com', port=443): Read timed out. (read timeout=10)

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "main.py", line 194, in main() File "main.py", line 137, in main new_coins, all_coins_recheck = get_new_coins(all_coins) File "main.py", line 27, in get_new_coins all_coins_recheck = get_all_coins() File "main.py", line 20, in get_all_coins return client.get_all_tickers() File "/home/**/.local/lib/python3.8/site-packages/binance/client.py", line 437, in get_all_tickers return self._get('ticker/price', version=self.PRIVATE_API_VERSION) File "/home/**/.local/lib/python3.8/site-packages/binance/client.py", line 237, in _get return self._request_api('get', path, signed, version, kwargs) File "/home/****/.local/lib/python3.8/site-packages/binance/client.py", line 202, in _request_api return self._request(method, uri, signed, kwargs) File "/home/****/.local/lib/python3.8/site-packages/binance/client.py", line 196, in _request self.response = getattr(self.session, method)(uri, kwargs) File "/usr/lib/python3/dist-packages/requests/sessions.py", line 546, in get return self.request('GET', url, kwargs) File "/usr/lib/python3/dist-packages/requests/sessions.py", line 533, in request resp = self.send(prep, send_kwargs) File "/usr/lib/python3/dist-packages/requests/sessions.py", line 646, in send r = adapter.send(request, kwargs) File "/usr/lib/python3/dist-packages/requests/adapters.py", line 529, in send raise ReadTimeout(e, request=request) requests.exceptions.ReadTimeout: HTTPSConnectionPool(host='api.binance.com', port=443): Read timed out. (read timeout=10)

Varingon commented 3 years ago

Yes I experienced this as well, so I run a script as a temp fix. For anyone who is a Linux user and is experiencing the issue and does not know how to mitigate it:

#!/bin/bash
myscript(){
    python3 main.py
}
until myscript; do
    echo "'main' crashed with exit code $?. Restarting..." >&2
    sleep 1
done
CyberPunkMetalHead commented 3 years ago

I have wrapped the main function in a try/except block in the last commit. This should allow the script to continue past the exception in the next iteration

vmajor commented 3 years ago

Well, I do not know if my git skills are lacking (very probably), but there may be an error with the latest commits. I made no changes to the mentioned files in my local repository and I do not want to merge whatever gitthinks I did back to main:

Auto-merging trade_client.py CONFLICT (content): Merge conflict in trade_client.py Auto-merging main.py CONFLICT (content): Merge conflict in main.py CONFLICT (add/add): Merge conflict in README.md Auto-merging README.md Automatic merge failed; fix conflicts and then commit the result.

CyberPunkMetalHead commented 3 years ago

Are you trying to push a PR? You might need to rebase first