"""OHLCV resampling — replaces `technical.util.resample_to_interval`. That was the only symbol this project imported from `technical`, which in turn pulled in the freqtrade dependency chain. Behaviour is preserved exactly, including the left-labelled bins (rows are candle *open* times) and the `dropna()` that drops empty intervals. """ from __future__ import annotations import pandas as pd __all__ = ["TICKER_INTERVAL_MINUTES", "resample_to_interval"] TICKER_INTERVAL_MINUTES: dict[str, int] = { "1m": 1, "5m": 5, "15m": 15, "30m": 30, "1h": 60, "60m": 60, "2h": 120, "4h": 240, "6h": 360, "12h": 720, "1d": 1440, "1w": 10080, } _OHLC_AGG = { "open": "first", "high": "max", "low": "min", "close": "last", "volume": "sum", } def resample_to_interval(dataframe: pd.DataFrame, interval: int | str) -> pd.DataFrame: """Resample OHLCV rows to `interval` minutes (or a timeframe string). Merging the result back onto a finer frame requires care to avoid lookahead bias; this function only resamples. """ if isinstance(interval, str): interval = TICKER_INTERVAL_MINUTES[interval] df = dataframe.copy() df = df.set_index(pd.DatetimeIndex(df["date"])) df = df.resample(f"{interval}min", label="left").agg(_OHLC_AGG).dropna() df.reset_index(inplace=True) return df