The Candle adapter is the only insert-only adapter in the stack. Rather than overwriting existing candle data, it uses aDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/theonetrade/backtest-kit-redis-mongo-docker/llms.txt
Use this file to discover all available pages before exploring further.
$setOnInsert strategy so that historical OHLCV bars written during a backtest run are never clobbered by a subsequent run over the same time range. Reads reconstruct a contiguous candle array by stepping through timestamps at the correct interval cadence and returning null if any bar in the requested window is missing.
Constructor
The trading pair symbol, e.g.
"BTCUSDT".The candle timeframe. Must be one of the supported values listed below.
The exchange identifier. In the default implementation the value
"ccxt_binance" is hardcoded inside CandleDbService and is used as part of the Redis cache key.Supported Intervals
The adapter resolves eachCandleInterval to a millisecond step size using the following map:
INTERVAL_MINUTES[interval] * MS_PER_MINUTE.
Methods
writeCandlesData
Persists an array ofCandleData objects to the candle-items collection. Each candle is written individually with an insert-only upsert — if a document already exists for the (symbol, interval, timestamp) triple, the write is a no-op.
Array of candle objects. Each entry must include
timestamp, open, high, low, close, and volume.candleDbService.create uses MongoDB’s $setOnInsert operator under the hood. Duplicate
(symbol, interval, timestamp) entries are silently skipped rather than overwritten.readCandlesData
Reconstructs a contiguous window of candles starting atsinceTimestamp by fetching exactly limit bars, each separated by the interval step size. If any bar in the window is absent from MongoDB, the method returns null immediately.
The number of candles to retrieve. Must be a positive integer.
Unix timestamp in milliseconds for the first candle in the window.
CandleData[] when all limit bars are present, or null if any bar is missing.
Redis Cache Key Format
Each candle lookup is backed by a Redis key with the following structure:1700000000000 maps to:
Collection
| Field | Value |
|---|---|
| Collection name | candle-items |
| Context key | (symbol, interval, timestamp) |
| Write strategy | Insert-only ($setOnInsert) |
| Soft delete | No |