chore: don't rerun binance futures migration

once it's migrated, new migrations shouldn't be necessary.
This commit is contained in:
Matthias
2025-04-27 08:44:48 +02:00
parent e1bf3bb825
commit 8a8cc5e563
3 changed files with 16 additions and 10 deletions

View File

@@ -1,6 +1,6 @@
from datetime import datetime, timezone
from enum import Enum
from typing import ClassVar
from typing import ClassVar, Literal
from sqlalchemy import String
from sqlalchemy.orm import Mapped, mapped_column
@@ -18,9 +18,11 @@ class ValueTypesEnum(str, Enum):
INT = "int"
class KeyStoreKeys(str, Enum):
BOT_START_TIME = "bot_start_time"
STARTUP_TIME = "startup_time"
KeyStoreKeys = Literal[
"bot_start_time",
"startup_time",
"binance_migration",
]
class _KeyValueStoreModel(ModelBase):
@@ -192,7 +194,7 @@ class KeyValueStore:
return kv.int_value
def set_startup_time():
def set_startup_time() -> None:
"""
sets bot_start_time to the first trade open date - or "now" on new databases.
sets startup_time to "now"

View File

@@ -33,7 +33,7 @@ from freqtrade.exceptions import ExchangeError, PricingError
from freqtrade.exchange import Exchange, timeframe_to_minutes, timeframe_to_msecs
from freqtrade.exchange.exchange_utils import price_to_precision
from freqtrade.loggers import bufferHandler
from freqtrade.persistence import CustomDataWrapper, KeyStoreKeys, KeyValueStore, PairLocks, Trade
from freqtrade.persistence import CustomDataWrapper, KeyValueStore, PairLocks, Trade
from freqtrade.persistence.models import PairLock
from freqtrade.plugins.pairlist.pairlist_helpers import expand_pairlist
from freqtrade.rpc.fiat_convert import CryptoToFiatConverter
@@ -635,7 +635,7 @@ class RPC:
first_date = trades[0].open_date_utc if trades else None
last_date = trades[-1].open_date_utc if trades else None
num = float(len(durations) or 1)
bot_start = KeyValueStore.get_datetime_value(KeyStoreKeys.BOT_START_TIME)
bot_start = KeyValueStore.get_datetime_value("bot_start_time")
return {
"profit_closed_coin": profit_closed_coin_sum,
"profit_closed_percent_mean": round(profit_closed_ratio_mean * 100, 2),
@@ -1601,7 +1601,7 @@ class RPC:
}
)
if bot_start := KeyValueStore.get_datetime_value(KeyStoreKeys.BOT_START_TIME):
if bot_start := KeyValueStore.get_datetime_value("bot_start_time"):
res.update(
{
"bot_start": str(bot_start),
@@ -1609,7 +1609,7 @@ class RPC:
"bot_start_ts": int(bot_start.timestamp()),
}
)
if bot_startup := KeyValueStore.get_datetime_value(KeyStoreKeys.STARTUP_TIME):
if bot_startup := KeyValueStore.get_datetime_value("startup_time"):
res.update(
{
"bot_startup": str(bot_startup),

View File

@@ -6,8 +6,8 @@ from sqlalchemy import select
from freqtrade.constants import DOCS_LINK, Config
from freqtrade.enums import TradingMode
from freqtrade.exceptions import OperationalException
from freqtrade.persistence import KeyValueStore, Trade
from freqtrade.persistence.pairlock import PairLock
from freqtrade.persistence.trade_model import Trade
logger = logging.getLogger(__name__)
@@ -20,6 +20,9 @@ def migrate_binance_futures_names(config: Config):
):
# only act on new futures
return
if KeyValueStore.get_int_value("binance_migration"):
# already migrated
return
import ccxt
if version.parse("2.6.26") > version.parse(ccxt.__version__):
@@ -29,6 +32,7 @@ def migrate_binance_futures_names(config: Config):
)
_migrate_binance_futures_db(config)
migrate_binance_futures_data(config)
KeyValueStore.store_value("binance_migration", 1)
def _migrate_binance_futures_db(config: Config):