Purpose and Scope: This page covers the installation process, package structure, module entry points, and build system configuration for the backtest-kit framework. For information about configuring strategies, exchanges, and frames after installation, see Configuration Functions. For architecture details and service layer setup, see Architecture and Dependency Injection System.
The backtest-kit framework requires TypeScript 5.0 or higher as a peer dependency. Ensure your project meets this requirement before installation.
Required peer dependency:
typescript: ^5.0.0Supported Node.js versions: Node.js 14.18.0 or higher (inferred from build tool requirements)
Install backtest-kit from npm:
npm install backtest-kit
This installs the framework along with its runtime dependencies:
di-kit (^1.0.18) - Dependency injection containerdi-scoped (^1.0.20) - Scoped context managementfunctools-kit (^1.0.93) - Functional programming utilitiesget-moment-stamp (^1.1.1) - Timestamp utilitiesThe distributed npm package contains three primary artifacts:
Package contents:
| File/Directory | Purpose | Referenced By |
|---|---|---|
build/index.cjs |
CommonJS entry point | main, exports.require |
build/index.mjs |
ES Module entry point | module, exports.import |
types.d.ts |
TypeScript type definitions | types, exports.types |
README.md |
Documentation | Package metadata |
The package supports both CommonJS and ES Modules through conditional exports:
import {
Backtest,
Live,
addStrategy,
addExchange,
addFrame
} from "backtest-kit";
Resolves to: build/index.mjs
const {
Backtest,
Live,
addStrategy,
addExchange,
addFrame
} = require("backtest-kit");
Resolves to: build/index.cjs
TypeScript automatically resolves types from types.d.ts for both import styles.
The package uses Rollup to compile TypeScript source into distributable JavaScript and type definitions.
The following npm scripts manage the build process:
| Script | Command | Purpose |
|---|---|---|
build |
rollup -c |
Compile source to build/ and generate types.d.ts |
build:docs |
rimraf docs && mkdir docs && node ./scripts/dts-docs.cjs ./types.d.ts ./docs |
Generate documentation from types |
docs:www |
rimraf docs/wwwroot && typedoc |
Generate TypeDoc HTML documentation |
The build system uses these plugins:
types.d.tsThe framework's runtime dependencies form a lightweight tree:
Key Dependencies:
Create a file verify-install.ts:
import { Backtest, Live, addExchange, addStrategy, addFrame } from "backtest-kit";
console.log("✓ Import successful");
console.log("Backtest:", typeof Backtest.run);
console.log("Live:", typeof Live.run);
console.log("addExchange:", typeof addExchange);
console.log("addStrategy:", typeof addStrategy);
console.log("addFrame:", typeof addFrame);
Run with:
npx ts-node verify-install.ts
Expected output:
✓ Import successful
Backtest: function
Live: function
addExchange: function
addStrategy: function
addFrame: function
npm list backtest-kit
Expected output:
your-project@1.0.0
└── backtest-kit@1.0.4
Understanding how public API functions map to internal implementation:
Key Export Mappings:
| Public Export | Source File | Internal Implementation |
|---|---|---|
Backtest |
src/lib/index.ts |
Service aggregator exposing BacktestLogicPublicService |
Live |
src/lib/index.ts |
Service aggregator exposing LiveLogicPublicService |
addStrategy |
src/function/add.ts |
Registers schema in StrategySchemaService |
addExchange |
src/function/add.ts |
Registers schema in ExchangeSchemaService |
addFrame |
src/function/add.ts |
Registers schema in FrameSchemaService |
getCandles |
src/function/exchange.ts |
Proxies to ExchangeGlobalService.getCandles |
getAveragePrice |
src/function/exchange.ts |
Proxies to ExchangeGlobalService.getAveragePrice |
Error:
npm ERR! peer typescript@"^5.0.0" from backtest-kit@1.0.4
Solution: Upgrade TypeScript to version 5.0 or higher:
npm install --save-dev typescript@^5.0.0
Error:
Cannot find module 'backtest-kit'
Solutions:
Ensure node_modules is not corrupted:
rm -rf node_modules package-lock.json
npm install
Check tsconfig.json has proper module resolution:
{
"compilerOptions": {
"moduleResolution": "node",
"esModuleInterop": true
}
}
Error:
Could not find a declaration file for module 'backtest-kit'
Solution: Verify types.d.ts exists in node_modules/backtest-kit/:
ls node_modules/backtest-kit/types.d.ts
If missing, reinstall:
npm install backtest-kit --force
If you're contributing to backtest-kit or need to build from source:
git clone https://github.com/tripolskypetr/backtest-kit
cd backtest-kit
npm install
npm run build
This generates:
build/index.cjs - CommonJS bundlebuild/index.mjs - ES Module bundletypes.d.ts - TypeScript definitions| Script | Purpose |
|---|---|
npm run build |
Compile TypeScript to distributable format |
npm run build:docs |
Generate markdown documentation from types |
npm run docs:www |
Generate TypeDoc HTML documentation |
npm run repl |
Start interactive REPL for testing |
After successful installation:
addExchangeaddStrategyaddFrame