chore: rename WalletHistory model to better match it's intend
This commit is contained in:
@@ -10,4 +10,4 @@ from freqtrade.persistence.usedb_context import (
|
|||||||
disable_database_use,
|
disable_database_use,
|
||||||
enable_database_use,
|
enable_database_use,
|
||||||
)
|
)
|
||||||
from freqtrade.persistence.wallet_history import WalletBalance
|
from freqtrade.persistence.wallet_history import WalletHistory
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ from freqtrade.persistence.key_value_store import _KeyValueStoreModel
|
|||||||
from freqtrade.persistence.migrations import check_migrate
|
from freqtrade.persistence.migrations import check_migrate
|
||||||
from freqtrade.persistence.pairlock import PairLock
|
from freqtrade.persistence.pairlock import PairLock
|
||||||
from freqtrade.persistence.trade_model import Order, Trade
|
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__)
|
logger = logging.getLogger(__name__)
|
||||||
@@ -92,7 +92,7 @@ def init_db(db_url: str) -> None:
|
|||||||
_CustomData.session = scoped_session(
|
_CustomData.session = scoped_session(
|
||||||
sessionmaker(bind=engine, autoflush=True), scopefunc=get_request_or_thread_id
|
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()
|
previous_tables = inspect(engine).get_table_names()
|
||||||
ModelBase.metadata.create_all(engine)
|
ModelBase.metadata.create_all(engine)
|
||||||
|
|||||||
@@ -7,12 +7,12 @@ from sqlalchemy.orm import Mapped, mapped_column
|
|||||||
from freqtrade.persistence.base import ModelBase, SessionType
|
from freqtrade.persistence.base import ModelBase, SessionType
|
||||||
|
|
||||||
|
|
||||||
class WalletBalance(ModelBase):
|
class WalletHistory(ModelBase):
|
||||||
"""
|
"""
|
||||||
Daily wallet state tracking with minimal fields
|
Daily wallet state tracking with minimal fields
|
||||||
"""
|
"""
|
||||||
|
|
||||||
__tablename__ = "wallet_balance"
|
__tablename__ = "wallet_history"
|
||||||
session: ClassVar[SessionType]
|
session: ClassVar[SessionType]
|
||||||
|
|
||||||
id: Mapped[int] = mapped_column(Integer, primary_key=True)
|
id: Mapped[int] = mapped_column(Integer, primary_key=True)
|
||||||
|
|||||||
@@ -790,7 +790,7 @@ class RPC:
|
|||||||
Returns the historic balance of the bot
|
Returns the historic balance of the bot
|
||||||
:return: DataFrame with the balance history
|
: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.loc[:, "total"] = results["price"] * results["balance"]
|
||||||
results = results.rename({"timestamp": "date"}, axis=1)
|
results = results.rename({"timestamp": "date"}, axis=1)
|
||||||
results.loc[:, "__date_ts"] = results.loc[:, "date"].astype("int64") // 1000 // 1000
|
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.exchange.exchange_utils_timeframe import timeframe_to_prev_date
|
||||||
from freqtrade.persistence.key_value_store import KeyValueStore
|
from freqtrade.persistence.key_value_store import KeyValueStore
|
||||||
from freqtrade.persistence.trade_model import Trade
|
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
|
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]
|
[f"{p}_value" for p in pairlist] + [stake_currency]
|
||||||
].sum(axis=1)
|
].sum(axis=1)
|
||||||
|
|
||||||
# Convert balance_dist to WalletBalance entries
|
# Convert balance_dist to WalletHistory entries
|
||||||
wallet_entries = []
|
wallet_entries = []
|
||||||
for date, row in balance_dist.iterrows():
|
for date, row in balance_dist.iterrows():
|
||||||
# Add stake currency entry
|
# Add stake currency entry
|
||||||
if not pd.isna(row[stake_currency]):
|
if not pd.isna(row[stake_currency]):
|
||||||
wallet_entries.append(
|
wallet_entries.append(
|
||||||
WalletBalance(
|
WalletHistory(
|
||||||
timestamp=date,
|
timestamp=date,
|
||||||
currency=stake_currency,
|
currency=stake_currency,
|
||||||
price=1.0, # Stake currency price is always 1.0
|
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
|
price = row[price_col] if not pd.isna(row[price_col]) else None
|
||||||
|
|
||||||
wallet_entries.append(
|
wallet_entries.append(
|
||||||
WalletBalance(
|
WalletHistory(
|
||||||
timestamp=date, currency=base_currency, price=price, balance=row[pair]
|
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:
|
if wallet_entries:
|
||||||
try:
|
try:
|
||||||
# Use bulk_save_objects for better performance
|
# Use bulk_save_objects for better performance
|
||||||
WalletBalance.session.bulk_save_objects(wallet_entries)
|
WalletHistory.session.bulk_save_objects(wallet_entries)
|
||||||
WalletBalance.session.commit()
|
WalletHistory.session.commit()
|
||||||
KeyValueStore.store_value("wallet_history_migration_date", dt_now())
|
KeyValueStore.store_value("wallet_history_migration_date", dt_now())
|
||||||
print(f"Successfully created {len(wallet_entries)} wallet balance records")
|
print(f"Successfully created {len(wallet_entries)} wallet balance records")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
WalletBalance.session.rollback()
|
WalletHistory.session.rollback()
|
||||||
print(f"Error saving wallet balance records: {e}")
|
print(f"Error saving wallet balance records: {e}")
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ from freqtrade.enums import RunMode, TradingMode
|
|||||||
from freqtrade.exceptions import DependencyException
|
from freqtrade.exceptions import DependencyException
|
||||||
from freqtrade.exchange import Exchange
|
from freqtrade.exchange import Exchange
|
||||||
from freqtrade.misc import safe_value_fallback
|
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
|
from freqtrade.util.datetime_helpers import dt_now
|
||||||
|
|
||||||
|
|
||||||
@@ -459,21 +459,21 @@ class Wallets:
|
|||||||
for wallet in self.get_all_balances().values():
|
for wallet in self.get_all_balances().values():
|
||||||
# TODO: exclude minimal balances
|
# TODO: exclude minimal balances
|
||||||
price = self._exchange.get_conversion_rate(wallet.currency, self._stake_currency)
|
price = self._exchange.get_conversion_rate(wallet.currency, self._stake_currency)
|
||||||
wallet_record = WalletBalance(
|
wallet_record = WalletHistory(
|
||||||
timestamp=timestamp,
|
timestamp=timestamp,
|
||||||
currency=wallet.currency,
|
currency=wallet.currency,
|
||||||
price=price,
|
price=price,
|
||||||
balance=wallet.total,
|
balance=wallet.total,
|
||||||
)
|
)
|
||||||
WalletBalance.session.add(wallet_record)
|
WalletHistory.session.add(wallet_record)
|
||||||
|
|
||||||
for position in self.get_all_positions().values():
|
for position in self.get_all_positions().values():
|
||||||
price = self._exchange.get_conversion_rate(position.symbol, self._stake_currency)
|
price = self._exchange.get_conversion_rate(position.symbol, self._stake_currency)
|
||||||
position_record = WalletBalance(
|
position_record = WalletHistory(
|
||||||
timestamp=timestamp,
|
timestamp=timestamp,
|
||||||
currency=position.symbol,
|
currency=position.symbol,
|
||||||
price=price,
|
price=price,
|
||||||
balance=position.position,
|
balance=position.position,
|
||||||
)
|
)
|
||||||
WalletBalance.session.add(position_record)
|
WalletHistory.session.add(position_record)
|
||||||
WalletBalance.session.commit()
|
WalletHistory.session.commit()
|
||||||
|
|||||||
Reference in New Issue
Block a user