Skip to content

Commit

Permalink
[Exchange] fix open position check and set_symbol_position_mode
Browse files Browse the repository at this point in the history
tmp


tmp
  • Loading branch information
techfreaque committed Feb 10, 2023
1 parent 61a442a commit 8fe3eb8
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ async def set_symbol_margin_type(self, symbol: str, isolated: bool):
marginType=self.CCXT_ISOLATED if isolated else self.CCXT_CROSSED)

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

async def set_symbol_partial_take_profit_stop_loss(self, symbol: str, inverse: bool,
tp_sl_mode: enums.TakeProfitStopLossMode):
Expand Down
3 changes: 2 additions & 1 deletion octobot_trading/exchanges/traders/trader.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,5 @@ cdef class Trader(util.Initializable):
cpdef object set_risk(self, object risk)
cpdef object convert_order_to_trade(self, object order)

cdef bint _has_open_position(self, str symbol)
# any() cant be cythonized
# cdef bool _has_open_position(self, str symbol)
7 changes: 5 additions & 2 deletions octobot_trading/exchanges/traders/trader.py
Original file line number Diff line number Diff line change
Expand Up @@ -676,5 +676,8 @@ def _has_open_position(self, symbol):
:param symbol: the position symbol
:return: True if open position for :symbol: exists
"""
return len(self.exchange_manager.exchange_personal_data.positions_manager.get_symbol_positions(
symbol=symbol)) != 0
return any(
position.size
for position in self.exchange_manager.exchange_personal_data.positions_manager.get_symbol_positions(
symbol=symbol
))
6 changes: 4 additions & 2 deletions tests/exchanges/traders/test_trader.py
Original file line number Diff line number Diff line change
Expand Up @@ -1049,7 +1049,8 @@ async def test_set_position_mode(future_trader_simulator_with_default_linear):
await position_inst.initialize()
position_inst.update_from_raw(
{
ExchangeConstantsPositionColumns.SYMBOL.value: DEFAULT_FUTURE_SYMBOL
ExchangeConstantsPositionColumns.SYMBOL.value: DEFAULT_FUTURE_SYMBOL,
ExchangeConstantsPositionColumns.SIZE.value: 1
}
)
exchange_manager_inst.exchange_personal_data.positions_manager.upsert_position_instance(position_inst)
Expand All @@ -1071,7 +1072,8 @@ async def test__has_open_position(future_trader_simulator_with_default_linear):
await position_inst.initialize()
position_inst.update_from_raw(
{
ExchangeConstantsPositionColumns.SYMBOL.value: DEFAULT_FUTURE_SYMBOL
ExchangeConstantsPositionColumns.SYMBOL.value: DEFAULT_FUTURE_SYMBOL,
ExchangeConstantsPositionColumns.SIZE.value: 1
}
)
exchange_manager_inst.exchange_personal_data.positions_manager.upsert_position_instance(position_inst)
Expand Down

0 comments on commit 8fe3eb8

Please sign in to comment.