diff --git a/freqtrade/freqtradebot.py b/freqtrade/freqtradebot.py index 42ac85fdb..91ece65c6 100644 --- a/freqtrade/freqtradebot.py +++ b/freqtrade/freqtradebot.py @@ -844,7 +844,6 @@ class FreqtradeBot(LoggingMixin): open_rate_requested=enter_limit_requested, open_date=open_date, exchange=self.exchange.id, - open_order_id=order_id, strategy=self.strategy.get_strategy_name(), enter_tag=enter_tag, timeframe=timeframe_to_minutes(self.config['timeframe']), @@ -865,7 +864,6 @@ class FreqtradeBot(LoggingMixin): trade.is_open = True trade.fee_open_currency = None trade.open_rate_requested = enter_limit_requested - trade.open_order_id = order_id trade.orders.append(order_obj) trade.recalc_trade_from_orders() @@ -1905,11 +1903,11 @@ class FreqtradeBot(LoggingMixin): trade.amount, abs_tol=constants.MATH_CLOSE_PREC) if order.ft_order_side == trade.exit_side: # Exit notification - if send_msg and not stoploss_order and not trade.open_order_id: + if send_msg and not stoploss_order and order.order_id not in trade.open_orders_ids: self._notify_exit(trade, '', fill=True, sub_trade=sub_trade, order=order) if not trade.is_open: self.handle_protections(trade.pair, trade.trade_direction) - elif send_msg and not trade.open_order_id and not stoploss_order: + elif send_msg and order.order_id not in trade.open_orders_ids and not stoploss_order: # Enter fill self._notify_enter(trade, order, order.order_type, fill=True, sub_trade=sub_trade) diff --git a/freqtrade/persistence/trade_model.py b/freqtrade/persistence/trade_model.py index 2525a33ad..1e1a497de 100644 --- a/freqtrade/persistence/trade_model.py +++ b/freqtrade/persistence/trade_model.py @@ -1440,7 +1440,7 @@ class Trade(ModelBase, LocalTrade): Returns all open trades NOTE: Not supported in Backtesting. """ - return cast(List[Trade], Trade.get_trades(Trade.open_order_id.isnot(None)).all()) + return cast(List[Trade], Trade.get_trades(Trade.open_orders_count.isnot(0)).all()) @staticmethod def get_open_trades_without_assigned_fees(): diff --git a/tests/test_freqtradebot.py b/tests/test_freqtradebot.py index 71f494372..49b83701c 100644 --- a/tests/test_freqtradebot.py +++ b/tests/test_freqtradebot.py @@ -872,7 +872,8 @@ def test_execute_entry(mocker, default_conf_usdt, fee, limit_order, trade.is_short = is_short assert trade assert trade.is_open is True - assert trade.open_order_id == '22' + assert trade.open_orders_count > 0 + assert '22' in trade.open_orders_ids # Test calling with price open_order['id'] = '33' @@ -898,7 +899,7 @@ def test_execute_entry(mocker, default_conf_usdt, fee, limit_order, trade = Trade.session.scalars(select(Trade)).all()[2] trade.is_short = is_short assert trade - assert trade.open_order_id is None + assert trade.open_orders_count == 0 assert trade.open_rate == 10 assert trade.stake_amount == round(order['average'] * order['filled'] / leverage, 8) assert pytest.approx(trade.liquidation_price) == liq_price @@ -916,7 +917,7 @@ def test_execute_entry(mocker, default_conf_usdt, fee, limit_order, trade = Trade.session.scalars(select(Trade)).all()[3] trade.is_short = is_short assert trade - assert trade.open_order_id is None + assert trade.open_orders_count == 0 assert trade.open_rate == 0.5 assert trade.stake_amount == round(order['average'] * order['filled'] / leverage, 8)