Skip to content

Commit

Permalink
Merge branch 'altmarkets-development-pr' into development
Browse files Browse the repository at this point in the history
  • Loading branch information
TheHolyRoger committed Feb 28, 2021
2 parents 2d0a4c2 + e3a062e commit 71f9671
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ cdef class AltmarketsExchange(ExchangeBase):
timeout=100
)

parsed_response, request_errors = None, False
http_status, parsed_response, request_errors = None, None, False
try:
async with response_coro as response:
try:
Expand All @@ -302,20 +302,21 @@ cdef class AltmarketsExchange(ExchangeBase):
pass
if response.status not in [200, 201] or parsed_response is None:
request_errors = True
http_status = response.status
except Exception:
request_errors = True
if request_errors or parsed_response is None:
if try_count < 4:
try_count += 1
time_sleep = retry_sleep_time(try_count)
print(f"Error fetching data from {url}. HTTP status is {response.status}. "
print(f"Error fetching data from {url}. HTTP status is {http_status}. "
f"Retrying in {time_sleep:.1f}s.")
await asyncio.sleep(time_sleep)
return await self._api_request(method=method, path_url=path_url, params=params,
data=data, is_auth_required = is_auth_required,
try_count=try_count, request_weight=request_weight)
else:
print(f"Error fetching data from {url}. HTTP status is {response.status}. "
print(f"Error fetching data from {url}. HTTP status is {http_status}. "
f"Final msg: {parsed_response}.")
raise AltmarketsAPIError({"error": parsed_response})
return parsed_response
Expand Down
7 changes: 4 additions & 3 deletions hummingbot/connector/exchange/altmarkets/altmarkets_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ async def generic_api_request(method,
response_coro = http_client.request(
method=method.upper(), url=url, headers=headers, params=params, timeout=Constants.API_CALL_TIMEOUT
)
parsed_response, request_errors = None, False
http_status, parsed_response, request_errors = None, None, False
try:
async with response_coro as response:
try:
Expand All @@ -83,19 +83,20 @@ async def generic_api_request(method,
pass
if response.status not in [200, 201] or parsed_response is None:
request_errors = True
http_status = response.status
except Exception:
request_errors = True
if request_errors or parsed_response is None:
if try_count < 4:
try_count += 1
time_sleep = retry_sleep_time(try_count)
print(f"Error fetching data from {url}. HTTP status is {response.status}. "
print(f"Error fetching data from {url}. HTTP status is {http_status}. "
f"Retrying in {time_sleep:.1f}s.")
await asyncio.sleep(time_sleep)
return await generic_api_request(method=method, path_url=path_url, params=params,
client=client, try_count=try_count)
else:
print(f"Error fetching data from {url}. HTTP status is {response.status}. "
print(f"Error fetching data from {url}. HTTP status is {http_status}. "
f"Final msg: {parsed_response}.")
raise AltmarketsAPIError({"error": parsed_response})
return parsed_response
Expand Down

0 comments on commit 71f9671

Please sign in to comment.