From dd8938ced218c03b1802295480bbe43ce9ab706a Mon Sep 17 00:00:00 2001 From: Matthias Date: Thu, 20 Feb 2025 19:22:03 +0100 Subject: [PATCH] test: add test for adjust_order_price and adjust_entry_price collision --- .../broken_futures_strategies.py | 35 ++++++++++++++++++- tests/strategy/test_strategy_loading.py | 4 +++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/tests/strategy/strats/broken_strats/broken_futures_strategies.py b/tests/strategy/strats/broken_strats/broken_futures_strategies.py index b2131e63e..a3e51bc50 100644 --- a/tests/strategy/strats/broken_strats/broken_futures_strategies.py +++ b/tests/strategy/strats/broken_strats/broken_futures_strategies.py @@ -21,10 +21,12 @@ class TestStrategyNoImplementSell(TestStrategyNoImplements): return super().populate_entry_trend(dataframe, metadata) -class TestStrategyImplementCustomSell(TestStrategyNoImplementSell): +class TestStrategyImplementEmptyWorking(TestStrategyNoImplementSell): def populate_exit_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame: return super().populate_exit_trend(dataframe, metadata) + +class TestStrategyImplementCustomSell(TestStrategyImplementEmptyWorking): def custom_sell( self, pair: str, @@ -55,3 +57,34 @@ class TestStrategyImplementSellTimeout(TestStrategyNoImplementSell): self, pair: str, trade, order: Order, current_time: datetime, **kwargs ) -> bool: return False + + +class TestStrategyAdjustOrderPrice(TestStrategyImplementEmptyWorking): + def adjust_entry_price( + self, + trade, + order, + pair, + current_time, + proposed_rate, + current_order_rate, + entry_tag, + side, + **kwargs, + ): + return proposed_rate + + def adjust_order_price( + self, + trade, + order, + pair, + current_time, + proposed_rate, + current_order_rate, + entry_tag, + side, + is_entry, + **kwargs, + ): + return proposed_rate diff --git a/tests/strategy/test_strategy_loading.py b/tests/strategy/test_strategy_loading.py index 9b143ace6..927f33461 100644 --- a/tests/strategy/test_strategy_loading.py +++ b/tests/strategy/test_strategy_loading.py @@ -460,6 +460,10 @@ def test_missing_implements(default_conf, caplog): ): StrategyResolver.load_strategy(default_conf) + default_conf["strategy"] = "TestStrategyAdjustOrderPrice" + with pytest.raises(OperationalException, match=r"If you implement `adjust_order_price`.*"): + StrategyResolver.load_strategy(default_conf) + def test_call_deprecated_function(default_conf): default_location = Path(__file__).parent / "strats/broken_strats/"