diff --git a/freqtrade/freqtradebot.py b/freqtrade/freqtradebot.py index 5b71d6ec4..bb66303a8 100644 --- a/freqtrade/freqtradebot.py +++ b/freqtrade/freqtradebot.py @@ -290,13 +290,14 @@ class FreqtradeBot(LoggingMixin): def startup_backpopulate_precision(self): - trades = Trade.get_trades([Trade.precision_mode.is_(None)]) + trades = Trade.get_trades([Trade.contract_size.is_(None)]) for trade in trades: if trade.exchange != self.exchange.id: continue trade.precision_mode = self.exchange.precisionMode trade.amount_precision = self.exchange.get_precision_amount(trade.pair) trade.price_precision = self.exchange.get_precision_price(trade.pair) + trade.contract_size = self.exchange.get_contract_size(trade.pair) Trade.commit() def startup_update_open_orders(self): diff --git a/freqtrade/persistence/migrations.py b/freqtrade/persistence/migrations.py index 311554359..1131c88b4 100644 --- a/freqtrade/persistence/migrations.py +++ b/freqtrade/persistence/migrations.py @@ -133,6 +133,7 @@ def migrate_trades_and_orders_table( amount_precision = get_column_def(cols, 'amount_precision', 'null') price_precision = get_column_def(cols, 'price_precision', 'null') precision_mode = get_column_def(cols, 'precision_mode', 'null') + contract_size = get_column_def(cols, 'contract_size', 'null') # Schema migration necessary with engine.begin() as connection: @@ -161,7 +162,7 @@ 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 + amount_precision, price_precision, precision_mode, contract_size ) select id, lower(exchange), pair, {base_currency} base_currency, {stake_currency} stake_currency, @@ -189,7 +190,7 @@ 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 + {precision_mode} precision_mode, {contract_size} contract_size from {trade_back_name} """)) @@ -308,7 +309,7 @@ def check_migrate(engine, decl_base, previous_tables) -> None: # if ('orders' not in previous_tables # or not has_column(cols_orders, 'stop_price')): migrating = False - if not has_column(cols_trades, 'precision_mode'): + if not has_column(cols_trades, 'contract_size'): 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 0c438956a..a46a2dd9f 100644 --- a/freqtrade/persistence/trade_model.py +++ b/freqtrade/persistence/trade_model.py @@ -296,6 +296,7 @@ class LocalTrade(): amount_precision: Optional[float] = None price_precision: Optional[float] = None precision_mode: Optional[int] = None + contract_size: Optional[float] = None # Leverage trading properties liquidation_price: Optional[float] = None @@ -1142,6 +1143,7 @@ class Trade(_DECL_BASE, LocalTrade): amount_precision = Column(Float, nullable=True) price_precision = Column(Float, nullable=True) precision_mode = Column(Integer, nullable=True) + contract_size = Column(Float, nullable=True) # Leverage trading properties leverage = Column(Float, nullable=True, default=1.0)