Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Mouthwatering777 committed Sep 21, 2020
1 parent 90965af commit b46e1a1
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,17 @@ async def __aenter__(self):
try:
if isinstance(uri, dict):
# dict = error, string = valid url
if uri['code'] == -2014 or uri['code'] == -2015 or uri['code'] == -2008:
if uri['code'] == -1102 or \
uri['code'] == -2008 or \
uri['code'] == -2014 or \
uri['code'] == -2015 or \
uri['code'] == -11001:
# -1102 = Mandatory parameter 'symbol' was not sent, was empty/null, or malformed.
# -2008 = Invalid Api-Key ID
# -2014 = API-key format invalid
# -2015 = Invalid API-key, IP, or permissions for action
# -2008 = Invalid Api-Key ID
# cant get a valid listen_key, so this stream has to crash
# -11001 = Isolated margin account does not exist.
# Cant get a valid listen_key, so this stream has to crash:
logging.critical("BinanceWebSocketApiConnection->await._conn.__aenter__(" + str(self.stream_id) +
", " + str(self.channels) + ", " + str(self.markets) + ") - " + " error: 4 - " +
str(uri['msg']))
Expand All @@ -98,7 +104,7 @@ async def __aenter__(self):
" error msg from Binance: " + str(uri['msg']))
self.handler_binance_websocket_api_manager.stream_is_crashing(self.stream_id, str(uri['msg']))
if self.handler_binance_websocket_api_manager.throw_exception_if_unrepairable:
raise StreamRecoveryError("stream_id " + str(self.stream_id) + ": " + str(uri['msg']))
raise StreamRecoveryError("stream_id " + str(self.stream_id) + ": " + str(uri))
sys.exit(1)
except KeyError:
logging.error("BinanceWebSocketApiConnection->__enter__(" + str(self.stream_id) + ", " + str(self.channels) +
Expand Down Expand Up @@ -276,15 +282,6 @@ async def receive(self):
if self.handler_binance_websocket_api_manager.is_stop_request(self.stream_id) is False:
self.handler_binance_websocket_api_manager.set_restart_request(self.stream_id)
sys.exit(1)
except asyncio.base_futures.InvalidStateError as error_msg:
logging.error("binance_websocket_api_connection->receive(" +
str(self.stream_id) + ") - asyncio.base_futures.InvalidStateError - error_msg: " +
str(error_msg) + " - Extra info: https://github.com/oliver-zehentleitner/unicorn-binance-"
"websocket-api/issues/18 - open an own issue if needed!")
self.handler_binance_websocket_api_manager.stream_is_stopping(self.stream_id)
if self.handler_binance_websocket_api_manager.is_stop_request(self.stream_id) is False:
self.handler_binance_websocket_api_manager.set_restart_request(self.stream_id)
sys.exit(1)

async def send(self, data):
try:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -908,7 +908,16 @@ def create_websocket_uri(self, channels, markets, stream_id=False, api_key=False
if stream_id is not False:
response = self.get_listen_key_from_restclient(stream_id, api_key, api_secret, symbol=symbol)
try:
if response['code'] == -2014 or response['code'] == -2015:
if response['code'] == -1102 or \
response['code'] == -2008 or \
response['code'] == -2014 or \
response['code'] == -2015 or \
response['code'] == -11001:
# -1102 = Mandatory parameter 'symbol' was not sent, was empty/null, or malformed.
# -2008 = Invalid Api-Key ID
# -2014 = API-key format invalid
# -2015 = Invalid API-key, IP, or permissions for action
# -11001 = Isolated margin account does not exist.
logging.critical("Received known error code from rest client: " + str(response))
return response
else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,10 @@ def _request(self, method, path, query=False, data=False):
uri = self.restful_base_uri + path
try:
if method == "post":
request_handler = requests.post(uri, headers=requests_headers)
if data is False:
request_handler = requests.post(uri, headers=requests_headers)
else:
request_handler = requests.post(uri, headers=requests_headers, data=data)
elif method == "put":
request_handler = requests.put(uri, headers=requests_headers, data=data)
elif method == "delete":
Expand Down Expand Up @@ -182,7 +185,7 @@ def get_listen_key(self):
logging.critical("BinanceWebSocketApiRestclient->get_listen_key() Info: Parameter `symbol` is missing!")
return False
else:
response = self._request(method, self.path_userdata, False, {'symbol': str(self.symbol.lower())})
response = self._request(method, self.path_userdata, False, {'symbol': str(self.symbol)})
else:
response = self._request(method, self.path_userdata)
try:
Expand Down

0 comments on commit b46e1a1

Please sign in to comment.