Update dry-order-fix to use sqlalchemy internals

This commit is contained in:
Matthias 2022-07-04 17:17:39 +02:00
parent fe8083c7f8
commit 6f0721ae2b

View File

@ -1,9 +1,10 @@
import logging import logging
from typing import List from typing import List
from sqlalchemy import inspect, text from sqlalchemy import inspect, select, text, tuple_, update
from freqtrade.exceptions import OperationalException from freqtrade.exceptions import OperationalException
from freqtrade.persistence.trade_model import Order, Trade
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -251,31 +252,31 @@ def set_sqlite_to_wal(engine):
def fix_old_dry_orders(engine): def fix_old_dry_orders(engine):
with engine.begin() as connection: with engine.begin() as connection:
connection.execute( stmt = update(Order).where(
text( Order.ft_is_open.is_(True),
""" tuple_(Order.ft_trade_id, Order.order_id).not_in(
update orders select(
set ft_is_open = false Trade.id, Trade.stoploss_order_id
where ft_is_open = true and (ft_trade_id, order_id) not in ( ).where(Trade.stoploss_order_id.is_not(None))
select id, stoploss_order_id from trades where stoploss_order_id is not null ),
) and ft_order_side = 'stoploss' Order.ft_order_side == 'stoploss',
and order_id like 'dry_%' Order.order_id.like('dry%'),
"""
) ).values(ft_is_open=False)
) connection.execute(stmt)
connection.execute(
text( stmt = update(Order).where(
""" Order.ft_is_open.is_(True),
update orders tuple_(Order.ft_trade_id, Order.order_id).not_in(
set ft_is_open = false select(
where ft_is_open = true Trade.id, Trade.open_order_id
and (ft_trade_id, order_id) not in ( ).where(Trade.open_order_id.is_not(None))
select id, open_order_id from trades where open_order_id is not null ),
) and ft_order_side != 'stoploss' Order.ft_order_side != 'stoploss',
and order_id like 'dry_%' Order.order_id.like('dry%')
"""
) ).values(ft_is_open=False)
) connection.execute(stmt)
def check_migrate(engine, decl_base, previous_tables) -> None: def check_migrate(engine, decl_base, previous_tables) -> None: