From bbbc8a760c7ef3e9498153ed29ea8aea36b7feb9 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sun, 22 Oct 2023 09:24:28 +0200 Subject: [PATCH] Fix stop evaluation sequence to have stop before liquidation Adjust test to have liquidation above stop closes #9296 --- freqtrade/strategy/interface.py | 8 ++++---- tests/strategy/test_interface.py | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/freqtrade/strategy/interface.py b/freqtrade/strategy/interface.py index 5cdbb6bf6..cbe6afc26 100644 --- a/freqtrade/strategy/interface.py +++ b/freqtrade/strategy/interface.py @@ -1244,10 +1244,6 @@ class IStrategy(ABC, HyperStrategyMixin): and trade.liquidation_price <= (high or current_rate) and trade.is_short) - if (liq_higher_long or liq_lower_short): - logger.debug(f"{trade.pair} - Liquidation price hit. exit_type=ExitType.LIQUIDATION") - return ExitCheckTuple(exit_type=ExitType.LIQUIDATION) - # evaluate if the stoploss was hit if stoploss is not on exchange # in Dry-Run, this handles stoploss logic as well, as the logic will not be different to # regular stoploss handling. @@ -1268,6 +1264,10 @@ class IStrategy(ABC, HyperStrategyMixin): return ExitCheckTuple(exit_type=exit_type) + if (liq_higher_long or liq_lower_short): + logger.debug(f"{trade.pair} - Liquidation price hit. exit_type=ExitType.LIQUIDATION") + return ExitCheckTuple(exit_type=ExitType.LIQUIDATION) + return ExitCheckTuple(exit_type=ExitType.NONE) def min_roi_reached_entry(self, trade_dur: int) -> Tuple[Optional[int], Optional[float]]: diff --git a/tests/strategy/test_interface.py b/tests/strategy/test_interface.py index e8abcb362..226bbc7ae 100644 --- a/tests/strategy/test_interface.py +++ b/tests/strategy/test_interface.py @@ -422,7 +422,7 @@ def test_min_roi_reached3(default_conf, fee) -> None: # enable custom stoploss, expected after 1st call, expected after 2nd call (0.2, 0.9, ExitType.NONE, None, False, False, 0.3, 0.9, ExitType.NONE, None), (0.2, 0.9, ExitType.NONE, None, False, False, -0.2, 0.9, ExitType.STOP_LOSS, None), - (0.2, 0.9, ExitType.NONE, 0.8, False, False, -0.2, 0.9, ExitType.LIQUIDATION, None), + (0.2, 0.9, ExitType.NONE, 0.92, False, False, -0.09, 0.9, ExitType.LIQUIDATION, None), (0.2, 1.14, ExitType.NONE, None, True, False, 0.05, 1.14, ExitType.TRAILING_STOP_LOSS, None), (0.01, 0.96, ExitType.NONE, None, True, False, 0.05, 1, ExitType.NONE, None),