Skip to content

Commit 31c2468

Browse files
committed
[Exchange] fix open position check and set_symbol_position_mode
tmp
1 parent 498842d commit 31c2468

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

octobot_trading/exchanges/connectors/ccxt/ccxt_connector.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -427,9 +427,11 @@ async def get_positions(self, symbols=None, **kwargs: dict) -> list:
427427
]
428428

429429
async def get_position(self, symbol: str, **kwargs: dict) -> dict:
430-
return self.adapter.adapt_position(
431-
await self.client.fetch_position(symbol=symbol, params=kwargs)
432-
)
430+
if self.client.has.get("fetchPosition"):
431+
return self.adapter.adapt_position(
432+
await self.client.fetch_position(symbol=symbol, params=kwargs)
433+
)
434+
raise NotImplementedError("get_position is not implemented")
433435

434436
async def get_funding_rate(self, symbol: str, **kwargs: dict) -> dict:
435437
return self.adapter.adapt_funding_rate(
@@ -449,7 +451,7 @@ async def set_symbol_margin_type(self, symbol: str, isolated: bool):
449451
marginType=self.CCXT_ISOLATED if isolated else self.CCXT_CROSSED)
450452

451453
async def set_symbol_position_mode(self, symbol: str, one_way: bool):
452-
return await self.client.set_position_mode(self, hedged=not one_way, symbol=symbol)
454+
return await self.client.set_position_mode(hedged=not one_way, symbol=symbol)
453455

454456
async def set_symbol_partial_take_profit_stop_loss(self, symbol: str, inverse: bool,
455457
tp_sl_mode: enums.TakeProfitStopLossMode):

octobot_trading/exchanges/traders/trader.pxd

+2-1
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,5 @@ cdef class Trader(util.Initializable):
4040
cpdef object set_risk(self, object risk)
4141
cpdef object convert_order_to_trade(self, object order)
4242

43-
cdef bint _has_open_position(self, str symbol)
43+
# any() cant be cythonized
44+
# cdef bool _has_open_position(self, str symbol)

octobot_trading/exchanges/traders/trader.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -670,5 +670,8 @@ def _has_open_position(self, symbol):
670670
:param symbol: the position symbol
671671
:return: True if open position for :symbol: exists
672672
"""
673-
return len(self.exchange_manager.exchange_personal_data.positions_manager.get_symbol_positions(
674-
symbol=symbol)) != 0
673+
return any(
674+
position.size
675+
for position in self.exchange_manager.exchange_personal_data.positions_manager.get_symbol_positions(
676+
symbol=symbol
677+
))

0 commit comments

Comments
 (0)