From 55001bf321db562fd6592dcd5e8612835033cc1d Mon Sep 17 00:00:00 2001 From: Matthias Date: Tue, 27 Dec 2022 13:42:56 +0100 Subject: [PATCH] Keep max_stake_amount (only relevant for DCA orders). --- freqtrade/persistence/migrations.py | 15 ++++++++------- freqtrade/persistence/trade_model.py | 3 +++ tests/persistence/test_migrations.py | 1 + 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/freqtrade/persistence/migrations.py b/freqtrade/persistence/migrations.py index edbcd6be3..44a6756d1 100644 --- a/freqtrade/persistence/migrations.py +++ b/freqtrade/persistence/migrations.py @@ -109,11 +109,10 @@ def migrate_trades_and_orders_table( else: is_short = get_column_def(cols, 'is_short', '0') - # Margin Properties + # Futures Properties interest_rate = get_column_def(cols, 'interest_rate', '0.0') - - # Futures properties funding_fees = get_column_def(cols, 'funding_fees', '0.0') + max_stake_amount = get_column_def(cols, 'max_stake_amount', 'stake_amount') # If ticker-interval existed use that, else null. if has_column(cols, 'ticker_interval'): @@ -162,7 +161,8 @@ def migrate_trades_and_orders_table( timeframe, open_trade_value, close_profit_abs, trading_mode, leverage, liquidation_price, is_short, interest_rate, funding_fees, realized_profit, - amount_precision, price_precision, precision_mode, contract_size + amount_precision, price_precision, precision_mode, contract_size, + max_stake_amount ) select id, lower(exchange), pair, {base_currency} base_currency, {stake_currency} stake_currency, @@ -190,7 +190,8 @@ def migrate_trades_and_orders_table( {is_short} is_short, {interest_rate} interest_rate, {funding_fees} funding_fees, {realized_profit} realized_profit, {amount_precision} amount_precision, {price_precision} price_precision, - {precision_mode} precision_mode, {contract_size} contract_size + {precision_mode} precision_mode, {contract_size} contract_size, + {max_stake_amount} max_stake_amount from {trade_back_name} """)) @@ -310,8 +311,8 @@ def check_migrate(engine, decl_base, previous_tables) -> None: # if ('orders' not in previous_tables # or not has_column(cols_orders, 'funding_fee')): migrating = False - # if not has_column(cols_trades, 'contract_size'): - if not has_column(cols_orders, 'funding_fee'): + # if not has_column(cols_orders, 'funding_fee'): + if not has_column(cols_trades, 'max_stake_amount'): migrating = True logger.info(f"Running database migration for trades - " f"backup: {table_back_name}, {order_table_bak_name}") diff --git a/freqtrade/persistence/trade_model.py b/freqtrade/persistence/trade_model.py index 186a1e584..ad3f9e3b9 100644 --- a/freqtrade/persistence/trade_model.py +++ b/freqtrade/persistence/trade_model.py @@ -293,6 +293,7 @@ class LocalTrade(): close_profit: Optional[float] = None close_profit_abs: Optional[float] = None stake_amount: float = 0.0 + max_stake_amount: float = 0.0 amount: float = 0.0 amount_requested: Optional[float] = None open_date: datetime @@ -918,6 +919,7 @@ class LocalTrade(): else: total_stake = total_stake + self._calc_open_trade_value(tmp_amount, price) self.funding_fees = funding_fees + self.max_stake_amount = total_stake if close_profit: self.close_profit = close_profit @@ -1169,6 +1171,7 @@ class Trade(_DECL_BASE, LocalTrade): close_profit = Column(Float) close_profit_abs = Column(Float) stake_amount = Column(Float, nullable=False) + max_stake_amount = Column(Float) amount = Column(Float) amount_requested = Column(Float) open_date = Column(DateTime, nullable=False, default=datetime.utcnow) diff --git a/tests/persistence/test_migrations.py b/tests/persistence/test_migrations.py index 1cd236005..2a6959d58 100644 --- a/tests/persistence/test_migrations.py +++ b/tests/persistence/test_migrations.py @@ -264,6 +264,7 @@ def test_migrate_new(mocker, default_conf, fee, caplog): assert pytest.approx(trade.open_trade_value) == trade._calc_open_trade_value( trade.amount, trade.open_rate) assert trade.close_profit_abs is None + assert trade.stake_amount == trade.max_stake_amount orders = trade.orders assert len(orders) == 4