From 59b34865740cdeb170971034c58cf1f8c7914022 Mon Sep 17 00:00:00 2001 From: Matthias Date: Fri, 19 Jan 2024 06:49:49 +0100 Subject: [PATCH] Update migrations --- freqtrade/persistence/migrations.py | 21 +++++++++------------ tests/persistence/test_migrations.py | 6 +++--- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/freqtrade/persistence/migrations.py b/freqtrade/persistence/migrations.py index fc67448eb..2970da918 100644 --- a/freqtrade/persistence/migrations.py +++ b/freqtrade/persistence/migrations.py @@ -276,23 +276,20 @@ def fix_old_dry_orders(engine): with engine.begin() as connection: # Update current dry-run Orders where + # - stoploss order is Open (will be replaced eventually) + # 2nd query: # - current Order is open # - current Trade is closed # - current Order trade_id not equal to current Trade.id # - current Order not stoploss - # TODO: is this still necessary ? how can this be done now ? - # stmt = update(Order).where( - # Order.ft_is_open.is_(True), - # tuple_(Order.ft_trade_id, Order.order_id).not_in( - # select( - # Trade.id, Trade.stoploss_order_id - # ).where(Trade.stoploss_order_id.is_not(None)) - # ), - # Order.ft_order_side == 'stoploss', - # Order.order_id.like('dry%'), - # ).values(ft_is_open=False) - # connection.execute(stmt) + stmt = update(Order).where( + Order.ft_is_open.is_(True), + Order.ft_order_side == 'stoploss', + Order.order_id.like('dry%'), + + ).values(ft_is_open=False) + connection.execute(stmt) # Close dry-run orders for closed trades. stmt = update(Order).where( diff --git a/tests/persistence/test_migrations.py b/tests/persistence/test_migrations.py index f2bb0b2f1..6ef098cb3 100644 --- a/tests/persistence/test_migrations.py +++ b/tests/persistence/test_migrations.py @@ -74,7 +74,7 @@ def test_init_dryrun_db(default_conf, tmpdir): assert Path(filename).is_file() -def test_migrate_new(mocker, default_conf, fee, caplog): +def test_migrate(mocker, default_conf, fee, caplog): """ Test Database migration (starting with new pairformat) """ @@ -277,7 +277,6 @@ def test_migrate_new(mocker, default_conf, fee, caplog): assert trade.exit_reason is None assert trade.strategy is None assert trade.timeframe == '5m' - assert trade.stoploss_order_id == 'dry_stop_order_id222' assert trade.stoploss_last_update is None assert log_has("trying trades_bak1", caplog) assert log_has("trying trades_bak2", caplog) @@ -294,9 +293,10 @@ def test_migrate_new(mocker, default_conf, fee, caplog): assert orders[0].order_id == 'dry_buy_order' assert orders[0].ft_order_side == 'buy' + # All dry-run stoploss orders will be closed assert orders[-1].order_id == 'dry_stop_order_id222' assert orders[-1].ft_order_side == 'stoploss' - assert orders[-1].ft_is_open is True + assert orders[-1].ft_is_open is False assert orders[1].order_id == 'dry_buy_order22' assert orders[1].ft_order_side == 'buy'