From 93ed61a623c991d9fd08b6a22e0d019c07fc1b87 Mon Sep 17 00:00:00 2001 From: Matthias Date: Fri, 21 Jun 2024 16:40:44 +0200 Subject: [PATCH] Improve stoploss test accuracy --- tests/strategy/test_interface.py | 39 +++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/tests/strategy/test_interface.py b/tests/strategy/test_interface.py index 531d05c0c..d10afd73b 100644 --- a/tests/strategy/test_interface.py +++ b/tests/strategy/test_interface.py @@ -458,55 +458,66 @@ def test_min_roi_reached3(default_conf, fee) -> None: ExitType.TRAILING_STOP_LOSS, None, ), - (0.01, 0.96, ExitType.NONE, None, True, False, 0.05, 1, ExitType.NONE, None), - (0.05, 1, ExitType.NONE, None, True, False, -0.01, 1, ExitType.TRAILING_STOP_LOSS, None), + (0.01, 0.96, ExitType.NONE, None, True, False, 0.05, 0.998, ExitType.NONE, None), + ( + 0.05, + 0.998, + ExitType.NONE, + None, + True, + False, + -0.01, + 0.998, + ExitType.TRAILING_STOP_LOSS, + None, + ), # Default custom case - trails with 10% - (0.05, 0.95, ExitType.NONE, None, False, True, -0.02, 0.95, ExitType.NONE, None), + (0.05, 0.945, ExitType.NONE, None, False, True, -0.02, 0.945, ExitType.NONE, None), ( 0.05, - 0.95, + 0.945, ExitType.NONE, None, False, True, -0.06, - 0.95, + 0.945, ExitType.TRAILING_STOP_LOSS, None, ), ( 0.05, - 1, + 0.998, ExitType.NONE, None, False, True, -0.06, - 1, + 0.998, ExitType.TRAILING_STOP_LOSS, lambda **kwargs: -0.05, ), ( 0.05, - 1, + 0.998, ExitType.NONE, None, False, True, 0.09, - 1.04, + 1.036, ExitType.NONE, lambda **kwargs: -0.05, ), ( 0.05, - 0.95, + 0.945, ExitType.NONE, None, False, True, 0.09, - 0.98, + 0.981, ExitType.NONE, lambda current_profit, **kwargs: ( -0.1 if current_profit < 0.6 else -(current_profit * 2) @@ -552,6 +563,8 @@ def test_ft_stoploss_reached( exchange="binance", open_rate=1, liquidation_price=liq, + price_precision=4, + precision_mode=2, ) trade.adjust_min_max_rates(trade.open_rate, trade.open_rate) strategy.trailing_stop = trailing @@ -577,7 +590,7 @@ def test_ft_stoploss_reached( assert sl_flag.exit_flag is False else: assert sl_flag.exit_flag is True - assert round(trade.stop_loss, 2) == adjusted + assert round(trade.stop_loss, 3) == adjusted current_rate2 = trade.open_rate * (1 + profit2) sl_flag = strategy.ft_stoploss_reached( @@ -593,7 +606,7 @@ def test_ft_stoploss_reached( assert sl_flag.exit_flag is False else: assert sl_flag.exit_flag is True - assert round(trade.stop_loss, 2) == adjusted2 + assert round(trade.stop_loss, 3) == adjusted2 strategy.custom_stoploss = original_stopvalue