@backtest-kit/cli 9.8.1 → 9.8.3

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/build/index.cjs CHANGED
@@ -58,36 +58,6 @@ var BacktestKitOllama__namespace = /*#__PURE__*/_interopNamespaceDefault(Backtes
58
58
  var BacktestKitPinets__namespace = /*#__PURE__*/_interopNamespaceDefault(BacktestKitPinets);
59
59
  var BacktestKitSignals__namespace = /*#__PURE__*/_interopNamespaceDefault(BacktestKitSignals);
60
60
 
61
- /**
62
- * Fix for `Attempted to assign to readonly property (at redactToken)`
63
- * @see https://github.com/telegraf/telegraf/issues/2078
64
- */
65
- {
66
- const OriginalError = globalThis.Error;
67
- globalThis.Error = new Proxy(OriginalError, {
68
- construct(target, args) {
69
- const instance = new target(...args);
70
- let customMessage = instance.message;
71
- const handler = {
72
- get(target, prop, receiver) {
73
- if (prop === "message") {
74
- return customMessage;
75
- }
76
- return Reflect.get(target, prop, receiver);
77
- },
78
- set(target, prop, value, receiver) {
79
- if (prop === "message") {
80
- customMessage = value;
81
- return true;
82
- }
83
- return Reflect.set(target, prop, value, receiver);
84
- },
85
- };
86
- return new Proxy(instance, handler);
87
- },
88
- });
89
- }
90
-
91
61
  BacktestKit.setConfig({
92
62
  CC_MAX_NOTIFICATIONS: 5000,
93
63
  CC_MAX_SIGNALS: 750,
@@ -264,8 +234,6 @@ const TYPES = {
264
234
  ...templateServices$1,
265
235
  };
266
236
 
267
- const entrySubject = new functoolsKit.BehaviorSubject();
268
-
269
237
  const SETUP_ADAPTER_FN = () => {
270
238
  {
271
239
  BacktestKit.Dump.useMarkdown();
@@ -464,9 +432,9 @@ class ResolveService {
464
432
  dotenv.config({ path: path.join(cwd, '.env'), override: true, quiet: true });
465
433
  dotenv.config({ path: path.join(moduleRoot, '.env'), override: true, quiet: true });
466
434
  this.loaderService.import(absolutePath);
467
- await entrySubject.next(absolutePath);
468
435
  }
469
436
  _is_launched = true;
437
+ return absolutePath;
470
438
  };
471
439
  this.attachEntry = async (jsPath) => {
472
440
  this.loggerService.log("resolveService attachEntry", {
@@ -481,9 +449,9 @@ class ResolveService {
481
449
  dotenv.config({ path: path.join(cwd, '.env'), override: true, quiet: true });
482
450
  {
483
451
  this.loaderService.import(absolutePath);
484
- await entrySubject.next(absolutePath);
485
452
  }
486
453
  _is_launched = true;
454
+ return absolutePath;
487
455
  };
488
456
  }
489
457
  }
@@ -886,6 +854,8 @@ const notifyVerbose = functoolsKit.singleshot(() => {
886
854
  });
887
855
  });
888
856
 
857
+ const entrySubject = new functoolsKit.BehaviorSubject();
858
+
889
859
  const DEFAULT_CACHE_LIST$1 = ["1m", "15m", "30m", "1h", "4h"];
890
860
  const GET_CACHE_INTERVAL_LIST_FN$1 = () => {
891
861
  const { values } = getArgs();
@@ -916,11 +886,17 @@ class BacktestMainService {
916
886
  await this.configConnectionService.loadConfig("setup.config");
917
887
  {
918
888
  const loader = await this.configConnectionService.loadConfig("loader.config");
919
- if (typeof loader === "function") {
920
- await loader();
889
+ try {
890
+ if (typeof loader === "function") {
891
+ await loader();
892
+ }
893
+ if (typeof loader?.loader === "function") {
894
+ await loader.loader();
895
+ }
921
896
  }
922
- if (typeof loader?.loader === "function") {
923
- await loader.loader();
897
+ catch (error) {
898
+ console.error("Module loader failed", error);
899
+ process.exit(-1);
924
900
  }
925
901
  }
926
902
  {
@@ -935,8 +911,9 @@ class BacktestMainService {
935
911
  const cwd = process.cwd();
936
912
  dotenv.config({ path: path.join(cwd, '.env'), override: true, quiet: true });
937
913
  }
914
+ let absolutePath;
938
915
  {
939
- await this.resolveService.attachJavascript(payload.entryPoint);
916
+ absolutePath = await this.resolveService.attachJavascript(payload.entryPoint);
940
917
  await this.moduleConnectionService.loadModule("backtest.module");
941
918
  }
942
919
  {
@@ -978,6 +955,7 @@ class BacktestMainService {
978
955
  });
979
956
  notifyVerbose();
980
957
  }
958
+ await entrySubject.next(absolutePath);
981
959
  BacktestKit.Backtest.background(symbol, {
982
960
  strategyName,
983
961
  frameName,
@@ -1044,11 +1022,17 @@ class WalkerMainService {
1044
1022
  await this.configConnectionService.loadConfig("setup.config");
1045
1023
  {
1046
1024
  const loader = await this.configConnectionService.loadConfig("loader.config");
1047
- if (typeof loader === "function") {
1048
- await loader();
1025
+ try {
1026
+ if (typeof loader === "function") {
1027
+ await loader();
1028
+ }
1029
+ if (typeof loader?.loader === "function") {
1030
+ await loader.loader();
1031
+ }
1049
1032
  }
1050
- if (typeof loader?.loader === "function") {
1051
- await loader.loader();
1033
+ catch (error) {
1034
+ console.error("Module loader failed", error);
1035
+ process.exit(-1);
1052
1036
  }
1053
1037
  }
1054
1038
  {
@@ -1278,11 +1262,17 @@ class LiveMainService {
1278
1262
  await this.configConnectionService.loadConfig("setup.config");
1279
1263
  {
1280
1264
  const loader = await this.configConnectionService.loadConfig("loader.config");
1281
- if (typeof loader === "function") {
1282
- await loader();
1265
+ try {
1266
+ if (typeof loader === "function") {
1267
+ await loader();
1268
+ }
1269
+ if (typeof loader?.loader === "function") {
1270
+ await loader.loader();
1271
+ }
1283
1272
  }
1284
- if (typeof loader?.loader === "function") {
1285
- await loader.loader();
1273
+ catch (error) {
1274
+ console.error("Module loader failed", error);
1275
+ process.exit(-1);
1286
1276
  }
1287
1277
  }
1288
1278
  {
@@ -1297,8 +1287,9 @@ class LiveMainService {
1297
1287
  const cwd = process.cwd();
1298
1288
  dotenv.config({ path: path.join(cwd, '.env'), override: true, quiet: true });
1299
1289
  }
1290
+ let absolutePath;
1300
1291
  {
1301
- await this.resolveService.attachJavascript(payload.entryPoint);
1292
+ absolutePath = await this.resolveService.attachJavascript(payload.entryPoint);
1302
1293
  await this.moduleConnectionService.loadModule("live.module");
1303
1294
  }
1304
1295
  {
@@ -1327,6 +1318,7 @@ class LiveMainService {
1327
1318
  });
1328
1319
  notifyVerbose();
1329
1320
  }
1321
+ await entrySubject.next(absolutePath);
1330
1322
  BacktestKit.Live.background(symbol, {
1331
1323
  strategyName,
1332
1324
  exchangeName,
@@ -1373,11 +1365,17 @@ class PaperMainService {
1373
1365
  await this.configConnectionService.loadConfig("setup.config");
1374
1366
  {
1375
1367
  const loader = await this.configConnectionService.loadConfig("loader.config");
1376
- if (typeof loader === "function") {
1377
- await loader();
1368
+ try {
1369
+ if (typeof loader === "function") {
1370
+ await loader();
1371
+ }
1372
+ if (typeof loader?.loader === "function") {
1373
+ await loader.loader();
1374
+ }
1378
1375
  }
1379
- if (typeof loader?.loader === "function") {
1380
- await loader.loader();
1376
+ catch (error) {
1377
+ console.error("Module loader failed", error);
1378
+ process.exit(-1);
1381
1379
  }
1382
1380
  }
1383
1381
  {
@@ -1392,8 +1390,9 @@ class PaperMainService {
1392
1390
  const cwd = process.cwd();
1393
1391
  dotenv.config({ path: path.join(cwd, '.env'), override: true, quiet: true });
1394
1392
  }
1393
+ let absolutePath;
1395
1394
  {
1396
- await this.resolveService.attachJavascript(payload.entryPoint);
1395
+ absolutePath = await this.resolveService.attachJavascript(payload.entryPoint);
1397
1396
  await this.moduleConnectionService.loadModule("paper.module");
1398
1397
  }
1399
1398
  {
@@ -1422,6 +1421,7 @@ class PaperMainService {
1422
1421
  });
1423
1422
  notifyVerbose();
1424
1423
  }
1424
+ await entrySubject.next(absolutePath);
1425
1425
  BacktestKit.Live.background(symbol, {
1426
1426
  strategyName,
1427
1427
  exchangeName,
@@ -2015,7 +2015,8 @@ const GET_TIMEFRAME_RANGE_FN = async (frameName) => {
2015
2015
  };
2016
2016
  const CACHE_CANDLES_FN = functoolsKit.retry(async (interval, dto) => {
2017
2017
  try {
2018
- console.log(`Checking candles cache for ${dto.symbol} ${interval} from ${dto.from} to ${dto.to}`);
2018
+ process.stdout.write("\n");
2019
+ process.stdout.write(`Checking candles cache for ${dto.symbol} ${interval} from ${dto.from} to ${dto.to}\n`);
2019
2020
  await BacktestKit.checkCandles({
2020
2021
  exchangeName: dto.exchangeName,
2021
2022
  from: dto.from,
@@ -2025,7 +2026,8 @@ const CACHE_CANDLES_FN = functoolsKit.retry(async (interval, dto) => {
2025
2026
  });
2026
2027
  }
2027
2028
  catch (error) {
2028
- console.log(`Caching candles for ${dto.symbol} ${interval} from ${dto.from} to ${dto.to}`);
2029
+ process.stdout.write("\n\n");
2030
+ process.stdout.write(`Caching candles for ${dto.symbol} ${interval} from ${dto.from} to ${dto.to}\n`);
2029
2031
  await BacktestKit.warmCandles({
2030
2032
  symbol: dto.symbol,
2031
2033
  exchangeName: dto.exchangeName,
@@ -3210,10 +3212,10 @@ init();
3210
3212
 
3211
3213
  const MODES = ["backtest", "walker", "paper", "live", "pine", "editor", "dump", "pnldebug", "brokerdebug", "flush", "init", "docker", "help", "version"];
3212
3214
  const ENTRY_PATH$1 = "./node_modules/@backtest-kit/cli/build/index.mjs";
3213
- const HELP_TEXT$1 = `
3214
- Example:
3215
-
3216
- node ${ENTRY_PATH$1} --help
3215
+ const HELP_TEXT$1 = `
3216
+ Example:
3217
+
3218
+ node ${ENTRY_PATH$1} --help
3217
3219
  `.trimStart();
3218
3220
  const main$g = async () => {
3219
3221
  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)))) {
@@ -3223,7 +3225,7 @@ const main$g = async () => {
3223
3225
  if (MODES.some((mode) => values[mode])) {
3224
3226
  return;
3225
3227
  }
3226
- process.stdout.write(`@backtest-kit/cli ${"9.8.1"}\n`);
3228
+ process.stdout.write(`@backtest-kit/cli ${"9.8.3"}\n`);
3227
3229
  process.stdout.write("\n");
3228
3230
  process.stdout.write(`Run with --help to see available commands.\n`);
3229
3231
  process.stdout.write("\n");
@@ -3511,11 +3513,17 @@ const main$a = async () => {
3511
3513
  await cli.configConnectionService.loadConfig("setup.config");
3512
3514
  {
3513
3515
  const loader = await cli.configConnectionService.loadConfig("loader.config");
3514
- if (typeof loader === "function") {
3515
- await loader();
3516
+ try {
3517
+ if (typeof loader === "function") {
3518
+ await loader();
3519
+ }
3520
+ if (typeof loader?.loader === "function") {
3521
+ await loader.loader();
3522
+ }
3516
3523
  }
3517
- if (typeof loader?.loader === "function") {
3518
- await loader.loader();
3524
+ catch (error) {
3525
+ console.error("Module loader failed", error);
3526
+ process.exit(-1);
3519
3527
  }
3520
3528
  }
3521
3529
  {
@@ -3539,14 +3547,18 @@ const main$a = async () => {
3539
3547
  if (values.noFlush) {
3540
3548
  continue;
3541
3549
  }
3542
- await flush(entryPoint);
3550
+ const absolutePath = path.resolve(cwd, entryPoint);
3551
+ await flush(absolutePath);
3543
3552
  }
3544
3553
  await cli.moduleConnectionService.loadModule(MODE_MODULE[mode]);
3545
3554
  listenFinish();
3546
3555
  createGracefulShutdown(mode)();
3556
+ let absolutePath;
3547
3557
  for (const entryPoint of entryPoints) {
3548
- await cli.resolveService.attachEntry(entryPoint);
3558
+ absolutePath = path.resolve(cwd, entryPoint);
3559
+ await cli.resolveService.attachEntry(absolutePath);
3549
3560
  }
3561
+ await entrySubject.next(absolutePath);
3550
3562
  };
3551
3563
  main$a();
3552
3564
 
@@ -3634,11 +3646,17 @@ const main$7 = async () => {
3634
3646
  await cli.configConnectionService.loadConfig("setup.config");
3635
3647
  {
3636
3648
  const loader = await cli.configConnectionService.loadConfig("loader.config");
3637
- if (typeof loader === "function") {
3638
- await loader();
3649
+ try {
3650
+ if (typeof loader === "function") {
3651
+ await loader();
3652
+ }
3653
+ if (typeof loader?.loader === "function") {
3654
+ await loader.loader();
3655
+ }
3639
3656
  }
3640
- if (typeof loader?.loader === "function") {
3641
- await loader.loader();
3657
+ catch (error) {
3658
+ console.error("Module loader failed", error);
3659
+ process.exit(-1);
3642
3660
  }
3643
3661
  }
3644
3662
  await cli.moduleConnectionService.loadModule("pine.module");
@@ -3721,11 +3739,17 @@ const main$6 = async () => {
3721
3739
  await cli.configConnectionService.loadConfig("setup.config");
3722
3740
  {
3723
3741
  const loader = await cli.configConnectionService.loadConfig("loader.config");
3724
- if (typeof loader === "function") {
3725
- await loader();
3742
+ try {
3743
+ if (typeof loader === "function") {
3744
+ await loader();
3745
+ }
3746
+ if (typeof loader?.loader === "function") {
3747
+ await loader.loader();
3748
+ }
3726
3749
  }
3727
- if (typeof loader?.loader === "function") {
3728
- await loader.loader();
3750
+ catch (error) {
3751
+ console.error("Module loader failed", error);
3752
+ process.exit(-1);
3729
3753
  }
3730
3754
  }
3731
3755
  {
@@ -3742,11 +3766,15 @@ const main$6 = async () => {
3742
3766
  }
3743
3767
  const { CC_WWWROOT_HOST, CC_WWWROOT_PORT } = getEnv();
3744
3768
  const unServer = BacktestKitUi.serve(CC_WWWROOT_HOST, CC_WWWROOT_PORT, cli.resolveService.PROJECT_ROOT_DIR);
3769
+ let isOk = true;
3745
3770
  try {
3746
3771
  await open(`http://localhost:${CC_WWWROOT_PORT}?pine=1`);
3772
+ isOk = true;
3773
+ }
3774
+ catch {
3747
3775
  }
3748
3776
  finally {
3749
- console.log(`Editor launched: http://localhost:${CC_WWWROOT_PORT}?pine=1`);
3777
+ isOk && console.log(`Editor launched: http://localhost:${CC_WWWROOT_PORT}?pine=1`);
3750
3778
  }
3751
3779
  const beforeExit = () => {
3752
3780
  process.off("SIGINT", beforeExit);
@@ -3772,11 +3800,17 @@ const main$5 = async () => {
3772
3800
  await cli.configConnectionService.loadConfig("setup.config");
3773
3801
  {
3774
3802
  const loader = await cli.configConnectionService.loadConfig("loader.config");
3775
- if (typeof loader === "function") {
3776
- await loader();
3803
+ try {
3804
+ if (typeof loader === "function") {
3805
+ await loader();
3806
+ }
3807
+ if (typeof loader?.loader === "function") {
3808
+ await loader.loader();
3809
+ }
3777
3810
  }
3778
- if (typeof loader?.loader === "function") {
3779
- await loader.loader();
3811
+ catch (error) {
3812
+ console.error("Module loader failed", error);
3813
+ process.exit(-1);
3780
3814
  }
3781
3815
  }
3782
3816
  await cli.moduleConnectionService.loadModule("dump.module");
@@ -3849,11 +3883,17 @@ const main$4 = async () => {
3849
3883
  await cli.configConnectionService.loadConfig("setup.config");
3850
3884
  {
3851
3885
  const loader = await cli.configConnectionService.loadConfig("loader.config");
3852
- if (typeof loader === "function") {
3853
- await loader();
3886
+ try {
3887
+ if (typeof loader === "function") {
3888
+ await loader();
3889
+ }
3890
+ if (typeof loader?.loader === "function") {
3891
+ await loader.loader();
3892
+ }
3854
3893
  }
3855
- if (typeof loader?.loader === "function") {
3856
- await loader.loader();
3894
+ catch (error) {
3895
+ console.error("Module loader failed", error);
3896
+ process.exit(-1);
3857
3897
  }
3858
3898
  }
3859
3899
  await cli.moduleConnectionService.loadModule("pnldebug.module");
@@ -4124,183 +4164,183 @@ const main$2 = async () => {
4124
4164
  main$2();
4125
4165
 
4126
4166
  const ENTRY_PATH = "./node_modules/@backtest-kit/cli/build/index.mjs";
4127
- const HELP_TEXT = `
4128
- Usage:
4129
- node index.mjs --<mode> [flags] [entry-point]
4130
-
4131
- Modes:
4132
-
4133
- --backtest <entry> Run strategy against historical candle data
4134
- --walker <entry...> Run Walker A/B strategy comparison across multiple strategies
4135
- --paper <entry> Paper trading (live prices, no real orders)
4136
- --live <entry> Live trading with real orders
4137
- --pine <entry> Execute a local .pine indicator file
4138
- --editor Open the Pine Script visual editor in the browser
4139
- --dump Fetch and save raw OHLCV candles
4140
- --pnldebug Simulate PnL per minute for a given entry price and direction
4141
- --brokerdebug Fire a single broker commit against the live broker adapter
4142
- --flush <entry...> Delete report/log/markdown/agent folders from strategy dump dir
4143
- --init Scaffold a new project in the current directory
4144
- --docker Scaffold a Docker workspace for running strategies in a container
4145
- --help Print this help message
4146
-
4147
- Backtest flags:
4148
-
4149
- --symbol <string> Trading pair (default: BTCUSDT)
4150
- --strategy <string> Strategy name from addStrategySchema (default: first registered)
4151
- --exchange <string> Exchange name from addExchangeSchema (default: first registered)
4152
- --frame <string> Frame name from addFrameSchema (default: first registered)
4153
- --cacheInterval <string> Comma-separated intervals to pre-cache (default: "1m, 15m, 30m, 4h")
4154
- --noCache Skip candle cache warming before the run
4155
- --noFlush Skip removing report/log/markdown/agent folders before backtest run
4156
- --verbose Log every candle fetch to stdout
4157
- --ui Start web dashboard at http://localhost:60050
4158
- --telegram Send trade notifications to Telegram
4159
-
4160
- Walker flags (--walker):
4161
-
4162
- --symbol <string> Trading pair (default: BTCUSDT)
4163
- --cacheInterval <string> Comma-separated intervals to pre-cache (default: "1m, 15m, 30m, 4h")
4164
- --noCache Skip candle cache warming before the run
4165
- --noFlush Skip removing report/log/markdown/agent folders before walker run
4166
- --verbose Log every candle fetch to stdout
4167
- --output <string> Output file base name (default: walker_{SYMBOL}_{TIMESTAMP})
4168
- --json Save results as JSON to ./dump/<output>.json
4169
- --markdown Save report as Markdown to ./dump/<output>.md
4170
-
4171
- Each positional argument is a strategy entry point. All strategy files are loaded without
4172
- changing process.cwd() — .env is read from the working directory only.
4173
- addWalkerSchema is called automatically using the registered exchange and frame.
4174
- After comparison completes the report is printed to stdout (or saved if --json/--markdown).
4175
-
4176
- Module file ./modules/walker.module is loaded automatically if it exists.
4177
-
4178
- Paper / Live flags:
4179
-
4180
- --symbol <string> Trading pair (default: BTCUSDT)
4181
- --strategy <string> Strategy name (default: first registered)
4182
- --exchange <string> Exchange name (default: first registered)
4183
- --verbose Log every candle fetch to stdout
4184
- --ui Start web dashboard
4185
- --telegram Send Telegram notifications
4186
-
4187
- PineScript flags (--pine):
4188
-
4189
- --symbol <string> Trading pair (default: BTCUSDT)
4190
- --timeframe <string> Candle interval (default: 15m)
4191
- --limit <string> Number of candles to fetch (default: 250)
4192
- --when <string> End date — ISO 8601 or Unix ms (default: now)
4193
- --exchange <string> Exchange name (default: first registered)
4194
- --output <string> Output file base name without extension
4195
- --json Save output as JSON array to <pine-dir>/dump/<output>.json
4196
- --jsonl Save output as JSONL to <pine-dir>/dump/<output>.jsonl
4197
- --markdown Save output as Markdown table to <pine-dir>/dump/<output>.md
4198
-
4199
- Only plot() calls with display=display.data_window produce output columns.
4200
- Module file ./modules/pine.module is loaded automatically if it exists.
4201
-
4202
- Candle dump flags (--dump):
4203
-
4204
- --symbol <string> Trading pair (default: BTCUSDT)
4205
- --timeframe <string> Candle interval (default: 15m)
4206
- --limit <string> Number of candles (default: 250)
4207
- --when <string> End date — ISO 8601 or Unix ms (default: now)
4208
- --exchange <string> Exchange name (default: first registered)
4209
- --output <string> Output file base name (default: {SYMBOL}_{LIMIT}_{TIMEFRAME}_{TIMESTAMP})
4210
- --json Save as JSON array to ./dump/<output>.json
4211
- --jsonl Save as JSONL to ./dump/<output>.jsonl
4212
-
4213
- Module file ./modules/dump.module is loaded automatically if it exists.
4214
-
4215
- PnL debug flags (--pnldebug):
4216
-
4217
- --symbol <string> Trading pair (default: BTCUSDT)
4218
- --priceopen <number> Entry price (required)
4219
- --direction <string> Position direction: long or short (default: long)
4220
- --when <string> Start timestamp — ISO 8601 or Unix ms (default: now)
4221
- --minutes <string> Number of 1m candles to simulate (default: 60)
4222
- --exchange <string> Exchange name (default: first registered)
4223
- --output <string> Output file base name (default: {SYMBOL}_{DIRECTION}_{PRICEOPEN}_{TIMESTAMP})
4224
- --json Save as JSON array to ./dump/<output>.json
4225
- --jsonl Save as JSONL to ./dump/<output>.jsonl
4226
- --markdown Save as Markdown table to ./dump/<output>.md
4227
-
4228
- Module file ./modules/pnldebug.module is loaded automatically if it exists.
4229
-
4230
- Broker debug flags (--brokerdebug):
4231
-
4232
- --symbol <string> Trading pair (default: BTCUSDT)
4233
- --exchange <string> Exchange name (default: first registered)
4234
- --commit <string> Commit type to fire: signal-open, signal-close, partial-profit,
4235
- partial-loss, average-buy, trailing-stop, trailing-take, breakeven
4236
- (default: signal-open)
4237
-
4238
- Loads ./live.module, fetches the last candle for --symbol/--timeframe, and calls
4239
- the selected broker commit with synthetic payload values derived from current price.
4240
-
4241
- Flush flags (--flush):
4242
-
4243
- One or more positional entry points. For each entry point the following
4244
- subdirectories are removed from <entry-dir>/dump/:
4245
-
4246
- report log markdown agent
4247
-
4248
- Init flags (--init):
4249
-
4250
- --output <string> Target directory name (default: backtest-kit-project)
4251
-
4252
- Scaffolds a project and runs scripts/fetch_docs.mjs to download library docs.
4253
-
4254
- Docker flags (--docker):
4255
-
4256
- --output <string> Target directory name (default: backtest-kit-docker)
4257
-
4258
- Scaffolds a Docker workspace: docker-compose.yaml, .env.example, package.json,
4259
- tsconfig.json, and a sample strategy under content/. Run npm install then
4260
- docker compose up to start the container.
4261
-
4262
- Module hooks (loaded automatically by each mode):
4263
-
4264
- modules/backtest.module --backtest Broker adapter for backtest
4265
- modules/walker.module --walker Broker adapter for walker comparison
4266
- modules/paper.module --paper Broker adapter for paper trading
4267
- modules/live.module --live Broker adapter for live trading
4268
- modules/pine.module --pine Exchange schema for PineScript runs
4269
- modules/editor.module --editor Exchange schema for the visual Pine editor
4270
- modules/dump.module --dump Exchange schema for candle dumps
4271
- modules/pnldebug.module --pnldebug Exchange schema for PnL debug runs
4272
- modules/brokerdebug.module --brokerdebug Broker adapter used for broker commit testing
4273
-
4274
- --flush has no associated module. It only removes dump subdirectories.
4275
-
4276
- Extensions .ts, .mjs, .cjs are tried automatically. Missing module = soft warning.
4277
-
4278
- Environment variables:
4279
-
4280
- CC_TELEGRAM_TOKEN Telegram bot token (required for --telegram)
4281
- CC_TELEGRAM_CHANNEL Telegram channel or chat ID (required for --telegram)
4282
- CC_WWWROOT_HOST UI server bind address (default: 0.0.0.0)
4283
- CC_WWWROOT_PORT UI server port (default: 60050)
4284
-
4285
- Examples:
4286
-
4287
- node ${ENTRY_PATH} --backtest ./content/feb_2026.strategy.ts
4288
- node ${ENTRY_PATH} --backtest --symbol BTCUSDT --noCache --noFlush --ui ./content/feb_2026.strategy.ts
4289
- node ${ENTRY_PATH} --walker ./content/feb_2026_v1.strategy.ts ./content/feb_2026_v2.strategy.ts ./content/feb_2026_v3.strategy.ts
4290
- node ${ENTRY_PATH} --walker --symbol BTCUSDT --noCache --noFlush --markdown ./content/feb_2026_v1.ts ./content/feb_2026_v2.ts
4291
- node ${ENTRY_PATH} --paper --symbol ETHUSDT ./content/feb_2026.strategy.ts
4292
- node ${ENTRY_PATH} --live --ui --telegram ./content/feb_2026.strategy.ts
4293
- node ${ENTRY_PATH} --pine ./math/feb_2026.pine --timeframe 15m --limit 500 --jsonl
4294
- node ${ENTRY_PATH} --editor
4295
- node ${ENTRY_PATH} --dump --symbol BTCUSDT --timeframe 15m --limit 500 --jsonl
4296
- node ${ENTRY_PATH} --pnldebug --symbol BTCUSDT --priceopen 64069.50 --direction short --when "2025-02-25" --minutes 120
4297
- node ${ENTRY_PATH} --pnldebug --priceopen 67956.73 --direction long --when 1772064000000 --minutes 60 --markdown
4298
- node ${ENTRY_PATH} --brokerdebug --commit signal-open --symbol BTCUSDT
4299
- node ${ENTRY_PATH} --brokerdebug --commit partial-profit --symbol ETHUSDT
4300
- node ${ENTRY_PATH} --flush ./content/feb_2026.strategy/feb_2026.strategy.ts
4301
- node ${ENTRY_PATH} --flush ./content/feb_2026.strategy/feb_2026.strategy.ts ./content/feb_2026.strategy/feb_2026.test.ts
4302
- node ${ENTRY_PATH} --init --output my-trading-bot
4303
- node ${ENTRY_PATH} --docker --output my-docker-workspace
4167
+ const HELP_TEXT = `
4168
+ Usage:
4169
+ node index.mjs --<mode> [flags] [entry-point]
4170
+
4171
+ Modes:
4172
+
4173
+ --backtest <entry> Run strategy against historical candle data
4174
+ --walker <entry...> Run Walker A/B strategy comparison across multiple strategies
4175
+ --paper <entry> Paper trading (live prices, no real orders)
4176
+ --live <entry> Live trading with real orders
4177
+ --pine <entry> Execute a local .pine indicator file
4178
+ --editor Open the Pine Script visual editor in the browser
4179
+ --dump Fetch and save raw OHLCV candles
4180
+ --pnldebug Simulate PnL per minute for a given entry price and direction
4181
+ --brokerdebug Fire a single broker commit against the live broker adapter
4182
+ --flush <entry...> Delete report/log/markdown/agent folders from strategy dump dir
4183
+ --init Scaffold a new project in the current directory
4184
+ --docker Scaffold a Docker workspace for running strategies in a container
4185
+ --help Print this help message
4186
+
4187
+ Backtest flags:
4188
+
4189
+ --symbol <string> Trading pair (default: BTCUSDT)
4190
+ --strategy <string> Strategy name from addStrategySchema (default: first registered)
4191
+ --exchange <string> Exchange name from addExchangeSchema (default: first registered)
4192
+ --frame <string> Frame name from addFrameSchema (default: first registered)
4193
+ --cacheInterval <string> Comma-separated intervals to pre-cache (default: "1m, 15m, 30m, 4h")
4194
+ --noCache Skip candle cache warming before the run
4195
+ --noFlush Skip removing report/log/markdown/agent folders before backtest run
4196
+ --verbose Log every candle fetch to stdout
4197
+ --ui Start web dashboard at http://localhost:60050
4198
+ --telegram Send trade notifications to Telegram
4199
+
4200
+ Walker flags (--walker):
4201
+
4202
+ --symbol <string> Trading pair (default: BTCUSDT)
4203
+ --cacheInterval <string> Comma-separated intervals to pre-cache (default: "1m, 15m, 30m, 4h")
4204
+ --noCache Skip candle cache warming before the run
4205
+ --noFlush Skip removing report/log/markdown/agent folders before walker run
4206
+ --verbose Log every candle fetch to stdout
4207
+ --output <string> Output file base name (default: walker_{SYMBOL}_{TIMESTAMP})
4208
+ --json Save results as JSON to ./dump/<output>.json
4209
+ --markdown Save report as Markdown to ./dump/<output>.md
4210
+
4211
+ Each positional argument is a strategy entry point. All strategy files are loaded without
4212
+ changing process.cwd() — .env is read from the working directory only.
4213
+ addWalkerSchema is called automatically using the registered exchange and frame.
4214
+ After comparison completes the report is printed to stdout (or saved if --json/--markdown).
4215
+
4216
+ Module file ./modules/walker.module is loaded automatically if it exists.
4217
+
4218
+ Paper / Live flags:
4219
+
4220
+ --symbol <string> Trading pair (default: BTCUSDT)
4221
+ --strategy <string> Strategy name (default: first registered)
4222
+ --exchange <string> Exchange name (default: first registered)
4223
+ --verbose Log every candle fetch to stdout
4224
+ --ui Start web dashboard
4225
+ --telegram Send Telegram notifications
4226
+
4227
+ PineScript flags (--pine):
4228
+
4229
+ --symbol <string> Trading pair (default: BTCUSDT)
4230
+ --timeframe <string> Candle interval (default: 15m)
4231
+ --limit <string> Number of candles to fetch (default: 250)
4232
+ --when <string> End date — ISO 8601 or Unix ms (default: now)
4233
+ --exchange <string> Exchange name (default: first registered)
4234
+ --output <string> Output file base name without extension
4235
+ --json Save output as JSON array to <pine-dir>/dump/<output>.json
4236
+ --jsonl Save output as JSONL to <pine-dir>/dump/<output>.jsonl
4237
+ --markdown Save output as Markdown table to <pine-dir>/dump/<output>.md
4238
+
4239
+ Only plot() calls with display=display.data_window produce output columns.
4240
+ Module file ./modules/pine.module is loaded automatically if it exists.
4241
+
4242
+ Candle dump flags (--dump):
4243
+
4244
+ --symbol <string> Trading pair (default: BTCUSDT)
4245
+ --timeframe <string> Candle interval (default: 15m)
4246
+ --limit <string> Number of candles (default: 250)
4247
+ --when <string> End date — ISO 8601 or Unix ms (default: now)
4248
+ --exchange <string> Exchange name (default: first registered)
4249
+ --output <string> Output file base name (default: {SYMBOL}_{LIMIT}_{TIMEFRAME}_{TIMESTAMP})
4250
+ --json Save as JSON array to ./dump/<output>.json
4251
+ --jsonl Save as JSONL to ./dump/<output>.jsonl
4252
+
4253
+ Module file ./modules/dump.module is loaded automatically if it exists.
4254
+
4255
+ PnL debug flags (--pnldebug):
4256
+
4257
+ --symbol <string> Trading pair (default: BTCUSDT)
4258
+ --priceopen <number> Entry price (required)
4259
+ --direction <string> Position direction: long or short (default: long)
4260
+ --when <string> Start timestamp — ISO 8601 or Unix ms (default: now)
4261
+ --minutes <string> Number of 1m candles to simulate (default: 60)
4262
+ --exchange <string> Exchange name (default: first registered)
4263
+ --output <string> Output file base name (default: {SYMBOL}_{DIRECTION}_{PRICEOPEN}_{TIMESTAMP})
4264
+ --json Save as JSON array to ./dump/<output>.json
4265
+ --jsonl Save as JSONL to ./dump/<output>.jsonl
4266
+ --markdown Save as Markdown table to ./dump/<output>.md
4267
+
4268
+ Module file ./modules/pnldebug.module is loaded automatically if it exists.
4269
+
4270
+ Broker debug flags (--brokerdebug):
4271
+
4272
+ --symbol <string> Trading pair (default: BTCUSDT)
4273
+ --exchange <string> Exchange name (default: first registered)
4274
+ --commit <string> Commit type to fire: signal-open, signal-close, partial-profit,
4275
+ partial-loss, average-buy, trailing-stop, trailing-take, breakeven
4276
+ (default: signal-open)
4277
+
4278
+ Loads ./live.module, fetches the last candle for --symbol/--timeframe, and calls
4279
+ the selected broker commit with synthetic payload values derived from current price.
4280
+
4281
+ Flush flags (--flush):
4282
+
4283
+ One or more positional entry points. For each entry point the following
4284
+ subdirectories are removed from <entry-dir>/dump/:
4285
+
4286
+ report log markdown agent
4287
+
4288
+ Init flags (--init):
4289
+
4290
+ --output <string> Target directory name (default: backtest-kit-project)
4291
+
4292
+ Scaffolds a project and runs scripts/fetch_docs.mjs to download library docs.
4293
+
4294
+ Docker flags (--docker):
4295
+
4296
+ --output <string> Target directory name (default: backtest-kit-docker)
4297
+
4298
+ Scaffolds a Docker workspace: docker-compose.yaml, .env.example, package.json,
4299
+ tsconfig.json, and a sample strategy under content/. Run npm install then
4300
+ docker compose up to start the container.
4301
+
4302
+ Module hooks (loaded automatically by each mode):
4303
+
4304
+ modules/backtest.module --backtest Broker adapter for backtest
4305
+ modules/walker.module --walker Broker adapter for walker comparison
4306
+ modules/paper.module --paper Broker adapter for paper trading
4307
+ modules/live.module --live Broker adapter for live trading
4308
+ modules/pine.module --pine Exchange schema for PineScript runs
4309
+ modules/editor.module --editor Exchange schema for the visual Pine editor
4310
+ modules/dump.module --dump Exchange schema for candle dumps
4311
+ modules/pnldebug.module --pnldebug Exchange schema for PnL debug runs
4312
+ modules/brokerdebug.module --brokerdebug Broker adapter used for broker commit testing
4313
+
4314
+ --flush has no associated module. It only removes dump subdirectories.
4315
+
4316
+ Extensions .ts, .mjs, .cjs are tried automatically. Missing module = soft warning.
4317
+
4318
+ Environment variables:
4319
+
4320
+ CC_TELEGRAM_TOKEN Telegram bot token (required for --telegram)
4321
+ CC_TELEGRAM_CHANNEL Telegram channel or chat ID (required for --telegram)
4322
+ CC_WWWROOT_HOST UI server bind address (default: 0.0.0.0)
4323
+ CC_WWWROOT_PORT UI server port (default: 60050)
4324
+
4325
+ Examples:
4326
+
4327
+ node ${ENTRY_PATH} --backtest ./content/feb_2026.strategy.ts
4328
+ node ${ENTRY_PATH} --backtest --symbol BTCUSDT --noCache --noFlush --ui ./content/feb_2026.strategy.ts
4329
+ node ${ENTRY_PATH} --walker ./content/feb_2026_v1.strategy.ts ./content/feb_2026_v2.strategy.ts ./content/feb_2026_v3.strategy.ts
4330
+ node ${ENTRY_PATH} --walker --symbol BTCUSDT --noCache --noFlush --markdown ./content/feb_2026_v1.ts ./content/feb_2026_v2.ts
4331
+ node ${ENTRY_PATH} --paper --symbol ETHUSDT ./content/feb_2026.strategy.ts
4332
+ node ${ENTRY_PATH} --live --ui --telegram ./content/feb_2026.strategy.ts
4333
+ node ${ENTRY_PATH} --pine ./math/feb_2026.pine --timeframe 15m --limit 500 --jsonl
4334
+ node ${ENTRY_PATH} --editor
4335
+ node ${ENTRY_PATH} --dump --symbol BTCUSDT --timeframe 15m --limit 500 --jsonl
4336
+ node ${ENTRY_PATH} --pnldebug --symbol BTCUSDT --priceopen 64069.50 --direction short --when "2025-02-25" --minutes 120
4337
+ node ${ENTRY_PATH} --pnldebug --priceopen 67956.73 --direction long --when 1772064000000 --minutes 60 --markdown
4338
+ node ${ENTRY_PATH} --brokerdebug --commit signal-open --symbol BTCUSDT
4339
+ node ${ENTRY_PATH} --brokerdebug --commit partial-profit --symbol ETHUSDT
4340
+ node ${ENTRY_PATH} --flush ./content/feb_2026.strategy/feb_2026.strategy.ts
4341
+ node ${ENTRY_PATH} --flush ./content/feb_2026.strategy/feb_2026.strategy.ts ./content/feb_2026.strategy/feb_2026.test.ts
4342
+ node ${ENTRY_PATH} --init --output my-trading-bot
4343
+ node ${ENTRY_PATH} --docker --output my-docker-workspace
4304
4344
  `.trimStart();
4305
4345
  const main$1 = async () => {
4306
4346
  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)))) {
@@ -4310,7 +4350,7 @@ const main$1 = async () => {
4310
4350
  if (!values.help) {
4311
4351
  return;
4312
4352
  }
4313
- process.stdout.write(`@backtest-kit/cli ${"9.8.1"}\n\n`);
4353
+ process.stdout.write(`@backtest-kit/cli ${"9.8.3"}\n\n`);
4314
4354
  process.stdout.write(HELP_TEXT);
4315
4355
  process.exit(0);
4316
4356
  };
@@ -4324,7 +4364,7 @@ const main = async () => {
4324
4364
  if (!values.version) {
4325
4365
  return;
4326
4366
  }
4327
- process.stdout.write(`@backtest-kit/cli ${"9.8.1"}\n`);
4367
+ process.stdout.write(`@backtest-kit/cli ${"9.8.3"}\n`);
4328
4368
  process.exit(0);
4329
4369
  };
4330
4370
  main();