From 01b7ad4a3f6d4bacd089c7dabeeedea51cfc9beb Mon Sep 17 00:00:00 2001 From: Matthias Date: Fri, 23 Aug 2024 18:16:01 +0200 Subject: [PATCH] feat: prevent freqAI startup on exchanges without history closes #10570 --- freqtrade/exchange/exchange.py | 8 ++++++++ tests/exchange/test_exchange.py | 21 +++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/freqtrade/exchange/exchange.py b/freqtrade/exchange/exchange.py index 9e58acc27..eb842e39a 100644 --- a/freqtrade/exchange/exchange.py +++ b/freqtrade/exchange/exchange.py @@ -337,6 +337,7 @@ class Exchange: self.validate_pricing(config["exit_pricing"]) self.validate_pricing(config["entry_pricing"]) self.validate_orderflow(config["exchange"]) + self.validate_freqai(config) def _init_ccxt( self, exchange_config: Dict[str, Any], sync: bool, ccxt_kwargs: Dict[str, Any] @@ -826,6 +827,13 @@ class Exchange: f"Trade data not available for {self.name}. Can't use orderflow feature." ) + def validate_freqai(self, config: Config) -> None: + freqai_enabled = config.get("freqai", {}).get("enabled", False) + if freqai_enabled and not self._ft_has["ohlcv_has_history"]: + raise ConfigurationError( + f"Historic OHLCV data not available for {self.name}. Can't use freqAI." + ) + def validate_required_startup_candles(self, startup_candles: int, timeframe: str) -> int: """ Checks if required startup_candles is more than ohlcv_candle_limit(). diff --git a/tests/exchange/test_exchange.py b/tests/exchange/test_exchange.py index 4a1865658..1e43cf51b 100644 --- a/tests/exchange/test_exchange.py +++ b/tests/exchange/test_exchange.py @@ -342,6 +342,27 @@ def test_validate_orderflow(default_conf, mocker, caplog): ex.validate_orderflow({"use_public_trades": True}) +def test_validate_freqai_compat(default_conf, mocker, caplog): + caplog.set_level(logging.INFO) + # Test kraken - as it doesn't support historic trades data. + ex = get_patched_exchange(mocker, default_conf, exchange="kraken") + mocker.patch(f"{EXMS}.exchange_has", return_value=True) + + default_conf["freqai"] = {"enabled": False} + ex.validate_freqai(default_conf) + + default_conf["freqai"] = {"enabled": True} + with pytest.raises(ConfigurationError, match=r"Historic OHLCV data not available for.*"): + ex.validate_freqai(default_conf) + + # Binance supports historic data. + ex = get_patched_exchange(mocker, default_conf, exchange="binance") + default_conf["freqai"] = {"enabled": True} + ex.validate_freqai(default_conf) + default_conf["freqai"] = {"enabled": False} + ex.validate_freqai(default_conf) + + @pytest.mark.parametrize( "price,precision_mode,precision,expected", [