The candle-fetching functions are the primary data source for strategies. They useDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/theonetrade/backtest-kit/llms.txt
Use this file to discover all available pages before exploring further.
AsyncLocalStorage to read the current execution context (symbol, timestamp, backtest flag) and align all requests to the correct interval boundary automatically, making it impossible to accidentally introduce look-ahead bias. Results are backed by a persistent file-based cache (PersistCandleAdapter) — a cache hit means all expected timestamps were found; a miss triggers a fresh fetch from the registered exchange adapter.
ICandleData
All candle functions return arrays ofICandleData:
timestamp is always the openTime of the candle, not the close time. A candle at 00:00 for a 15-minute interval covers the period [00:00, 00:15).getCandles
Fetch historical candles backwards from the current execution context timestamp.Trading pair symbol (e.g.,
"BTCUSDT").Candle time interval. One of:
"1m" | "3m" | "5m" | "15m" | "30m" | "1h" | "2h" | "4h" | "6h" | "8h" | "12h" | "1d".Number of candles to return.
alignedWhen = Math.floor(when / stepMs) * stepMs— rounded down to interval boundary.since = alignedWhen - limit * stepMs(inclusive start).alignedWhenis exclusive — the candle opening at that moment is still pending/incomplete and is never included.- Returns exactly
limitfully-closed candles.
when from the frame iterator) and live (uses Date.now() aligned to the minute).
getNextCandles
Fetch candles forward from the current execution context timestamp. Backtest only.Trading pair symbol.
Candle time interval.
Number of future candles to return.
alignedWhen is inclusive for getNextCandles — the first candle starts at the aligned timestamp. Range: [alignedWhen, alignedWhen + limit * stepMs).
getRawCandles
Fetch candles with flexible date range and limit combinations.Trading pair symbol.
Candle time interval.
Optional number of candles to fetch.
Optional start date in milliseconds (inclusive after alignment).
Optional end date in milliseconds (exclusive — the candle opening at
eDate is not included).limit | sDate | eDate | Behaviour |
|---|---|---|---|
| ✅ | — | — | limit candles backward from context when |
| ✅ | ✅ | — | limit candles forward from align(sDate) |
| ✅ | — | ✅ | limit candles ending before align(eDate) |
| — | ✅ | ✅ | All candles in [align(sDate), align(eDate)) |
| ✅ | ✅ | ✅ | limit candles starting at align(sDate) |
eDate or the calculated end timestamp must not exceed the current execution when.
getAveragePrice
Calculate the VWAP (Volume Weighted Average Price) from the lastCC_AVG_PRICE_CANDLES_COUNT 1-minute candles (default: 5 candles).
Trading pair symbol.
VWAP = Σ(typicalPrice × volume) / Σ(volume) where typicalPrice = (high + low + close) / 3. Falls back to a simple average of close prices if volume is zero.
Persistent Cache Behavior
The cache usesPersistCandleAdapter with a file-based backend by default. On every getCandles or getNextCandles call:
- Cache key is computed as the aligned
sincetimestamp. - Cache hit — all expected timestamps (
since + i * stepMsfori = 0..limit-1) are present → returns cached candles immediately. - Cache miss — any timestamp is absent → calls the exchange adapter’s
getCandlesimplementation, validates the result (first candle must matchsince), then writes to cache.
closeTime > now) are never written to cache. Switch the adapter with PersistCandleAdapter.useDummy() (disable caching) or PersistCandleAdapter.usePersistCandleAdapter(CustomCtor) (custom backend).
Cache Management Utilities
checkCandles
Validate that candles for a given date range are present in the persistent cache. Issues one ranged read — if any expected timestamp is missing, the check fails without loading the full dataset.warmCandles
Pre-populate the persistent cache for a symbol and interval by downloading all candles fromfrom to to via the registered exchange adapter.
cacheCandles
Run a combined check-then-warm flow with one retry. First validates the cache; on a miss, downloads the missing data viawarmCandles and re-validates. Lifecycle callbacks allow progress reporting.