Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/backtest-kit/backtest-monorepo-parallel/llms.txt

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

The file config/setup.config.ts is the single place in the monorepo that decides which storage adapter each backtest-kit subsystem uses. Live modes write to Mongo for durability; backtest replay modes use in-memory or local-file adapters so they never block on disk I/O during the hot loop. Switching any subsystem to a different adapter — including a custom one — is a one-line change in this file.

Full file listing

// config/setup.config.ts
import { setup } from "@backtest-kit/mongo";

import {
  Markdown,
  StorageLive,
  StorageBacktest,
  NotificationLive,
  NotificationBacktest,
  RecentLive,
  RecentBacktest,
  Dump,
  MemoryLive,
  MemoryBacktest,
  StateLive,
  StateBacktest,
  SessionLive,
  SessionBacktest,
  Log,
} from "backtest-kit";

{
  Dump.useMarkdown();
}

{
  SessionLive.usePersist();
  SessionBacktest.useLocal();
}

{
  StorageLive.usePersist();
  StorageBacktest.useMemory();
}

{
  RecentLive.usePersist();
  RecentBacktest.useMemory();
}

{
  NotificationLive.usePersist();
  NotificationBacktest.useMemory();
}

{
  RecentLive.usePersist();
  RecentBacktest.useMemory();
}

{
  MemoryLive.usePersist();
  MemoryBacktest.useLocal();
}

{
  StateLive.usePersist();
  StateBacktest.useLocal();
}

{
  Markdown.useDummy();
  Log.useJsonl();
}

setup();

Adapter table

Each subsystem has two sides: Live (used during --live and --paper runs) and Backtest (used during --backtest runs). The current configuration is:
SubsystemLive adapterBacktest adapter
DumpDump.useMarkdown() — Markdown serialisersame Markdown serialiser
SessionSessionLive.usePersist() — MongoSessionBacktest.useLocal() — local file
StorageStorageLive.usePersist() — MongoStorageBacktest.useMemory() — in-process RAM
RecentRecentLive.usePersist() — MongoRecentBacktest.useMemory() — in-process RAM
NotificationNotificationLive.usePersist() — MongoNotificationBacktest.useMemory() — in-process RAM
MemoryMemoryLive.usePersist() — MongoMemoryBacktest.useLocal() — local file
StateStateLive.usePersist() — MongoStateBacktest.useLocal() — local file
MarkdownMarkdown.useDummy() — no-opsame no-op
LogLog.useJsonl() — JSONL filesame JSONL file
Replacing any adapter in the table above is one line: swap the method call on the right-hand side. For example, to persist backtest storage to Mongo instead of memory, change StorageBacktest.useMemory() to StorageBacktest.usePersist(). The adapter interface is identical regardless of the backing store.

Why backtest uses memory and local file

Backtest replay is CPU-bound, not I/O-bound. At ~6 300× real-time aggregate throughput, the hot loop executes listenActivePing → getPositionEntries → commitAverageBuy at ~103 events/second across 9 parallel symbols in a single Node process. Writing transient state to Mongo on every tick would serialize on the Mongo connection pool and reduce that throughput dramatically.

Memory adapters

Subsystems like Storage, Recent, and Notification hold state that is only meaningful within a single replay run. Memory adapters eliminate all network round-trips for these, keeping the event loop hot.

Local-file adapters

Session, Memory, and State need to survive process restarts between debug sessions, so they write to local files. File I/O is still orders of magnitude faster than Mongo for the small, structured payloads these subsystems produce.
Live mode inverts these priorities: positions, sessions, and state must survive infrastructure restarts and be readable by external tooling (dashboards, audit logs), so every subsystem writes to Mongo via the usePersist() adapter.

Dump.useMarkdown()

Dump controls how the engine serialises position summaries for human review. useMarkdown() is the only call currently active for Dump, but Markdown.useDummy() is set immediately after — so the Markdown renderer itself is a no-op in the current configuration. To enable rendered Markdown output, replace Markdown.useDummy() with an active Markdown adapter (e.g. Markdown.useFile() if such an adapter is available in your backtest-kit version, or a custom implementation). The Dump.useMarkdown() call will then route summaries through that renderer.

Log.useJsonl()

Log is the structured logging channel used by Log.info(...), Log.debug(...), and related calls throughout strategy files and services. useJsonl() writes one JSON object per line to a .jsonl file, which is easy to tail, grep, and ingest into log-aggregation tooling. This adapter is shared between live and backtest modes — all runs produce machine-readable logs in the same format.

setup() — wiring the Mongo connection

The setup() call at the bottom of the file is imported from @backtest-kit/mongo. It reads CC_MONGO_CONNECTION_STRING from the environment (default: mongodb://localhost:27017/backtest-pro?wtimeoutMS=15000) and establishes the Mongoose connection that backs all usePersist() adapters and the @pro/core DbServices.
# .env (or docker-compose environment block)
CC_MONGO_CONNECTION_STRING=mongodb://localhost:27017/backtest-pro?wtimeoutMS=15000
setup() must remain the last statement in setup.config.ts. All usePersist() adapter registrations must complete before the connection is opened, or the adapters will not be bound to the Mongoose instance that setup() creates.

How to re-point a subsystem

1
Open config/setup.config.ts
2
Find the subsystem block you want to change
3
Each subsystem has its own scoped { } block. For example, to change how backtest sessions are stored:
4
{
  SessionLive.usePersist();
  SessionBacktest.useLocal();   // ← this line
}
5
Replace the method call
6
Change useLocal() to useMemory() or usePersist() (or a custom adapter method):
7
{
  SessionLive.usePersist();
  SessionBacktest.useMemory();  // ← changed to memory
}
8
Save and restart
9
No rebuild is needed — setup.config.ts is loaded at runtime by the loader config. Restart the process and the new adapter is active.

Build docs developers (and LLMs) love