From 816ca2ea15cd79868471b4c0f25ec159528cf071 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sat, 6 Sep 2025 09:38:23 +0200 Subject: [PATCH] feat: add error in case of non-available informative dataframe --- freqtrade/strategy/informative_decorator.py | 5 +++++ tests/strategy/test_strategy_helpers.py | 16 +++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/freqtrade/strategy/informative_decorator.py b/freqtrade/strategy/informative_decorator.py index 167d8237e..ac9a2a1ad 100644 --- a/freqtrade/strategy/informative_decorator.py +++ b/freqtrade/strategy/informative_decorator.py @@ -133,6 +133,11 @@ def _create_and_merge_informative_pair( inf_metadata = {"pair": asset, "timeframe": timeframe} inf_dataframe = strategy.dp.get_pair_dataframe(asset, timeframe, candle_type) + if inf_dataframe.empty: + raise ValueError( + f"Informative dataframe for ({asset}, {timeframe}, {candle_type}) is empty. " + "Can't populate informative indicators." + ) inf_dataframe = populate_indicators_fn(strategy, inf_dataframe, inf_metadata) formatter: Any = None diff --git a/tests/strategy/test_strategy_helpers.py b/tests/strategy/test_strategy_helpers.py index 605579191..53e6501cf 100644 --- a/tests/strategy/test_strategy_helpers.py +++ b/tests/strategy/test_strategy_helpers.py @@ -380,9 +380,10 @@ def test_informative_decorator(mocker, default_conf_usdt, trading_mode): assert inf_pair in strategy.gather_informative_pairs() def test_historic_ohlcv(pair, timeframe, candle_type): - return data[ - (pair, timeframe or strategy.timeframe, CandleType.from_string(candle_type)) - ].copy() + return data.get( + (pair, timeframe or strategy.timeframe, CandleType.from_string(candle_type)), + pd.DataFrame(), + ).copy() mocker.patch( "freqtrade.data.dataprovider.DataProvider.historic_ohlcv", side_effect=test_historic_ohlcv @@ -405,3 +406,12 @@ def test_informative_decorator(mocker, default_conf_usdt, trading_mode): for _, dataframe in analyzed.items(): for col in expected_columns: assert col in dataframe.columns + + # Test non-available pairs + del data[("ETH/BTC", "1h", CandleType.SPOT)] + with pytest.raises( + ValueError, match=r"Informative dataframe for \(ETH\/BTC, 1h, spot\) is empty.*" + ): + strategy.advise_all_indicators( + {p: data[(p, strategy.timeframe, candle_def)] for p in ("XRP/USDT", "LTC/USDT")} + )