Skip to main content

Documentation 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-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, and 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.
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.
1
Start the Pgpool-II cluster
2
docker-compose -f docker/pgpool/docker-compose.yaml up -d
3
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.
4
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.
5
Start Redis
6
docker-compose -f docker/redis/docker-compose.yaml up -d
7
This starts redis:7.4.1 on :6379 with password mysecurepassword. Data is bind-mounted to docker/redis/redis_data/ so it survives restarts.
8
Copy the environment file
9
cp .env.example .env
10
The example file ships with the correct defaults for the local cluster:
11
CC_REDIS_HOST=host.docker.internal
CC_POSTGRES_CONNECTION_STRING=postgres://backtest:mysecurepassword@host.docker.internal:5432/backtest-pro
12
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.
13
Choose a mode and run
14
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.
15
Backtest
Replay historical candles over the configured time window:
npm run start -- --entry --backtest --ui ./build/index.cjs
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:
npm run start -- --entry --live --ui ./build/index.cjs
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:
npm run start -- --entry --paper --ui ./build/index.cjs
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.
16
Verify the web UI
17
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.
18
The container healthcheck also polls http://localhost:60050/api/v1/health/health_check every 30 seconds, so a healthy response confirms the full stack is running.

Environment Variables Reference

The container and the CLI both consume variables from .env. The full set of recognized variables:
VariablePurposeDefault
MODERunning mode: backtest | live | paper
STRATEGY_FILEPath to the compiled strategy bundle./build/index.cjs
ENTRYSet to 1 to actually run (mirrors --entry CLI flag)
UISet to 1 to enable the web dashboard on :60050
SYMBOLOverride strategy symbol context
STRATEGYOverride strategy name context
EXCHANGEOverride exchange name context
FRAMEOverride frame name context
TELEGRAMEnable Telegram notifications
VERBOSEEnable verbose logging
NO_CACHEDisable the Redis read cache
NO_FLUSHSkip cache flush on startup
CC_POSTGRES_CONNECTION_STRINGFull Postgres connection stringsee .env.example
CC_REDIS_HOSTRedis hostnamehost.docker.internal
CC_REDIS_PORTRedis port6379
CC_REDIS_USERRedis usernamedefault
CC_REDIS_PASSWORDRedis passwordmysecurepassword

CLI Flags

When running locally via npm run start, the flags are passed directly to @backtest-kit/cli:
FlagTypeDescription
--entrybooleanRequired. Without it, every main() function returns immediately and nothing runs.
--backtestbooleanSelect backtest mode. Mutually exclusive with --live and --paper.
--livebooleanSelect live trading mode.
--paperbooleanSelect paper trading mode.
--uibooleanEnable 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:
docker-compose -f docker/postgres/docker-compose.yaml up -d
This starts postgres:16-alpine directly on :5432 with the same credentials as the cluster. The .env.example connection string works without modification.
The single-node container hides stale-read bugs. A write followed by a separate SELECT always looks correct on one node because all I/O goes through the same process. Use the Pgpool cluster for any testing that involves concurrent writes or connection pooling.
The schema (tables, unique indexes) is created automatically on first connect via TypeORM synchronize: true. There is no manual migration step for either the cluster or the single-node alternative.

Build docs developers (and LLMs) love