Skip to content

Commit 9635318

Browse files
committed
[Exchange] fix open position check and set_symbol_position_mode
tmp tmp
1 parent 658792e commit 9635318

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
@@ -469,7 +469,7 @@ async def set_symbol_margin_type(self, symbol: str, isolated: bool):
469469
marginType=self.CCXT_ISOLATED if isolated else self.CCXT_CROSSED)
470470

471471
async def set_symbol_position_mode(self, symbol: str, one_way: bool):
472-
return await self.client.set_position_mode(self, hedged=not one_way, symbol=symbol)
472+
return await self.client.set_position_mode(hedged=not one_way, symbol=symbol)
473473

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

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)