@backtest-kit/cli 9.8.0 → 9.8.2

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();
@@ -383,6 +351,9 @@ class SetupUtils {
383
351
  BacktestKit.RecentLive.clear();
384
352
  BacktestKit.RecentBacktest.clear();
385
353
  }
354
+ {
355
+ BacktestKit.Broker.clear();
356
+ }
386
357
  };
387
358
  this.update = () => {
388
359
  cli.loggerService.debug("SetupUtils update");
@@ -461,9 +432,9 @@ class ResolveService {
461
432
  dotenv.config({ path: path.join(cwd, '.env'), override: true, quiet: true });
462
433
  dotenv.config({ path: path.join(moduleRoot, '.env'), override: true, quiet: true });
463
434
  this.loaderService.import(absolutePath);
464
- await entrySubject.next(absolutePath);
465
435
  }
466
436
  _is_launched = true;
437
+ return absolutePath;
467
438
  };
468
439
  this.attachEntry = async (jsPath) => {
469
440
  this.loggerService.log("resolveService attachEntry", {
@@ -478,9 +449,9 @@ class ResolveService {
478
449
  dotenv.config({ path: path.join(cwd, '.env'), override: true, quiet: true });
479
450
  {
480
451
  this.loaderService.import(absolutePath);
481
- await entrySubject.next(absolutePath);
482
452
  }
483
453
  _is_launched = true;
454
+ return absolutePath;
484
455
  };
485
456
  }
486
457
  }
@@ -883,6 +854,8 @@ const notifyVerbose = functoolsKit.singleshot(() => {
883
854
  });
884
855
  });
885
856
 
857
+ const entrySubject = new functoolsKit.BehaviorSubject();
858
+
886
859
  const DEFAULT_CACHE_LIST$1 = ["1m", "15m", "30m", "1h", "4h"];
887
860
  const GET_CACHE_INTERVAL_LIST_FN$1 = () => {
888
861
  const { values } = getArgs();
@@ -913,11 +886,17 @@ class BacktestMainService {
913
886
  await this.configConnectionService.loadConfig("setup.config");
914
887
  {
915
888
  const loader = await this.configConnectionService.loadConfig("loader.config");
916
- if (typeof loader === "function") {
917
- await loader();
889
+ try {
890
+ if (typeof loader === "function") {
891
+ await loader();
892
+ }
893
+ if (typeof loader?.loader === "function") {
894
+ await loader.loader();
895
+ }
918
896
  }
919
- if (typeof loader?.loader === "function") {
920
- await loader.loader();
897
+ catch (error) {
898
+ console.error("Module loader failed", error);
899
+ process.exit(-1);
921
900
  }
922
901
  }
923
902
  {
@@ -932,8 +911,9 @@ class BacktestMainService {
932
911
  const cwd = process.cwd();
933
912
  dotenv.config({ path: path.join(cwd, '.env'), override: true, quiet: true });
934
913
  }
914
+ let absolutePath;
935
915
  {
936
- await this.resolveService.attachJavascript(payload.entryPoint);
916
+ absolutePath = await this.resolveService.attachJavascript(payload.entryPoint);
937
917
  await this.moduleConnectionService.loadModule("backtest.module");
938
918
  }
939
919
  {
@@ -975,6 +955,7 @@ class BacktestMainService {
975
955
  });
976
956
  notifyVerbose();
977
957
  }
958
+ await entrySubject.next(absolutePath);
978
959
  BacktestKit.Backtest.background(symbol, {
979
960
  strategyName,
980
961
  frameName,
@@ -1041,11 +1022,17 @@ class WalkerMainService {
1041
1022
  await this.configConnectionService.loadConfig("setup.config");
1042
1023
  {
1043
1024
  const loader = await this.configConnectionService.loadConfig("loader.config");
1044
- if (typeof loader === "function") {
1045
- await loader();
1025
+ try {
1026
+ if (typeof loader === "function") {
1027
+ await loader();
1028
+ }
1029
+ if (typeof loader?.loader === "function") {
1030
+ await loader.loader();
1031
+ }
1046
1032
  }
1047
- if (typeof loader?.loader === "function") {
1048
- await loader.loader();
1033
+ catch (error) {
1034
+ console.error("Module loader failed", error);
1035
+ process.exit(-1);
1049
1036
  }
1050
1037
  }
1051
1038
  {
@@ -1275,11 +1262,17 @@ class LiveMainService {
1275
1262
  await this.configConnectionService.loadConfig("setup.config");
1276
1263
  {
1277
1264
  const loader = await this.configConnectionService.loadConfig("loader.config");
1278
- if (typeof loader === "function") {
1279
- await loader();
1265
+ try {
1266
+ if (typeof loader === "function") {
1267
+ await loader();
1268
+ }
1269
+ if (typeof loader?.loader === "function") {
1270
+ await loader.loader();
1271
+ }
1280
1272
  }
1281
- if (typeof loader?.loader === "function") {
1282
- await loader.loader();
1273
+ catch (error) {
1274
+ console.error("Module loader failed", error);
1275
+ process.exit(-1);
1283
1276
  }
1284
1277
  }
1285
1278
  {
@@ -1294,8 +1287,9 @@ class LiveMainService {
1294
1287
  const cwd = process.cwd();
1295
1288
  dotenv.config({ path: path.join(cwd, '.env'), override: true, quiet: true });
1296
1289
  }
1290
+ let absolutePath;
1297
1291
  {
1298
- await this.resolveService.attachJavascript(payload.entryPoint);
1292
+ absolutePath = await this.resolveService.attachJavascript(payload.entryPoint);
1299
1293
  await this.moduleConnectionService.loadModule("live.module");
1300
1294
  }
1301
1295
  {
@@ -1324,6 +1318,7 @@ class LiveMainService {
1324
1318
  });
1325
1319
  notifyVerbose();
1326
1320
  }
1321
+ await entrySubject.next(absolutePath);
1327
1322
  BacktestKit.Live.background(symbol, {
1328
1323
  strategyName,
1329
1324
  exchangeName,
@@ -1370,11 +1365,17 @@ class PaperMainService {
1370
1365
  await this.configConnectionService.loadConfig("setup.config");
1371
1366
  {
1372
1367
  const loader = await this.configConnectionService.loadConfig("loader.config");
1373
- if (typeof loader === "function") {
1374
- await loader();
1368
+ try {
1369
+ if (typeof loader === "function") {
1370
+ await loader();
1371
+ }
1372
+ if (typeof loader?.loader === "function") {
1373
+ await loader.loader();
1374
+ }
1375
1375
  }
1376
- if (typeof loader?.loader === "function") {
1377
- await loader.loader();
1376
+ catch (error) {
1377
+ console.error("Module loader failed", error);
1378
+ process.exit(-1);
1378
1379
  }
1379
1380
  }
1380
1381
  {
@@ -1389,8 +1390,9 @@ class PaperMainService {
1389
1390
  const cwd = process.cwd();
1390
1391
  dotenv.config({ path: path.join(cwd, '.env'), override: true, quiet: true });
1391
1392
  }
1393
+ let absolutePath;
1392
1394
  {
1393
- await this.resolveService.attachJavascript(payload.entryPoint);
1395
+ absolutePath = await this.resolveService.attachJavascript(payload.entryPoint);
1394
1396
  await this.moduleConnectionService.loadModule("paper.module");
1395
1397
  }
1396
1398
  {
@@ -1419,6 +1421,7 @@ class PaperMainService {
1419
1421
  });
1420
1422
  notifyVerbose();
1421
1423
  }
1424
+ await entrySubject.next(absolutePath);
1422
1425
  BacktestKit.Live.background(symbol, {
1423
1426
  strategyName,
1424
1427
  exchangeName,
@@ -2012,7 +2015,8 @@ const GET_TIMEFRAME_RANGE_FN = async (frameName) => {
2012
2015
  };
2013
2016
  const CACHE_CANDLES_FN = functoolsKit.retry(async (interval, dto) => {
2014
2017
  try {
2015
- 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`);
2016
2020
  await BacktestKit.checkCandles({
2017
2021
  exchangeName: dto.exchangeName,
2018
2022
  from: dto.from,
@@ -2022,7 +2026,8 @@ const CACHE_CANDLES_FN = functoolsKit.retry(async (interval, dto) => {
2022
2026
  });
2023
2027
  }
2024
2028
  catch (error) {
2025
- 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`);
2026
2031
  await BacktestKit.warmCandles({
2027
2032
  symbol: dto.symbol,
2028
2033
  exchangeName: dto.exchangeName,
@@ -3207,10 +3212,10 @@ init();
3207
3212
 
3208
3213
  const MODES = ["backtest", "walker", "paper", "live", "pine", "editor", "dump", "pnldebug", "brokerdebug", "flush", "init", "docker", "help", "version"];
3209
3214
  const ENTRY_PATH$1 = "./node_modules/@backtest-kit/cli/build/index.mjs";
3210
- const HELP_TEXT$1 = `
3211
- Example:
3212
-
3213
- node ${ENTRY_PATH$1} --help
3215
+ const HELP_TEXT$1 = `
3216
+ Example:
3217
+
3218
+ node ${ENTRY_PATH$1} --help
3214
3219
  `.trimStart();
3215
3220
  const main$g = async () => {
3216
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)))) {
@@ -3220,7 +3225,7 @@ const main$g = async () => {
3220
3225
  if (MODES.some((mode) => values[mode])) {
3221
3226
  return;
3222
3227
  }
3223
- process.stdout.write(`@backtest-kit/cli ${"9.8.0"}\n`);
3228
+ process.stdout.write(`@backtest-kit/cli ${"9.8.2"}\n`);
3224
3229
  process.stdout.write("\n");
3225
3230
  process.stdout.write(`Run with --help to see available commands.\n`);
3226
3231
  process.stdout.write("\n");
@@ -3505,20 +3510,20 @@ const main$a = async () => {
3505
3510
  if (!entryPoints.length) {
3506
3511
  throw new Error("At least one entry point is required");
3507
3512
  }
3508
- for (const entryPoint of entryPoints) {
3509
- if (values.noFlush) {
3510
- continue;
3511
- }
3512
- await flush(entryPoint);
3513
- }
3514
3513
  await cli.configConnectionService.loadConfig("setup.config");
3515
3514
  {
3516
3515
  const loader = await cli.configConnectionService.loadConfig("loader.config");
3517
- if (typeof loader === "function") {
3518
- await loader();
3516
+ try {
3517
+ if (typeof loader === "function") {
3518
+ await loader();
3519
+ }
3520
+ if (typeof loader?.loader === "function") {
3521
+ await loader.loader();
3522
+ }
3519
3523
  }
3520
- if (typeof loader?.loader === "function") {
3521
- await loader.loader();
3524
+ catch (error) {
3525
+ console.error("Module loader failed", error);
3526
+ process.exit(-1);
3522
3527
  }
3523
3528
  }
3524
3529
  {
@@ -3527,19 +3532,33 @@ const main$a = async () => {
3527
3532
  }
3528
3533
  cli.frontendProviderService.connect();
3529
3534
  cli.telegramProviderService.connect();
3535
+ const cwd = process.cwd();
3530
3536
  {
3531
- const cwd = process.cwd();
3532
3537
  dotenv.config({ path: path.join(cwd, '.env'), override: true, quiet: true });
3533
3538
  }
3534
3539
  if (entryPoints.length === 1) {
3535
- process.chdir(path.dirname(path.resolve(entryPoints[0])));
3540
+ const absolutePath = path.resolve(entryPoints[0]);
3541
+ const moduleRoot = path.dirname(absolutePath);
3542
+ process.chdir(moduleRoot);
3543
+ cwd !== moduleRoot && Setup.update();
3544
+ dotenv.config({ path: path.join(moduleRoot, '.env'), override: true, quiet: true });
3545
+ }
3546
+ for (const entryPoint of entryPoints) {
3547
+ if (values.noFlush) {
3548
+ continue;
3549
+ }
3550
+ const absolutePath = path.resolve(cwd, entryPoint);
3551
+ await flush(absolutePath);
3536
3552
  }
3537
3553
  await cli.moduleConnectionService.loadModule(MODE_MODULE[mode]);
3538
3554
  listenFinish();
3539
3555
  createGracefulShutdown(mode)();
3556
+ let absolutePath;
3540
3557
  for (const entryPoint of entryPoints) {
3541
- await cli.resolveService.attachEntry(entryPoint);
3558
+ absolutePath = path.resolve(cwd, entryPoint);
3559
+ await cli.resolveService.attachEntry(absolutePath);
3542
3560
  }
3561
+ await entrySubject.next(absolutePath);
3543
3562
  };
3544
3563
  main$a();
3545
3564
 
@@ -3627,11 +3646,17 @@ const main$7 = async () => {
3627
3646
  await cli.configConnectionService.loadConfig("setup.config");
3628
3647
  {
3629
3648
  const loader = await cli.configConnectionService.loadConfig("loader.config");
3630
- if (typeof loader === "function") {
3631
- await loader();
3649
+ try {
3650
+ if (typeof loader === "function") {
3651
+ await loader();
3652
+ }
3653
+ if (typeof loader?.loader === "function") {
3654
+ await loader.loader();
3655
+ }
3632
3656
  }
3633
- if (typeof loader?.loader === "function") {
3634
- await loader.loader();
3657
+ catch (error) {
3658
+ console.error("Module loader failed", error);
3659
+ process.exit(-1);
3635
3660
  }
3636
3661
  }
3637
3662
  await cli.moduleConnectionService.loadModule("pine.module");
@@ -3714,11 +3739,17 @@ const main$6 = async () => {
3714
3739
  await cli.configConnectionService.loadConfig("setup.config");
3715
3740
  {
3716
3741
  const loader = await cli.configConnectionService.loadConfig("loader.config");
3717
- if (typeof loader === "function") {
3718
- await loader();
3742
+ try {
3743
+ if (typeof loader === "function") {
3744
+ await loader();
3745
+ }
3746
+ if (typeof loader?.loader === "function") {
3747
+ await loader.loader();
3748
+ }
3719
3749
  }
3720
- if (typeof loader?.loader === "function") {
3721
- await loader.loader();
3750
+ catch (error) {
3751
+ console.error("Module loader failed", error);
3752
+ process.exit(-1);
3722
3753
  }
3723
3754
  }
3724
3755
  {
@@ -3735,11 +3766,15 @@ const main$6 = async () => {
3735
3766
  }
3736
3767
  const { CC_WWWROOT_HOST, CC_WWWROOT_PORT } = getEnv();
3737
3768
  const unServer = BacktestKitUi.serve(CC_WWWROOT_HOST, CC_WWWROOT_PORT, cli.resolveService.PROJECT_ROOT_DIR);
3769
+ let isOk = true;
3738
3770
  try {
3739
3771
  await open(`http://localhost:${CC_WWWROOT_PORT}?pine=1`);
3772
+ isOk = true;
3773
+ }
3774
+ catch {
3740
3775
  }
3741
3776
  finally {
3742
- console.log(`Editor launched: http://localhost:${CC_WWWROOT_PORT}?pine=1`);
3777
+ isOk && console.log(`Editor launched: http://localhost:${CC_WWWROOT_PORT}?pine=1`);
3743
3778
  }
3744
3779
  const beforeExit = () => {
3745
3780
  process.off("SIGINT", beforeExit);
@@ -3765,11 +3800,17 @@ const main$5 = async () => {
3765
3800
  await cli.configConnectionService.loadConfig("setup.config");
3766
3801
  {
3767
3802
  const loader = await cli.configConnectionService.loadConfig("loader.config");
3768
- if (typeof loader === "function") {
3769
- await loader();
3803
+ try {
3804
+ if (typeof loader === "function") {
3805
+ await loader();
3806
+ }
3807
+ if (typeof loader?.loader === "function") {
3808
+ await loader.loader();
3809
+ }
3770
3810
  }
3771
- if (typeof loader?.loader === "function") {
3772
- await loader.loader();
3811
+ catch (error) {
3812
+ console.error("Module loader failed", error);
3813
+ process.exit(-1);
3773
3814
  }
3774
3815
  }
3775
3816
  await cli.moduleConnectionService.loadModule("dump.module");
@@ -3842,11 +3883,17 @@ const main$4 = async () => {
3842
3883
  await cli.configConnectionService.loadConfig("setup.config");
3843
3884
  {
3844
3885
  const loader = await cli.configConnectionService.loadConfig("loader.config");
3845
- if (typeof loader === "function") {
3846
- await loader();
3886
+ try {
3887
+ if (typeof loader === "function") {
3888
+ await loader();
3889
+ }
3890
+ if (typeof loader?.loader === "function") {
3891
+ await loader.loader();
3892
+ }
3847
3893
  }
3848
- if (typeof loader?.loader === "function") {
3849
- await loader.loader();
3894
+ catch (error) {
3895
+ console.error("Module loader failed", error);
3896
+ process.exit(-1);
3850
3897
  }
3851
3898
  }
3852
3899
  await cli.moduleConnectionService.loadModule("pnldebug.module");
@@ -4117,183 +4164,183 @@ const main$2 = async () => {
4117
4164
  main$2();
4118
4165
 
4119
4166
  const ENTRY_PATH = "./node_modules/@backtest-kit/cli/build/index.mjs";
4120
- const HELP_TEXT = `
4121
- Usage:
4122
- node index.mjs --<mode> [flags] [entry-point]
4123
-
4124
- Modes:
4125
-
4126
- --backtest <entry> Run strategy against historical candle data
4127
- --walker <entry...> Run Walker A/B strategy comparison across multiple strategies
4128
- --paper <entry> Paper trading (live prices, no real orders)
4129
- --live <entry> Live trading with real orders
4130
- --pine <entry> Execute a local .pine indicator file
4131
- --editor Open the Pine Script visual editor in the browser
4132
- --dump Fetch and save raw OHLCV candles
4133
- --pnldebug Simulate PnL per minute for a given entry price and direction
4134
- --brokerdebug Fire a single broker commit against the live broker adapter
4135
- --flush <entry...> Delete report/log/markdown/agent folders from strategy dump dir
4136
- --init Scaffold a new project in the current directory
4137
- --docker Scaffold a Docker workspace for running strategies in a container
4138
- --help Print this help message
4139
-
4140
- Backtest flags:
4141
-
4142
- --symbol <string> Trading pair (default: BTCUSDT)
4143
- --strategy <string> Strategy name from addStrategySchema (default: first registered)
4144
- --exchange <string> Exchange name from addExchangeSchema (default: first registered)
4145
- --frame <string> Frame name from addFrameSchema (default: first registered)
4146
- --cacheInterval <string> Comma-separated intervals to pre-cache (default: "1m, 15m, 30m, 4h")
4147
- --noCache Skip candle cache warming before the run
4148
- --noFlush Skip removing report/log/markdown/agent folders before backtest run
4149
- --verbose Log every candle fetch to stdout
4150
- --ui Start web dashboard at http://localhost:60050
4151
- --telegram Send trade notifications to Telegram
4152
-
4153
- Walker flags (--walker):
4154
-
4155
- --symbol <string> Trading pair (default: BTCUSDT)
4156
- --cacheInterval <string> Comma-separated intervals to pre-cache (default: "1m, 15m, 30m, 4h")
4157
- --noCache Skip candle cache warming before the run
4158
- --noFlush Skip removing report/log/markdown/agent folders before walker run
4159
- --verbose Log every candle fetch to stdout
4160
- --output <string> Output file base name (default: walker_{SYMBOL}_{TIMESTAMP})
4161
- --json Save results as JSON to ./dump/<output>.json
4162
- --markdown Save report as Markdown to ./dump/<output>.md
4163
-
4164
- Each positional argument is a strategy entry point. All strategy files are loaded without
4165
- changing process.cwd() — .env is read from the working directory only.
4166
- addWalkerSchema is called automatically using the registered exchange and frame.
4167
- After comparison completes the report is printed to stdout (or saved if --json/--markdown).
4168
-
4169
- Module file ./modules/walker.module is loaded automatically if it exists.
4170
-
4171
- Paper / Live flags:
4172
-
4173
- --symbol <string> Trading pair (default: BTCUSDT)
4174
- --strategy <string> Strategy name (default: first registered)
4175
- --exchange <string> Exchange name (default: first registered)
4176
- --verbose Log every candle fetch to stdout
4177
- --ui Start web dashboard
4178
- --telegram Send Telegram notifications
4179
-
4180
- PineScript flags (--pine):
4181
-
4182
- --symbol <string> Trading pair (default: BTCUSDT)
4183
- --timeframe <string> Candle interval (default: 15m)
4184
- --limit <string> Number of candles to fetch (default: 250)
4185
- --when <string> End date — ISO 8601 or Unix ms (default: now)
4186
- --exchange <string> Exchange name (default: first registered)
4187
- --output <string> Output file base name without extension
4188
- --json Save output as JSON array to <pine-dir>/dump/<output>.json
4189
- --jsonl Save output as JSONL to <pine-dir>/dump/<output>.jsonl
4190
- --markdown Save output as Markdown table to <pine-dir>/dump/<output>.md
4191
-
4192
- Only plot() calls with display=display.data_window produce output columns.
4193
- Module file ./modules/pine.module is loaded automatically if it exists.
4194
-
4195
- Candle dump flags (--dump):
4196
-
4197
- --symbol <string> Trading pair (default: BTCUSDT)
4198
- --timeframe <string> Candle interval (default: 15m)
4199
- --limit <string> Number of candles (default: 250)
4200
- --when <string> End date — ISO 8601 or Unix ms (default: now)
4201
- --exchange <string> Exchange name (default: first registered)
4202
- --output <string> Output file base name (default: {SYMBOL}_{LIMIT}_{TIMEFRAME}_{TIMESTAMP})
4203
- --json Save as JSON array to ./dump/<output>.json
4204
- --jsonl Save as JSONL to ./dump/<output>.jsonl
4205
-
4206
- Module file ./modules/dump.module is loaded automatically if it exists.
4207
-
4208
- PnL debug flags (--pnldebug):
4209
-
4210
- --symbol <string> Trading pair (default: BTCUSDT)
4211
- --priceopen <number> Entry price (required)
4212
- --direction <string> Position direction: long or short (default: long)
4213
- --when <string> Start timestamp — ISO 8601 or Unix ms (default: now)
4214
- --minutes <string> Number of 1m candles to simulate (default: 60)
4215
- --exchange <string> Exchange name (default: first registered)
4216
- --output <string> Output file base name (default: {SYMBOL}_{DIRECTION}_{PRICEOPEN}_{TIMESTAMP})
4217
- --json Save as JSON array to ./dump/<output>.json
4218
- --jsonl Save as JSONL to ./dump/<output>.jsonl
4219
- --markdown Save as Markdown table to ./dump/<output>.md
4220
-
4221
- Module file ./modules/pnldebug.module is loaded automatically if it exists.
4222
-
4223
- Broker debug flags (--brokerdebug):
4224
-
4225
- --symbol <string> Trading pair (default: BTCUSDT)
4226
- --exchange <string> Exchange name (default: first registered)
4227
- --commit <string> Commit type to fire: signal-open, signal-close, partial-profit,
4228
- partial-loss, average-buy, trailing-stop, trailing-take, breakeven
4229
- (default: signal-open)
4230
-
4231
- Loads ./live.module, fetches the last candle for --symbol/--timeframe, and calls
4232
- the selected broker commit with synthetic payload values derived from current price.
4233
-
4234
- Flush flags (--flush):
4235
-
4236
- One or more positional entry points. For each entry point the following
4237
- subdirectories are removed from <entry-dir>/dump/:
4238
-
4239
- report log markdown agent
4240
-
4241
- Init flags (--init):
4242
-
4243
- --output <string> Target directory name (default: backtest-kit-project)
4244
-
4245
- Scaffolds a project and runs scripts/fetch_docs.mjs to download library docs.
4246
-
4247
- Docker flags (--docker):
4248
-
4249
- --output <string> Target directory name (default: backtest-kit-docker)
4250
-
4251
- Scaffolds a Docker workspace: docker-compose.yaml, .env.example, package.json,
4252
- tsconfig.json, and a sample strategy under content/. Run npm install then
4253
- docker compose up to start the container.
4254
-
4255
- Module hooks (loaded automatically by each mode):
4256
-
4257
- modules/backtest.module --backtest Broker adapter for backtest
4258
- modules/walker.module --walker Broker adapter for walker comparison
4259
- modules/paper.module --paper Broker adapter for paper trading
4260
- modules/live.module --live Broker adapter for live trading
4261
- modules/pine.module --pine Exchange schema for PineScript runs
4262
- modules/editor.module --editor Exchange schema for the visual Pine editor
4263
- modules/dump.module --dump Exchange schema for candle dumps
4264
- modules/pnldebug.module --pnldebug Exchange schema for PnL debug runs
4265
- modules/brokerdebug.module --brokerdebug Broker adapter used for broker commit testing
4266
-
4267
- --flush has no associated module. It only removes dump subdirectories.
4268
-
4269
- Extensions .ts, .mjs, .cjs are tried automatically. Missing module = soft warning.
4270
-
4271
- Environment variables:
4272
-
4273
- CC_TELEGRAM_TOKEN Telegram bot token (required for --telegram)
4274
- CC_TELEGRAM_CHANNEL Telegram channel or chat ID (required for --telegram)
4275
- CC_WWWROOT_HOST UI server bind address (default: 0.0.0.0)
4276
- CC_WWWROOT_PORT UI server port (default: 60050)
4277
-
4278
- Examples:
4279
-
4280
- node ${ENTRY_PATH} --backtest ./content/feb_2026.strategy.ts
4281
- node ${ENTRY_PATH} --backtest --symbol BTCUSDT --noCache --noFlush --ui ./content/feb_2026.strategy.ts
4282
- node ${ENTRY_PATH} --walker ./content/feb_2026_v1.strategy.ts ./content/feb_2026_v2.strategy.ts ./content/feb_2026_v3.strategy.ts
4283
- node ${ENTRY_PATH} --walker --symbol BTCUSDT --noCache --noFlush --markdown ./content/feb_2026_v1.ts ./content/feb_2026_v2.ts
4284
- node ${ENTRY_PATH} --paper --symbol ETHUSDT ./content/feb_2026.strategy.ts
4285
- node ${ENTRY_PATH} --live --ui --telegram ./content/feb_2026.strategy.ts
4286
- node ${ENTRY_PATH} --pine ./math/feb_2026.pine --timeframe 15m --limit 500 --jsonl
4287
- node ${ENTRY_PATH} --editor
4288
- node ${ENTRY_PATH} --dump --symbol BTCUSDT --timeframe 15m --limit 500 --jsonl
4289
- node ${ENTRY_PATH} --pnldebug --symbol BTCUSDT --priceopen 64069.50 --direction short --when "2025-02-25" --minutes 120
4290
- node ${ENTRY_PATH} --pnldebug --priceopen 67956.73 --direction long --when 1772064000000 --minutes 60 --markdown
4291
- node ${ENTRY_PATH} --brokerdebug --commit signal-open --symbol BTCUSDT
4292
- node ${ENTRY_PATH} --brokerdebug --commit partial-profit --symbol ETHUSDT
4293
- node ${ENTRY_PATH} --flush ./content/feb_2026.strategy/feb_2026.strategy.ts
4294
- node ${ENTRY_PATH} --flush ./content/feb_2026.strategy/feb_2026.strategy.ts ./content/feb_2026.strategy/feb_2026.test.ts
4295
- node ${ENTRY_PATH} --init --output my-trading-bot
4296
- 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
4297
4344
  `.trimStart();
4298
4345
  const main$1 = async () => {
4299
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)))) {
@@ -4303,7 +4350,7 @@ const main$1 = async () => {
4303
4350
  if (!values.help) {
4304
4351
  return;
4305
4352
  }
4306
- process.stdout.write(`@backtest-kit/cli ${"9.8.0"}\n\n`);
4353
+ process.stdout.write(`@backtest-kit/cli ${"9.8.2"}\n\n`);
4307
4354
  process.stdout.write(HELP_TEXT);
4308
4355
  process.exit(0);
4309
4356
  };
@@ -4317,7 +4364,7 @@ const main = async () => {
4317
4364
  if (!values.version) {
4318
4365
  return;
4319
4366
  }
4320
- process.stdout.write(`@backtest-kit/cli ${"9.8.0"}\n`);
4367
+ process.stdout.write(`@backtest-kit/cli ${"9.8.2"}\n`);
4321
4368
  process.exit(0);
4322
4369
  };
4323
4370
  main();