The Candle schema defines the MongoDB document structure for OHLCV candle data. It is the core persistence layer for the backtest candle cache — every call toDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/theonetrade/backtest-monorepo-parallel/llms.txt
Use this file to discover all available pages before exploring further.
cacheCandles() in backtest.ts ultimately writes through this schema. The schema lives at packages/core/src/schema/Candle.schema.ts and is consumed exclusively by CandleDbService.
Supported Intervals
Theinterval field is constrained to the values in INTERVAL_ENUM. Any value outside this set will fail Mongoose validation.
ICandleDto — Write Interface
ICandleDto is the data-transfer object used when creating a new candle document. All fields are required.
The trading pair symbol, e.g.
"BTCUSDT".One of the
INTERVAL_ENUM values: "1m" | "3m" | "5m" | "15m" | "30m" | "1h" | "2h" | "4h" | "6h" | "8h" | "1d".Unix timestamp in milliseconds for the candle open time.
Opening price of the candle.
Highest price during the candle period.
Lowest price during the candle period.
Closing price of the candle.
Traded volume during the candle period.
ICandleRow — Read Interface
ICandleRow extends ICandleDto with fields added by Mongoose after a document is persisted.
String-serialized MongoDB
_id (via readTransform).Always
"ccxt_binance" — hardcoded by CandleDbService. See EXCHANGE_NAME constant below.Document creation timestamp, mapped from Mongoose
timestamps.createdAt.Last-update timestamp, mapped from Mongoose
timestamps.updatedAt.Compound Unique Index
{ symbol, interval, timestamp }. This guarantees no duplicate candles per symbol/interval/timestamp combination, regardless of how many times cacheCandles() is called for overlapping ranges.
EXCHANGE_NAME Constant
CandleDbService hardcodes exchangeName to "ccxt_binance" for all writes and all lookups. The exchangeName field is included in the Mongoose filter for findBySymbolIntervalTimestamp to prevent cross-exchange collisions if the schema is ever reused for a different exchange.
CandleDbService
CandleDbService extends BaseCRUD(CandleModel) and adds three candle-specific methods on top of the inherited CRUD operations.
CandleDbService Methods
Upserts a candle using
findOneAndUpdate with $setOnInsert. The filter is { symbol, interval, timestamp } — if a matching document already exists it is returned unchanged. This makes create fully idempotent and safe to call multiple times for the same candle (e.g. during overlapping cacheCandles calls).hasCandle(symbol, interval, timestamp)
(symbol: string, interval: CandleInterval, timestamp: number) => Promise<boolean>
Convenience wrapper around
findBySymbolIntervalTimestamp. Returns true if a candle exists for the given symbol, interval, and timestamp, otherwise false.findBySymbolIntervalTimestamp(symbol, interval, timestamp)
(symbol: string, interval: CandleInterval, timestamp: number) => Promise<ICandleRow | null>
Exact lookup by
{ symbol, interval, exchangeName: 'ccxt_binance', timestamp }. Returns the ICandleRow document or null if not found. Delegates to BaseCRUD.findByFilter().