diff --git a/freqtrade/persistence/trade_model.py b/freqtrade/persistence/trade_model.py index ff0fff703..6f31444d4 100644 --- a/freqtrade/persistence/trade_model.py +++ b/freqtrade/persistence/trade_model.py @@ -924,15 +924,14 @@ class LocalTrade: short_close_zero = (self.is_short and close_trade_value == 0.0) long_close_zero = (not self.is_short and open_trade_value == 0.0) - leverage = self.leverage or 1.0 if (short_close_zero or long_close_zero): return 0.0 else: if self.is_short: - profit_ratio = (1 - (close_trade_value / open_trade_value)) * leverage + profit_ratio = (1 - (close_trade_value / open_trade_value)) * self.leverage else: - profit_ratio = ((close_trade_value / open_trade_value) - 1) * leverage + profit_ratio = ((close_trade_value / open_trade_value) - 1) * self.leverage return float(f"{profit_ratio:.8f}") diff --git a/tests/rpc/test_rpc_apiserver.py b/tests/rpc/test_rpc_apiserver.py index a85d15365..a3c16d16e 100644 --- a/tests/rpc/test_rpc_apiserver.py +++ b/tests/rpc/test_rpc_apiserver.py @@ -986,7 +986,7 @@ def test_api_performance(botclient, fee): fee_close=fee.return_value, fee_open=fee.return_value, close_rate=0.265441, - + leverage=1.0, ) trade.close_profit = trade.calc_profit_ratio(trade.close_rate) trade.close_profit_abs = trade.calc_profit(trade.close_rate) @@ -1002,7 +1002,8 @@ def test_api_performance(botclient, fee): is_open=False, fee_close=fee.return_value, fee_open=fee.return_value, - close_rate=0.391 + close_rate=0.391, + leverage=1.0, ) trade.close_profit = trade.calc_profit_ratio(trade.close_rate) trade.close_profit_abs = trade.calc_profit(trade.close_rate) diff --git a/tests/strategy/test_interface.py b/tests/strategy/test_interface.py index 8a609cf30..e8abcb362 100644 --- a/tests/strategy/test_interface.py +++ b/tests/strategy/test_interface.py @@ -503,6 +503,7 @@ def test_custom_exit(default_conf, fee, caplog) -> None: fee_close=fee.return_value, exchange='binance', open_rate=1, + leverage=1.0, ) now = dt_now() @@ -552,6 +553,7 @@ def test_should_sell(default_conf, fee) -> None: fee_close=fee.return_value, exchange='binance', open_rate=1, + leverage=1.0, ) now = dt_now() res = strategy.should_exit(trade, 1, now, diff --git a/tests/test_freqtradebot.py b/tests/test_freqtradebot.py index 088c9ee5e..b1f72f2f1 100644 --- a/tests/test_freqtradebot.py +++ b/tests/test_freqtradebot.py @@ -3458,6 +3458,7 @@ def test_handle_cancel_exit_limit(mocker, default_conf_usdt, fee) -> None: close_date=dt_now(), exit_reason="sell_reason_whatever", stake_amount=0.245441 * 2, + leverage=1, ) trade.orders = [ Order(