backtest-kit-redis-postgres-pgpool-docker ships three execution modes — backtest, live, and paper — each gated by a pair of CLI flags and backed by a dedicated entry-point file inDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/theonetrade/backtest-kit-redis-postgres-pgpool-docker/llms.txt
Use this file to discover all available pages before exploring further.
src/main/. All three share the same strategy logic and persist adapters; only the data source (historical candles vs. live exchange feed) and position execution path differ.
CLI Flags and the getArgs() Helper
All CLI flags are parsed by src/helpers/getArgs.ts using Node’s built-in parseArgs. The result is memoised via singleshot so every module that calls getArgs() receives the same object:
| Flag | Type | Purpose |
|---|---|---|
--entry | boolean | Allows the strategy to actually execute. Without it, the module is imported but main() returns immediately — useful for REPL inspection. |
--backtest | boolean | Activates the backtest entry point (src/main/backtest.ts). |
--live | boolean | Activates the live trading entry point (src/main/live.ts). |
--paper | boolean | Activates the paper trading entry point (src/main/paper.ts). |
The
--ui flag (e.g. --ui ./build/index.cjs) is consumed by the @backtest-kit/cli runtime, not by getArgs. It tells the CLI which compiled bundle to load and enables the web UI on port :60050.Backtest Mode
Backtest mode replays historical candles stored in PostgreSQL, running the strategy tick-by-tick against the persisted OHLCV data. Because all data is local, an entire month of 1-minute candles can replay in seconds.Entry point: src/main/backtest.ts
warmCandles fetches OHLCV data from the registered exchange adapter and writes it to the candle-items table via the Candle persist adapter. The candles are fetched once and cached permanently, so subsequent replays of the same window do not hit the exchange.
Backtest.background starts the replay loop as a non-blocking background task. The frameName selects the time window and interval defined by addFrameSchema; strategyName selects the getSignal function registered by addStrategySchema.
CLI command
Docker Compose
Live Mode
Live mode connects to the exchange in real time, subscribes to the candle stream for each symbol, and callsgetSignal on every new closed candle. Positions are placed as real orders.
Entry point: src/main/live.ts
warmCandles or a frameName — the frame is only relevant to backtest replay. waitForReady(false) signals to the framework that look-ahead bias protection should not enforce a simulation timestamp ceiling.
CLI command
Docker Compose
Paper Mode
Paper mode uses the exact sameLive.background path as live mode, but the CLI and Docker environment route order execution to a simulated (paper) account — no real funds are used. The strategy, persist adapters, and web UI all behave identically to live mode.
Entry point: src/main/paper.ts
CLI command
Docker Compose
Mode Comparison
Backtest
Replays historical OHLCV data stored in PostgreSQL. Requires
warmCandles to pre-fill the candle cache and a frameName to define the replay window. Fastest feedback loop.Live
Streams real candles from the exchange via
getCandles in the registered exchange adapter. Places real orders. Requires valid API credentials in the exchange adapter.Paper
Uses the same live candle stream as live mode but simulates order execution with no real funds. Ideal for validating strategy behaviour in current market conditions.
Additional npm Scripts
- start
- start:debug
- start:repl
- start:docker
Builds the bundle with Rollup then starts the CLI. The
-- separator passes additional flags directly to the CLI binary.The --entry Flag: Module-Only vs. Execution Mode
Without --entry every main() function returns immediately after getArgs() is called. This means the strategy module is imported and registered (all addStrategySchema, addFrameSchema, addExchangeSchema calls run) but no connection to PostgreSQL or Redis is opened and no trading loop is started.
This is intentional: it lets tooling or the start:repl script load the module for introspection without triggering side-effects.
Web UI and Health Check
Pass--ui ./build/index.cjs (CLI) or set UI=1 (Docker) to enable the web UI served by @backtest-kit/ui on port 60050.
| URL | Purpose |
|---|---|
http://localhost:60050 | Strategy dashboard — open positions, closed signals, P&L curves |
http://localhost:60050/api/v1/health/health_check | Health check endpoint polled by Docker every 30 s |
unhealthy.
Backtest.background Call Pattern
When adding a new symbol or strategy context, follow this pattern in src/main/backtest.ts:
Backtest.background calls can run in parallel — each symbol gets its own independent replay loop. The persist adapters use (symbol, strategyName, exchangeName) as the unique context key, so there is no state bleed between symbols.