Skip to main content

Documentation Index

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

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

Running a live trading bot in Docker gives you zero-downtime operation, automatic restarts on crashes, and a clean separation between your strategy code and the host machine. Backtest Kit’s @backtest-kit/cli --docker flag scaffolds a self-contained workspace — complete with a docker-compose.yaml, a strategy entry point, and a healthcheck endpoint — so you can go from a local backtest to a containerized live bot without writing any infrastructure code yourself.

Quick Setup

Generate the Docker workspace with a single CLI command, then start your bot with the desired symbol and strategy file:
npx @backtest-kit/cli --docker
cd backtest-kit-docker
MODE=live SYMBOL=TRXUSDT STRATEGY_FILE=./content/feb_2026/feb_2026.strategy.ts docker-compose up -d
docker-compose logs -f
The --docker flag creates a backtest-kit-docker/ directory (override with --output) containing:
backtest-kit-docker/
├── docker-compose.yaml         # ready-to-run service definition with healthcheck
├── .env.example                # environment variable reference
├── package.json
├── tsconfig.json
└── content/
    └── feb_2026/
        ├── feb_2026.strategy.ts
        └── modules/backtest.module.ts
The docker-compose.yaml includes a healthcheck stanza against http://localhost:60050/api/v1/health/health_check. The container is considered healthy only after the strategy process passes this check, preventing dependent services from starting prematurely.

Environment Variables

Three environment variables control the bot’s runtime behaviour:
VariableRequiredValuesDescription
MODEYeslive, backtest, paperExecution mode. Use paper to validate against live prices without placing real orders.
SYMBOLYese.g. TRXUSDT, BTCUSDTTrading pair passed to the strategy.
STRATEGY_FILEYespath inside the containerEntry-point TypeScript file for the strategy.
For live trading you must also provide exchange credentials:
VariableRequiredDescription
BINANCE_API_KEYLive modeBinance API key with trading permissions.
BINANCE_API_SECRETLive modeBinance API secret corresponding to the key.
Never hardcode API keys in your source files or docker-compose.yaml. Pass them exclusively via environment variables, a .env file that is listed in .gitignore, or a secrets management tool (Docker Secrets, HashiCorp Vault, AWS SSM). Leaked keys can result in total loss of the associated account.
A safe pattern using a .env file:
# .env  — add this file to .gitignore
MODE=live
SYMBOL=BTCUSDT
STRATEGY_FILE=./content/feb_2026/feb_2026.strategy.ts
BINANCE_API_KEY=your_key_here
BINANCE_API_SECRET=your_secret_here
docker-compose --env-file .env up -d

Auto-Restart on Crash

The generated docker-compose.yaml includes restart: always, which tells Docker to restart the container automatically whenever the process exits — whether due to a network error, an unhandled exception, or a host reboot:
services:
  bot:
    build: .
    restart: always          # auto-restart on any exit
    environment:
      - MODE=${MODE}
      - SYMBOL=${SYMBOL}
      - STRATEGY_FILE=${STRATEGY_FILE}
      - BINANCE_API_KEY=${BINANCE_API_KEY}
      - BINANCE_API_SECRET=${BINANCE_API_SECRET}
Backtest Kit’s crash-safe persistence layer ensures that position state is recovered on restart — open signals, DCA entries, and partial close history are all rehydrated from the ./dump/ directory (or MongoDB, if configured) before the strategy resumes ticking.

Running Multiple Symbols in Parallel

For multi-symbol deployments, @backtest-kit/cli supports a Multiple Symbol Parallel mode. Use the --entry flag to point the CLI at your own entry file where you call Backtest.background() or Live.background() for each symbol:
MODE=live ENTRY=1 STRATEGY_FILE=./src/multi-symbol.mjs docker-compose up -d
Inside your entry file you control the full symbol list:
import { Live } from "backtest-kit";

const symbols = ["BTCUSDT", "ETHUSDT", "SOLUSDT", "BNBUSDT", "TRXUSDT"];

for (const symbol of symbols) {
  Live.background(symbol, {
    strategyName: "my-strategy",
    exchangeName: "binance",
  });
}
This keeps all symbols inside a single container and a single Node.js process, sharing one MongoDB pool and one Redis pool with no IPC overhead. See the backtest-monorepo-parallel community repository for a complete reference implementation running 9 symbols in parallel.

Production Persistence with MongoDB and Redis

By default, Backtest Kit persists state to the local ./dump/ file tree. In production Docker deployments, file-based storage can be a reliability concern — container restarts may lose data if the volume is not mounted correctly, and concurrent writes under multiple symbols can create race conditions. The @backtest-kit/mongo package replaces all 15 persistence adapters with MongoDB as the source of truth and Redis as an O(1) lookup cache. Drop a single config/setup.config.ts into your project:
// config/setup.config.ts
import { setup } from "@backtest-kit/mongo";

setup();
Then configure the connection in your environment:
CC_MONGO_CONNECTION_STRING=mongodb://mongo:27017/backtest-kit
CC_REDIS_HOST=redis
CC_REDIS_PORT=6379
For a complete, battle-tested docker-compose.yaml that wires MongoDB, Redis, and the Backtest Kit container together, see the community repository:

backtest-kit-redis-mongo-docker

Production MongoDB + Redis + Docker stack with all 15 persistence adapters implemented, atomic findOneAndUpdate writes, O(1) Redis cache lookups, and a ready-to-run docker-compose.yaml. Drop-in upgrade for any Backtest Kit project that outgrows file-based storage.

Build docs developers (and LLMs) love