chore: rename WalletHistory model to better match it's intend

This commit is contained in:
Matthias
2025-06-15 06:56:04 +02:00
parent c7878130f1
commit d6a0a4ec6c
6 changed files with 19 additions and 19 deletions
+1 -1
View File
@@ -10,4 +10,4 @@ from freqtrade.persistence.usedb_context import (
disable_database_use,
enable_database_use,
)
from freqtrade.persistence.wallet_history import WalletBalance
from freqtrade.persistence.wallet_history import WalletHistory
+2 -2
View File
@@ -20,7 +20,7 @@ from freqtrade.persistence.key_value_store import _KeyValueStoreModel
from freqtrade.persistence.migrations import check_migrate
from freqtrade.persistence.pairlock import PairLock
from freqtrade.persistence.trade_model import Order, Trade
from freqtrade.persistence.wallet_history import WalletBalance
from freqtrade.persistence.wallet_history import WalletHistory
logger = logging.getLogger(__name__)
@@ -92,7 +92,7 @@ def init_db(db_url: str) -> None:
_CustomData.session = scoped_session(
sessionmaker(bind=engine, autoflush=True), scopefunc=get_request_or_thread_id
)
WalletBalance.session = Trade.session
WalletHistory.session = Trade.session
previous_tables = inspect(engine).get_table_names()
ModelBase.metadata.create_all(engine)
+2 -2
View File
@@ -7,12 +7,12 @@ from sqlalchemy.orm import Mapped, mapped_column
from freqtrade.persistence.base import ModelBase, SessionType
class WalletBalance(ModelBase):
class WalletHistory(ModelBase):
"""
Daily wallet state tracking with minimal fields
"""
__tablename__ = "wallet_balance"
__tablename__ = "wallet_history"
session: ClassVar[SessionType]
id: Mapped[int] = mapped_column(Integer, primary_key=True)
+1 -1
View File
@@ -790,7 +790,7 @@ class RPC:
Returns the historic balance of the bot
:return: DataFrame with the balance history
"""
results = read_sql("wallet_balance", con=Trade.session.bind, parse_dates=["timestamp"])
results = read_sql("wallet_history", con=Trade.session.bind, parse_dates=["timestamp"])
results.loc[:, "total"] = results["price"] * results["balance"]
results = results.rename({"timestamp": "date"}, axis=1)
results.loc[:, "__date_ts"] = results.loc[:, "date"].astype("int64") // 1000 // 1000
@@ -9,7 +9,7 @@ from freqtrade.exchange import Exchange
from freqtrade.exchange.exchange_utils_timeframe import timeframe_to_prev_date
from freqtrade.persistence.key_value_store import KeyValueStore
from freqtrade.persistence.trade_model import Trade
from freqtrade.persistence.wallet_history import WalletBalance
from freqtrade.persistence.wallet_history import WalletHistory
from freqtrade.util.datetime_helpers import dt_now, dt_ts
@@ -73,13 +73,13 @@ def _migrate_wallet_history(config: Config, exchange: Exchange):
[f"{p}_value" for p in pairlist] + [stake_currency]
].sum(axis=1)
# Convert balance_dist to WalletBalance entries
# Convert balance_dist to WalletHistory entries
wallet_entries = []
for date, row in balance_dist.iterrows():
# Add stake currency entry
if not pd.isna(row[stake_currency]):
wallet_entries.append(
WalletBalance(
WalletHistory(
timestamp=date,
currency=stake_currency,
price=1.0, # Stake currency price is always 1.0
@@ -96,7 +96,7 @@ def _migrate_wallet_history(config: Config, exchange: Exchange):
price = row[price_col] if not pd.isna(row[price_col]) else None
wallet_entries.append(
WalletBalance(
WalletHistory(
timestamp=date, currency=base_currency, price=price, balance=row[pair]
)
)
@@ -105,10 +105,10 @@ def _migrate_wallet_history(config: Config, exchange: Exchange):
if wallet_entries:
try:
# Use bulk_save_objects for better performance
WalletBalance.session.bulk_save_objects(wallet_entries)
WalletBalance.session.commit()
WalletHistory.session.bulk_save_objects(wallet_entries)
WalletHistory.session.commit()
KeyValueStore.store_value("wallet_history_migration_date", dt_now())
print(f"Successfully created {len(wallet_entries)} wallet balance records")
except Exception as e:
WalletBalance.session.rollback()
WalletHistory.session.rollback()
print(f"Error saving wallet balance records: {e}")
+6 -6
View File
@@ -10,7 +10,7 @@ from freqtrade.enums import RunMode, TradingMode
from freqtrade.exceptions import DependencyException
from freqtrade.exchange import Exchange
from freqtrade.misc import safe_value_fallback
from freqtrade.persistence import LocalTrade, Trade, WalletBalance
from freqtrade.persistence import LocalTrade, Trade, WalletHistory
from freqtrade.util.datetime_helpers import dt_now
@@ -459,21 +459,21 @@ class Wallets:
for wallet in self.get_all_balances().values():
# TODO: exclude minimal balances
price = self._exchange.get_conversion_rate(wallet.currency, self._stake_currency)
wallet_record = WalletBalance(
wallet_record = WalletHistory(
timestamp=timestamp,
currency=wallet.currency,
price=price,
balance=wallet.total,
)
WalletBalance.session.add(wallet_record)
WalletHistory.session.add(wallet_record)
for position in self.get_all_positions().values():
price = self._exchange.get_conversion_rate(position.symbol, self._stake_currency)
position_record = WalletBalance(
position_record = WalletHistory(
timestamp=timestamp,
currency=position.symbol,
price=price,
balance=position.position,
)
WalletBalance.session.add(position_record)
WalletBalance.session.commit()
WalletHistory.session.add(position_record)
WalletHistory.session.commit()