Skip to content

Commit

Permalink
1.4.16
Browse files Browse the repository at this point in the history
  • Loading branch information
DogsTailFarmer committed Feb 25, 2024
1 parent afd1b5c commit aae7a34
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 16 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
## 1.4.15 2024-02-2
## 1.4.16 2024-02-25
### Fix
* `CreateLimitOrder()`: Missed `trade_id` parameter in fetch_order() call

### Update
* Refine error handling in `http_client`

## 1.4.15 2024-02-02
### Fix
* `HTX`: order Status set on cumulative_filled_quantity value only and `status` from event is ignored

Expand Down
16 changes: 10 additions & 6 deletions exchanges_wrapper/exch_srv.py
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,8 @@ async def CreateLimitOrder(self, request: api_pb2.CreateLimitOrderRequest,
iceberg_quantity=None,
response_type=ResponseType.RESULT.value,
receive_window=None,
test=False)
test=False
)
except errors.HTTPError as ex:
logger.error(f"CreateLimitOrder for {open_client.name}:{request.symbol}:{request.new_client_order_id}"
f" exception: {ex}")
Expand All @@ -845,11 +846,14 @@ async def CreateLimitOrder(self, request: api_pb2.CreateLimitOrderRequest,
_context.set_code(grpc.StatusCode.UNKNOWN)
else:
if not res and client.exchange in ('binance', 'huobi', 'okx'):
res = await client.fetch_order(symbol=request.symbol,
order_id=None,
origin_client_order_id=request.new_client_order_id,
receive_window=None,
response_type=False)
res = await client.fetch_order(
trade_id=request.trade_id,
symbol=request.symbol,
order_id=None,
origin_client_order_id=request.new_client_order_id,
receive_window=None,
response_type=False
)
json_format.ParseDict(res, response, ignore_unknown_fields=True)
logger.debug(f"CreateLimitOrder: for {open_client.name}:{request.symbol}: created: {res.get('orderId')}")
return response
Expand Down
18 changes: 9 additions & 9 deletions exchanges_wrapper/http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,15 @@ async def handle_errors(self, response):
raise ExchangeError(f"An issue occurred on exchange's side: {response.status}: {response.url}:"
f" {response.reason}")
if response.status == 429:
logger.error(f"handle_errors RateLimitReached:response.url: {response.url}")
logger.error(f"API RateLimitReached: {response.url}")
self.rate_limit_reached = self.exchange in ('binance', 'okx')
raise RateLimitReached(RateLimitReached.message)

try:
payload = await response.json()
except aiohttp.ContentTypeError:
payload = None
if self.exchange == 'binance' and payload and "code" in payload:
# as defined here: https://github.com/binance/binance-spot-api-docs/blob/
# master/errors.md#error-codes-for-binance-2019-09-25
raise ExchangeError(payload["msg"])

if response.status >= 400:
logger.debug(f"handle_errors.response: {response.text}")
if response.status == 400 and payload and payload.get("error", str()) == "ERR_RATE_LIMIT":
Expand All @@ -59,16 +57,18 @@ async def handle_errors(self, response):
raise IPAddressBanned(IPAddressBanned.message)
else:
raise HTTPError(f"Malformed request: status: {response.status}, reason: {response.reason}")
if self.exchange in ('binance', 'bitfinex'):
return payload
elif self.exchange == 'bybit' and payload and payload.get('retCode') == 0:

if self.exchange == 'bybit' and payload and payload.get('retCode') == 0:
return payload.get('result'), payload.get('time')
elif self.exchange == 'huobi' and payload and (payload.get('status') == 'ok' or payload.get('ok')):
return payload.get('data', payload.get('tick'))
elif self.exchange == 'okx' and payload and payload.get('code') == '0':
return payload.get('data', [])
elif (self.exchange not in ('binance', 'bitfinex') or
(self.exchange == 'binance' and payload and "code" in payload)):
raise ExchangeError(f"API request failed: {response.status}:{response.reason}:{payload}")
else:
raise HTTPError(f"API request failed: {response.status}:{response.reason}:{payload}")
return payload

async def send_api_call(self,
path,
Expand Down

0 comments on commit aae7a34

Please sign in to comment.