Skip to main content

Documentation 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.

backtest-kit-redis-mongo-docker upgrades the default file-based ./dump/ storage in backtest-kit to a production-grade dual-store: MongoDB as the source of truth and Redis as an O(1) ID lookup cache. All 15 IPersist* adapter contracts are implemented, so your strategy code, runners, and CLI entrypoint stay completely unchanged — only the persistence layer is swapped.

Quickstart

Run a backtest or live strategy in minutes with the local dev setup.

Deployment

One-command full Docker deployment with MongoDB, Redis, and the runner container.

Architecture

Understand the dual-store persistence model and how the 15 adapters fit together.

Persist Adapters

Full reference for all 15 MongoDB-backed IPersist* adapter implementations.

What this project does

backtest-kit ships a pluggable persistence interface. By default it writes state to JSON files in ./dump/. This repository replaces every adapter with a dual-store implementation:
  • MongoDB stores every record durably. findOneAndUpdate with upsert: true guarantees read-after-write consistency.
  • Redis caches compound context keys → MongoDB document IDs. Reads hit Redis first (O(1)); misses fall through to Mongo and backfill the cache automatically.
  • Look-ahead bias protection — every write adapter accepts a when: Date argument, preventing future data from influencing historical backtest results.

15 Adapters

All IPersist* interfaces implemented over MongoDB + Redis

O(1) Reads

Redis ID cache eliminates repeated compound-key Mongo queries

One Command

docker-compose up deploys the full stack instantly

Run modes

The project supports three distinct run modes, each gated by a CLI flag:
1

Backtest mode

Replays historical candle data from MongoDB. Candles are warmed from the exchange and stored once, then read repeatedly with zero latency.
npm run start -- --entry --backtest --ui ./build/index.cjs
2

Paper mode

Runs the live strategy against real market data without executing orders — ideal for forward-testing before going live.
npm run start -- --entry --paper --ui ./build/index.cjs
3

Live mode

Executes real trades on the configured exchange. Persists all state to MongoDB with full Redis caching.
npm run start -- --entry --live --ui ./build/index.cjs

Key sections

Environment Variables

Configure MongoDB connection strings, Redis host and credentials, and Docker env vars.

Writing a Strategy

Add frames, strategies, and signal logic backed by the MongoDB persistence layer.

Service Layer

MongooseService, RedisService, and the IoC container that wires all 33 services.

Atomicity & Guarantees

How read-after-write consistency and look-ahead bias protection are enforced.

Build docs developers (and LLMs) love