Skip to content

Commit 8fe3eb8

Browse files
committed
[Exchange] fix open position check and set_symbol_position_mode
tmp tmp
1 parent 61a442a commit 8fe3eb8

File tree

4 files changed

+12
-6
lines changed

4 files changed

+12
-6
lines changed

octobot_trading/exchanges/connectors/ccxt/ccxt_connector.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ async def set_symbol_margin_type(self, symbol: str, isolated: bool):
460460
marginType=self.CCXT_ISOLATED if isolated else self.CCXT_CROSSED)
461461

462462
async def set_symbol_position_mode(self, symbol: str, one_way: bool):
463-
return await self.client.set_position_mode(self, hedged=not one_way, symbol=symbol)
463+
return await self.client.set_position_mode(hedged=not one_way, symbol=symbol)
464464

465465
async def set_symbol_partial_take_profit_stop_loss(self, symbol: str, inverse: bool,
466466
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
@@ -676,5 +676,8 @@ def _has_open_position(self, symbol):
676676
:param symbol: the position symbol
677677
:return: True if open position for :symbol: exists
678678
"""
679-
return len(self.exchange_manager.exchange_personal_data.positions_manager.get_symbol_positions(
680-
symbol=symbol)) != 0
679+
return any(
680+
position.size
681+
for position in self.exchange_manager.exchange_personal_data.positions_manager.get_symbol_positions(
682+
symbol=symbol
683+
))

tests/exchanges/traders/test_trader.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -1049,7 +1049,8 @@ async def test_set_position_mode(future_trader_simulator_with_default_linear):
10491049
await position_inst.initialize()
10501050
position_inst.update_from_raw(
10511051
{
1052-
ExchangeConstantsPositionColumns.SYMBOL.value: DEFAULT_FUTURE_SYMBOL
1052+
ExchangeConstantsPositionColumns.SYMBOL.value: DEFAULT_FUTURE_SYMBOL,
1053+
ExchangeConstantsPositionColumns.SIZE.value: 1
10531054
}
10541055
)
10551056
exchange_manager_inst.exchange_personal_data.positions_manager.upsert_position_instance(position_inst)
@@ -1071,7 +1072,8 @@ async def test__has_open_position(future_trader_simulator_with_default_linear):
10711072
await position_inst.initialize()
10721073
position_inst.update_from_raw(
10731074
{
1074-
ExchangeConstantsPositionColumns.SYMBOL.value: DEFAULT_FUTURE_SYMBOL
1075+
ExchangeConstantsPositionColumns.SYMBOL.value: DEFAULT_FUTURE_SYMBOL,
1076+
ExchangeConstantsPositionColumns.SIZE.value: 1
10751077
}
10761078
)
10771079
exchange_manager_inst.exchange_personal_data.positions_manager.upsert_position_instance(position_inst)

0 commit comments

Comments
 (0)