@backtest-kit/cli 10.1.0 → 11.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1854 -1854
- package/build/index.cjs +205 -193
- package/build/index.mjs +207 -195
- package/config/notification.config.mjs +13 -13
- package/config/symbol.config.mjs +460 -460
- package/docker/.env.example +2 -2
- package/docker/content/feb_2026/feb_2026.strategy.ts +11 -11
- package/docker/content/feb_2026/modules/backtest.module.ts +83 -83
- package/docker/docker-compose.yaml +46 -46
- package/docker/package.json +38 -38
- package/docker/tsconfig.json +36 -36
- package/package.json +126 -126
- package/template/average-buy.mustache +22 -22
- package/template/breakeven.mustache +21 -21
- package/template/cancel-scheduled.mustache +14 -14
- package/template/cancelled.mustache +21 -21
- package/template/close-pending.mustache +16 -16
- package/template/closed.mustache +23 -23
- package/template/opened.mustache +22 -22
- package/template/partial-loss.mustache +22 -22
- package/template/partial-profit.mustache +22 -22
- package/template/project/config/symbol.config.ts +460 -460
- package/template/project/package.mustache +28 -28
- package/template/risk.mustache +19 -19
- package/template/scheduled.mustache +22 -22
- package/template/signal-close.mustache +22 -22
- package/template/signal-info.mustache +20 -20
- package/template/signal-open.mustache +22 -22
- package/template/source/CLAUDE.md +160 -160
- package/template/trailing-stop.mustache +21 -21
- package/template/trailing-take.mustache +21 -21
package/build/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import * as BacktestKit from 'backtest-kit';
|
|
3
|
-
import { setConfig, Notification, Cron, Recent, Storage, Markdown, Report, Dump, State, Memory, MarkdownWriter, ReportWriter, PersistSignalAdapter, PersistRiskAdapter, PersistScheduleAdapter, PersistPartialAdapter, PersistBreakevenAdapter, PersistCandleAdapter, PersistStorageAdapter, PersistNotificationAdapter, PersistLogAdapter, PersistMeasureAdapter, PersistIntervalAdapter, PersistMemoryAdapter, PersistRecentAdapter, PersistStateAdapter, PersistSessionAdapter, Log, StorageLive, StorageBacktest, NotificationLive, NotificationBacktest, RecentLive, RecentBacktest, Broker, SessionLive, SessionBacktest, MemoryLive, MemoryBacktest, StateLive, StateBacktest, listExchangeSchema, addExchangeSchema, roundTicks, listFrameSchema, addFrameSchema, listenDoneLive, listenDoneBacktest, shutdown, listenSignal, listStrategySchema, overrideExchangeSchema, Backtest, System, Cache, Interval, alignToInterval, addWalkerSchema, overrideWalkerSchema, Walker, listenDoneWalker, Live, getCandles, checkCandles, warmCandles, listenRisk, listenStrategyCommit, listenSync, listenSignalNotify, Exchange } from 'backtest-kit';
|
|
4
|
-
import { getErrorMessage, errorData,
|
|
3
|
+
import { setConfig, emitters, Notification, Cron, Recent, Storage, Markdown, Report, Dump, State, Memory, MarkdownWriter, ReportWriter, PersistSignalAdapter, PersistRiskAdapter, PersistScheduleAdapter, PersistPartialAdapter, PersistBreakevenAdapter, PersistCandleAdapter, PersistStorageAdapter, PersistNotificationAdapter, PersistLogAdapter, PersistMeasureAdapter, PersistIntervalAdapter, PersistMemoryAdapter, PersistRecentAdapter, PersistStateAdapter, PersistSessionAdapter, Log, StorageLive, StorageBacktest, NotificationLive, NotificationBacktest, RecentLive, RecentBacktest, Broker, SessionLive, SessionBacktest, MemoryLive, MemoryBacktest, StateLive, StateBacktest, listExchangeSchema, addExchangeSchema, roundTicks, listFrameSchema, addFrameSchema, listenDoneLive, listenDoneBacktest, shutdown, listenSignal, listStrategySchema, overrideExchangeSchema, Backtest, System, Cache, Interval, alignToInterval, addWalkerSchema, overrideWalkerSchema, Walker, listenDoneWalker, Live, getCandles, checkCandles, warmCandles, listenRisk, listenStrategyCommit, listenSync, listenSignalNotify, Exchange } from 'backtest-kit';
|
|
4
|
+
import { singleshot, BehaviorSubject, getErrorMessage, errorData, str, compose, sleep, createAwaiter, execpool, queued, randomString, TIMEOUT_SYMBOL, typo, retry, trycatch, memoize, isObject } from 'functools-kit';
|
|
5
5
|
import fs, { constants, realpathSync } from 'fs';
|
|
6
6
|
import * as stackTrace from 'stack-trace';
|
|
7
7
|
import path, { join, resolve, dirname, basename, extname } from 'path';
|
|
@@ -65,6 +65,20 @@ setConfig({
|
|
|
65
65
|
CC_WALKER_MARKDOWN_TOP_N: 10,
|
|
66
66
|
});
|
|
67
67
|
|
|
68
|
+
const getEntrySubject = singleshot(() => {
|
|
69
|
+
const entrySubject = emitters["entrySubject"];
|
|
70
|
+
if (entrySubject) {
|
|
71
|
+
return entrySubject;
|
|
72
|
+
}
|
|
73
|
+
return new BehaviorSubject();
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
const main$h = () => {
|
|
77
|
+
const entrySubject = getEntrySubject();
|
|
78
|
+
entrySubject.subscribe((path) => console.log("Running", path));
|
|
79
|
+
};
|
|
80
|
+
main$h();
|
|
81
|
+
|
|
68
82
|
const ERROR_HANDLER_INSTALLED = Symbol.for("error-handler-installed");
|
|
69
83
|
function dumpStackTrace() {
|
|
70
84
|
const trace = stackTrace.get();
|
|
@@ -835,8 +849,6 @@ const notifyVerbose = singleshot(() => {
|
|
|
835
849
|
});
|
|
836
850
|
});
|
|
837
851
|
|
|
838
|
-
const entrySubject = new BehaviorSubject();
|
|
839
|
-
|
|
840
852
|
function killPid(pid, signal) {
|
|
841
853
|
try {
|
|
842
854
|
process.kill(pid, signal);
|
|
@@ -1060,7 +1072,7 @@ class BacktestMainService {
|
|
|
1060
1072
|
});
|
|
1061
1073
|
notifyVerbose();
|
|
1062
1074
|
}
|
|
1063
|
-
await
|
|
1075
|
+
await getEntrySubject().next(absolutePath);
|
|
1064
1076
|
Backtest.background(symbol, {
|
|
1065
1077
|
strategyName,
|
|
1066
1078
|
frameName,
|
|
@@ -1426,7 +1438,7 @@ class LiveMainService {
|
|
|
1426
1438
|
});
|
|
1427
1439
|
notifyVerbose();
|
|
1428
1440
|
}
|
|
1429
|
-
await
|
|
1441
|
+
await getEntrySubject().next(absolutePath);
|
|
1430
1442
|
Live.background(symbol, {
|
|
1431
1443
|
strategyName,
|
|
1432
1444
|
exchangeName,
|
|
@@ -1530,7 +1542,7 @@ class PaperMainService {
|
|
|
1530
1542
|
});
|
|
1531
1543
|
notifyVerbose();
|
|
1532
1544
|
}
|
|
1533
|
-
await
|
|
1545
|
+
await getEntrySubject().next(absolutePath);
|
|
1534
1546
|
Live.background(symbol, {
|
|
1535
1547
|
strategyName,
|
|
1536
1548
|
exchangeName,
|
|
@@ -1562,7 +1574,7 @@ class PaperMainService {
|
|
|
1562
1574
|
}
|
|
1563
1575
|
|
|
1564
1576
|
const getEnv = singleshot(() => {
|
|
1565
|
-
if (!
|
|
1577
|
+
if (!getEntrySubject().data) {
|
|
1566
1578
|
getEnv.clear();
|
|
1567
1579
|
}
|
|
1568
1580
|
return {
|
|
@@ -1655,7 +1667,7 @@ class FrontendProviderService {
|
|
|
1655
1667
|
if (!getArgs().values.ui) {
|
|
1656
1668
|
return;
|
|
1657
1669
|
}
|
|
1658
|
-
return
|
|
1670
|
+
return getEntrySubject().subscribe(this.enable);
|
|
1659
1671
|
});
|
|
1660
1672
|
}
|
|
1661
1673
|
}
|
|
@@ -1691,7 +1703,7 @@ class TelegramProviderService {
|
|
|
1691
1703
|
if (!getArgs().values.telegram) {
|
|
1692
1704
|
return;
|
|
1693
1705
|
}
|
|
1694
|
-
return
|
|
1706
|
+
return getEntrySubject().subscribe(this.enable);
|
|
1695
1707
|
});
|
|
1696
1708
|
}
|
|
1697
1709
|
}
|
|
@@ -3319,10 +3331,10 @@ init();
|
|
|
3319
3331
|
|
|
3320
3332
|
const MODES = ["backtest", "walker", "paper", "live", "pine", "editor", "dump", "pnldebug", "brokerdebug", "flush", "init", "docker", "help", "version"];
|
|
3321
3333
|
const ENTRY_PATH$1 = "./node_modules/@backtest-kit/cli/build/index.mjs";
|
|
3322
|
-
const HELP_TEXT$1 = `
|
|
3323
|
-
Example:
|
|
3324
|
-
|
|
3325
|
-
node ${ENTRY_PATH$1} --help
|
|
3334
|
+
const HELP_TEXT$1 = `
|
|
3335
|
+
Example:
|
|
3336
|
+
|
|
3337
|
+
node ${ENTRY_PATH$1} --help
|
|
3326
3338
|
`.trimStart();
|
|
3327
3339
|
const main$g = async () => {
|
|
3328
3340
|
if (!getEntry(import.meta.url)) {
|
|
@@ -3332,7 +3344,7 @@ const main$g = async () => {
|
|
|
3332
3344
|
if (MODES.some((mode) => values[mode])) {
|
|
3333
3345
|
return;
|
|
3334
3346
|
}
|
|
3335
|
-
process.stdout.write(`@backtest-kit/cli ${"
|
|
3347
|
+
process.stdout.write(`@backtest-kit/cli ${"11.0.0"}\n`);
|
|
3336
3348
|
process.stdout.write("\n");
|
|
3337
3349
|
process.stdout.write(`Run with --help to see available commands.\n`);
|
|
3338
3350
|
process.stdout.write("\n");
|
|
@@ -3672,7 +3684,7 @@ const main$a = async () => {
|
|
|
3672
3684
|
absolutePath = path.resolve(cwd, entryPoint);
|
|
3673
3685
|
await cli.resolveService.attachEntry(absolutePath);
|
|
3674
3686
|
}
|
|
3675
|
-
await
|
|
3687
|
+
await getEntrySubject().next(absolutePath);
|
|
3676
3688
|
};
|
|
3677
3689
|
main$a();
|
|
3678
3690
|
|
|
@@ -4283,183 +4295,183 @@ const main$2 = async () => {
|
|
|
4283
4295
|
main$2();
|
|
4284
4296
|
|
|
4285
4297
|
const ENTRY_PATH = "./node_modules/@backtest-kit/cli/build/index.mjs";
|
|
4286
|
-
const HELP_TEXT = `
|
|
4287
|
-
Usage:
|
|
4288
|
-
node index.mjs --<mode> [flags] [entry-point]
|
|
4289
|
-
|
|
4290
|
-
Modes:
|
|
4291
|
-
|
|
4292
|
-
--backtest <entry> Run strategy against historical candle data
|
|
4293
|
-
--walker <entry...> Run Walker A/B strategy comparison across multiple strategies
|
|
4294
|
-
--paper <entry> Paper trading (live prices, no real orders)
|
|
4295
|
-
--live <entry> Live trading with real orders
|
|
4296
|
-
--pine <entry> Execute a local .pine indicator file
|
|
4297
|
-
--editor Open the Pine Script visual editor in the browser
|
|
4298
|
-
--dump Fetch and save raw OHLCV candles
|
|
4299
|
-
--pnldebug Simulate PnL per minute for a given entry price and direction
|
|
4300
|
-
--brokerdebug Fire a single broker commit against the live broker adapter
|
|
4301
|
-
--flush <entry...> Delete report/log/markdown/agent folders from strategy dump dir
|
|
4302
|
-
--init Scaffold a new project in the current directory
|
|
4303
|
-
--docker Scaffold a Docker workspace for running strategies in a container
|
|
4304
|
-
--help Print this help message
|
|
4305
|
-
|
|
4306
|
-
Backtest flags:
|
|
4307
|
-
|
|
4308
|
-
--symbol <string> Trading pair (default: BTCUSDT)
|
|
4309
|
-
--strategy <string> Strategy name from addStrategySchema (default: first registered)
|
|
4310
|
-
--exchange <string> Exchange name from addExchangeSchema (default: first registered)
|
|
4311
|
-
--frame <string> Frame name from addFrameSchema (default: first registered)
|
|
4312
|
-
--cacheInterval <string> Comma-separated intervals to pre-cache (default: "1m, 15m, 30m, 4h")
|
|
4313
|
-
--noCache Skip candle cache warming before the run
|
|
4314
|
-
--noFlush Skip removing report/log/markdown/agent folders before backtest run
|
|
4315
|
-
--verbose Log every candle fetch to stdout
|
|
4316
|
-
--ui Start web dashboard at http://localhost:60050
|
|
4317
|
-
--telegram Send trade notifications to Telegram
|
|
4318
|
-
|
|
4319
|
-
Walker flags (--walker):
|
|
4320
|
-
|
|
4321
|
-
--symbol <string> Trading pair (default: BTCUSDT)
|
|
4322
|
-
--cacheInterval <string> Comma-separated intervals to pre-cache (default: "1m, 15m, 30m, 4h")
|
|
4323
|
-
--noCache Skip candle cache warming before the run
|
|
4324
|
-
--noFlush Skip removing report/log/markdown/agent folders before walker run
|
|
4325
|
-
--verbose Log every candle fetch to stdout
|
|
4326
|
-
--output <string> Output file base name (default: walker_{SYMBOL}_{TIMESTAMP})
|
|
4327
|
-
--json Save results as JSON to ./dump/<output>.json
|
|
4328
|
-
--markdown Save report as Markdown to ./dump/<output>.md
|
|
4329
|
-
|
|
4330
|
-
Each positional argument is a strategy entry point. All strategy files are loaded without
|
|
4331
|
-
changing process.cwd() — .env is read from the working directory only.
|
|
4332
|
-
addWalkerSchema is called automatically using the registered exchange and frame.
|
|
4333
|
-
After comparison completes the report is printed to stdout (or saved if --json/--markdown).
|
|
4334
|
-
|
|
4335
|
-
Module file ./modules/walker.module is loaded automatically if it exists.
|
|
4336
|
-
|
|
4337
|
-
Paper / Live flags:
|
|
4338
|
-
|
|
4339
|
-
--symbol <string> Trading pair (default: BTCUSDT)
|
|
4340
|
-
--strategy <string> Strategy name (default: first registered)
|
|
4341
|
-
--exchange <string> Exchange name (default: first registered)
|
|
4342
|
-
--verbose Log every candle fetch to stdout
|
|
4343
|
-
--ui Start web dashboard
|
|
4344
|
-
--telegram Send Telegram notifications
|
|
4345
|
-
|
|
4346
|
-
PineScript flags (--pine):
|
|
4347
|
-
|
|
4348
|
-
--symbol <string> Trading pair (default: BTCUSDT)
|
|
4349
|
-
--timeframe <string> Candle interval (default: 15m)
|
|
4350
|
-
--limit <string> Number of candles to fetch (default: 250)
|
|
4351
|
-
--when <string> End date — ISO 8601 or Unix ms (default: now)
|
|
4352
|
-
--exchange <string> Exchange name (default: first registered)
|
|
4353
|
-
--output <string> Output file base name without extension
|
|
4354
|
-
--json Save output as JSON array to <pine-dir>/dump/<output>.json
|
|
4355
|
-
--jsonl Save output as JSONL to <pine-dir>/dump/<output>.jsonl
|
|
4356
|
-
--markdown Save output as Markdown table to <pine-dir>/dump/<output>.md
|
|
4357
|
-
|
|
4358
|
-
Only plot() calls with display=display.data_window produce output columns.
|
|
4359
|
-
Module file ./modules/pine.module is loaded automatically if it exists.
|
|
4360
|
-
|
|
4361
|
-
Candle dump flags (--dump):
|
|
4362
|
-
|
|
4363
|
-
--symbol <string> Trading pair (default: BTCUSDT)
|
|
4364
|
-
--timeframe <string> Candle interval (default: 15m)
|
|
4365
|
-
--limit <string> Number of candles (default: 250)
|
|
4366
|
-
--when <string> End date — ISO 8601 or Unix ms (default: now)
|
|
4367
|
-
--exchange <string> Exchange name (default: first registered)
|
|
4368
|
-
--output <string> Output file base name (default: {SYMBOL}_{LIMIT}_{TIMEFRAME}_{TIMESTAMP})
|
|
4369
|
-
--json Save as JSON array to ./dump/<output>.json
|
|
4370
|
-
--jsonl Save as JSONL to ./dump/<output>.jsonl
|
|
4371
|
-
|
|
4372
|
-
Module file ./modules/dump.module is loaded automatically if it exists.
|
|
4373
|
-
|
|
4374
|
-
PnL debug flags (--pnldebug):
|
|
4375
|
-
|
|
4376
|
-
--symbol <string> Trading pair (default: BTCUSDT)
|
|
4377
|
-
--priceopen <number> Entry price (required)
|
|
4378
|
-
--direction <string> Position direction: long or short (default: long)
|
|
4379
|
-
--when <string> Start timestamp — ISO 8601 or Unix ms (default: now)
|
|
4380
|
-
--minutes <string> Number of 1m candles to simulate (default: 60)
|
|
4381
|
-
--exchange <string> Exchange name (default: first registered)
|
|
4382
|
-
--output <string> Output file base name (default: {SYMBOL}_{DIRECTION}_{PRICEOPEN}_{TIMESTAMP})
|
|
4383
|
-
--json Save as JSON array to ./dump/<output>.json
|
|
4384
|
-
--jsonl Save as JSONL to ./dump/<output>.jsonl
|
|
4385
|
-
--markdown Save as Markdown table to ./dump/<output>.md
|
|
4386
|
-
|
|
4387
|
-
Module file ./modules/pnldebug.module is loaded automatically if it exists.
|
|
4388
|
-
|
|
4389
|
-
Broker debug flags (--brokerdebug):
|
|
4390
|
-
|
|
4391
|
-
--symbol <string> Trading pair (default: BTCUSDT)
|
|
4392
|
-
--exchange <string> Exchange name (default: first registered)
|
|
4393
|
-
--commit <string> Commit type to fire: signal-open, signal-close, partial-profit,
|
|
4394
|
-
partial-loss, average-buy, trailing-stop, trailing-take, breakeven
|
|
4395
|
-
(default: signal-open)
|
|
4396
|
-
|
|
4397
|
-
Loads ./live.module, fetches the last candle for --symbol/--timeframe, and calls
|
|
4398
|
-
the selected broker commit with synthetic payload values derived from current price.
|
|
4399
|
-
|
|
4400
|
-
Flush flags (--flush):
|
|
4401
|
-
|
|
4402
|
-
One or more positional entry points. For each entry point the following
|
|
4403
|
-
subdirectories are removed from <entry-dir>/dump/:
|
|
4404
|
-
|
|
4405
|
-
report log markdown agent
|
|
4406
|
-
|
|
4407
|
-
Init flags (--init):
|
|
4408
|
-
|
|
4409
|
-
--output <string> Target directory name (default: backtest-kit-project)
|
|
4410
|
-
|
|
4411
|
-
Scaffolds a project and runs scripts/fetch_docs.mjs to download library docs.
|
|
4412
|
-
|
|
4413
|
-
Docker flags (--docker):
|
|
4414
|
-
|
|
4415
|
-
--output <string> Target directory name (default: backtest-kit-docker)
|
|
4416
|
-
|
|
4417
|
-
Scaffolds a Docker workspace: docker-compose.yaml, .env.example, package.json,
|
|
4418
|
-
tsconfig.json, and a sample strategy under content/. Run npm install then
|
|
4419
|
-
docker compose up to start the container.
|
|
4420
|
-
|
|
4421
|
-
Module hooks (loaded automatically by each mode):
|
|
4422
|
-
|
|
4423
|
-
modules/backtest.module --backtest Broker adapter for backtest
|
|
4424
|
-
modules/walker.module --walker Broker adapter for walker comparison
|
|
4425
|
-
modules/paper.module --paper Broker adapter for paper trading
|
|
4426
|
-
modules/live.module --live Broker adapter for live trading
|
|
4427
|
-
modules/pine.module --pine Exchange schema for PineScript runs
|
|
4428
|
-
modules/editor.module --editor Exchange schema for the visual Pine editor
|
|
4429
|
-
modules/dump.module --dump Exchange schema for candle dumps
|
|
4430
|
-
modules/pnldebug.module --pnldebug Exchange schema for PnL debug runs
|
|
4431
|
-
modules/brokerdebug.module --brokerdebug Broker adapter used for broker commit testing
|
|
4432
|
-
|
|
4433
|
-
--flush has no associated module. It only removes dump subdirectories.
|
|
4434
|
-
|
|
4435
|
-
Extensions .ts, .mjs, .cjs are tried automatically. Missing module = soft warning.
|
|
4436
|
-
|
|
4437
|
-
Environment variables:
|
|
4438
|
-
|
|
4439
|
-
CC_TELEGRAM_TOKEN Telegram bot token (required for --telegram)
|
|
4440
|
-
CC_TELEGRAM_CHANNEL Telegram channel or chat ID (required for --telegram)
|
|
4441
|
-
CC_WWWROOT_HOST UI server bind address (default: 0.0.0.0)
|
|
4442
|
-
CC_WWWROOT_PORT UI server port (default: 60050)
|
|
4443
|
-
|
|
4444
|
-
Examples:
|
|
4445
|
-
|
|
4446
|
-
node ${ENTRY_PATH} --backtest ./content/feb_2026.strategy.ts
|
|
4447
|
-
node ${ENTRY_PATH} --backtest --symbol BTCUSDT --noCache --noFlush --ui ./content/feb_2026.strategy.ts
|
|
4448
|
-
node ${ENTRY_PATH} --walker ./content/feb_2026_v1.strategy.ts ./content/feb_2026_v2.strategy.ts ./content/feb_2026_v3.strategy.ts
|
|
4449
|
-
node ${ENTRY_PATH} --walker --symbol BTCUSDT --noCache --noFlush --markdown ./content/feb_2026_v1.ts ./content/feb_2026_v2.ts
|
|
4450
|
-
node ${ENTRY_PATH} --paper --symbol ETHUSDT ./content/feb_2026.strategy.ts
|
|
4451
|
-
node ${ENTRY_PATH} --live --ui --telegram ./content/feb_2026.strategy.ts
|
|
4452
|
-
node ${ENTRY_PATH} --pine ./math/feb_2026.pine --timeframe 15m --limit 500 --jsonl
|
|
4453
|
-
node ${ENTRY_PATH} --editor
|
|
4454
|
-
node ${ENTRY_PATH} --dump --symbol BTCUSDT --timeframe 15m --limit 500 --jsonl
|
|
4455
|
-
node ${ENTRY_PATH} --pnldebug --symbol BTCUSDT --priceopen 64069.50 --direction short --when "2025-02-25" --minutes 120
|
|
4456
|
-
node ${ENTRY_PATH} --pnldebug --priceopen 67956.73 --direction long --when 1772064000000 --minutes 60 --markdown
|
|
4457
|
-
node ${ENTRY_PATH} --brokerdebug --commit signal-open --symbol BTCUSDT
|
|
4458
|
-
node ${ENTRY_PATH} --brokerdebug --commit partial-profit --symbol ETHUSDT
|
|
4459
|
-
node ${ENTRY_PATH} --flush ./content/feb_2026.strategy/feb_2026.strategy.ts
|
|
4460
|
-
node ${ENTRY_PATH} --flush ./content/feb_2026.strategy/feb_2026.strategy.ts ./content/feb_2026.strategy/feb_2026.test.ts
|
|
4461
|
-
node ${ENTRY_PATH} --init --output my-trading-bot
|
|
4462
|
-
node ${ENTRY_PATH} --docker --output my-docker-workspace
|
|
4298
|
+
const HELP_TEXT = `
|
|
4299
|
+
Usage:
|
|
4300
|
+
node index.mjs --<mode> [flags] [entry-point]
|
|
4301
|
+
|
|
4302
|
+
Modes:
|
|
4303
|
+
|
|
4304
|
+
--backtest <entry> Run strategy against historical candle data
|
|
4305
|
+
--walker <entry...> Run Walker A/B strategy comparison across multiple strategies
|
|
4306
|
+
--paper <entry> Paper trading (live prices, no real orders)
|
|
4307
|
+
--live <entry> Live trading with real orders
|
|
4308
|
+
--pine <entry> Execute a local .pine indicator file
|
|
4309
|
+
--editor Open the Pine Script visual editor in the browser
|
|
4310
|
+
--dump Fetch and save raw OHLCV candles
|
|
4311
|
+
--pnldebug Simulate PnL per minute for a given entry price and direction
|
|
4312
|
+
--brokerdebug Fire a single broker commit against the live broker adapter
|
|
4313
|
+
--flush <entry...> Delete report/log/markdown/agent folders from strategy dump dir
|
|
4314
|
+
--init Scaffold a new project in the current directory
|
|
4315
|
+
--docker Scaffold a Docker workspace for running strategies in a container
|
|
4316
|
+
--help Print this help message
|
|
4317
|
+
|
|
4318
|
+
Backtest flags:
|
|
4319
|
+
|
|
4320
|
+
--symbol <string> Trading pair (default: BTCUSDT)
|
|
4321
|
+
--strategy <string> Strategy name from addStrategySchema (default: first registered)
|
|
4322
|
+
--exchange <string> Exchange name from addExchangeSchema (default: first registered)
|
|
4323
|
+
--frame <string> Frame name from addFrameSchema (default: first registered)
|
|
4324
|
+
--cacheInterval <string> Comma-separated intervals to pre-cache (default: "1m, 15m, 30m, 4h")
|
|
4325
|
+
--noCache Skip candle cache warming before the run
|
|
4326
|
+
--noFlush Skip removing report/log/markdown/agent folders before backtest run
|
|
4327
|
+
--verbose Log every candle fetch to stdout
|
|
4328
|
+
--ui Start web dashboard at http://localhost:60050
|
|
4329
|
+
--telegram Send trade notifications to Telegram
|
|
4330
|
+
|
|
4331
|
+
Walker flags (--walker):
|
|
4332
|
+
|
|
4333
|
+
--symbol <string> Trading pair (default: BTCUSDT)
|
|
4334
|
+
--cacheInterval <string> Comma-separated intervals to pre-cache (default: "1m, 15m, 30m, 4h")
|
|
4335
|
+
--noCache Skip candle cache warming before the run
|
|
4336
|
+
--noFlush Skip removing report/log/markdown/agent folders before walker run
|
|
4337
|
+
--verbose Log every candle fetch to stdout
|
|
4338
|
+
--output <string> Output file base name (default: walker_{SYMBOL}_{TIMESTAMP})
|
|
4339
|
+
--json Save results as JSON to ./dump/<output>.json
|
|
4340
|
+
--markdown Save report as Markdown to ./dump/<output>.md
|
|
4341
|
+
|
|
4342
|
+
Each positional argument is a strategy entry point. All strategy files are loaded without
|
|
4343
|
+
changing process.cwd() — .env is read from the working directory only.
|
|
4344
|
+
addWalkerSchema is called automatically using the registered exchange and frame.
|
|
4345
|
+
After comparison completes the report is printed to stdout (or saved if --json/--markdown).
|
|
4346
|
+
|
|
4347
|
+
Module file ./modules/walker.module is loaded automatically if it exists.
|
|
4348
|
+
|
|
4349
|
+
Paper / Live flags:
|
|
4350
|
+
|
|
4351
|
+
--symbol <string> Trading pair (default: BTCUSDT)
|
|
4352
|
+
--strategy <string> Strategy name (default: first registered)
|
|
4353
|
+
--exchange <string> Exchange name (default: first registered)
|
|
4354
|
+
--verbose Log every candle fetch to stdout
|
|
4355
|
+
--ui Start web dashboard
|
|
4356
|
+
--telegram Send Telegram notifications
|
|
4357
|
+
|
|
4358
|
+
PineScript flags (--pine):
|
|
4359
|
+
|
|
4360
|
+
--symbol <string> Trading pair (default: BTCUSDT)
|
|
4361
|
+
--timeframe <string> Candle interval (default: 15m)
|
|
4362
|
+
--limit <string> Number of candles to fetch (default: 250)
|
|
4363
|
+
--when <string> End date — ISO 8601 or Unix ms (default: now)
|
|
4364
|
+
--exchange <string> Exchange name (default: first registered)
|
|
4365
|
+
--output <string> Output file base name without extension
|
|
4366
|
+
--json Save output as JSON array to <pine-dir>/dump/<output>.json
|
|
4367
|
+
--jsonl Save output as JSONL to <pine-dir>/dump/<output>.jsonl
|
|
4368
|
+
--markdown Save output as Markdown table to <pine-dir>/dump/<output>.md
|
|
4369
|
+
|
|
4370
|
+
Only plot() calls with display=display.data_window produce output columns.
|
|
4371
|
+
Module file ./modules/pine.module is loaded automatically if it exists.
|
|
4372
|
+
|
|
4373
|
+
Candle dump flags (--dump):
|
|
4374
|
+
|
|
4375
|
+
--symbol <string> Trading pair (default: BTCUSDT)
|
|
4376
|
+
--timeframe <string> Candle interval (default: 15m)
|
|
4377
|
+
--limit <string> Number of candles (default: 250)
|
|
4378
|
+
--when <string> End date — ISO 8601 or Unix ms (default: now)
|
|
4379
|
+
--exchange <string> Exchange name (default: first registered)
|
|
4380
|
+
--output <string> Output file base name (default: {SYMBOL}_{LIMIT}_{TIMEFRAME}_{TIMESTAMP})
|
|
4381
|
+
--json Save as JSON array to ./dump/<output>.json
|
|
4382
|
+
--jsonl Save as JSONL to ./dump/<output>.jsonl
|
|
4383
|
+
|
|
4384
|
+
Module file ./modules/dump.module is loaded automatically if it exists.
|
|
4385
|
+
|
|
4386
|
+
PnL debug flags (--pnldebug):
|
|
4387
|
+
|
|
4388
|
+
--symbol <string> Trading pair (default: BTCUSDT)
|
|
4389
|
+
--priceopen <number> Entry price (required)
|
|
4390
|
+
--direction <string> Position direction: long or short (default: long)
|
|
4391
|
+
--when <string> Start timestamp — ISO 8601 or Unix ms (default: now)
|
|
4392
|
+
--minutes <string> Number of 1m candles to simulate (default: 60)
|
|
4393
|
+
--exchange <string> Exchange name (default: first registered)
|
|
4394
|
+
--output <string> Output file base name (default: {SYMBOL}_{DIRECTION}_{PRICEOPEN}_{TIMESTAMP})
|
|
4395
|
+
--json Save as JSON array to ./dump/<output>.json
|
|
4396
|
+
--jsonl Save as JSONL to ./dump/<output>.jsonl
|
|
4397
|
+
--markdown Save as Markdown table to ./dump/<output>.md
|
|
4398
|
+
|
|
4399
|
+
Module file ./modules/pnldebug.module is loaded automatically if it exists.
|
|
4400
|
+
|
|
4401
|
+
Broker debug flags (--brokerdebug):
|
|
4402
|
+
|
|
4403
|
+
--symbol <string> Trading pair (default: BTCUSDT)
|
|
4404
|
+
--exchange <string> Exchange name (default: first registered)
|
|
4405
|
+
--commit <string> Commit type to fire: signal-open, signal-close, partial-profit,
|
|
4406
|
+
partial-loss, average-buy, trailing-stop, trailing-take, breakeven
|
|
4407
|
+
(default: signal-open)
|
|
4408
|
+
|
|
4409
|
+
Loads ./live.module, fetches the last candle for --symbol/--timeframe, and calls
|
|
4410
|
+
the selected broker commit with synthetic payload values derived from current price.
|
|
4411
|
+
|
|
4412
|
+
Flush flags (--flush):
|
|
4413
|
+
|
|
4414
|
+
One or more positional entry points. For each entry point the following
|
|
4415
|
+
subdirectories are removed from <entry-dir>/dump/:
|
|
4416
|
+
|
|
4417
|
+
report log markdown agent
|
|
4418
|
+
|
|
4419
|
+
Init flags (--init):
|
|
4420
|
+
|
|
4421
|
+
--output <string> Target directory name (default: backtest-kit-project)
|
|
4422
|
+
|
|
4423
|
+
Scaffolds a project and runs scripts/fetch_docs.mjs to download library docs.
|
|
4424
|
+
|
|
4425
|
+
Docker flags (--docker):
|
|
4426
|
+
|
|
4427
|
+
--output <string> Target directory name (default: backtest-kit-docker)
|
|
4428
|
+
|
|
4429
|
+
Scaffolds a Docker workspace: docker-compose.yaml, .env.example, package.json,
|
|
4430
|
+
tsconfig.json, and a sample strategy under content/. Run npm install then
|
|
4431
|
+
docker compose up to start the container.
|
|
4432
|
+
|
|
4433
|
+
Module hooks (loaded automatically by each mode):
|
|
4434
|
+
|
|
4435
|
+
modules/backtest.module --backtest Broker adapter for backtest
|
|
4436
|
+
modules/walker.module --walker Broker adapter for walker comparison
|
|
4437
|
+
modules/paper.module --paper Broker adapter for paper trading
|
|
4438
|
+
modules/live.module --live Broker adapter for live trading
|
|
4439
|
+
modules/pine.module --pine Exchange schema for PineScript runs
|
|
4440
|
+
modules/editor.module --editor Exchange schema for the visual Pine editor
|
|
4441
|
+
modules/dump.module --dump Exchange schema for candle dumps
|
|
4442
|
+
modules/pnldebug.module --pnldebug Exchange schema for PnL debug runs
|
|
4443
|
+
modules/brokerdebug.module --brokerdebug Broker adapter used for broker commit testing
|
|
4444
|
+
|
|
4445
|
+
--flush has no associated module. It only removes dump subdirectories.
|
|
4446
|
+
|
|
4447
|
+
Extensions .ts, .mjs, .cjs are tried automatically. Missing module = soft warning.
|
|
4448
|
+
|
|
4449
|
+
Environment variables:
|
|
4450
|
+
|
|
4451
|
+
CC_TELEGRAM_TOKEN Telegram bot token (required for --telegram)
|
|
4452
|
+
CC_TELEGRAM_CHANNEL Telegram channel or chat ID (required for --telegram)
|
|
4453
|
+
CC_WWWROOT_HOST UI server bind address (default: 0.0.0.0)
|
|
4454
|
+
CC_WWWROOT_PORT UI server port (default: 60050)
|
|
4455
|
+
|
|
4456
|
+
Examples:
|
|
4457
|
+
|
|
4458
|
+
node ${ENTRY_PATH} --backtest ./content/feb_2026.strategy.ts
|
|
4459
|
+
node ${ENTRY_PATH} --backtest --symbol BTCUSDT --noCache --noFlush --ui ./content/feb_2026.strategy.ts
|
|
4460
|
+
node ${ENTRY_PATH} --walker ./content/feb_2026_v1.strategy.ts ./content/feb_2026_v2.strategy.ts ./content/feb_2026_v3.strategy.ts
|
|
4461
|
+
node ${ENTRY_PATH} --walker --symbol BTCUSDT --noCache --noFlush --markdown ./content/feb_2026_v1.ts ./content/feb_2026_v2.ts
|
|
4462
|
+
node ${ENTRY_PATH} --paper --symbol ETHUSDT ./content/feb_2026.strategy.ts
|
|
4463
|
+
node ${ENTRY_PATH} --live --ui --telegram ./content/feb_2026.strategy.ts
|
|
4464
|
+
node ${ENTRY_PATH} --pine ./math/feb_2026.pine --timeframe 15m --limit 500 --jsonl
|
|
4465
|
+
node ${ENTRY_PATH} --editor
|
|
4466
|
+
node ${ENTRY_PATH} --dump --symbol BTCUSDT --timeframe 15m --limit 500 --jsonl
|
|
4467
|
+
node ${ENTRY_PATH} --pnldebug --symbol BTCUSDT --priceopen 64069.50 --direction short --when "2025-02-25" --minutes 120
|
|
4468
|
+
node ${ENTRY_PATH} --pnldebug --priceopen 67956.73 --direction long --when 1772064000000 --minutes 60 --markdown
|
|
4469
|
+
node ${ENTRY_PATH} --brokerdebug --commit signal-open --symbol BTCUSDT
|
|
4470
|
+
node ${ENTRY_PATH} --brokerdebug --commit partial-profit --symbol ETHUSDT
|
|
4471
|
+
node ${ENTRY_PATH} --flush ./content/feb_2026.strategy/feb_2026.strategy.ts
|
|
4472
|
+
node ${ENTRY_PATH} --flush ./content/feb_2026.strategy/feb_2026.strategy.ts ./content/feb_2026.strategy/feb_2026.test.ts
|
|
4473
|
+
node ${ENTRY_PATH} --init --output my-trading-bot
|
|
4474
|
+
node ${ENTRY_PATH} --docker --output my-docker-workspace
|
|
4463
4475
|
`.trimStart();
|
|
4464
4476
|
const main$1 = async () => {
|
|
4465
4477
|
if (!getEntry(import.meta.url)) {
|
|
@@ -4469,7 +4481,7 @@ const main$1 = async () => {
|
|
|
4469
4481
|
if (!values.help) {
|
|
4470
4482
|
return;
|
|
4471
4483
|
}
|
|
4472
|
-
process.stdout.write(`@backtest-kit/cli ${"
|
|
4484
|
+
process.stdout.write(`@backtest-kit/cli ${"11.0.0"}\n\n`);
|
|
4473
4485
|
process.stdout.write(HELP_TEXT);
|
|
4474
4486
|
process.exit(0);
|
|
4475
4487
|
};
|
|
@@ -4483,7 +4495,7 @@ const main = async () => {
|
|
|
4483
4495
|
if (!values.version) {
|
|
4484
4496
|
return;
|
|
4485
4497
|
}
|
|
4486
|
-
process.stdout.write(`@backtest-kit/cli ${"
|
|
4498
|
+
process.stdout.write(`@backtest-kit/cli ${"11.0.0"}\n`);
|
|
4487
4499
|
process.exit(0);
|
|
4488
4500
|
};
|
|
4489
4501
|
main();
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
export default {
|
|
2
|
-
signal: true,
|
|
3
|
-
risk: true,
|
|
4
|
-
info: true,
|
|
5
|
-
breakeven: true,
|
|
6
|
-
common_error: true,
|
|
7
|
-
critical_error: true,
|
|
8
|
-
validation_error: true,
|
|
9
|
-
partial_loss: false,
|
|
10
|
-
partial_profit: false,
|
|
11
|
-
signal_sync: false,
|
|
12
|
-
strategy_commit: true,
|
|
13
|
-
};
|
|
1
|
+
export default {
|
|
2
|
+
signal: true,
|
|
3
|
+
risk: true,
|
|
4
|
+
info: true,
|
|
5
|
+
breakeven: true,
|
|
6
|
+
common_error: true,
|
|
7
|
+
critical_error: true,
|
|
8
|
+
validation_error: true,
|
|
9
|
+
partial_loss: false,
|
|
10
|
+
partial_profit: false,
|
|
11
|
+
signal_sync: false,
|
|
12
|
+
strategy_commit: true,
|
|
13
|
+
};
|