@backtest-kit/cli 9.8.1 → 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.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import * as BacktestKit from 'backtest-kit';
3
3
  import { setConfig, Notification, Recent, Storage, Markdown, Report, Dump, State, Memory, MarkdownWriter, ReportWriter, PersistSignalAdapter, PersistRiskAdapter, PersistScheduleAdapter, PersistPartialAdapter, PersistBreakevenAdapter, PersistCandleAdapter, PersistStorageAdapter, PersistNotificationAdapter, PersistLogAdapter, PersistMeasureAdapter, PersistIntervalAdapter, PersistMemoryAdapter, PersistRecentAdapter, PersistStateAdapter, PersistSessionAdapter, Log, StorageLive, StorageBacktest, NotificationLive, NotificationBacktest, RecentLive, RecentBacktest, Broker, SessionLive, SessionBacktest, MemoryLive, MemoryBacktest, StateLive, StateBacktest, listExchangeSchema, addExchangeSchema, roundTicks, listFrameSchema, addFrameSchema, listenDoneLive, listenDoneBacktest, shutdown, listenSignal, listStrategySchema, overrideExchangeSchema, Backtest, System, Cache, Interval, alignToInterval, addWalkerSchema, overrideWalkerSchema, Walker, listenDoneWalker, Live, getCandles, checkCandles, warmCandles, listenRisk, listenStrategyCommit, listenSync, listenSignalNotify, Exchange } from 'backtest-kit';
4
- import { getErrorMessage, errorData, singleshot, str, BehaviorSubject, compose, createAwaiter, execpool, queued, sleep, randomString, TIMEOUT_SYMBOL, typo, retry, trycatch, memoize, isObject } from 'functools-kit';
4
+ import { getErrorMessage, errorData, singleshot, str, compose, BehaviorSubject, createAwaiter, execpool, queued, sleep, randomString, TIMEOUT_SYMBOL, typo, retry, trycatch, memoize, isObject } from 'functools-kit';
5
5
  import fs, { constants, realpathSync } from 'fs';
6
6
  import * as stackTrace from 'stack-trace';
7
7
  import path, { join, resolve, dirname, basename, extname } from 'path';
@@ -33,36 +33,6 @@ import * as BacktestKitSignals from '@backtest-kit/signals';
33
33
  import open from 'open';
34
34
  import { spawn } from 'child_process';
35
35
 
36
- /**
37
- * Fix for `Attempted to assign to readonly property (at redactToken)`
38
- * @see https://github.com/telegraf/telegraf/issues/2078
39
- */
40
- {
41
- const OriginalError = globalThis.Error;
42
- globalThis.Error = new Proxy(OriginalError, {
43
- construct(target, args) {
44
- const instance = new target(...args);
45
- let customMessage = instance.message;
46
- const handler = {
47
- get(target, prop, receiver) {
48
- if (prop === "message") {
49
- return customMessage;
50
- }
51
- return Reflect.get(target, prop, receiver);
52
- },
53
- set(target, prop, value, receiver) {
54
- if (prop === "message") {
55
- customMessage = value;
56
- return true;
57
- }
58
- return Reflect.set(target, prop, value, receiver);
59
- },
60
- };
61
- return new Proxy(instance, handler);
62
- },
63
- });
64
- }
65
-
66
36
  setConfig({
67
37
  CC_MAX_NOTIFICATIONS: 5000,
68
38
  CC_MAX_SIGNALS: 750,
@@ -239,8 +209,6 @@ const TYPES = {
239
209
  ...templateServices$1,
240
210
  };
241
211
 
242
- const entrySubject = new BehaviorSubject();
243
-
244
212
  const SETUP_ADAPTER_FN = () => {
245
213
  {
246
214
  Dump.useMarkdown();
@@ -439,9 +407,9 @@ class ResolveService {
439
407
  dotenv.config({ path: path.join(cwd, '.env'), override: true, quiet: true });
440
408
  dotenv.config({ path: path.join(moduleRoot, '.env'), override: true, quiet: true });
441
409
  this.loaderService.import(absolutePath);
442
- await entrySubject.next(absolutePath);
443
410
  }
444
411
  _is_launched = true;
412
+ return absolutePath;
445
413
  };
446
414
  this.attachEntry = async (jsPath) => {
447
415
  this.loggerService.log("resolveService attachEntry", {
@@ -456,9 +424,9 @@ class ResolveService {
456
424
  dotenv.config({ path: path.join(cwd, '.env'), override: true, quiet: true });
457
425
  {
458
426
  this.loaderService.import(absolutePath);
459
- await entrySubject.next(absolutePath);
460
427
  }
461
428
  _is_launched = true;
429
+ return absolutePath;
462
430
  };
463
431
  }
464
432
  }
@@ -861,6 +829,8 @@ const notifyVerbose = singleshot(() => {
861
829
  });
862
830
  });
863
831
 
832
+ const entrySubject = new BehaviorSubject();
833
+
864
834
  const DEFAULT_CACHE_LIST$1 = ["1m", "15m", "30m", "1h", "4h"];
865
835
  const GET_CACHE_INTERVAL_LIST_FN$1 = () => {
866
836
  const { values } = getArgs();
@@ -891,11 +861,17 @@ class BacktestMainService {
891
861
  await this.configConnectionService.loadConfig("setup.config");
892
862
  {
893
863
  const loader = await this.configConnectionService.loadConfig("loader.config");
894
- if (typeof loader === "function") {
895
- await loader();
864
+ try {
865
+ if (typeof loader === "function") {
866
+ await loader();
867
+ }
868
+ if (typeof loader?.loader === "function") {
869
+ await loader.loader();
870
+ }
896
871
  }
897
- if (typeof loader?.loader === "function") {
898
- await loader.loader();
872
+ catch (error) {
873
+ console.error("Module loader failed", error);
874
+ process.exit(-1);
899
875
  }
900
876
  }
901
877
  {
@@ -910,8 +886,9 @@ class BacktestMainService {
910
886
  const cwd = process.cwd();
911
887
  dotenv.config({ path: path.join(cwd, '.env'), override: true, quiet: true });
912
888
  }
889
+ let absolutePath;
913
890
  {
914
- await this.resolveService.attachJavascript(payload.entryPoint);
891
+ absolutePath = await this.resolveService.attachJavascript(payload.entryPoint);
915
892
  await this.moduleConnectionService.loadModule("backtest.module");
916
893
  }
917
894
  {
@@ -953,6 +930,7 @@ class BacktestMainService {
953
930
  });
954
931
  notifyVerbose();
955
932
  }
933
+ await entrySubject.next(absolutePath);
956
934
  Backtest.background(symbol, {
957
935
  strategyName,
958
936
  frameName,
@@ -1019,11 +997,17 @@ class WalkerMainService {
1019
997
  await this.configConnectionService.loadConfig("setup.config");
1020
998
  {
1021
999
  const loader = await this.configConnectionService.loadConfig("loader.config");
1022
- if (typeof loader === "function") {
1023
- await loader();
1000
+ try {
1001
+ if (typeof loader === "function") {
1002
+ await loader();
1003
+ }
1004
+ if (typeof loader?.loader === "function") {
1005
+ await loader.loader();
1006
+ }
1024
1007
  }
1025
- if (typeof loader?.loader === "function") {
1026
- await loader.loader();
1008
+ catch (error) {
1009
+ console.error("Module loader failed", error);
1010
+ process.exit(-1);
1027
1011
  }
1028
1012
  }
1029
1013
  {
@@ -1253,11 +1237,17 @@ class LiveMainService {
1253
1237
  await this.configConnectionService.loadConfig("setup.config");
1254
1238
  {
1255
1239
  const loader = await this.configConnectionService.loadConfig("loader.config");
1256
- if (typeof loader === "function") {
1257
- await loader();
1240
+ try {
1241
+ if (typeof loader === "function") {
1242
+ await loader();
1243
+ }
1244
+ if (typeof loader?.loader === "function") {
1245
+ await loader.loader();
1246
+ }
1258
1247
  }
1259
- if (typeof loader?.loader === "function") {
1260
- await loader.loader();
1248
+ catch (error) {
1249
+ console.error("Module loader failed", error);
1250
+ process.exit(-1);
1261
1251
  }
1262
1252
  }
1263
1253
  {
@@ -1272,8 +1262,9 @@ class LiveMainService {
1272
1262
  const cwd = process.cwd();
1273
1263
  dotenv.config({ path: path.join(cwd, '.env'), override: true, quiet: true });
1274
1264
  }
1265
+ let absolutePath;
1275
1266
  {
1276
- await this.resolveService.attachJavascript(payload.entryPoint);
1267
+ absolutePath = await this.resolveService.attachJavascript(payload.entryPoint);
1277
1268
  await this.moduleConnectionService.loadModule("live.module");
1278
1269
  }
1279
1270
  {
@@ -1302,6 +1293,7 @@ class LiveMainService {
1302
1293
  });
1303
1294
  notifyVerbose();
1304
1295
  }
1296
+ await entrySubject.next(absolutePath);
1305
1297
  Live.background(symbol, {
1306
1298
  strategyName,
1307
1299
  exchangeName,
@@ -1348,11 +1340,17 @@ class PaperMainService {
1348
1340
  await this.configConnectionService.loadConfig("setup.config");
1349
1341
  {
1350
1342
  const loader = await this.configConnectionService.loadConfig("loader.config");
1351
- if (typeof loader === "function") {
1352
- await loader();
1343
+ try {
1344
+ if (typeof loader === "function") {
1345
+ await loader();
1346
+ }
1347
+ if (typeof loader?.loader === "function") {
1348
+ await loader.loader();
1349
+ }
1353
1350
  }
1354
- if (typeof loader?.loader === "function") {
1355
- await loader.loader();
1351
+ catch (error) {
1352
+ console.error("Module loader failed", error);
1353
+ process.exit(-1);
1356
1354
  }
1357
1355
  }
1358
1356
  {
@@ -1367,8 +1365,9 @@ class PaperMainService {
1367
1365
  const cwd = process.cwd();
1368
1366
  dotenv.config({ path: path.join(cwd, '.env'), override: true, quiet: true });
1369
1367
  }
1368
+ let absolutePath;
1370
1369
  {
1371
- await this.resolveService.attachJavascript(payload.entryPoint);
1370
+ absolutePath = await this.resolveService.attachJavascript(payload.entryPoint);
1372
1371
  await this.moduleConnectionService.loadModule("paper.module");
1373
1372
  }
1374
1373
  {
@@ -1397,6 +1396,7 @@ class PaperMainService {
1397
1396
  });
1398
1397
  notifyVerbose();
1399
1398
  }
1399
+ await entrySubject.next(absolutePath);
1400
1400
  Live.background(symbol, {
1401
1401
  strategyName,
1402
1402
  exchangeName,
@@ -1990,7 +1990,8 @@ const GET_TIMEFRAME_RANGE_FN = async (frameName) => {
1990
1990
  };
1991
1991
  const CACHE_CANDLES_FN = retry(async (interval, dto) => {
1992
1992
  try {
1993
- console.log(`Checking candles cache for ${dto.symbol} ${interval} from ${dto.from} to ${dto.to}`);
1993
+ process.stdout.write("\n");
1994
+ process.stdout.write(`Checking candles cache for ${dto.symbol} ${interval} from ${dto.from} to ${dto.to}\n`);
1994
1995
  await checkCandles({
1995
1996
  exchangeName: dto.exchangeName,
1996
1997
  from: dto.from,
@@ -2000,7 +2001,8 @@ const CACHE_CANDLES_FN = retry(async (interval, dto) => {
2000
2001
  });
2001
2002
  }
2002
2003
  catch (error) {
2003
- console.log(`Caching candles for ${dto.symbol} ${interval} from ${dto.from} to ${dto.to}`);
2004
+ process.stdout.write("\n\n");
2005
+ process.stdout.write(`Caching candles for ${dto.symbol} ${interval} from ${dto.from} to ${dto.to}\n`);
2004
2006
  await warmCandles({
2005
2007
  symbol: dto.symbol,
2006
2008
  exchangeName: dto.exchangeName,
@@ -3181,10 +3183,10 @@ init();
3181
3183
 
3182
3184
  const MODES = ["backtest", "walker", "paper", "live", "pine", "editor", "dump", "pnldebug", "brokerdebug", "flush", "init", "docker", "help", "version"];
3183
3185
  const ENTRY_PATH$1 = "./node_modules/@backtest-kit/cli/build/index.mjs";
3184
- const HELP_TEXT$1 = `
3185
- Example:
3186
-
3187
- node ${ENTRY_PATH$1} --help
3186
+ const HELP_TEXT$1 = `
3187
+ Example:
3188
+
3189
+ node ${ENTRY_PATH$1} --help
3188
3190
  `.trimStart();
3189
3191
  const main$g = async () => {
3190
3192
  if (!getEntry(import.meta.url)) {
@@ -3194,7 +3196,7 @@ const main$g = async () => {
3194
3196
  if (MODES.some((mode) => values[mode])) {
3195
3197
  return;
3196
3198
  }
3197
- process.stdout.write(`@backtest-kit/cli ${"9.8.1"}\n`);
3199
+ process.stdout.write(`@backtest-kit/cli ${"9.8.2"}\n`);
3198
3200
  process.stdout.write("\n");
3199
3201
  process.stdout.write(`Run with --help to see available commands.\n`);
3200
3202
  process.stdout.write("\n");
@@ -3482,11 +3484,17 @@ const main$a = async () => {
3482
3484
  await cli.configConnectionService.loadConfig("setup.config");
3483
3485
  {
3484
3486
  const loader = await cli.configConnectionService.loadConfig("loader.config");
3485
- if (typeof loader === "function") {
3486
- await loader();
3487
+ try {
3488
+ if (typeof loader === "function") {
3489
+ await loader();
3490
+ }
3491
+ if (typeof loader?.loader === "function") {
3492
+ await loader.loader();
3493
+ }
3487
3494
  }
3488
- if (typeof loader?.loader === "function") {
3489
- await loader.loader();
3495
+ catch (error) {
3496
+ console.error("Module loader failed", error);
3497
+ process.exit(-1);
3490
3498
  }
3491
3499
  }
3492
3500
  {
@@ -3510,14 +3518,18 @@ const main$a = async () => {
3510
3518
  if (values.noFlush) {
3511
3519
  continue;
3512
3520
  }
3513
- await flush(entryPoint);
3521
+ const absolutePath = path.resolve(cwd, entryPoint);
3522
+ await flush(absolutePath);
3514
3523
  }
3515
3524
  await cli.moduleConnectionService.loadModule(MODE_MODULE[mode]);
3516
3525
  listenFinish();
3517
3526
  createGracefulShutdown(mode)();
3527
+ let absolutePath;
3518
3528
  for (const entryPoint of entryPoints) {
3519
- await cli.resolveService.attachEntry(entryPoint);
3529
+ absolutePath = path.resolve(cwd, entryPoint);
3530
+ await cli.resolveService.attachEntry(absolutePath);
3520
3531
  }
3532
+ await entrySubject.next(absolutePath);
3521
3533
  };
3522
3534
  main$a();
3523
3535
 
@@ -3605,11 +3617,17 @@ const main$7 = async () => {
3605
3617
  await cli.configConnectionService.loadConfig("setup.config");
3606
3618
  {
3607
3619
  const loader = await cli.configConnectionService.loadConfig("loader.config");
3608
- if (typeof loader === "function") {
3609
- await loader();
3620
+ try {
3621
+ if (typeof loader === "function") {
3622
+ await loader();
3623
+ }
3624
+ if (typeof loader?.loader === "function") {
3625
+ await loader.loader();
3626
+ }
3610
3627
  }
3611
- if (typeof loader?.loader === "function") {
3612
- await loader.loader();
3628
+ catch (error) {
3629
+ console.error("Module loader failed", error);
3630
+ process.exit(-1);
3613
3631
  }
3614
3632
  }
3615
3633
  await cli.moduleConnectionService.loadModule("pine.module");
@@ -3692,11 +3710,17 @@ const main$6 = async () => {
3692
3710
  await cli.configConnectionService.loadConfig("setup.config");
3693
3711
  {
3694
3712
  const loader = await cli.configConnectionService.loadConfig("loader.config");
3695
- if (typeof loader === "function") {
3696
- await loader();
3713
+ try {
3714
+ if (typeof loader === "function") {
3715
+ await loader();
3716
+ }
3717
+ if (typeof loader?.loader === "function") {
3718
+ await loader.loader();
3719
+ }
3697
3720
  }
3698
- if (typeof loader?.loader === "function") {
3699
- await loader.loader();
3721
+ catch (error) {
3722
+ console.error("Module loader failed", error);
3723
+ process.exit(-1);
3700
3724
  }
3701
3725
  }
3702
3726
  {
@@ -3713,11 +3737,15 @@ const main$6 = async () => {
3713
3737
  }
3714
3738
  const { CC_WWWROOT_HOST, CC_WWWROOT_PORT } = getEnv();
3715
3739
  const unServer = serve(CC_WWWROOT_HOST, CC_WWWROOT_PORT, cli.resolveService.PROJECT_ROOT_DIR);
3740
+ let isOk = true;
3716
3741
  try {
3717
3742
  await open(`http://localhost:${CC_WWWROOT_PORT}?pine=1`);
3743
+ isOk = true;
3744
+ }
3745
+ catch {
3718
3746
  }
3719
3747
  finally {
3720
- console.log(`Editor launched: http://localhost:${CC_WWWROOT_PORT}?pine=1`);
3748
+ isOk && console.log(`Editor launched: http://localhost:${CC_WWWROOT_PORT}?pine=1`);
3721
3749
  }
3722
3750
  const beforeExit = () => {
3723
3751
  process.off("SIGINT", beforeExit);
@@ -3743,11 +3771,17 @@ const main$5 = async () => {
3743
3771
  await cli.configConnectionService.loadConfig("setup.config");
3744
3772
  {
3745
3773
  const loader = await cli.configConnectionService.loadConfig("loader.config");
3746
- if (typeof loader === "function") {
3747
- await loader();
3774
+ try {
3775
+ if (typeof loader === "function") {
3776
+ await loader();
3777
+ }
3778
+ if (typeof loader?.loader === "function") {
3779
+ await loader.loader();
3780
+ }
3748
3781
  }
3749
- if (typeof loader?.loader === "function") {
3750
- await loader.loader();
3782
+ catch (error) {
3783
+ console.error("Module loader failed", error);
3784
+ process.exit(-1);
3751
3785
  }
3752
3786
  }
3753
3787
  await cli.moduleConnectionService.loadModule("dump.module");
@@ -3820,11 +3854,17 @@ const main$4 = async () => {
3820
3854
  await cli.configConnectionService.loadConfig("setup.config");
3821
3855
  {
3822
3856
  const loader = await cli.configConnectionService.loadConfig("loader.config");
3823
- if (typeof loader === "function") {
3824
- await loader();
3857
+ try {
3858
+ if (typeof loader === "function") {
3859
+ await loader();
3860
+ }
3861
+ if (typeof loader?.loader === "function") {
3862
+ await loader.loader();
3863
+ }
3825
3864
  }
3826
- if (typeof loader?.loader === "function") {
3827
- await loader.loader();
3865
+ catch (error) {
3866
+ console.error("Module loader failed", error);
3867
+ process.exit(-1);
3828
3868
  }
3829
3869
  }
3830
3870
  await cli.moduleConnectionService.loadModule("pnldebug.module");
@@ -4095,183 +4135,183 @@ const main$2 = async () => {
4095
4135
  main$2();
4096
4136
 
4097
4137
  const ENTRY_PATH = "./node_modules/@backtest-kit/cli/build/index.mjs";
4098
- const HELP_TEXT = `
4099
- Usage:
4100
- node index.mjs --<mode> [flags] [entry-point]
4101
-
4102
- Modes:
4103
-
4104
- --backtest <entry> Run strategy against historical candle data
4105
- --walker <entry...> Run Walker A/B strategy comparison across multiple strategies
4106
- --paper <entry> Paper trading (live prices, no real orders)
4107
- --live <entry> Live trading with real orders
4108
- --pine <entry> Execute a local .pine indicator file
4109
- --editor Open the Pine Script visual editor in the browser
4110
- --dump Fetch and save raw OHLCV candles
4111
- --pnldebug Simulate PnL per minute for a given entry price and direction
4112
- --brokerdebug Fire a single broker commit against the live broker adapter
4113
- --flush <entry...> Delete report/log/markdown/agent folders from strategy dump dir
4114
- --init Scaffold a new project in the current directory
4115
- --docker Scaffold a Docker workspace for running strategies in a container
4116
- --help Print this help message
4117
-
4118
- Backtest flags:
4119
-
4120
- --symbol <string> Trading pair (default: BTCUSDT)
4121
- --strategy <string> Strategy name from addStrategySchema (default: first registered)
4122
- --exchange <string> Exchange name from addExchangeSchema (default: first registered)
4123
- --frame <string> Frame name from addFrameSchema (default: first registered)
4124
- --cacheInterval <string> Comma-separated intervals to pre-cache (default: "1m, 15m, 30m, 4h")
4125
- --noCache Skip candle cache warming before the run
4126
- --noFlush Skip removing report/log/markdown/agent folders before backtest run
4127
- --verbose Log every candle fetch to stdout
4128
- --ui Start web dashboard at http://localhost:60050
4129
- --telegram Send trade notifications to Telegram
4130
-
4131
- Walker flags (--walker):
4132
-
4133
- --symbol <string> Trading pair (default: BTCUSDT)
4134
- --cacheInterval <string> Comma-separated intervals to pre-cache (default: "1m, 15m, 30m, 4h")
4135
- --noCache Skip candle cache warming before the run
4136
- --noFlush Skip removing report/log/markdown/agent folders before walker run
4137
- --verbose Log every candle fetch to stdout
4138
- --output <string> Output file base name (default: walker_{SYMBOL}_{TIMESTAMP})
4139
- --json Save results as JSON to ./dump/<output>.json
4140
- --markdown Save report as Markdown to ./dump/<output>.md
4141
-
4142
- Each positional argument is a strategy entry point. All strategy files are loaded without
4143
- changing process.cwd() — .env is read from the working directory only.
4144
- addWalkerSchema is called automatically using the registered exchange and frame.
4145
- After comparison completes the report is printed to stdout (or saved if --json/--markdown).
4146
-
4147
- Module file ./modules/walker.module is loaded automatically if it exists.
4148
-
4149
- Paper / Live flags:
4150
-
4151
- --symbol <string> Trading pair (default: BTCUSDT)
4152
- --strategy <string> Strategy name (default: first registered)
4153
- --exchange <string> Exchange name (default: first registered)
4154
- --verbose Log every candle fetch to stdout
4155
- --ui Start web dashboard
4156
- --telegram Send Telegram notifications
4157
-
4158
- PineScript flags (--pine):
4159
-
4160
- --symbol <string> Trading pair (default: BTCUSDT)
4161
- --timeframe <string> Candle interval (default: 15m)
4162
- --limit <string> Number of candles to fetch (default: 250)
4163
- --when <string> End date — ISO 8601 or Unix ms (default: now)
4164
- --exchange <string> Exchange name (default: first registered)
4165
- --output <string> Output file base name without extension
4166
- --json Save output as JSON array to <pine-dir>/dump/<output>.json
4167
- --jsonl Save output as JSONL to <pine-dir>/dump/<output>.jsonl
4168
- --markdown Save output as Markdown table to <pine-dir>/dump/<output>.md
4169
-
4170
- Only plot() calls with display=display.data_window produce output columns.
4171
- Module file ./modules/pine.module is loaded automatically if it exists.
4172
-
4173
- Candle dump flags (--dump):
4174
-
4175
- --symbol <string> Trading pair (default: BTCUSDT)
4176
- --timeframe <string> Candle interval (default: 15m)
4177
- --limit <string> Number of candles (default: 250)
4178
- --when <string> End date — ISO 8601 or Unix ms (default: now)
4179
- --exchange <string> Exchange name (default: first registered)
4180
- --output <string> Output file base name (default: {SYMBOL}_{LIMIT}_{TIMEFRAME}_{TIMESTAMP})
4181
- --json Save as JSON array to ./dump/<output>.json
4182
- --jsonl Save as JSONL to ./dump/<output>.jsonl
4183
-
4184
- Module file ./modules/dump.module is loaded automatically if it exists.
4185
-
4186
- PnL debug flags (--pnldebug):
4187
-
4188
- --symbol <string> Trading pair (default: BTCUSDT)
4189
- --priceopen <number> Entry price (required)
4190
- --direction <string> Position direction: long or short (default: long)
4191
- --when <string> Start timestamp — ISO 8601 or Unix ms (default: now)
4192
- --minutes <string> Number of 1m candles to simulate (default: 60)
4193
- --exchange <string> Exchange name (default: first registered)
4194
- --output <string> Output file base name (default: {SYMBOL}_{DIRECTION}_{PRICEOPEN}_{TIMESTAMP})
4195
- --json Save as JSON array to ./dump/<output>.json
4196
- --jsonl Save as JSONL to ./dump/<output>.jsonl
4197
- --markdown Save as Markdown table to ./dump/<output>.md
4198
-
4199
- Module file ./modules/pnldebug.module is loaded automatically if it exists.
4200
-
4201
- Broker debug flags (--brokerdebug):
4202
-
4203
- --symbol <string> Trading pair (default: BTCUSDT)
4204
- --exchange <string> Exchange name (default: first registered)
4205
- --commit <string> Commit type to fire: signal-open, signal-close, partial-profit,
4206
- partial-loss, average-buy, trailing-stop, trailing-take, breakeven
4207
- (default: signal-open)
4208
-
4209
- Loads ./live.module, fetches the last candle for --symbol/--timeframe, and calls
4210
- the selected broker commit with synthetic payload values derived from current price.
4211
-
4212
- Flush flags (--flush):
4213
-
4214
- One or more positional entry points. For each entry point the following
4215
- subdirectories are removed from <entry-dir>/dump/:
4216
-
4217
- report log markdown agent
4218
-
4219
- Init flags (--init):
4220
-
4221
- --output <string> Target directory name (default: backtest-kit-project)
4222
-
4223
- Scaffolds a project and runs scripts/fetch_docs.mjs to download library docs.
4224
-
4225
- Docker flags (--docker):
4226
-
4227
- --output <string> Target directory name (default: backtest-kit-docker)
4228
-
4229
- Scaffolds a Docker workspace: docker-compose.yaml, .env.example, package.json,
4230
- tsconfig.json, and a sample strategy under content/. Run npm install then
4231
- docker compose up to start the container.
4232
-
4233
- Module hooks (loaded automatically by each mode):
4234
-
4235
- modules/backtest.module --backtest Broker adapter for backtest
4236
- modules/walker.module --walker Broker adapter for walker comparison
4237
- modules/paper.module --paper Broker adapter for paper trading
4238
- modules/live.module --live Broker adapter for live trading
4239
- modules/pine.module --pine Exchange schema for PineScript runs
4240
- modules/editor.module --editor Exchange schema for the visual Pine editor
4241
- modules/dump.module --dump Exchange schema for candle dumps
4242
- modules/pnldebug.module --pnldebug Exchange schema for PnL debug runs
4243
- modules/brokerdebug.module --brokerdebug Broker adapter used for broker commit testing
4244
-
4245
- --flush has no associated module. It only removes dump subdirectories.
4246
-
4247
- Extensions .ts, .mjs, .cjs are tried automatically. Missing module = soft warning.
4248
-
4249
- Environment variables:
4250
-
4251
- CC_TELEGRAM_TOKEN Telegram bot token (required for --telegram)
4252
- CC_TELEGRAM_CHANNEL Telegram channel or chat ID (required for --telegram)
4253
- CC_WWWROOT_HOST UI server bind address (default: 0.0.0.0)
4254
- CC_WWWROOT_PORT UI server port (default: 60050)
4255
-
4256
- Examples:
4257
-
4258
- node ${ENTRY_PATH} --backtest ./content/feb_2026.strategy.ts
4259
- node ${ENTRY_PATH} --backtest --symbol BTCUSDT --noCache --noFlush --ui ./content/feb_2026.strategy.ts
4260
- node ${ENTRY_PATH} --walker ./content/feb_2026_v1.strategy.ts ./content/feb_2026_v2.strategy.ts ./content/feb_2026_v3.strategy.ts
4261
- node ${ENTRY_PATH} --walker --symbol BTCUSDT --noCache --noFlush --markdown ./content/feb_2026_v1.ts ./content/feb_2026_v2.ts
4262
- node ${ENTRY_PATH} --paper --symbol ETHUSDT ./content/feb_2026.strategy.ts
4263
- node ${ENTRY_PATH} --live --ui --telegram ./content/feb_2026.strategy.ts
4264
- node ${ENTRY_PATH} --pine ./math/feb_2026.pine --timeframe 15m --limit 500 --jsonl
4265
- node ${ENTRY_PATH} --editor
4266
- node ${ENTRY_PATH} --dump --symbol BTCUSDT --timeframe 15m --limit 500 --jsonl
4267
- node ${ENTRY_PATH} --pnldebug --symbol BTCUSDT --priceopen 64069.50 --direction short --when "2025-02-25" --minutes 120
4268
- node ${ENTRY_PATH} --pnldebug --priceopen 67956.73 --direction long --when 1772064000000 --minutes 60 --markdown
4269
- node ${ENTRY_PATH} --brokerdebug --commit signal-open --symbol BTCUSDT
4270
- node ${ENTRY_PATH} --brokerdebug --commit partial-profit --symbol ETHUSDT
4271
- node ${ENTRY_PATH} --flush ./content/feb_2026.strategy/feb_2026.strategy.ts
4272
- node ${ENTRY_PATH} --flush ./content/feb_2026.strategy/feb_2026.strategy.ts ./content/feb_2026.strategy/feb_2026.test.ts
4273
- node ${ENTRY_PATH} --init --output my-trading-bot
4274
- node ${ENTRY_PATH} --docker --output my-docker-workspace
4138
+ const HELP_TEXT = `
4139
+ Usage:
4140
+ node index.mjs --<mode> [flags] [entry-point]
4141
+
4142
+ Modes:
4143
+
4144
+ --backtest <entry> Run strategy against historical candle data
4145
+ --walker <entry...> Run Walker A/B strategy comparison across multiple strategies
4146
+ --paper <entry> Paper trading (live prices, no real orders)
4147
+ --live <entry> Live trading with real orders
4148
+ --pine <entry> Execute a local .pine indicator file
4149
+ --editor Open the Pine Script visual editor in the browser
4150
+ --dump Fetch and save raw OHLCV candles
4151
+ --pnldebug Simulate PnL per minute for a given entry price and direction
4152
+ --brokerdebug Fire a single broker commit against the live broker adapter
4153
+ --flush <entry...> Delete report/log/markdown/agent folders from strategy dump dir
4154
+ --init Scaffold a new project in the current directory
4155
+ --docker Scaffold a Docker workspace for running strategies in a container
4156
+ --help Print this help message
4157
+
4158
+ Backtest flags:
4159
+
4160
+ --symbol <string> Trading pair (default: BTCUSDT)
4161
+ --strategy <string> Strategy name from addStrategySchema (default: first registered)
4162
+ --exchange <string> Exchange name from addExchangeSchema (default: first registered)
4163
+ --frame <string> Frame name from addFrameSchema (default: first registered)
4164
+ --cacheInterval <string> Comma-separated intervals to pre-cache (default: "1m, 15m, 30m, 4h")
4165
+ --noCache Skip candle cache warming before the run
4166
+ --noFlush Skip removing report/log/markdown/agent folders before backtest run
4167
+ --verbose Log every candle fetch to stdout
4168
+ --ui Start web dashboard at http://localhost:60050
4169
+ --telegram Send trade notifications to Telegram
4170
+
4171
+ Walker flags (--walker):
4172
+
4173
+ --symbol <string> Trading pair (default: BTCUSDT)
4174
+ --cacheInterval <string> Comma-separated intervals to pre-cache (default: "1m, 15m, 30m, 4h")
4175
+ --noCache Skip candle cache warming before the run
4176
+ --noFlush Skip removing report/log/markdown/agent folders before walker run
4177
+ --verbose Log every candle fetch to stdout
4178
+ --output <string> Output file base name (default: walker_{SYMBOL}_{TIMESTAMP})
4179
+ --json Save results as JSON to ./dump/<output>.json
4180
+ --markdown Save report as Markdown to ./dump/<output>.md
4181
+
4182
+ Each positional argument is a strategy entry point. All strategy files are loaded without
4183
+ changing process.cwd() — .env is read from the working directory only.
4184
+ addWalkerSchema is called automatically using the registered exchange and frame.
4185
+ After comparison completes the report is printed to stdout (or saved if --json/--markdown).
4186
+
4187
+ Module file ./modules/walker.module is loaded automatically if it exists.
4188
+
4189
+ Paper / Live flags:
4190
+
4191
+ --symbol <string> Trading pair (default: BTCUSDT)
4192
+ --strategy <string> Strategy name (default: first registered)
4193
+ --exchange <string> Exchange name (default: first registered)
4194
+ --verbose Log every candle fetch to stdout
4195
+ --ui Start web dashboard
4196
+ --telegram Send Telegram notifications
4197
+
4198
+ PineScript flags (--pine):
4199
+
4200
+ --symbol <string> Trading pair (default: BTCUSDT)
4201
+ --timeframe <string> Candle interval (default: 15m)
4202
+ --limit <string> Number of candles to fetch (default: 250)
4203
+ --when <string> End date — ISO 8601 or Unix ms (default: now)
4204
+ --exchange <string> Exchange name (default: first registered)
4205
+ --output <string> Output file base name without extension
4206
+ --json Save output as JSON array to <pine-dir>/dump/<output>.json
4207
+ --jsonl Save output as JSONL to <pine-dir>/dump/<output>.jsonl
4208
+ --markdown Save output as Markdown table to <pine-dir>/dump/<output>.md
4209
+
4210
+ Only plot() calls with display=display.data_window produce output columns.
4211
+ Module file ./modules/pine.module is loaded automatically if it exists.
4212
+
4213
+ Candle dump flags (--dump):
4214
+
4215
+ --symbol <string> Trading pair (default: BTCUSDT)
4216
+ --timeframe <string> Candle interval (default: 15m)
4217
+ --limit <string> Number of candles (default: 250)
4218
+ --when <string> End date — ISO 8601 or Unix ms (default: now)
4219
+ --exchange <string> Exchange name (default: first registered)
4220
+ --output <string> Output file base name (default: {SYMBOL}_{LIMIT}_{TIMEFRAME}_{TIMESTAMP})
4221
+ --json Save as JSON array to ./dump/<output>.json
4222
+ --jsonl Save as JSONL to ./dump/<output>.jsonl
4223
+
4224
+ Module file ./modules/dump.module is loaded automatically if it exists.
4225
+
4226
+ PnL debug flags (--pnldebug):
4227
+
4228
+ --symbol <string> Trading pair (default: BTCUSDT)
4229
+ --priceopen <number> Entry price (required)
4230
+ --direction <string> Position direction: long or short (default: long)
4231
+ --when <string> Start timestamp — ISO 8601 or Unix ms (default: now)
4232
+ --minutes <string> Number of 1m candles to simulate (default: 60)
4233
+ --exchange <string> Exchange name (default: first registered)
4234
+ --output <string> Output file base name (default: {SYMBOL}_{DIRECTION}_{PRICEOPEN}_{TIMESTAMP})
4235
+ --json Save as JSON array to ./dump/<output>.json
4236
+ --jsonl Save as JSONL to ./dump/<output>.jsonl
4237
+ --markdown Save as Markdown table to ./dump/<output>.md
4238
+
4239
+ Module file ./modules/pnldebug.module is loaded automatically if it exists.
4240
+
4241
+ Broker debug flags (--brokerdebug):
4242
+
4243
+ --symbol <string> Trading pair (default: BTCUSDT)
4244
+ --exchange <string> Exchange name (default: first registered)
4245
+ --commit <string> Commit type to fire: signal-open, signal-close, partial-profit,
4246
+ partial-loss, average-buy, trailing-stop, trailing-take, breakeven
4247
+ (default: signal-open)
4248
+
4249
+ Loads ./live.module, fetches the last candle for --symbol/--timeframe, and calls
4250
+ the selected broker commit with synthetic payload values derived from current price.
4251
+
4252
+ Flush flags (--flush):
4253
+
4254
+ One or more positional entry points. For each entry point the following
4255
+ subdirectories are removed from <entry-dir>/dump/:
4256
+
4257
+ report log markdown agent
4258
+
4259
+ Init flags (--init):
4260
+
4261
+ --output <string> Target directory name (default: backtest-kit-project)
4262
+
4263
+ Scaffolds a project and runs scripts/fetch_docs.mjs to download library docs.
4264
+
4265
+ Docker flags (--docker):
4266
+
4267
+ --output <string> Target directory name (default: backtest-kit-docker)
4268
+
4269
+ Scaffolds a Docker workspace: docker-compose.yaml, .env.example, package.json,
4270
+ tsconfig.json, and a sample strategy under content/. Run npm install then
4271
+ docker compose up to start the container.
4272
+
4273
+ Module hooks (loaded automatically by each mode):
4274
+
4275
+ modules/backtest.module --backtest Broker adapter for backtest
4276
+ modules/walker.module --walker Broker adapter for walker comparison
4277
+ modules/paper.module --paper Broker adapter for paper trading
4278
+ modules/live.module --live Broker adapter for live trading
4279
+ modules/pine.module --pine Exchange schema for PineScript runs
4280
+ modules/editor.module --editor Exchange schema for the visual Pine editor
4281
+ modules/dump.module --dump Exchange schema for candle dumps
4282
+ modules/pnldebug.module --pnldebug Exchange schema for PnL debug runs
4283
+ modules/brokerdebug.module --brokerdebug Broker adapter used for broker commit testing
4284
+
4285
+ --flush has no associated module. It only removes dump subdirectories.
4286
+
4287
+ Extensions .ts, .mjs, .cjs are tried automatically. Missing module = soft warning.
4288
+
4289
+ Environment variables:
4290
+
4291
+ CC_TELEGRAM_TOKEN Telegram bot token (required for --telegram)
4292
+ CC_TELEGRAM_CHANNEL Telegram channel or chat ID (required for --telegram)
4293
+ CC_WWWROOT_HOST UI server bind address (default: 0.0.0.0)
4294
+ CC_WWWROOT_PORT UI server port (default: 60050)
4295
+
4296
+ Examples:
4297
+
4298
+ node ${ENTRY_PATH} --backtest ./content/feb_2026.strategy.ts
4299
+ node ${ENTRY_PATH} --backtest --symbol BTCUSDT --noCache --noFlush --ui ./content/feb_2026.strategy.ts
4300
+ node ${ENTRY_PATH} --walker ./content/feb_2026_v1.strategy.ts ./content/feb_2026_v2.strategy.ts ./content/feb_2026_v3.strategy.ts
4301
+ node ${ENTRY_PATH} --walker --symbol BTCUSDT --noCache --noFlush --markdown ./content/feb_2026_v1.ts ./content/feb_2026_v2.ts
4302
+ node ${ENTRY_PATH} --paper --symbol ETHUSDT ./content/feb_2026.strategy.ts
4303
+ node ${ENTRY_PATH} --live --ui --telegram ./content/feb_2026.strategy.ts
4304
+ node ${ENTRY_PATH} --pine ./math/feb_2026.pine --timeframe 15m --limit 500 --jsonl
4305
+ node ${ENTRY_PATH} --editor
4306
+ node ${ENTRY_PATH} --dump --symbol BTCUSDT --timeframe 15m --limit 500 --jsonl
4307
+ node ${ENTRY_PATH} --pnldebug --symbol BTCUSDT --priceopen 64069.50 --direction short --when "2025-02-25" --minutes 120
4308
+ node ${ENTRY_PATH} --pnldebug --priceopen 67956.73 --direction long --when 1772064000000 --minutes 60 --markdown
4309
+ node ${ENTRY_PATH} --brokerdebug --commit signal-open --symbol BTCUSDT
4310
+ node ${ENTRY_PATH} --brokerdebug --commit partial-profit --symbol ETHUSDT
4311
+ node ${ENTRY_PATH} --flush ./content/feb_2026.strategy/feb_2026.strategy.ts
4312
+ node ${ENTRY_PATH} --flush ./content/feb_2026.strategy/feb_2026.strategy.ts ./content/feb_2026.strategy/feb_2026.test.ts
4313
+ node ${ENTRY_PATH} --init --output my-trading-bot
4314
+ node ${ENTRY_PATH} --docker --output my-docker-workspace
4275
4315
  `.trimStart();
4276
4316
  const main$1 = async () => {
4277
4317
  if (!getEntry(import.meta.url)) {
@@ -4281,7 +4321,7 @@ const main$1 = async () => {
4281
4321
  if (!values.help) {
4282
4322
  return;
4283
4323
  }
4284
- process.stdout.write(`@backtest-kit/cli ${"9.8.1"}\n\n`);
4324
+ process.stdout.write(`@backtest-kit/cli ${"9.8.2"}\n\n`);
4285
4325
  process.stdout.write(HELP_TEXT);
4286
4326
  process.exit(0);
4287
4327
  };
@@ -4295,7 +4335,7 @@ const main = async () => {
4295
4335
  if (!values.version) {
4296
4336
  return;
4297
4337
  }
4298
- process.stdout.write(`@backtest-kit/cli ${"9.8.1"}\n`);
4338
+ process.stdout.write(`@backtest-kit/cli ${"9.8.2"}\n`);
4299
4339
  process.exit(0);
4300
4340
  };
4301
4341
  main();