2022-05-09 17:26:38 +00:00
|
|
|
import logging
|
2022-05-09 05:21:10 +00:00
|
|
|
from typing import Any, Dict
|
|
|
|
|
2022-09-09 18:31:30 +00:00
|
|
|
from freqtrade.enums import RunMode
|
2022-05-09 05:21:10 +00:00
|
|
|
|
|
|
|
|
2022-05-09 17:26:38 +00:00
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
2022-05-10 05:01:41 +00:00
|
|
|
def start_convert_db(args: Dict[str, Any]) -> None:
|
2024-10-03 03:33:52 +00:00
|
|
|
from sqlalchemy import func, select
|
2022-05-09 17:26:38 +00:00
|
|
|
from sqlalchemy.orm import make_transient
|
|
|
|
|
2024-10-03 03:33:52 +00:00
|
|
|
from freqtrade.configuration.config_setup import setup_utils_configuration
|
2022-05-11 04:30:40 +00:00
|
|
|
from freqtrade.persistence import Order, Trade, init_db
|
|
|
|
from freqtrade.persistence.migrations import set_sequence_ids
|
2022-05-09 17:26:38 +00:00
|
|
|
from freqtrade.persistence.pairlock import PairLock
|
|
|
|
|
2022-05-09 05:21:10 +00:00
|
|
|
config = setup_utils_configuration(args, RunMode.UTIL_NO_EXCHANGE)
|
2022-05-09 17:26:38 +00:00
|
|
|
|
2024-05-12 14:27:03 +00:00
|
|
|
init_db(config["db_url"])
|
2023-03-15 20:12:06 +00:00
|
|
|
session_target = Trade.session
|
2024-05-12 14:27:03 +00:00
|
|
|
init_db(config["db_url_from"])
|
2022-05-10 05:13:51 +00:00
|
|
|
logger.info("Starting db migration.")
|
2022-05-09 17:26:38 +00:00
|
|
|
|
|
|
|
trade_count = 0
|
|
|
|
pairlock_count = 0
|
|
|
|
for trade in Trade.get_trades():
|
|
|
|
trade_count += 1
|
|
|
|
make_transient(trade)
|
|
|
|
for o in trade.orders:
|
|
|
|
make_transient(o)
|
|
|
|
|
|
|
|
session_target.add(trade)
|
2022-05-10 05:13:51 +00:00
|
|
|
|
2022-05-09 17:26:38 +00:00
|
|
|
session_target.commit()
|
|
|
|
|
2023-03-16 05:48:12 +00:00
|
|
|
for pairlock in PairLock.get_all_locks():
|
2022-05-09 17:26:38 +00:00
|
|
|
pairlock_count += 1
|
|
|
|
make_transient(pairlock)
|
|
|
|
session_target.add(pairlock)
|
|
|
|
session_target.commit()
|
2022-05-10 05:13:51 +00:00
|
|
|
|
|
|
|
# Update sequences
|
2023-03-16 17:07:22 +00:00
|
|
|
max_trade_id = session_target.scalar(select(func.max(Trade.id)))
|
|
|
|
max_order_id = session_target.scalar(select(func.max(Order.id)))
|
|
|
|
max_pairlock_id = session_target.scalar(select(func.max(PairLock.id)))
|
2022-05-10 05:13:51 +00:00
|
|
|
|
2024-05-12 14:27:03 +00:00
|
|
|
set_sequence_ids(
|
|
|
|
session_target.get_bind(),
|
|
|
|
trade_id=max_trade_id,
|
|
|
|
order_id=max_order_id,
|
|
|
|
pairlock_id=max_pairlock_id,
|
|
|
|
)
|
2022-05-10 05:13:51 +00:00
|
|
|
|
2022-05-09 17:26:38 +00:00
|
|
|
logger.info(f"Migrated {trade_count} Trades, and {pairlock_count} Pairlocks.")
|