add open_sl_orders helper, use it in cancel_stoploss_on_exchange

This commit is contained in:
Axel-CH 2023-10-06 10:29:57 -04:00
parent 9214af6901
commit d5a0759051
2 changed files with 20 additions and 12 deletions

View File

@ -904,18 +904,16 @@ class FreqtradeBot(LoggingMixin):
def cancel_stoploss_on_exchange(self, trade: Trade) -> Trade:
# First cancelling stoploss on exchange ...
if trade.has_open_sl_orders:
for o in trade.orders:
if o.ft_order_side == 'stoploss' and o.ft_is_open:
try:
logger.info(f"Canceling stoploss on exchange for {trade} "
f"order: {o.order_id}")
co = self.exchange.cancel_stoploss_order_with_result(
o.order_id, trade.pair, trade.amount)
self.update_trade_state(trade, o.order_id, co, stoploss_order=True)
except InvalidOrderException:
logger.exception(f"Could not cancel stoploss order {o.order_id} "
f"for pair {trade.pair}")
for oslo in trade.open_sl_orders:
try:
logger.info(f"Canceling stoploss on exchange for {trade} "
f"order: {oslo.order_id}")
co = self.exchange.cancel_stoploss_order_with_result(
oslo.order_id, trade.pair, trade.amount)
self.update_trade_state(trade, oslo.order_id, co, stoploss_order=True)
except InvalidOrderException:
logger.exception(f"Could not cancel stoploss order {oslo.order_id} "
f"for pair {trade.pair}")
return trade
def get_valid_enter_price_and_stake(

View File

@ -523,6 +523,16 @@ class LocalTrade:
]
return len(open_orders_wo_sl) > 0
@property
def open_sl_orders(self) -> List[Order]:
"""
All open stoploss orders for this trade
"""
return [
o for o in self.orders
if o.ft_order_side in ['stoploss'] and o.ft_is_open
]
@property
def has_open_sl_orders(self) -> int:
"""