From b682fc446e10c3df0aee91776df7a6e0ccebf851 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sat, 13 Aug 2022 09:53:18 +0200 Subject: [PATCH] Graciously fail if strategy has freqAI code, but freqAI is not enabled. --- freqtrade/strategy/interface.py | 7 +++++++ tests/strategy/test_interface.py | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/freqtrade/strategy/interface.py b/freqtrade/strategy/interface.py index 760d852c4..45609beaa 100644 --- a/freqtrade/strategy/interface.py +++ b/freqtrade/strategy/interface.py @@ -152,6 +152,13 @@ class IStrategy(ABC, HyperStrategyMixin): self.freqai = FreqaiModelResolver.load_freqaimodel(self.config) self.freqai_info = self.config["freqai"] + else: + # Gracious failures if freqAI is disabled but "start" is called. + class DummyClass(): + def start(self, *args, **kwargs): + raise OperationalException( + 'freqAI is not enabled. Please enable it in your config to use this strategy.') + self.freqai = DummyClass() # type: ignore def ft_bot_start(self, **kwargs) -> None: """ diff --git a/tests/strategy/test_interface.py b/tests/strategy/test_interface.py index 8b4ba5f03..83f7d19b7 100644 --- a/tests/strategy/test_interface.py +++ b/tests/strategy/test_interface.py @@ -302,6 +302,13 @@ def test_populate_any_indicators(default_conf, testdatadir) -> None: assert len(processed['UNITTEST/BTC']) == 102 # partial candle was removed +def test_freqai_not_initialized(default_conf) -> None: + strategy = StrategyResolver.load_strategy(default_conf) + strategy.ft_bot_start() + with pytest.raises(OperationalException, match=r'freqAI is not enabled\.'): + strategy.freqai.start() + + def test_advise_all_indicators_copy(mocker, default_conf, testdatadir) -> None: strategy = StrategyResolver.load_strategy(default_conf) aimock = mocker.patch('freqtrade.strategy.interface.IStrategy.advise_indicators')