I am trying to make continuous requests to Binance. I am not going out of limit requests(> 1200) per minute. But still getting this error. Even my IP is not banned. After the error I rerun the code, it is working fine for the next 5-6 hours every time. And I am running this on VM. So, it is not the case that my IP is banned and after changing the internet connection my IP is changed.
from unicorn_binance_rest_api.unicorn_binance_rest_api_manager import BinanceRestApiManager
from unicorn_binance_rest_api.unicorn_binance_rest_api_exceptions import BinanceAPIException
import time
import logging
from requests.exceptions import ConnectionError
from urllib3.exceptions import ProtocolError
api_key = "key"
api_secret = "secret"
ubra = BinanceRestApiManager(api_key, api_secret)
avail_count = 10
coins = [{'symbol': 'QTUMUSDT'},
{'symbol': 'ADAUSDT'},
{'symbol': 'XRPUSDT'},
{'symbol': 'MIRUSDT'}]
def buy_coin():
global avail_count
for coin in coins:
current_price = float(ubra.get_symbol_ticker(symbol=coin["symbol"])["price"])
## Doing something with price
while True:
try:
buy_coin()
if avail_count == 0:
time.sleep(3)
except (ConnectionResetError, ConnectionError, ProtocolError) as e:
print(e)
ubra = BinanceRestApiManager(api_key, api_secret)
Traceback (most recent call last):
File "C:\Users\Administrator\Desktop\Binance\venv\lib\site-packages\urllib3\connectionpool.py", line 706, in urlopen
chunked=chunked,
File "C:\Users\Administrator\Desktop\Binance\venv\lib\site-packages\urllib3\connectionpool.py", line 445, in _make_request
six.raise_from(e, None)
File "<string>", line 3, in raise_from
File "C:\Users\Administrator\Desktop\Binance\venv\lib\site-packages\urllib3\connectionpool.py", line 440, in _make_request
httplib_response = conn.getresponse()
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\http\client.py", line 1336, in getresponse
response.begin()
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\http\client.py", line 306, in begin
version, status, reason = self._read_status()
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\http\client.py", line 267, in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\socket.py", line 589, in readinto
return self._sock.recv_into(b)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\ssl.py", line 1071, in recv_into
return self.read(nbytes, buffer)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\ssl.py", line 929, in read
return self._sslobj.read(len, buffer)
ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Administrator\Desktop\Binance\venv\lib\site-packages\requests\adapters.py", line 449, in send
timeout=timeout
File "C:\Users\Administrator\Desktop\Binance\venv\lib\site-packages\urllib3\connectionpool.py", line 756, in urlopen
method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
File "C:\Users\Administrator\Desktop\Binance\venv\lib\site-packages\urllib3\util\retry.py", line 532, in increment
raise six.reraise(type(error), error, _stacktrace)
File "C:\Users\Administrator\Desktop\Binance\venv\lib\site-packages\urllib3\packages\six.py", line 734, in reraise
raise value.with_traceback(tb)
File "C:\Users\Administrator\Desktop\Binance\venv\lib\site-packages\urllib3\connectionpool.py", line 706, in urlopen
chunked=chunked,
File "C:\Users\Administrator\Desktop\Binance\venv\lib\site-packages\urllib3\connectionpool.py", line 445, in _make_request
six.raise_from(e, None)
File "<string>", line 3, in raise_from
File "C:\Users\Administrator\Desktop\Binance\venv\lib\site-packages\urllib3\connectionpool.py", line 440, in _make_request
httplib_response = conn.getresponse()
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\http\client.py", line 1336, in getresponse
response.begin()
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\http\client.py", line 306, in begin
version, status, reason = self._read_status()
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\http\client.py", line 267, in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\socket.py", line 589, in readinto
return self._sock.recv_into(b)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\ssl.py", line 1071, in recv_into
return self.read(nbytes, buffer)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\ssl.py", line 929, in read
return self._sslobj.read(len, buffer)
urllib3.exceptions.ProtocolError: ('Connection aborted.', ConnectionResetError(10054, 'An existing connection was forcibly closed by the remote host', None, 10054, None))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "binance.py", line 243, in <module>
ubra = BinanceRestApiManager(api_key, api_secret)
File "C:\Users\Administrator\Desktop\Binance\venv\lib\site-packages\unicorn_binance_rest_api\unicorn_binance_rest_api_manager.py", line 179, in __init__
res = self.get_server_time()
File "C:\Users\Administrator\Desktop\Binance\venv\lib\site-packages\unicorn_binance_rest_api\unicorn_binance_rest_api_manager.py", line 577, in get_server_time
return self._get('time', version=self.PRIVATE_API_VERSION)
File "C:\Users\Administrator\Desktop\Binance\venv\lib\site-packages\unicorn_binance_rest_api\unicorn_binance_rest_api_manager.py", line 339, in _get
return self._request_api('get', path, signed, version, **kwargs)
File "C:\Users\Administrator\Desktop\Binance\venv\lib\site-packages\unicorn_binance_rest_api\unicorn_binance_rest_api_manager.py", line 287, in _request_api
return self._request(method, uri, signed, **kwargs)
File "C:\Users\Administrator\Desktop\Binance\venv\lib\site-packages\unicorn_binance_rest_api\unicorn_binance_rest_api_manager.py", line 281, in _request
self.response = getattr(self.session, method)(uri, **kwargs)
File "C:\Users\Administrator\Desktop\Binance\venv\lib\site-packages\requests\sessions.py", line 555, in get
return self.request('GET', url, **kwargs)
File "C:\Users\Administrator\Desktop\Binance\venv\lib\site-packages\requests\sessions.py", line 542, in request
resp = self.send(prep, **send_kwargs)
File "C:\Users\Administrator\Desktop\Binance\venv\lib\site-packages\requests\sessions.py", line 655, in send
r = adapter.send(request, **kwargs)
File "C:\Users\Administrator\Desktop\Binance\venv\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))