backtest-kit-redis-postgres-pgpool-docker provides two ways to run your strategy: a local run where Node.js executes on your host machine against dockerized infrastructure, and a full Docker deploy where the strategy, runner, andDocumentation 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.
backtest-kit container are bundled together. This page walks through both paths.
You need Docker, Docker Compose, and Node.js 20+ installed before
continuing. Clone the repository and run
npm install first.- Local Run
- Full Docker Deploy
The local path runs Node.js on your host machine while PostgreSQL (via Pgpool-II) and Redis run in containers. This is the fastest development loop because you can edit and rebuild without rebuilding a Docker image.
This starts the
tripolskypetr/pgpool:latest all-in-one container, which boots one primary + two streaming replicas behind a Pgpool-II proxy, all reachable on :5432. Writes are routed to the primary; reads are load-balanced across the replicas.First boot takes 60–90 seconds while the two replicas clone from the
primary. The healthcheck has a
start_period of 120 s to account for
this. Wait until docker ps shows the container as healthy before
proceeding to the next step.This starts
redis:7.4.1 on :6379 with password mysecurepassword. Data is bind-mounted to docker/redis/redis_data/ so it survives restarts.CC_REDIS_HOST=host.docker.internal
CC_POSTGRES_CONNECTION_STRING=postgres://backtest:mysecurepassword@host.docker.internal:5432/backtest-pro
host.docker.internal resolves to your host machine from inside
containers. For a purely host-side run the Node process reads .env
directly, so host.docker.internal is substituted at runtime. No
changes are needed for a standard local setup.The CLI accepts
--entry (required to actually execute), a mode flag, and an optional --ui flag that enables the web dashboard on :60050. Pass the compiled strategy bundle as the final positional argument. Backtest
Replay historical candles over the configured time window:The
backtest.ts entry point warms the candle cache via warmCandles() and then calls Backtest.background(). Both Postgres and Redis are fully initialized before any strategy code runs. Live
Connect to a live exchange feed:The
live.ts entry point skips candle warming and calls Live.background() directly. Real order execution is active in this mode — use paper mode for dry runs. Paper
Forward-test without real orders:The
paper.ts entry point follows the same runtime path as live mode but without sending orders to the exchange. Ideal for validating a strategy before going live.Open http://localhost:60050 in your browser. The
--ui flag instructs @backtest-kit/cli to serve the web dashboard, where you can monitor open signals, equity curves, and strategy logs in real time.Environment Variables Reference
The container and the CLI both consume variables from.env. The full set of recognized variables:
| Variable | Purpose | Default |
|---|---|---|
MODE | Running mode: backtest | live | paper | — |
STRATEGY_FILE | Path to the compiled strategy bundle | ./build/index.cjs |
ENTRY | Set to 1 to actually run (mirrors --entry CLI flag) | — |
UI | Set to 1 to enable the web dashboard on :60050 | — |
SYMBOL | Override strategy symbol context | — |
STRATEGY | Override strategy name context | — |
EXCHANGE | Override exchange name context | — |
FRAME | Override frame name context | — |
TELEGRAM | Enable Telegram notifications | — |
VERBOSE | Enable verbose logging | — |
NO_CACHE | Disable the Redis read cache | — |
NO_FLUSH | Skip cache flush on startup | — |
CC_POSTGRES_CONNECTION_STRING | Full Postgres connection string | see .env.example |
CC_REDIS_HOST | Redis hostname | host.docker.internal |
CC_REDIS_PORT | Redis port | 6379 |
CC_REDIS_USER | Redis username | default |
CC_REDIS_PASSWORD | Redis password | mysecurepassword |
CLI Flags
When running locally vianpm run start, the flags are passed directly to @backtest-kit/cli:
| Flag | Type | Description |
|---|---|---|
--entry | boolean | Required. Without it, every main() function returns immediately and nothing runs. |
--backtest | boolean | Select backtest mode. Mutually exclusive with --live and --paper. |
--live | boolean | Select live trading mode. |
--paper | boolean | Select paper trading mode. |
--ui | boolean | Enable the web dashboard on :60050. The strategy bundle path is passed as a positional argument (e.g. ./build/index.cjs). |
Single-Node Postgres for CI
The Pgpool-II cluster is designed for development and production. If you need a simpler setup — for example, in a CI pipeline where the replica boot delay is unacceptable — use the single-node alternative:postgres:16-alpine directly on :5432 with the same credentials as the cluster. The .env.example connection string works without modification.