@backtest-kit/cli 9.5.0 → 9.7.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.
Files changed (34) hide show
  1. package/README.md +1854 -1738
  2. package/build/index.cjs +302 -207
  3. package/build/index.mjs +302 -207
  4. package/config/notification.config.mjs +13 -13
  5. package/config/symbol.config.mjs +460 -460
  6. package/docker/.env.example +2 -2
  7. package/docker/README.md +1 -0
  8. package/docker/content/feb_2026/feb_2026.strategy.ts +11 -11
  9. package/docker/content/feb_2026/modules/backtest.module.ts +83 -83
  10. package/docker/docker-compose.yaml +46 -46
  11. package/docker/package.json +38 -38
  12. package/docker/tsconfig.json +36 -36
  13. package/package.json +126 -126
  14. package/template/average-buy.mustache +22 -22
  15. package/template/breakeven.mustache +21 -21
  16. package/template/cancel-scheduled.mustache +14 -14
  17. package/template/cancelled.mustache +21 -21
  18. package/template/close-pending.mustache +16 -16
  19. package/template/closed.mustache +23 -23
  20. package/template/opened.mustache +22 -22
  21. package/template/partial-loss.mustache +22 -22
  22. package/template/partial-profit.mustache +22 -22
  23. package/template/project/README.md +1 -0
  24. package/template/project/config/symbol.config.ts +460 -460
  25. package/template/project/package.mustache +28 -28
  26. package/template/risk.mustache +19 -19
  27. package/template/scheduled.mustache +22 -22
  28. package/template/signal-close.mustache +22 -22
  29. package/template/signal-info.mustache +20 -20
  30. package/template/signal-open.mustache +22 -22
  31. package/template/source/CLAUDE.md +160 -160
  32. package/template/trailing-stop.mustache +21 -21
  33. package/template/trailing-take.mustache +21 -21
  34. package/types.d.ts +1 -6
package/build/index.cjs CHANGED
@@ -910,9 +910,15 @@ class BacktestMainService {
910
910
  this.loggerService.log("backtestMainService run", {
911
911
  payload,
912
912
  });
913
+ await this.configConnectionService.loadConfig("setup.config");
913
914
  {
914
- await this.configConnectionService.loadConfig("setup.config");
915
- await this.configConnectionService.loadConfig("loader.config");
915
+ const loader = await this.configConnectionService.loadConfig("loader.config");
916
+ if (typeof loader === "function") {
917
+ await loader();
918
+ }
919
+ if (typeof loader?.loader === "function") {
920
+ await loader.loader();
921
+ }
916
922
  }
917
923
  {
918
924
  await this.configService.waitForInit();
@@ -1032,9 +1038,15 @@ class WalkerMainService {
1032
1038
  this.configConnectionService = inject(TYPES.configConnectionService);
1033
1039
  this.run = functoolsKit.singleshot(async (payload) => {
1034
1040
  this.loggerService.log("walkerMainService run", { payload });
1041
+ await this.configConnectionService.loadConfig("setup.config");
1035
1042
  {
1036
- await this.configConnectionService.loadConfig("setup.config");
1037
- await this.configConnectionService.loadConfig("loader.config");
1043
+ const loader = await this.configConnectionService.loadConfig("loader.config");
1044
+ if (typeof loader === "function") {
1045
+ await loader();
1046
+ }
1047
+ if (typeof loader?.loader === "function") {
1048
+ await loader.loader();
1049
+ }
1038
1050
  }
1039
1051
  {
1040
1052
  await this.configService.waitForInit();
@@ -1260,9 +1272,15 @@ class LiveMainService {
1260
1272
  this.loggerService.log("liveMainService run", {
1261
1273
  payload,
1262
1274
  });
1275
+ await this.configConnectionService.loadConfig("setup.config");
1263
1276
  {
1264
- await this.configConnectionService.loadConfig("setup.config");
1265
- await this.configConnectionService.loadConfig("loader.config");
1277
+ const loader = await this.configConnectionService.loadConfig("loader.config");
1278
+ if (typeof loader === "function") {
1279
+ await loader();
1280
+ }
1281
+ if (typeof loader?.loader === "function") {
1282
+ await loader.loader();
1283
+ }
1266
1284
  }
1267
1285
  {
1268
1286
  await this.configService.waitForInit();
@@ -1349,9 +1367,15 @@ class PaperMainService {
1349
1367
  this.configConnectionService = inject(TYPES.configConnectionService);
1350
1368
  this.run = functoolsKit.singleshot(async (payload) => {
1351
1369
  this.loggerService.log("paperMainService init");
1370
+ await this.configConnectionService.loadConfig("setup.config");
1352
1371
  {
1353
- await this.configConnectionService.loadConfig("setup.config");
1354
- await this.configConnectionService.loadConfig("loader.config");
1372
+ const loader = await this.configConnectionService.loadConfig("loader.config");
1373
+ if (typeof loader === "function") {
1374
+ await loader();
1375
+ }
1376
+ if (typeof loader?.loader === "function") {
1377
+ await loader.loader();
1378
+ }
1355
1379
  }
1356
1380
  {
1357
1381
  await this.configService.waitForInit();
@@ -2879,13 +2903,50 @@ overrideModule('@backtest-kit/ollama', BacktestKitOllama__namespace);
2879
2903
  overrideModule('@backtest-kit/pinets', BacktestKitPinets__namespace);
2880
2904
  overrideModule('@backtest-kit/signals', BacktestKitSignals__namespace);
2881
2905
 
2906
+ const GET_ALIAS_VARIANTS_FN = (self) => {
2907
+ const result = [];
2908
+ result.push({
2909
+ filePath: path.join(self.resolveService.OVERRIDE_CONFIG_DIR, "alias.config.cjs"),
2910
+ baseDir: self.resolveService.OVERRIDE_CONFIG_DIR,
2911
+ });
2912
+ result.push({
2913
+ filePath: path.join(self.resolveService.OVERRIDE_CONFIG_DIR, "alias.config.mjs"),
2914
+ baseDir: self.resolveService.OVERRIDE_CONFIG_DIR,
2915
+ });
2916
+ result.push({
2917
+ filePath: path.join(self.resolveService.OVERRIDE_CONFIG_DIR, "alias.config.ts"),
2918
+ baseDir: self.resolveService.OVERRIDE_CONFIG_DIR,
2919
+ });
2920
+ result.push({
2921
+ filePath: path.join(self.resolveService.OVERRIDE_CONFIG_DIR, "alias.config.tsx"),
2922
+ baseDir: self.resolveService.OVERRIDE_CONFIG_DIR,
2923
+ });
2924
+ result.push({
2925
+ filePath: path.join(self.resolveService.OVERRIDE_CONFIG_DIR, "alias.config.js"),
2926
+ baseDir: self.resolveService.OVERRIDE_CONFIG_DIR,
2927
+ });
2928
+ result.push({
2929
+ filePath: path.join(self.resolveService.OVERRIDE_CONFIG_DIR, "alias.config.json"),
2930
+ baseDir: self.resolveService.OVERRIDE_CONFIG_DIR,
2931
+ });
2932
+ return result;
2933
+ };
2882
2934
  const GET_ALIAS_EXPORTS_FN = (self) => {
2883
- const instance = self.getInstance(self.resolveService.OVERRIDE_CONFIG_DIR);
2884
- if (!instance.check("alias.config")) {
2885
- return null;
2935
+ for (const { filePath, baseDir } of GET_ALIAS_VARIANTS_FN(self)) {
2936
+ if (!fs.existsSync(filePath)) {
2937
+ continue;
2938
+ }
2939
+ const instance = self.getInstance(baseDir);
2940
+ const alias = instance.import(filePath);
2941
+ if (!alias) {
2942
+ return null;
2943
+ }
2944
+ if ("default" in alias) {
2945
+ return alias.default;
2946
+ }
2947
+ return alias;
2886
2948
  }
2887
- const exports = instance.import("alias.config");
2888
- return "default" in exports ? exports.default : exports;
2949
+ return null;
2889
2950
  };
2890
2951
  const INIT_ALIAS_FN = (self) => {
2891
2952
  const alias = GET_ALIAS_EXPORTS_FN(self);
@@ -2982,6 +3043,10 @@ class ConfigConnectionService {
2982
3043
  const config = await LOAD_CONFIG_CONFIG_FN(fileName, this);
2983
3044
  if (!config) {
2984
3045
  this.loadConfig.clear(fileName);
3046
+ return null;
3047
+ }
3048
+ if ("default" in config) {
3049
+ return config.default;
2985
3050
  }
2986
3051
  return config;
2987
3052
  });
@@ -3127,10 +3192,10 @@ init();
3127
3192
 
3128
3193
  const MODES = ["backtest", "walker", "paper", "live", "pine", "editor", "dump", "pnldebug", "brokerdebug", "flush", "init", "docker", "help", "version"];
3129
3194
  const ENTRY_PATH$1 = "./node_modules/@backtest-kit/cli/build/index.mjs";
3130
- const HELP_TEXT$1 = `
3131
- Example:
3132
-
3133
- node ${ENTRY_PATH$1} --help
3195
+ const HELP_TEXT$1 = `
3196
+ Example:
3197
+
3198
+ node ${ENTRY_PATH$1} --help
3134
3199
  `.trimStart();
3135
3200
  const main$g = async () => {
3136
3201
  if (!getEntry((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)))) {
@@ -3140,7 +3205,7 @@ const main$g = async () => {
3140
3205
  if (MODES.some((mode) => values[mode])) {
3141
3206
  return;
3142
3207
  }
3143
- process.stdout.write(`@backtest-kit/cli ${"9.5.0"}\n`);
3208
+ process.stdout.write(`@backtest-kit/cli ${"9.7.0"}\n`);
3144
3209
  process.stdout.write("\n");
3145
3210
  process.stdout.write(`Run with --help to see available commands.\n`);
3146
3211
  process.stdout.write("\n");
@@ -3431,9 +3496,15 @@ const main$a = async () => {
3431
3496
  }
3432
3497
  await flush(entryPoint);
3433
3498
  }
3499
+ await cli.configConnectionService.loadConfig("setup.config");
3434
3500
  {
3435
- await cli.configConnectionService.loadConfig("setup.config");
3436
- await cli.configConnectionService.loadConfig("loader.config");
3501
+ const loader = await cli.configConnectionService.loadConfig("loader.config");
3502
+ if (typeof loader === "function") {
3503
+ await loader();
3504
+ }
3505
+ if (typeof loader?.loader === "function") {
3506
+ await loader.loader();
3507
+ }
3437
3508
  }
3438
3509
  {
3439
3510
  await cli.configService.waitForInit();
@@ -3535,9 +3606,15 @@ const main$7 = async () => {
3535
3606
  const cwd = process.cwd();
3536
3607
  dotenv.config({ path: path.join(cwd, '.env'), override: true, quiet: true });
3537
3608
  }
3609
+ await cli.configConnectionService.loadConfig("setup.config");
3538
3610
  {
3539
- await cli.configConnectionService.loadConfig("setup.config");
3540
- await cli.configConnectionService.loadConfig("loader.config");
3611
+ const loader = await cli.configConnectionService.loadConfig("loader.config");
3612
+ if (typeof loader === "function") {
3613
+ await loader();
3614
+ }
3615
+ if (typeof loader?.loader === "function") {
3616
+ await loader.loader();
3617
+ }
3541
3618
  }
3542
3619
  await cli.moduleConnectionService.loadModule("pine.module");
3543
3620
  {
@@ -3616,9 +3693,15 @@ const main$6 = async () => {
3616
3693
  console.warn("--editor and --pine are mutually exclusive. Use one at a time.");
3617
3694
  process.exit(1);
3618
3695
  }
3696
+ await cli.configConnectionService.loadConfig("setup.config");
3619
3697
  {
3620
- await cli.configConnectionService.loadConfig("setup.config");
3621
- await cli.configConnectionService.loadConfig("loader.config");
3698
+ const loader = await cli.configConnectionService.loadConfig("loader.config");
3699
+ if (typeof loader === "function") {
3700
+ await loader();
3701
+ }
3702
+ if (typeof loader?.loader === "function") {
3703
+ await loader.loader();
3704
+ }
3622
3705
  }
3623
3706
  {
3624
3707
  await cli.configService.waitForInit();
@@ -3661,9 +3744,15 @@ const main$5 = async () => {
3661
3744
  const cwd = process.cwd();
3662
3745
  dotenv.config({ path: path.join(cwd, '.env'), override: true, quiet: true });
3663
3746
  }
3747
+ await cli.configConnectionService.loadConfig("setup.config");
3664
3748
  {
3665
- await cli.configConnectionService.loadConfig("setup.config");
3666
- await cli.configConnectionService.loadConfig("loader.config");
3749
+ const loader = await cli.configConnectionService.loadConfig("loader.config");
3750
+ if (typeof loader === "function") {
3751
+ await loader();
3752
+ }
3753
+ if (typeof loader?.loader === "function") {
3754
+ await loader.loader();
3755
+ }
3667
3756
  }
3668
3757
  await cli.moduleConnectionService.loadModule("dump.module");
3669
3758
  {
@@ -3732,9 +3821,15 @@ const main$4 = async () => {
3732
3821
  const cwd = process.cwd();
3733
3822
  dotenv.config({ path: path.join(cwd, '.env'), override: true, quiet: true });
3734
3823
  }
3824
+ await cli.configConnectionService.loadConfig("setup.config");
3735
3825
  {
3736
- await cli.configConnectionService.loadConfig("setup.config");
3737
- await cli.configConnectionService.loadConfig("loader.config");
3826
+ const loader = await cli.configConnectionService.loadConfig("loader.config");
3827
+ if (typeof loader === "function") {
3828
+ await loader();
3829
+ }
3830
+ if (typeof loader?.loader === "function") {
3831
+ await loader.loader();
3832
+ }
3738
3833
  }
3739
3834
  await cli.moduleConnectionService.loadModule("pnldebug.module");
3740
3835
  {
@@ -4004,183 +4099,183 @@ const main$2 = async () => {
4004
4099
  main$2();
4005
4100
 
4006
4101
  const ENTRY_PATH = "./node_modules/@backtest-kit/cli/build/index.mjs";
4007
- const HELP_TEXT = `
4008
- Usage:
4009
- node index.mjs --<mode> [flags] [entry-point]
4010
-
4011
- Modes:
4012
-
4013
- --backtest <entry> Run strategy against historical candle data
4014
- --walker <entry...> Run Walker A/B strategy comparison across multiple strategies
4015
- --paper <entry> Paper trading (live prices, no real orders)
4016
- --live <entry> Live trading with real orders
4017
- --pine <entry> Execute a local .pine indicator file
4018
- --editor Open the Pine Script visual editor in the browser
4019
- --dump Fetch and save raw OHLCV candles
4020
- --pnldebug Simulate PnL per minute for a given entry price and direction
4021
- --brokerdebug Fire a single broker commit against the live broker adapter
4022
- --flush <entry...> Delete report/log/markdown/agent folders from strategy dump dir
4023
- --init Scaffold a new project in the current directory
4024
- --docker Scaffold a Docker workspace for running strategies in a container
4025
- --help Print this help message
4026
-
4027
- Backtest flags:
4028
-
4029
- --symbol <string> Trading pair (default: BTCUSDT)
4030
- --strategy <string> Strategy name from addStrategySchema (default: first registered)
4031
- --exchange <string> Exchange name from addExchangeSchema (default: first registered)
4032
- --frame <string> Frame name from addFrameSchema (default: first registered)
4033
- --cacheInterval <string> Comma-separated intervals to pre-cache (default: "1m, 15m, 30m, 4h")
4034
- --noCache Skip candle cache warming before the run
4035
- --noFlush Skip removing report/log/markdown/agent folders before backtest run
4036
- --verbose Log every candle fetch to stdout
4037
- --ui Start web dashboard at http://localhost:60050
4038
- --telegram Send trade notifications to Telegram
4039
-
4040
- Walker flags (--walker):
4041
-
4042
- --symbol <string> Trading pair (default: BTCUSDT)
4043
- --cacheInterval <string> Comma-separated intervals to pre-cache (default: "1m, 15m, 30m, 4h")
4044
- --noCache Skip candle cache warming before the run
4045
- --noFlush Skip removing report/log/markdown/agent folders before walker run
4046
- --verbose Log every candle fetch to stdout
4047
- --output <string> Output file base name (default: walker_{SYMBOL}_{TIMESTAMP})
4048
- --json Save results as JSON to ./dump/<output>.json
4049
- --markdown Save report as Markdown to ./dump/<output>.md
4050
-
4051
- Each positional argument is a strategy entry point. All strategy files are loaded without
4052
- changing process.cwd() — .env is read from the working directory only.
4053
- addWalkerSchema is called automatically using the registered exchange and frame.
4054
- After comparison completes the report is printed to stdout (or saved if --json/--markdown).
4055
-
4056
- Module file ./modules/walker.module is loaded automatically if it exists.
4057
-
4058
- Paper / Live flags:
4059
-
4060
- --symbol <string> Trading pair (default: BTCUSDT)
4061
- --strategy <string> Strategy name (default: first registered)
4062
- --exchange <string> Exchange name (default: first registered)
4063
- --verbose Log every candle fetch to stdout
4064
- --ui Start web dashboard
4065
- --telegram Send Telegram notifications
4066
-
4067
- PineScript flags (--pine):
4068
-
4069
- --symbol <string> Trading pair (default: BTCUSDT)
4070
- --timeframe <string> Candle interval (default: 15m)
4071
- --limit <string> Number of candles to fetch (default: 250)
4072
- --when <string> End date — ISO 8601 or Unix ms (default: now)
4073
- --exchange <string> Exchange name (default: first registered)
4074
- --output <string> Output file base name without extension
4075
- --json Save output as JSON array to <pine-dir>/dump/<output>.json
4076
- --jsonl Save output as JSONL to <pine-dir>/dump/<output>.jsonl
4077
- --markdown Save output as Markdown table to <pine-dir>/dump/<output>.md
4078
-
4079
- Only plot() calls with display=display.data_window produce output columns.
4080
- Module file ./modules/pine.module is loaded automatically if it exists.
4081
-
4082
- Candle dump flags (--dump):
4083
-
4084
- --symbol <string> Trading pair (default: BTCUSDT)
4085
- --timeframe <string> Candle interval (default: 15m)
4086
- --limit <string> Number of candles (default: 250)
4087
- --when <string> End date — ISO 8601 or Unix ms (default: now)
4088
- --exchange <string> Exchange name (default: first registered)
4089
- --output <string> Output file base name (default: {SYMBOL}_{LIMIT}_{TIMEFRAME}_{TIMESTAMP})
4090
- --json Save as JSON array to ./dump/<output>.json
4091
- --jsonl Save as JSONL to ./dump/<output>.jsonl
4092
-
4093
- Module file ./modules/dump.module is loaded automatically if it exists.
4094
-
4095
- PnL debug flags (--pnldebug):
4096
-
4097
- --symbol <string> Trading pair (default: BTCUSDT)
4098
- --priceopen <number> Entry price (required)
4099
- --direction <string> Position direction: long or short (default: long)
4100
- --when <string> Start timestamp — ISO 8601 or Unix ms (default: now)
4101
- --minutes <string> Number of 1m candles to simulate (default: 60)
4102
- --exchange <string> Exchange name (default: first registered)
4103
- --output <string> Output file base name (default: {SYMBOL}_{DIRECTION}_{PRICEOPEN}_{TIMESTAMP})
4104
- --json Save as JSON array to ./dump/<output>.json
4105
- --jsonl Save as JSONL to ./dump/<output>.jsonl
4106
- --markdown Save as Markdown table to ./dump/<output>.md
4107
-
4108
- Module file ./modules/pnldebug.module is loaded automatically if it exists.
4109
-
4110
- Broker debug flags (--brokerdebug):
4111
-
4112
- --symbol <string> Trading pair (default: BTCUSDT)
4113
- --exchange <string> Exchange name (default: first registered)
4114
- --commit <string> Commit type to fire: signal-open, signal-close, partial-profit,
4115
- partial-loss, average-buy, trailing-stop, trailing-take, breakeven
4116
- (default: signal-open)
4117
-
4118
- Loads ./live.module, fetches the last candle for --symbol/--timeframe, and calls
4119
- the selected broker commit with synthetic payload values derived from current price.
4120
-
4121
- Flush flags (--flush):
4122
-
4123
- One or more positional entry points. For each entry point the following
4124
- subdirectories are removed from <entry-dir>/dump/:
4125
-
4126
- report log markdown agent
4127
-
4128
- Init flags (--init):
4129
-
4130
- --output <string> Target directory name (default: backtest-kit-project)
4131
-
4132
- Scaffolds a project and runs scripts/fetch_docs.mjs to download library docs.
4133
-
4134
- Docker flags (--docker):
4135
-
4136
- --output <string> Target directory name (default: backtest-kit-docker)
4137
-
4138
- Scaffolds a Docker workspace: docker-compose.yaml, .env.example, package.json,
4139
- tsconfig.json, and a sample strategy under content/. Run npm install then
4140
- docker compose up to start the container.
4141
-
4142
- Module hooks (loaded automatically by each mode):
4143
-
4144
- modules/backtest.module --backtest Broker adapter for backtest
4145
- modules/walker.module --walker Broker adapter for walker comparison
4146
- modules/paper.module --paper Broker adapter for paper trading
4147
- modules/live.module --live Broker adapter for live trading
4148
- modules/pine.module --pine Exchange schema for PineScript runs
4149
- modules/editor.module --editor Exchange schema for the visual Pine editor
4150
- modules/dump.module --dump Exchange schema for candle dumps
4151
- modules/pnldebug.module --pnldebug Exchange schema for PnL debug runs
4152
- modules/brokerdebug.module --brokerdebug Broker adapter used for broker commit testing
4153
-
4154
- --flush has no associated module. It only removes dump subdirectories.
4155
-
4156
- Extensions .ts, .mjs, .cjs are tried automatically. Missing module = soft warning.
4157
-
4158
- Environment variables:
4159
-
4160
- CC_TELEGRAM_TOKEN Telegram bot token (required for --telegram)
4161
- CC_TELEGRAM_CHANNEL Telegram channel or chat ID (required for --telegram)
4162
- CC_WWWROOT_HOST UI server bind address (default: 0.0.0.0)
4163
- CC_WWWROOT_PORT UI server port (default: 60050)
4164
-
4165
- Examples:
4166
-
4167
- node ${ENTRY_PATH} --backtest ./content/feb_2026.strategy.ts
4168
- node ${ENTRY_PATH} --backtest --symbol BTCUSDT --noCache --noFlush --ui ./content/feb_2026.strategy.ts
4169
- node ${ENTRY_PATH} --walker ./content/feb_2026_v1.strategy.ts ./content/feb_2026_v2.strategy.ts ./content/feb_2026_v3.strategy.ts
4170
- node ${ENTRY_PATH} --walker --symbol BTCUSDT --noCache --noFlush --markdown ./content/feb_2026_v1.ts ./content/feb_2026_v2.ts
4171
- node ${ENTRY_PATH} --paper --symbol ETHUSDT ./content/feb_2026.strategy.ts
4172
- node ${ENTRY_PATH} --live --ui --telegram ./content/feb_2026.strategy.ts
4173
- node ${ENTRY_PATH} --pine ./math/feb_2026.pine --timeframe 15m --limit 500 --jsonl
4174
- node ${ENTRY_PATH} --editor
4175
- node ${ENTRY_PATH} --dump --symbol BTCUSDT --timeframe 15m --limit 500 --jsonl
4176
- node ${ENTRY_PATH} --pnldebug --symbol BTCUSDT --priceopen 64069.50 --direction short --when "2025-02-25" --minutes 120
4177
- node ${ENTRY_PATH} --pnldebug --priceopen 67956.73 --direction long --when 1772064000000 --minutes 60 --markdown
4178
- node ${ENTRY_PATH} --brokerdebug --commit signal-open --symbol BTCUSDT
4179
- node ${ENTRY_PATH} --brokerdebug --commit partial-profit --symbol ETHUSDT
4180
- node ${ENTRY_PATH} --flush ./content/feb_2026.strategy/feb_2026.strategy.ts
4181
- node ${ENTRY_PATH} --flush ./content/feb_2026.strategy/feb_2026.strategy.ts ./content/feb_2026.strategy/feb_2026.test.ts
4182
- node ${ENTRY_PATH} --init --output my-trading-bot
4183
- node ${ENTRY_PATH} --docker --output my-docker-workspace
4102
+ const HELP_TEXT = `
4103
+ Usage:
4104
+ node index.mjs --<mode> [flags] [entry-point]
4105
+
4106
+ Modes:
4107
+
4108
+ --backtest <entry> Run strategy against historical candle data
4109
+ --walker <entry...> Run Walker A/B strategy comparison across multiple strategies
4110
+ --paper <entry> Paper trading (live prices, no real orders)
4111
+ --live <entry> Live trading with real orders
4112
+ --pine <entry> Execute a local .pine indicator file
4113
+ --editor Open the Pine Script visual editor in the browser
4114
+ --dump Fetch and save raw OHLCV candles
4115
+ --pnldebug Simulate PnL per minute for a given entry price and direction
4116
+ --brokerdebug Fire a single broker commit against the live broker adapter
4117
+ --flush <entry...> Delete report/log/markdown/agent folders from strategy dump dir
4118
+ --init Scaffold a new project in the current directory
4119
+ --docker Scaffold a Docker workspace for running strategies in a container
4120
+ --help Print this help message
4121
+
4122
+ Backtest flags:
4123
+
4124
+ --symbol <string> Trading pair (default: BTCUSDT)
4125
+ --strategy <string> Strategy name from addStrategySchema (default: first registered)
4126
+ --exchange <string> Exchange name from addExchangeSchema (default: first registered)
4127
+ --frame <string> Frame name from addFrameSchema (default: first registered)
4128
+ --cacheInterval <string> Comma-separated intervals to pre-cache (default: "1m, 15m, 30m, 4h")
4129
+ --noCache Skip candle cache warming before the run
4130
+ --noFlush Skip removing report/log/markdown/agent folders before backtest run
4131
+ --verbose Log every candle fetch to stdout
4132
+ --ui Start web dashboard at http://localhost:60050
4133
+ --telegram Send trade notifications to Telegram
4134
+
4135
+ Walker flags (--walker):
4136
+
4137
+ --symbol <string> Trading pair (default: BTCUSDT)
4138
+ --cacheInterval <string> Comma-separated intervals to pre-cache (default: "1m, 15m, 30m, 4h")
4139
+ --noCache Skip candle cache warming before the run
4140
+ --noFlush Skip removing report/log/markdown/agent folders before walker run
4141
+ --verbose Log every candle fetch to stdout
4142
+ --output <string> Output file base name (default: walker_{SYMBOL}_{TIMESTAMP})
4143
+ --json Save results as JSON to ./dump/<output>.json
4144
+ --markdown Save report as Markdown to ./dump/<output>.md
4145
+
4146
+ Each positional argument is a strategy entry point. All strategy files are loaded without
4147
+ changing process.cwd() — .env is read from the working directory only.
4148
+ addWalkerSchema is called automatically using the registered exchange and frame.
4149
+ After comparison completes the report is printed to stdout (or saved if --json/--markdown).
4150
+
4151
+ Module file ./modules/walker.module is loaded automatically if it exists.
4152
+
4153
+ Paper / Live flags:
4154
+
4155
+ --symbol <string> Trading pair (default: BTCUSDT)
4156
+ --strategy <string> Strategy name (default: first registered)
4157
+ --exchange <string> Exchange name (default: first registered)
4158
+ --verbose Log every candle fetch to stdout
4159
+ --ui Start web dashboard
4160
+ --telegram Send Telegram notifications
4161
+
4162
+ PineScript flags (--pine):
4163
+
4164
+ --symbol <string> Trading pair (default: BTCUSDT)
4165
+ --timeframe <string> Candle interval (default: 15m)
4166
+ --limit <string> Number of candles to fetch (default: 250)
4167
+ --when <string> End date — ISO 8601 or Unix ms (default: now)
4168
+ --exchange <string> Exchange name (default: first registered)
4169
+ --output <string> Output file base name without extension
4170
+ --json Save output as JSON array to <pine-dir>/dump/<output>.json
4171
+ --jsonl Save output as JSONL to <pine-dir>/dump/<output>.jsonl
4172
+ --markdown Save output as Markdown table to <pine-dir>/dump/<output>.md
4173
+
4174
+ Only plot() calls with display=display.data_window produce output columns.
4175
+ Module file ./modules/pine.module is loaded automatically if it exists.
4176
+
4177
+ Candle dump flags (--dump):
4178
+
4179
+ --symbol <string> Trading pair (default: BTCUSDT)
4180
+ --timeframe <string> Candle interval (default: 15m)
4181
+ --limit <string> Number of candles (default: 250)
4182
+ --when <string> End date — ISO 8601 or Unix ms (default: now)
4183
+ --exchange <string> Exchange name (default: first registered)
4184
+ --output <string> Output file base name (default: {SYMBOL}_{LIMIT}_{TIMEFRAME}_{TIMESTAMP})
4185
+ --json Save as JSON array to ./dump/<output>.json
4186
+ --jsonl Save as JSONL to ./dump/<output>.jsonl
4187
+
4188
+ Module file ./modules/dump.module is loaded automatically if it exists.
4189
+
4190
+ PnL debug flags (--pnldebug):
4191
+
4192
+ --symbol <string> Trading pair (default: BTCUSDT)
4193
+ --priceopen <number> Entry price (required)
4194
+ --direction <string> Position direction: long or short (default: long)
4195
+ --when <string> Start timestamp — ISO 8601 or Unix ms (default: now)
4196
+ --minutes <string> Number of 1m candles to simulate (default: 60)
4197
+ --exchange <string> Exchange name (default: first registered)
4198
+ --output <string> Output file base name (default: {SYMBOL}_{DIRECTION}_{PRICEOPEN}_{TIMESTAMP})
4199
+ --json Save as JSON array to ./dump/<output>.json
4200
+ --jsonl Save as JSONL to ./dump/<output>.jsonl
4201
+ --markdown Save as Markdown table to ./dump/<output>.md
4202
+
4203
+ Module file ./modules/pnldebug.module is loaded automatically if it exists.
4204
+
4205
+ Broker debug flags (--brokerdebug):
4206
+
4207
+ --symbol <string> Trading pair (default: BTCUSDT)
4208
+ --exchange <string> Exchange name (default: first registered)
4209
+ --commit <string> Commit type to fire: signal-open, signal-close, partial-profit,
4210
+ partial-loss, average-buy, trailing-stop, trailing-take, breakeven
4211
+ (default: signal-open)
4212
+
4213
+ Loads ./live.module, fetches the last candle for --symbol/--timeframe, and calls
4214
+ the selected broker commit with synthetic payload values derived from current price.
4215
+
4216
+ Flush flags (--flush):
4217
+
4218
+ One or more positional entry points. For each entry point the following
4219
+ subdirectories are removed from <entry-dir>/dump/:
4220
+
4221
+ report log markdown agent
4222
+
4223
+ Init flags (--init):
4224
+
4225
+ --output <string> Target directory name (default: backtest-kit-project)
4226
+
4227
+ Scaffolds a project and runs scripts/fetch_docs.mjs to download library docs.
4228
+
4229
+ Docker flags (--docker):
4230
+
4231
+ --output <string> Target directory name (default: backtest-kit-docker)
4232
+
4233
+ Scaffolds a Docker workspace: docker-compose.yaml, .env.example, package.json,
4234
+ tsconfig.json, and a sample strategy under content/. Run npm install then
4235
+ docker compose up to start the container.
4236
+
4237
+ Module hooks (loaded automatically by each mode):
4238
+
4239
+ modules/backtest.module --backtest Broker adapter for backtest
4240
+ modules/walker.module --walker Broker adapter for walker comparison
4241
+ modules/paper.module --paper Broker adapter for paper trading
4242
+ modules/live.module --live Broker adapter for live trading
4243
+ modules/pine.module --pine Exchange schema for PineScript runs
4244
+ modules/editor.module --editor Exchange schema for the visual Pine editor
4245
+ modules/dump.module --dump Exchange schema for candle dumps
4246
+ modules/pnldebug.module --pnldebug Exchange schema for PnL debug runs
4247
+ modules/brokerdebug.module --brokerdebug Broker adapter used for broker commit testing
4248
+
4249
+ --flush has no associated module. It only removes dump subdirectories.
4250
+
4251
+ Extensions .ts, .mjs, .cjs are tried automatically. Missing module = soft warning.
4252
+
4253
+ Environment variables:
4254
+
4255
+ CC_TELEGRAM_TOKEN Telegram bot token (required for --telegram)
4256
+ CC_TELEGRAM_CHANNEL Telegram channel or chat ID (required for --telegram)
4257
+ CC_WWWROOT_HOST UI server bind address (default: 0.0.0.0)
4258
+ CC_WWWROOT_PORT UI server port (default: 60050)
4259
+
4260
+ Examples:
4261
+
4262
+ node ${ENTRY_PATH} --backtest ./content/feb_2026.strategy.ts
4263
+ node ${ENTRY_PATH} --backtest --symbol BTCUSDT --noCache --noFlush --ui ./content/feb_2026.strategy.ts
4264
+ node ${ENTRY_PATH} --walker ./content/feb_2026_v1.strategy.ts ./content/feb_2026_v2.strategy.ts ./content/feb_2026_v3.strategy.ts
4265
+ node ${ENTRY_PATH} --walker --symbol BTCUSDT --noCache --noFlush --markdown ./content/feb_2026_v1.ts ./content/feb_2026_v2.ts
4266
+ node ${ENTRY_PATH} --paper --symbol ETHUSDT ./content/feb_2026.strategy.ts
4267
+ node ${ENTRY_PATH} --live --ui --telegram ./content/feb_2026.strategy.ts
4268
+ node ${ENTRY_PATH} --pine ./math/feb_2026.pine --timeframe 15m --limit 500 --jsonl
4269
+ node ${ENTRY_PATH} --editor
4270
+ node ${ENTRY_PATH} --dump --symbol BTCUSDT --timeframe 15m --limit 500 --jsonl
4271
+ node ${ENTRY_PATH} --pnldebug --symbol BTCUSDT --priceopen 64069.50 --direction short --when "2025-02-25" --minutes 120
4272
+ node ${ENTRY_PATH} --pnldebug --priceopen 67956.73 --direction long --when 1772064000000 --minutes 60 --markdown
4273
+ node ${ENTRY_PATH} --brokerdebug --commit signal-open --symbol BTCUSDT
4274
+ node ${ENTRY_PATH} --brokerdebug --commit partial-profit --symbol ETHUSDT
4275
+ node ${ENTRY_PATH} --flush ./content/feb_2026.strategy/feb_2026.strategy.ts
4276
+ node ${ENTRY_PATH} --flush ./content/feb_2026.strategy/feb_2026.strategy.ts ./content/feb_2026.strategy/feb_2026.test.ts
4277
+ node ${ENTRY_PATH} --init --output my-trading-bot
4278
+ node ${ENTRY_PATH} --docker --output my-docker-workspace
4184
4279
  `.trimStart();
4185
4280
  const main$1 = async () => {
4186
4281
  if (!getEntry((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)))) {
@@ -4190,7 +4285,7 @@ const main$1 = async () => {
4190
4285
  if (!values.help) {
4191
4286
  return;
4192
4287
  }
4193
- process.stdout.write(`@backtest-kit/cli ${"9.5.0"}\n\n`);
4288
+ process.stdout.write(`@backtest-kit/cli ${"9.7.0"}\n\n`);
4194
4289
  process.stdout.write(HELP_TEXT);
4195
4290
  process.exit(0);
4196
4291
  };
@@ -4204,7 +4299,7 @@ const main = async () => {
4204
4299
  if (!values.version) {
4205
4300
  return;
4206
4301
  }
4207
- process.stdout.write(`@backtest-kit/cli ${"9.5.0"}\n`);
4302
+ process.stdout.write(`@backtest-kit/cli ${"9.7.0"}\n`);
4208
4303
  process.exit(0);
4209
4304
  };
4210
4305
  main();