diff --git a/freqtrade/data/history/history_utils.py b/freqtrade/data/history/history_utils.py index 5c4bde06d..d370a80aa 100644 --- a/freqtrade/data/history/history_utils.py +++ b/freqtrade/data/history/history_utils.py @@ -391,6 +391,8 @@ def refresh_backtest_ohlcv_data( tf_mark = exchange.get_option("mark_ohlcv_timeframe") if candle_types: + for ct in candle_types: + exchange.verify_candle_type_support(ct) timeframes_with_candletype = [ (tf, ct) for ct in candle_types diff --git a/freqtrade/exchange/exchange.py b/freqtrade/exchange/exchange.py index dfa50a6be..6dd26c1a3 100644 --- a/freqtrade/exchange/exchange.py +++ b/freqtrade/exchange/exchange.py @@ -2895,9 +2895,10 @@ class Exchange: timeframe, candle_type=candle_type, since_ms=since_ms ) - if candle_type and candle_type not in (CandleType.SPOT, CandleType.FUTURES): - params.update({"price": str(candle_type)}) if candle_type != CandleType.FUNDING_RATE: + if candle_type and candle_type not in (CandleType.SPOT, CandleType.FUTURES): + self.verify_candle_type_support(candle_type) + params.update({"price": str(candle_type)}) data = await self._api_async.fetch_ohlcv( pair, timeframe=timeframe, since=since_ms, limit=candle_limit, params=params ) @@ -2962,6 +2963,30 @@ class Exchange: data = [[x["timestamp"], x["fundingRate"], 0, 0, 0, 0] for x in data] return data + def verify_candle_type_support(self, candle_type: CandleType) -> None: + """ + Verify that the exchange supports the given candle type. + :param candle_type: CandleType to verify + :raises OperationalException: if the candle type is not supported + """ + if candle_type == CandleType.FUNDING_RATE: + if not self.exchange_has("fetchFundingRateHistory"): + raise OperationalException( + f"Exchange {self._api.name} does not support fetching funding rate history." + ) + elif candle_type not in (CandleType.SPOT, CandleType.FUTURES): + mapping = { + CandleType.MARK: "fetchMarkOHLCV", + CandleType.INDEX: "fetchIndexOHLCV", + CandleType.PREMIUMINDEX: "fetchPremiumIndexOHLCV", + CandleType.FUNDING_RATE: "fetchFundingRateHistory", + } + _method = mapping.get(candle_type, "fetchOHLCV") + if not self.exchange_has(_method): + raise OperationalException( + f"Exchange {self._api.name} does not support fetching {candle_type} candles." + ) + # fetch Trade data stuff def needed_candle_for_trades_ms(self, timeframe: str, candle_type: CandleType) -> int: