Skip to content

Commit 8a8cc5e

Browse files
committed
chore: don't rerun binance futures migration
once it's migrated, new migrations shouldn't be necessary.
1 parent e1bf3bb commit 8a8cc5e

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

freqtrade/persistence/key_value_store.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from datetime import datetime, timezone
22
from enum import Enum
3-
from typing import ClassVar
3+
from typing import ClassVar, Literal
44

55
from sqlalchemy import String
66
from sqlalchemy.orm import Mapped, mapped_column
@@ -18,9 +18,11 @@ class ValueTypesEnum(str, Enum):
1818
INT = "int"
1919

2020

21-
class KeyStoreKeys(str, Enum):
22-
BOT_START_TIME = "bot_start_time"
23-
STARTUP_TIME = "startup_time"
21+
KeyStoreKeys = Literal[
22+
"bot_start_time",
23+
"startup_time",
24+
"binance_migration",
25+
]
2426

2527

2628
class _KeyValueStoreModel(ModelBase):
@@ -192,7 +194,7 @@ def get_int_value(key: KeyStoreKeys) -> int | None:
192194
return kv.int_value
193195

194196

195-
def set_startup_time():
197+
def set_startup_time() -> None:
196198
"""
197199
sets bot_start_time to the first trade open date - or "now" on new databases.
198200
sets startup_time to "now"

freqtrade/rpc/rpc.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
from freqtrade.exchange import Exchange, timeframe_to_minutes, timeframe_to_msecs
3434
from freqtrade.exchange.exchange_utils import price_to_precision
3535
from freqtrade.loggers import bufferHandler
36-
from freqtrade.persistence import CustomDataWrapper, KeyStoreKeys, KeyValueStore, PairLocks, Trade
36+
from freqtrade.persistence import CustomDataWrapper, KeyValueStore, PairLocks, Trade
3737
from freqtrade.persistence.models import PairLock
3838
from freqtrade.plugins.pairlist.pairlist_helpers import expand_pairlist
3939
from freqtrade.rpc.fiat_convert import CryptoToFiatConverter
@@ -635,7 +635,7 @@ def _rpc_trade_statistics(
635635
first_date = trades[0].open_date_utc if trades else None
636636
last_date = trades[-1].open_date_utc if trades else None
637637
num = float(len(durations) or 1)
638-
bot_start = KeyValueStore.get_datetime_value(KeyStoreKeys.BOT_START_TIME)
638+
bot_start = KeyValueStore.get_datetime_value("bot_start_time")
639639
return {
640640
"profit_closed_coin": profit_closed_coin_sum,
641641
"profit_closed_percent_mean": round(profit_closed_ratio_mean * 100, 2),
@@ -1601,15 +1601,15 @@ def health(self) -> dict[str, str | int | None]:
16011601
}
16021602
)
16031603

1604-
if bot_start := KeyValueStore.get_datetime_value(KeyStoreKeys.BOT_START_TIME):
1604+
if bot_start := KeyValueStore.get_datetime_value("bot_start_time"):
16051605
res.update(
16061606
{
16071607
"bot_start": str(bot_start),
16081608
"bot_start_loc": format_date(bot_start.astimezone(tzlocal())),
16091609
"bot_start_ts": int(bot_start.timestamp()),
16101610
}
16111611
)
1612-
if bot_startup := KeyValueStore.get_datetime_value(KeyStoreKeys.STARTUP_TIME):
1612+
if bot_startup := KeyValueStore.get_datetime_value("startup_time"):
16131613
res.update(
16141614
{
16151615
"bot_startup": str(bot_startup),

freqtrade/util/migrations/binance_mig.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
from freqtrade.constants import DOCS_LINK, Config
77
from freqtrade.enums import TradingMode
88
from freqtrade.exceptions import OperationalException
9+
from freqtrade.persistence import KeyValueStore, Trade
910
from freqtrade.persistence.pairlock import PairLock
10-
from freqtrade.persistence.trade_model import Trade
1111

1212

1313
logger = logging.getLogger(__name__)
@@ -20,6 +20,9 @@ def migrate_binance_futures_names(config: Config):
2020
):
2121
# only act on new futures
2222
return
23+
if KeyValueStore.get_int_value("binance_migration"):
24+
# already migrated
25+
return
2326
import ccxt
2427

2528
if version.parse("2.6.26") > version.parse(ccxt.__version__):
@@ -29,6 +32,7 @@ def migrate_binance_futures_names(config: Config):
2932
)
3033
_migrate_binance_futures_db(config)
3134
migrate_binance_futures_data(config)
35+
KeyValueStore.store_value("binance_migration", 1)
3236

3337

3438
def _migrate_binance_futures_db(config: Config):

0 commit comments

Comments
 (0)