Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/backtest-kit/backtest-kit-redis-mongo-docker/llms.txt

Use this file to discover all available pages before exploring further.

Persist adapters are the bridge between the backtest-kit engine and your storage infrastructure. Each adapter implements a corresponding IPersist*Instance interface defined by backtest-kit, and is registered once at startup via a static usePersist*Adapter call. When the engine needs to read or write strategy data, it instantiates the adapter class with a set of context fields — the exact combination of constructor arguments that uniquely identifies one logical slot (e.g. one symbol + strategy + exchange). The adapter is then responsible for resolving or persisting that slot to MongoDB, using Redis to cache the MongoDB _id so that subsequent reads skip the full filter query and go straight to a fast findById.

Common adapter skeleton

Every adapter in this project follows the same four-part pattern:
PersistXAdapter.usePersistXAdapter(class implements IPersistXInstance {
  constructor(/* context fields from backtest-kit */) {}

  async waitForInit(initial: boolean) {
    if (!initial) return;
    await waitForInfra();  // gate first-touch on Mongo + Redis ready
  }

  async readXData(...) {
    return await ioc.xDbService.findByContext(...);
  }

  async writeXData(..., when: Date) {
    await ioc.xDbService.upsert(..., when);
  }
});
waitForInfra is a singleshot-wrapped promise that resolves once both MongoDB and Redis have confirmed connectivity. The initial guard ensures the infra gate is only awaited on the very first instantiation, not on every subsequent context construction.

All 15 adapters at a glance

AdapterInterfaceCollectionContext keyPurpose
CandleIPersistCandleInstancecandle-items(symbol, interval, timestamp)OHLCV cache; immutable inserts
SignalIPersistSignalInstancesignal-items(symbol, strategyName, exchangeName)Live signal state per context
ScheduleIPersistScheduleInstanceschedule-items(symbol, strategyName, exchangeName)Pending scheduled signal
RiskIPersistRiskInstancerisk-items(riskName, exchangeName)Active risk positions snapshot
PartialIPersistPartialInstancepartial-items(symbol, strategyName, exchangeName, signalId)Partial profit/loss levels per signal
BreakevenIPersistBreakevenInstancebreakeven-items(symbol, strategyName, exchangeName, signalId)Breakeven reached flag
StorageIPersistStorageInstancestorage-items(backtest, signalId)Closed/opened signal log per mode
NotificationIPersistNotificationInstancenotification-items(backtest, notificationId)Event notifications
LogIPersistLogInstancelog-items(entryId)Strategy log entries
MeasureIPersistMeasureInstancemeasure-items(bucket, entryKey)LLM/API response cache (soft-delete)
IntervalIPersistIntervalInstanceinterval-items(bucket, entryKey)Once-per-interval markers (soft-delete)
MemoryIPersistMemoryInstancememory-items(signalId, bucketName, memoryId)Per-signal memory store (soft-delete)
RecentIPersistRecentInstancerecent-items(symbol, strategyName, exchangeName, frameName, backtest)Last public signal per context
StateIPersistStateInstancestate-items(signalId, bucketName)Per-signal state buckets
SessionIPersistSessionInstancesession-items(strategyName, exchangeName, frameName)One session per running strategy

Detailed adapter pages

Candle

OHLCV candle persistence with $setOnInsert immutability and compound unique index on (symbol, interval, timestamp).

Signal & Schedule

Live signal state and pending scheduled signal per (symbol, strategyName, exchangeName) context with Redis caching.

Risk / Partial / Breakeven

Signal-affecting adapters that store position snapshots, partial P&L levels, and breakeven flags — all with when: Date look-ahead bias protection.

Storage / Notification / Log

Audit trail adapters for closed/opened signals, event notifications, and strategy log entries, partitioned by backtest mode.

Measure / Interval / Memory

Soft-delete adapters for LLM response caching, once-per-interval markers, and per-signal key-value memory storage.

Recent / State / Session

Ongoing strategy state: last public signal per context, per-signal state buckets, and one session document per running strategy.

Build docs developers (and LLMs) love