From 9ddabbd849490851be35e282e5fb85a8bdf3a3c4 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sun, 14 Sep 2025 11:42:16 +0200 Subject: [PATCH] feat: use proper starting balance --- freqtrade/freqtradebot.py | 2 +- freqtrade/util/migrations/__init__.py | 7 ++++--- freqtrade/util/migrations/migrate_wallet_history.py | 8 +++----- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/freqtrade/freqtradebot.py b/freqtrade/freqtradebot.py index 40db0effe..1646cfa9b 100644 --- a/freqtrade/freqtradebot.py +++ b/freqtrade/freqtradebot.py @@ -237,7 +237,7 @@ class FreqtradeBot(LoggingMixin): Called on startup and after reloading the bot - triggers notifications and performs startup tasks """ - migrate_live_content(self.config, self.exchange) + migrate_live_content(self.config, self.exchange, self.wallets.get_starting_balance()) set_startup_time() self.rpc.startup_messages(self.config, self.pairlists, self.protections) diff --git a/freqtrade/util/migrations/__init__.py b/freqtrade/util/migrations/__init__.py index 0ed6c97da..90f866075 100644 --- a/freqtrade/util/migrations/__init__.py +++ b/freqtrade/util/migrations/__init__.py @@ -1,9 +1,10 @@ +from freqtrade.constants import Config from freqtrade.exchange import Exchange from freqtrade.util.migrations.funding_rate_mig import migrate_funding_fee_timeframe from freqtrade.util.migrations.migrate_wallet_history import migrate_wallet_history -def migrate_data(config, exchange: Exchange | None = None) -> None: +def migrate_data(config: Config, exchange: Exchange | None = None) -> None: """ Migrate persisted data from old formats to new formats """ @@ -11,9 +12,9 @@ def migrate_data(config, exchange: Exchange | None = None) -> None: migrate_funding_fee_timeframe(config, exchange) -def migrate_live_content(config, exchange: Exchange) -> None: +def migrate_live_content(config: Config, exchange: Exchange, starting_balance: float) -> None: """ Migrate database content from old formats to new formats Used for dry/live mode. """ - migrate_wallet_history(config, exchange) + migrate_wallet_history(config, exchange, starting_balance) diff --git a/freqtrade/util/migrations/migrate_wallet_history.py b/freqtrade/util/migrations/migrate_wallet_history.py index 86db525ac..316e74ab1 100644 --- a/freqtrade/util/migrations/migrate_wallet_history.py +++ b/freqtrade/util/migrations/migrate_wallet_history.py @@ -16,7 +16,7 @@ from freqtrade.util.datetime_helpers import dt_now, dt_ts logger = logging.getLogger(__name__) -def migrate_wallet_history(config: Config, exchange: Exchange): +def migrate_wallet_history(config: Config, exchange: Exchange, starting_balance: float): if not exchange.get_option("ohlcv_has_history", True): # we can't fill up wallet history without ohlcv history return @@ -24,18 +24,16 @@ def migrate_wallet_history(config: Config, exchange: Exchange): logger.debug("Wallet history migration already completed.") return logger.info("Starting wallet history migration...") - _migrate_wallet_history(config, exchange) + _migrate_wallet_history(config, exchange, starting_balance) logger.info("Wallet history migration completed.") KeyValueStore.store_value("wallet_history_migration", 1) -def _migrate_wallet_history(config: Config, exchange: Exchange): +def _migrate_wallet_history(config: Config, exchange: Exchange, starting_balance: float): trade_df = trade_list_to_dataframe(Trade.get_trades_proxy()) if trade_df.empty: # no trades, nothing to do return - # TODO: use a proper starting balance. - starting_balance = 1000 # wallets.get_starting_balance() pairlist = list(trade_df["pair"].unique()) timeframe = "1d" stake_currency = config["stake_currency"]