feat: prevent freqAI startup on exchanges without history

closes #10570
This commit is contained in:
Matthias 2024-08-23 18:16:01 +02:00
parent 235d38752c
commit 01b7ad4a3f
2 changed files with 29 additions and 0 deletions

View File

@ -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().

View File

@ -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",
[