Skip to content

Commit

Permalink
2.1.10
Browse files Browse the repository at this point in the history
  • Loading branch information
DogsTailFarmer committed Apr 16, 2024
1 parent 49088c4 commit eea8171
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 27 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.1.10 2024-04-16
### Update
* `Bitfinex`: `client.fetch_order()`: searching on `origin_client_order_id` also

## 2.1.9 2024-04-14
### Fix
* Creating and manage asynchronous tasks
Expand Down
2 changes: 1 addition & 1 deletion exchanges_wrapper/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
__contact__ = "https://github.com/DogsTailFarmer"
__email__ = "[email protected]"
__credits__ = ["https://github.com/DanyaSWorlD"]
__version__ = "2.1.9"
__version__ = "2.1.10"

from pathlib import Path
import shutil
Expand Down
54 changes: 32 additions & 22 deletions exchanges_wrapper/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ async def fetch_exchange_info(self, symbol):
"v2/tickers",
send_api_key=False,
endpoint=self.endpoint_api_public,
symbols=bfx.get_symbols(symbols_details)
symbols=bfx.get_symbols(symbols_details, symbol)
)
if symbols_details and tickers:
binance_res = bfx.exchange_info(symbols_details, tickers, symbol)
Expand Down Expand Up @@ -879,18 +879,22 @@ async def create_order(
if new_client_order_id:
params["cid"] = new_client_order_id
self.active_order(new_client_order_id, quantity)
res = (
await self.user_wss_session.handle_request(trade_id, "on", _params=params)
or await self.http.send_api_call(
"v2/auth/w/order/submit",
method="POST",
signed=True,
**params,
)
)

res = await self.user_wss_session.handle_request(trade_id, "on", _params=params)

if not res or (res and isinstance(res, list) and res[6] != 'SUCCESS'):
logger.debug(f"create_order.bitfinex {new_client_order_id}: {res}")
res = await self.http.send_api_call(
"v2/auth/w/order/submit",
method="POST",
signed=True,
**params
)
if res and isinstance(res, list) and res[6] == 'SUCCESS':
self.active_order(res[4][0][0], quantity)
binance_res = bfx.order(res[4][0], response_type=False)
else:
logger.debug(f"create_order.bitfinex {new_client_order_id}: {res}")
elif self.exchange == 'huobi':
params = {
'account-id': str(self.account_id),
Expand Down Expand Up @@ -966,9 +970,7 @@ async def fetch_order( # lgtm [py/similar-function]
response_type=None,
):
self.assert_symbol(symbol)
if self.exchange == 'bitfinex' and not order_id:
raise ValueError("This query requires an order_id")
elif self.exchange in ('binance', 'huobi', 'okx', 'bybit') and not order_id and not origin_client_order_id:
if not order_id and not origin_client_order_id:
raise ValueError("This query requires an order_id or an origin_client_order_id")

b_res = {}
Expand All @@ -995,20 +997,28 @@ async def fetch_order( # lgtm [py/similar-function]
)
)
elif self.exchange == 'bitfinex':
params = {'id': [order_id]}
res = await self.http.send_api_call(
params = {}
if order_id:
params['id'] = [order_id]
_res = await self.http.send_api_call(
f"v2/auth/r/orders/{self.symbol_to_bfx(symbol)}",
method="POST",
signed=True,
**params
) or await self.http.send_api_call(
f"v2/auth/r/orders/{self.symbol_to_bfx(symbol)}/hist",
method="POST",
signed=True,
**params
)
res = bfx.find_order(_res, order_id, origin_client_order_id)
if not res:
if not order_id:
params['start'] = int(time.time() * 1000) - 600000 # 10 mins
_res = await self.http.send_api_call(
f"v2/auth/r/orders/{self.symbol_to_bfx(symbol)}/hist",
method="POST",
signed=True,
**params
)
res = bfx.find_order(_res, order_id, origin_client_order_id)
if res:
b_res = bfx.order(res[0], response_type=response_type)
b_res = bfx.order(res, response_type=response_type)
self.active_order(b_res['orderId'], b_res['origQty'], b_res['executedQty'])
elif self.exchange == 'huobi':
if origin_client_order_id:
Expand Down Expand Up @@ -1185,7 +1195,7 @@ async def cancel_all_orders(self, trade_id, symbol, receive_window=None):
orders_id = [order.get('orderId') for order in orders]
params = {'id': orders_id}
res = await self.user_wss_session.handle_request(trade_id, "oc_multi", _params=params)
if res is None or (res and isinstance(res, list) and res[6] == 'ERROR'):
if not res or (res and isinstance(res, list) and res[6] != 'SUCCESS'):
logger.debug(f"cancel_all_orders.bitfinex {orders_id}: res1: {res}")
res = await self.http.send_api_call(
"v2/auth/w/order/cancel/multi",
Expand Down
21 changes: 17 additions & 4 deletions exchanges_wrapper/parsers/bitfinex_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ def __call__(self):
return self


def get_symbols(symbols_details: []) -> str:
def get_symbols(symbols_details: [], symbol) -> str:
symbols = []
res = ",t"
for symbol_details in symbols_details:
symbol = symbol_details['pair']
if 'f0' not in symbol:
symbols.append(symbol.upper())
_symbol = symbol_details['pair']
if 'f0' not in _symbol and _symbol.replace(":", "").upper() == symbol:
symbols.append(_symbol.upper())
return f"t{res.join(symbols)}"


Expand Down Expand Up @@ -623,3 +623,16 @@ def funding_wallet(res: []) -> []:
balances.append(_binance_res)

return balances


def find_order(_res, order_id, origin_client_order_id):
res = []
if _res:
if order_id:
res = _res[0]
else:
for i in _res:
if i[2] == int(origin_client_order_id):
res = i
break
return res

0 comments on commit eea8171

Please sign in to comment.