From 0ffc85fed91357218108a5f4c963123c49e83b28 Mon Sep 17 00:00:00 2001 From: Sam Germain Date: Sun, 4 Jul 2021 23:12:07 -0600 Subject: [PATCH] Set default leverage to 1.0 --- freqtrade/persistence/migrations.py | 4 ++-- freqtrade/persistence/models.py | 8 ++++---- tests/conftest_trades.py | 3 --- tests/rpc/test_rpc.py | 6 ++---- 4 files changed, 8 insertions(+), 13 deletions(-) diff --git a/freqtrade/persistence/migrations.py b/freqtrade/persistence/migrations.py index 8e2f708d5..fbf8d7943 100644 --- a/freqtrade/persistence/migrations.py +++ b/freqtrade/persistence/migrations.py @@ -48,7 +48,7 @@ def migrate_trades_table(decl_base, inspector, engine, table_back_name: str, col sell_reason = get_column_def(cols, 'sell_reason', 'null') strategy = get_column_def(cols, 'strategy', 'null') - leverage = get_column_def(cols, 'leverage', 'null') + leverage = get_column_def(cols, 'leverage', '1.0') interest_rate = get_column_def(cols, 'interest_rate', '0.0') liquidation_price = get_column_def(cols, 'liquidation_price', 'null') is_short = get_column_def(cols, 'is_short', 'False') @@ -146,7 +146,7 @@ def migrate_orders_table(decl_base, inspector, engine, table_back_name: str, col # let SQLAlchemy create the schema as required decl_base.metadata.create_all(engine) - leverage = get_column_def(cols, 'leverage', 'null') + leverage = get_column_def(cols, 'leverage', '1.0') is_short = get_column_def(cols, 'is_short', 'False') with engine.begin() as connection: connection.execute(text(f""" diff --git a/freqtrade/persistence/models.py b/freqtrade/persistence/models.py index ebfae72b9..a22ff6238 100644 --- a/freqtrade/persistence/models.py +++ b/freqtrade/persistence/models.py @@ -132,7 +132,7 @@ class Order(_DECL_BASE): order_filled_date = Column(DateTime, nullable=True) order_update_date = Column(DateTime, nullable=True) - leverage = Column(Float, nullable=True, default=None) + leverage = Column(Float, nullable=True, default=1.0) is_short = Column(Boolean, nullable=True, default=False) def __repr__(self): @@ -267,7 +267,7 @@ class LocalTrade(): interest_rate: float = 0.0 liquidation_price: float = None is_short: bool = False - leverage: float = None + leverage: float = 1.0 @property def has_no_leverage(self) -> bool: @@ -583,7 +583,7 @@ class LocalTrade(): zero = Decimal(0.0) # If nothing was borrowed - if (self.leverage == 1.0 and not self.is_short) or not self.leverage: + if self.has_no_leverage: return zero open_date = self.open_date.replace(tzinfo=None) @@ -853,7 +853,7 @@ class Trade(_DECL_BASE, LocalTrade): timeframe = Column(Integer, nullable=True) # Margin trading properties - leverage = Column(Float, nullable=True) + leverage = Column(Float, nullable=True, default=1.0) interest_rate = Column(Float, nullable=False, default=0.0) liquidation_price = Column(Float, nullable=True) is_short = Column(Boolean, nullable=False, default=False) diff --git a/tests/conftest_trades.py b/tests/conftest_trades.py index f6b38f59a..e46186039 100644 --- a/tests/conftest_trades.py +++ b/tests/conftest_trades.py @@ -305,9 +305,6 @@ def mock_trade_6(fee): return trade -#! TODO Currently the following short_trade test and leverage_trade test will fail - - def short_order(): return { 'id': '1236', diff --git a/tests/rpc/test_rpc.py b/tests/rpc/test_rpc.py index 4fd6e716a..3650aa57b 100644 --- a/tests/rpc/test_rpc.py +++ b/tests/rpc/test_rpc.py @@ -107,8 +107,7 @@ def test_rpc_trade_status(default_conf, ticker, fee, mocker) -> None: 'stoploss_entry_dist_ratio': -0.10448878, 'open_order': None, 'exchange': 'binance', - - 'leverage': None, + 'leverage': 1.0, 'interest_rate': 0.0, 'liquidation_price': None, 'is_short': False, @@ -178,8 +177,7 @@ def test_rpc_trade_status(default_conf, ticker, fee, mocker) -> None: 'stoploss_entry_dist_ratio': -0.10448878, 'open_order': None, 'exchange': 'binance', - - 'leverage': None, + 'leverage': 1.0, 'interest_rate': 0.0, 'liquidation_price': None, 'is_short': False,