@backtest-kit/cli 8.4.2 → 8.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/build/index.cjs CHANGED
@@ -521,6 +521,10 @@ const getArgs = functoolsKit.singleshot(() => {
521
521
  type: "boolean",
522
522
  default: false,
523
523
  },
524
+ entry: {
525
+ type: "boolean",
526
+ default: false,
527
+ },
524
528
  cacheInterval: {
525
529
  type: "string",
526
530
  default: "1m, 15m, 30m, 4h",
@@ -3014,12 +3018,12 @@ init();
3014
3018
 
3015
3019
  const MODES = ["backtest", "walker", "paper", "live", "pine", "editor", "dump", "pnldebug", "brokerdebug", "flush", "init", "docker", "help", "version"];
3016
3020
  const ENTRY_PATH$1 = "./node_modules/@backtest-kit/cli/build/index.mjs";
3017
- const HELP_TEXT$1 = `
3018
- Example:
3019
-
3020
- node ${ENTRY_PATH$1} --help
3021
+ const HELP_TEXT$1 = `
3022
+ Example:
3023
+
3024
+ node ${ENTRY_PATH$1} --help
3021
3025
  `.trimStart();
3022
- const main$f = async () => {
3026
+ const main$g = async () => {
3023
3027
  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)))) {
3024
3028
  return;
3025
3029
  }
@@ -3027,14 +3031,14 @@ const main$f = async () => {
3027
3031
  if (MODES.some((mode) => values[mode])) {
3028
3032
  return;
3029
3033
  }
3030
- process.stdout.write(`@backtest-kit/cli ${"8.4.2"}\n`);
3034
+ process.stdout.write(`@backtest-kit/cli ${"8.5.0"}\n`);
3031
3035
  process.stdout.write("\n");
3032
3036
  process.stdout.write(`Run with --help to see available commands.\n`);
3033
3037
  process.stdout.write("\n");
3034
3038
  process.stdout.write(HELP_TEXT$1);
3035
3039
  process.exit(0);
3036
3040
  };
3037
- main$f();
3041
+ main$g();
3038
3042
 
3039
3043
  const notifyShutdown = functoolsKit.singleshot(async () => {
3040
3044
  console.log("Graceful shutdown initiated. Press Ctrl+C again to force quit.");
@@ -3050,7 +3054,7 @@ const flush = async (entryPoint) => {
3050
3054
  console.log(`Removed: ${target}`);
3051
3055
  }
3052
3056
  };
3053
- const main$e = async () => {
3057
+ const main$f = async () => {
3054
3058
  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)))) {
3055
3059
  return;
3056
3060
  }
@@ -3067,7 +3071,7 @@ const main$e = async () => {
3067
3071
  }
3068
3072
  process.exit(0);
3069
3073
  };
3070
- main$e();
3074
+ main$f();
3071
3075
 
3072
3076
  const BEFORE_EXIT_FN$5 = functoolsKit.singleshot(async () => {
3073
3077
  process.off("SIGINT", BEFORE_EXIT_FN$5);
@@ -3089,7 +3093,7 @@ const BEFORE_EXIT_FN$5 = functoolsKit.singleshot(async () => {
3089
3093
  const listenGracefulShutdown$5 = functoolsKit.singleshot(() => {
3090
3094
  process.on("SIGINT", BEFORE_EXIT_FN$5);
3091
3095
  });
3092
- const main$d = async () => {
3096
+ const main$e = async () => {
3093
3097
  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)))) {
3094
3098
  return;
3095
3099
  }
@@ -3097,6 +3101,9 @@ const main$d = async () => {
3097
3101
  if (!values.backtest) {
3098
3102
  return;
3099
3103
  }
3104
+ if (values.entry) {
3105
+ return;
3106
+ }
3100
3107
  if (!values.noFlush) {
3101
3108
  const [entryPoint = null] = getPositionals();
3102
3109
  entryPoint && await flush(entryPoint);
@@ -3104,7 +3111,7 @@ const main$d = async () => {
3104
3111
  await cli.backtestMainService.connect();
3105
3112
  listenGracefulShutdown$5();
3106
3113
  };
3107
- main$d();
3114
+ main$e();
3108
3115
 
3109
3116
  const BEFORE_EXIT_FN$4 = functoolsKit.singleshot(async () => {
3110
3117
  process.off("SIGINT", BEFORE_EXIT_FN$4);
@@ -3122,7 +3129,7 @@ const BEFORE_EXIT_FN$4 = functoolsKit.singleshot(async () => {
3122
3129
  const listenGracefulShutdown$4 = functoolsKit.singleshot(() => {
3123
3130
  process.on("SIGINT", BEFORE_EXIT_FN$4);
3124
3131
  });
3125
- const main$c = async () => {
3132
+ const main$d = async () => {
3126
3133
  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)))) {
3127
3134
  return;
3128
3135
  }
@@ -3130,6 +3137,9 @@ const main$c = async () => {
3130
3137
  if (!values.walker) {
3131
3138
  return;
3132
3139
  }
3140
+ if (values.entry) {
3141
+ return;
3142
+ }
3133
3143
  if (!values.noFlush) {
3134
3144
  for (const entryPoint of getPositionals()) {
3135
3145
  await flush(entryPoint);
@@ -3138,7 +3148,7 @@ const main$c = async () => {
3138
3148
  listenGracefulShutdown$4();
3139
3149
  await cli.walkerMainService.connect();
3140
3150
  };
3141
- main$c();
3151
+ main$d();
3142
3152
 
3143
3153
  const BEFORE_EXIT_FN$3 = functoolsKit.singleshot(async () => {
3144
3154
  process.off("SIGINT", BEFORE_EXIT_FN$3);
@@ -3159,7 +3169,7 @@ const BEFORE_EXIT_FN$3 = functoolsKit.singleshot(async () => {
3159
3169
  const listenGracefulShutdown$3 = functoolsKit.singleshot(() => {
3160
3170
  process.on("SIGINT", BEFORE_EXIT_FN$3);
3161
3171
  });
3162
- const main$b = async () => {
3172
+ const main$c = async () => {
3163
3173
  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)))) {
3164
3174
  return;
3165
3175
  }
@@ -3167,10 +3177,13 @@ const main$b = async () => {
3167
3177
  if (!values.paper) {
3168
3178
  return;
3169
3179
  }
3180
+ if (values.entry) {
3181
+ return;
3182
+ }
3170
3183
  cli.paperMainService.connect();
3171
3184
  listenGracefulShutdown$3();
3172
3185
  };
3173
- main$b();
3186
+ main$c();
3174
3187
 
3175
3188
  const BEFORE_EXIT_FN$2 = functoolsKit.singleshot(async () => {
3176
3189
  process.off("SIGINT", BEFORE_EXIT_FN$2);
@@ -3191,7 +3204,7 @@ const BEFORE_EXIT_FN$2 = functoolsKit.singleshot(async () => {
3191
3204
  const listenGracefulShutdown$2 = functoolsKit.singleshot(() => {
3192
3205
  process.on("SIGINT", BEFORE_EXIT_FN$2);
3193
3206
  });
3194
- const main$a = async () => {
3207
+ const main$b = async () => {
3195
3208
  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)))) {
3196
3209
  return;
3197
3210
  }
@@ -3199,9 +3212,122 @@ const main$a = async () => {
3199
3212
  if (!values.live) {
3200
3213
  return;
3201
3214
  }
3215
+ if (values.entry) {
3216
+ return;
3217
+ }
3202
3218
  await cli.liveMainService.connect();
3203
3219
  listenGracefulShutdown$2();
3204
3220
  };
3221
+ main$b();
3222
+
3223
+ const MODE_MODULE = {
3224
+ backtest: "./backtest.module",
3225
+ live: "./live.module",
3226
+ paper: "./paper.module",
3227
+ walker: "./walker.module",
3228
+ };
3229
+ const resolveMode = (values) => {
3230
+ const enabled = ["backtest", "live", "paper", "walker"].filter((mode) => Boolean(values[mode]));
3231
+ if (enabled.length !== 1) {
3232
+ return null;
3233
+ }
3234
+ return enabled[0];
3235
+ };
3236
+ const stopBacktestList = async () => {
3237
+ for (const item of await BacktestKit.Backtest.list()) {
3238
+ if (item.status === "fulfilled") {
3239
+ continue;
3240
+ }
3241
+ BacktestKit.Backtest.stop(item.symbol, {
3242
+ exchangeName: item.exchangeName,
3243
+ strategyName: item.strategyName,
3244
+ frameName: item.frameName,
3245
+ });
3246
+ }
3247
+ };
3248
+ const stopLiveList = async () => {
3249
+ for (const item of await BacktestKit.Live.list()) {
3250
+ if (item.status === "fulfilled") {
3251
+ continue;
3252
+ }
3253
+ BacktestKit.Live.stop(item.symbol, {
3254
+ exchangeName: item.exchangeName,
3255
+ strategyName: item.strategyName,
3256
+ });
3257
+ }
3258
+ };
3259
+ const stopWalkerList = async () => {
3260
+ for (const item of await BacktestKit.Walker.list()) {
3261
+ if (item.status === "fulfilled") {
3262
+ continue;
3263
+ }
3264
+ BacktestKit.Walker.stop(item.symbol, { walkerName: item.walkerName });
3265
+ }
3266
+ };
3267
+ const MODE_STOP = {
3268
+ backtest: stopBacktestList,
3269
+ live: stopLiveList,
3270
+ paper: stopLiveList,
3271
+ walker: stopWalkerList,
3272
+ };
3273
+ const listenFinish = functoolsKit.singleshot(() => {
3274
+ let disposeRef;
3275
+ const unBacktest = BacktestKit.listenDoneBacktest(() => {
3276
+ console.log("Backtest trading finished");
3277
+ disposeRef && disposeRef();
3278
+ });
3279
+ const unLive = BacktestKit.listenDoneLive(() => {
3280
+ console.log("Live trading finished");
3281
+ disposeRef && disposeRef();
3282
+ });
3283
+ const unWalker = BacktestKit.listenDoneWalker(() => {
3284
+ console.log("Walker comparison finished");
3285
+ disposeRef && disposeRef();
3286
+ });
3287
+ disposeRef = functoolsKit.compose(() => unBacktest(), () => unLive(), () => unWalker());
3288
+ BacktestKit.shutdown();
3289
+ });
3290
+ const createGracefulShutdown = (mode) => {
3291
+ const stop = MODE_STOP[mode];
3292
+ const handler = functoolsKit.singleshot(async () => {
3293
+ process.off("SIGINT", handler);
3294
+ notifyShutdown();
3295
+ await stop();
3296
+ });
3297
+ return functoolsKit.singleshot(() => {
3298
+ process.on("SIGINT", handler);
3299
+ });
3300
+ };
3301
+ const main$a = async () => {
3302
+ 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)))) {
3303
+ return;
3304
+ }
3305
+ const { values } = getArgs();
3306
+ if (!values.entry) {
3307
+ return;
3308
+ }
3309
+ const mode = resolveMode(values);
3310
+ if (!mode) {
3311
+ console.error("--entry requires exactly one of --backtest, --live, --paper, --walker");
3312
+ process.exit(1);
3313
+ return;
3314
+ }
3315
+ const [entryPoint = null] = getPositionals();
3316
+ if (!entryPoint) {
3317
+ throw new Error("Entry point is required");
3318
+ }
3319
+ if (!values.noFlush) {
3320
+ await flush(entryPoint);
3321
+ }
3322
+ await cli.configService.waitForInit();
3323
+ Setup.enable();
3324
+ cli.frontendProviderService.connect();
3325
+ cli.telegramProviderService.connect();
3326
+ await cli.moduleConnectionService.loadModule(MODE_MODULE[mode]);
3327
+ listenFinish();
3328
+ createGracefulShutdown(mode)();
3329
+ await cli.resolveService.attachJavascript(entryPoint);
3330
+ };
3205
3331
  main$a();
3206
3332
 
3207
3333
  const BEFORE_EXIT_FN$1 = functoolsKit.singleshot(async () => {
@@ -3715,190 +3841,190 @@ const main$2 = async () => {
3715
3841
  console.log(`Done! Docker workspace created at ${projectPath}`);
3716
3842
  console.log(`Next steps:`);
3717
3843
  console.log(` cd ${projectName}`);
3718
- console.log(` docker compose up -d`);
3844
+ console.log(` MODE=live SYMBOL=TRXUSDT UI=1 docker compose up -d`);
3719
3845
  console.log(` docker compose logs -f`);
3720
3846
  process.exit(0);
3721
3847
  };
3722
3848
  main$2();
3723
3849
 
3724
3850
  const ENTRY_PATH = "./node_modules/@backtest-kit/cli/build/index.mjs";
3725
- const HELP_TEXT = `
3726
- Usage:
3727
- node index.mjs --<mode> [flags] [entry-point]
3728
-
3729
- Modes:
3730
-
3731
- --backtest <entry> Run strategy against historical candle data
3732
- --walker <entry...> Run Walker A/B strategy comparison across multiple strategies
3733
- --paper <entry> Paper trading (live prices, no real orders)
3734
- --live <entry> Live trading with real orders
3735
- --pine <entry> Execute a local .pine indicator file
3736
- --editor Open the Pine Script visual editor in the browser
3737
- --dump Fetch and save raw OHLCV candles
3738
- --pnldebug Simulate PnL per minute for a given entry price and direction
3739
- --brokerdebug Fire a single broker commit against the live broker adapter
3740
- --flush <entry...> Delete report/log/markdown/agent folders from strategy dump dir
3741
- --init Scaffold a new project in the current directory
3742
- --docker Scaffold a Docker workspace for running strategies in a container
3743
- --help Print this help message
3744
-
3745
- Backtest flags:
3746
-
3747
- --symbol <string> Trading pair (default: BTCUSDT)
3748
- --strategy <string> Strategy name from addStrategySchema (default: first registered)
3749
- --exchange <string> Exchange name from addExchangeSchema (default: first registered)
3750
- --frame <string> Frame name from addFrameSchema (default: first registered)
3751
- --cacheInterval <string> Comma-separated intervals to pre-cache (default: "1m, 15m, 30m, 4h")
3752
- --noCache Skip candle cache warming before the run
3753
- --noFlush Skip removing report/log/markdown/agent folders before backtest run
3754
- --verbose Log every candle fetch to stdout
3755
- --ui Start web dashboard at http://localhost:60050
3756
- --telegram Send trade notifications to Telegram
3757
-
3758
- Walker flags (--walker):
3759
-
3760
- --symbol <string> Trading pair (default: BTCUSDT)
3761
- --cacheInterval <string> Comma-separated intervals to pre-cache (default: "1m, 15m, 30m, 4h")
3762
- --noCache Skip candle cache warming before the run
3763
- --noFlush Skip removing report/log/markdown/agent folders before walker run
3764
- --verbose Log every candle fetch to stdout
3765
- --output <string> Output file base name (default: walker_{SYMBOL}_{TIMESTAMP})
3766
- --json Save results as JSON to ./dump/<output>.json
3767
- --markdown Save report as Markdown to ./dump/<output>.md
3768
-
3769
- Each positional argument is a strategy entry point. All strategy files are loaded without
3770
- changing process.cwd() — .env is read from the working directory only.
3771
- addWalkerSchema is called automatically using the registered exchange and frame.
3772
- After comparison completes the report is printed to stdout (or saved if --json/--markdown).
3773
-
3774
- Module file ./modules/walker.module is loaded automatically if it exists.
3775
-
3776
- Paper / Live flags:
3777
-
3778
- --symbol <string> Trading pair (default: BTCUSDT)
3779
- --strategy <string> Strategy name (default: first registered)
3780
- --exchange <string> Exchange name (default: first registered)
3781
- --verbose Log every candle fetch to stdout
3782
- --ui Start web dashboard
3783
- --telegram Send Telegram notifications
3784
-
3785
- PineScript flags (--pine):
3786
-
3787
- --symbol <string> Trading pair (default: BTCUSDT)
3788
- --timeframe <string> Candle interval (default: 15m)
3789
- --limit <string> Number of candles to fetch (default: 250)
3790
- --when <string> End date — ISO 8601 or Unix ms (default: now)
3791
- --exchange <string> Exchange name (default: first registered)
3792
- --output <string> Output file base name without extension
3793
- --json Save output as JSON array to <pine-dir>/dump/<output>.json
3794
- --jsonl Save output as JSONL to <pine-dir>/dump/<output>.jsonl
3795
- --markdown Save output as Markdown table to <pine-dir>/dump/<output>.md
3796
-
3797
- Only plot() calls with display=display.data_window produce output columns.
3798
- Module file ./modules/pine.module is loaded automatically if it exists.
3799
-
3800
- Candle dump flags (--dump):
3801
-
3802
- --symbol <string> Trading pair (default: BTCUSDT)
3803
- --timeframe <string> Candle interval (default: 15m)
3804
- --limit <string> Number of candles (default: 250)
3805
- --when <string> End date — ISO 8601 or Unix ms (default: now)
3806
- --exchange <string> Exchange name (default: first registered)
3807
- --output <string> Output file base name (default: {SYMBOL}_{LIMIT}_{TIMEFRAME}_{TIMESTAMP})
3808
- --json Save as JSON array to ./dump/<output>.json
3809
- --jsonl Save as JSONL to ./dump/<output>.jsonl
3810
-
3811
- Module file ./modules/dump.module is loaded automatically if it exists.
3812
-
3813
- PnL debug flags (--pnldebug):
3814
-
3815
- --symbol <string> Trading pair (default: BTCUSDT)
3816
- --priceopen <number> Entry price (required)
3817
- --direction <string> Position direction: long or short (default: long)
3818
- --when <string> Start timestamp — ISO 8601 or Unix ms (default: now)
3819
- --minutes <string> Number of 1m candles to simulate (default: 60)
3820
- --exchange <string> Exchange name (default: first registered)
3821
- --output <string> Output file base name (default: {SYMBOL}_{DIRECTION}_{PRICEOPEN}_{TIMESTAMP})
3822
- --json Save as JSON array to ./dump/<output>.json
3823
- --jsonl Save as JSONL to ./dump/<output>.jsonl
3824
- --markdown Save as Markdown table to ./dump/<output>.md
3825
-
3826
- Module file ./modules/pnldebug.module is loaded automatically if it exists.
3827
-
3828
- Broker debug flags (--brokerdebug):
3829
-
3830
- --symbol <string> Trading pair (default: BTCUSDT)
3831
- --exchange <string> Exchange name (default: first registered)
3832
- --commit <string> Commit type to fire: signal-open, signal-close, partial-profit,
3833
- partial-loss, average-buy, trailing-stop, trailing-take, breakeven
3834
- (default: signal-open)
3835
-
3836
- Loads ./live.module, fetches the last candle for --symbol/--timeframe, and calls
3837
- the selected broker commit with synthetic payload values derived from current price.
3838
-
3839
- Flush flags (--flush):
3840
-
3841
- One or more positional entry points. For each entry point the following
3842
- subdirectories are removed from <entry-dir>/dump/:
3843
-
3844
- report log markdown agent
3845
-
3846
- Init flags (--init):
3847
-
3848
- --output <string> Target directory name (default: backtest-kit-project)
3849
-
3850
- Scaffolds a project and runs scripts/fetch_docs.mjs to download library docs.
3851
-
3852
- Docker flags (--docker):
3853
-
3854
- --output <string> Target directory name (default: backtest-kit-docker)
3855
-
3856
- Scaffolds a Docker workspace: docker-compose.yaml, .env.example, package.json,
3857
- tsconfig.json, and a sample strategy under content/. Run npm install then
3858
- docker compose up to start the container.
3859
-
3860
- Module hooks (loaded automatically by each mode):
3861
-
3862
- modules/backtest.module --backtest Broker adapter for backtest
3863
- modules/walker.module --walker Broker adapter for walker comparison
3864
- modules/paper.module --paper Broker adapter for paper trading
3865
- modules/live.module --live Broker adapter for live trading
3866
- modules/pine.module --pine Exchange schema for PineScript runs
3867
- modules/editor.module --editor Exchange schema for the visual Pine editor
3868
- modules/dump.module --dump Exchange schema for candle dumps
3869
- modules/pnldebug.module --pnldebug Exchange schema for PnL debug runs
3870
- modules/brokerdebug.module --brokerdebug Broker adapter used for broker commit testing
3871
-
3872
- --flush has no associated module. It only removes dump subdirectories.
3873
-
3874
- Extensions .ts, .mjs, .cjs are tried automatically. Missing module = soft warning.
3875
-
3876
- Environment variables:
3877
-
3878
- CC_TELEGRAM_TOKEN Telegram bot token (required for --telegram)
3879
- CC_TELEGRAM_CHANNEL Telegram channel or chat ID (required for --telegram)
3880
- CC_WWWROOT_HOST UI server bind address (default: 0.0.0.0)
3881
- CC_WWWROOT_PORT UI server port (default: 60050)
3882
-
3883
- Examples:
3884
-
3885
- node ${ENTRY_PATH} --backtest ./content/feb_2026.strategy.ts
3886
- node ${ENTRY_PATH} --backtest --symbol BTCUSDT --noCache --noFlush --ui ./content/feb_2026.strategy.ts
3887
- node ${ENTRY_PATH} --walker ./content/feb_2026_v1.strategy.ts ./content/feb_2026_v2.strategy.ts ./content/feb_2026_v3.strategy.ts
3888
- node ${ENTRY_PATH} --walker --symbol BTCUSDT --noCache --noFlush --markdown ./content/feb_2026_v1.ts ./content/feb_2026_v2.ts
3889
- node ${ENTRY_PATH} --paper --symbol ETHUSDT ./content/feb_2026.strategy.ts
3890
- node ${ENTRY_PATH} --live --ui --telegram ./content/feb_2026.strategy.ts
3891
- node ${ENTRY_PATH} --pine ./math/feb_2026.pine --timeframe 15m --limit 500 --jsonl
3892
- node ${ENTRY_PATH} --editor
3893
- node ${ENTRY_PATH} --dump --symbol BTCUSDT --timeframe 15m --limit 500 --jsonl
3894
- node ${ENTRY_PATH} --pnldebug --symbol BTCUSDT --priceopen 64069.50 --direction short --when "2025-02-25" --minutes 120
3895
- node ${ENTRY_PATH} --pnldebug --priceopen 67956.73 --direction long --when 1772064000000 --minutes 60 --markdown
3896
- node ${ENTRY_PATH} --brokerdebug --commit signal-open --symbol BTCUSDT
3897
- node ${ENTRY_PATH} --brokerdebug --commit partial-profit --symbol ETHUSDT
3898
- node ${ENTRY_PATH} --flush ./content/feb_2026.strategy/feb_2026.strategy.ts
3899
- node ${ENTRY_PATH} --flush ./content/feb_2026.strategy/feb_2026.strategy.ts ./content/feb_2026.strategy/feb_2026.test.ts
3900
- node ${ENTRY_PATH} --init --output my-trading-bot
3901
- node ${ENTRY_PATH} --docker --output my-docker-workspace
3851
+ const HELP_TEXT = `
3852
+ Usage:
3853
+ node index.mjs --<mode> [flags] [entry-point]
3854
+
3855
+ Modes:
3856
+
3857
+ --backtest <entry> Run strategy against historical candle data
3858
+ --walker <entry...> Run Walker A/B strategy comparison across multiple strategies
3859
+ --paper <entry> Paper trading (live prices, no real orders)
3860
+ --live <entry> Live trading with real orders
3861
+ --pine <entry> Execute a local .pine indicator file
3862
+ --editor Open the Pine Script visual editor in the browser
3863
+ --dump Fetch and save raw OHLCV candles
3864
+ --pnldebug Simulate PnL per minute for a given entry price and direction
3865
+ --brokerdebug Fire a single broker commit against the live broker adapter
3866
+ --flush <entry...> Delete report/log/markdown/agent folders from strategy dump dir
3867
+ --init Scaffold a new project in the current directory
3868
+ --docker Scaffold a Docker workspace for running strategies in a container
3869
+ --help Print this help message
3870
+
3871
+ Backtest flags:
3872
+
3873
+ --symbol <string> Trading pair (default: BTCUSDT)
3874
+ --strategy <string> Strategy name from addStrategySchema (default: first registered)
3875
+ --exchange <string> Exchange name from addExchangeSchema (default: first registered)
3876
+ --frame <string> Frame name from addFrameSchema (default: first registered)
3877
+ --cacheInterval <string> Comma-separated intervals to pre-cache (default: "1m, 15m, 30m, 4h")
3878
+ --noCache Skip candle cache warming before the run
3879
+ --noFlush Skip removing report/log/markdown/agent folders before backtest run
3880
+ --verbose Log every candle fetch to stdout
3881
+ --ui Start web dashboard at http://localhost:60050
3882
+ --telegram Send trade notifications to Telegram
3883
+
3884
+ Walker flags (--walker):
3885
+
3886
+ --symbol <string> Trading pair (default: BTCUSDT)
3887
+ --cacheInterval <string> Comma-separated intervals to pre-cache (default: "1m, 15m, 30m, 4h")
3888
+ --noCache Skip candle cache warming before the run
3889
+ --noFlush Skip removing report/log/markdown/agent folders before walker run
3890
+ --verbose Log every candle fetch to stdout
3891
+ --output <string> Output file base name (default: walker_{SYMBOL}_{TIMESTAMP})
3892
+ --json Save results as JSON to ./dump/<output>.json
3893
+ --markdown Save report as Markdown to ./dump/<output>.md
3894
+
3895
+ Each positional argument is a strategy entry point. All strategy files are loaded without
3896
+ changing process.cwd() — .env is read from the working directory only.
3897
+ addWalkerSchema is called automatically using the registered exchange and frame.
3898
+ After comparison completes the report is printed to stdout (or saved if --json/--markdown).
3899
+
3900
+ Module file ./modules/walker.module is loaded automatically if it exists.
3901
+
3902
+ Paper / Live flags:
3903
+
3904
+ --symbol <string> Trading pair (default: BTCUSDT)
3905
+ --strategy <string> Strategy name (default: first registered)
3906
+ --exchange <string> Exchange name (default: first registered)
3907
+ --verbose Log every candle fetch to stdout
3908
+ --ui Start web dashboard
3909
+ --telegram Send Telegram notifications
3910
+
3911
+ PineScript flags (--pine):
3912
+
3913
+ --symbol <string> Trading pair (default: BTCUSDT)
3914
+ --timeframe <string> Candle interval (default: 15m)
3915
+ --limit <string> Number of candles to fetch (default: 250)
3916
+ --when <string> End date — ISO 8601 or Unix ms (default: now)
3917
+ --exchange <string> Exchange name (default: first registered)
3918
+ --output <string> Output file base name without extension
3919
+ --json Save output as JSON array to <pine-dir>/dump/<output>.json
3920
+ --jsonl Save output as JSONL to <pine-dir>/dump/<output>.jsonl
3921
+ --markdown Save output as Markdown table to <pine-dir>/dump/<output>.md
3922
+
3923
+ Only plot() calls with display=display.data_window produce output columns.
3924
+ Module file ./modules/pine.module is loaded automatically if it exists.
3925
+
3926
+ Candle dump flags (--dump):
3927
+
3928
+ --symbol <string> Trading pair (default: BTCUSDT)
3929
+ --timeframe <string> Candle interval (default: 15m)
3930
+ --limit <string> Number of candles (default: 250)
3931
+ --when <string> End date — ISO 8601 or Unix ms (default: now)
3932
+ --exchange <string> Exchange name (default: first registered)
3933
+ --output <string> Output file base name (default: {SYMBOL}_{LIMIT}_{TIMEFRAME}_{TIMESTAMP})
3934
+ --json Save as JSON array to ./dump/<output>.json
3935
+ --jsonl Save as JSONL to ./dump/<output>.jsonl
3936
+
3937
+ Module file ./modules/dump.module is loaded automatically if it exists.
3938
+
3939
+ PnL debug flags (--pnldebug):
3940
+
3941
+ --symbol <string> Trading pair (default: BTCUSDT)
3942
+ --priceopen <number> Entry price (required)
3943
+ --direction <string> Position direction: long or short (default: long)
3944
+ --when <string> Start timestamp — ISO 8601 or Unix ms (default: now)
3945
+ --minutes <string> Number of 1m candles to simulate (default: 60)
3946
+ --exchange <string> Exchange name (default: first registered)
3947
+ --output <string> Output file base name (default: {SYMBOL}_{DIRECTION}_{PRICEOPEN}_{TIMESTAMP})
3948
+ --json Save as JSON array to ./dump/<output>.json
3949
+ --jsonl Save as JSONL to ./dump/<output>.jsonl
3950
+ --markdown Save as Markdown table to ./dump/<output>.md
3951
+
3952
+ Module file ./modules/pnldebug.module is loaded automatically if it exists.
3953
+
3954
+ Broker debug flags (--brokerdebug):
3955
+
3956
+ --symbol <string> Trading pair (default: BTCUSDT)
3957
+ --exchange <string> Exchange name (default: first registered)
3958
+ --commit <string> Commit type to fire: signal-open, signal-close, partial-profit,
3959
+ partial-loss, average-buy, trailing-stop, trailing-take, breakeven
3960
+ (default: signal-open)
3961
+
3962
+ Loads ./live.module, fetches the last candle for --symbol/--timeframe, and calls
3963
+ the selected broker commit with synthetic payload values derived from current price.
3964
+
3965
+ Flush flags (--flush):
3966
+
3967
+ One or more positional entry points. For each entry point the following
3968
+ subdirectories are removed from <entry-dir>/dump/:
3969
+
3970
+ report log markdown agent
3971
+
3972
+ Init flags (--init):
3973
+
3974
+ --output <string> Target directory name (default: backtest-kit-project)
3975
+
3976
+ Scaffolds a project and runs scripts/fetch_docs.mjs to download library docs.
3977
+
3978
+ Docker flags (--docker):
3979
+
3980
+ --output <string> Target directory name (default: backtest-kit-docker)
3981
+
3982
+ Scaffolds a Docker workspace: docker-compose.yaml, .env.example, package.json,
3983
+ tsconfig.json, and a sample strategy under content/. Run npm install then
3984
+ docker compose up to start the container.
3985
+
3986
+ Module hooks (loaded automatically by each mode):
3987
+
3988
+ modules/backtest.module --backtest Broker adapter for backtest
3989
+ modules/walker.module --walker Broker adapter for walker comparison
3990
+ modules/paper.module --paper Broker adapter for paper trading
3991
+ modules/live.module --live Broker adapter for live trading
3992
+ modules/pine.module --pine Exchange schema for PineScript runs
3993
+ modules/editor.module --editor Exchange schema for the visual Pine editor
3994
+ modules/dump.module --dump Exchange schema for candle dumps
3995
+ modules/pnldebug.module --pnldebug Exchange schema for PnL debug runs
3996
+ modules/brokerdebug.module --brokerdebug Broker adapter used for broker commit testing
3997
+
3998
+ --flush has no associated module. It only removes dump subdirectories.
3999
+
4000
+ Extensions .ts, .mjs, .cjs are tried automatically. Missing module = soft warning.
4001
+
4002
+ Environment variables:
4003
+
4004
+ CC_TELEGRAM_TOKEN Telegram bot token (required for --telegram)
4005
+ CC_TELEGRAM_CHANNEL Telegram channel or chat ID (required for --telegram)
4006
+ CC_WWWROOT_HOST UI server bind address (default: 0.0.0.0)
4007
+ CC_WWWROOT_PORT UI server port (default: 60050)
4008
+
4009
+ Examples:
4010
+
4011
+ node ${ENTRY_PATH} --backtest ./content/feb_2026.strategy.ts
4012
+ node ${ENTRY_PATH} --backtest --symbol BTCUSDT --noCache --noFlush --ui ./content/feb_2026.strategy.ts
4013
+ node ${ENTRY_PATH} --walker ./content/feb_2026_v1.strategy.ts ./content/feb_2026_v2.strategy.ts ./content/feb_2026_v3.strategy.ts
4014
+ node ${ENTRY_PATH} --walker --symbol BTCUSDT --noCache --noFlush --markdown ./content/feb_2026_v1.ts ./content/feb_2026_v2.ts
4015
+ node ${ENTRY_PATH} --paper --symbol ETHUSDT ./content/feb_2026.strategy.ts
4016
+ node ${ENTRY_PATH} --live --ui --telegram ./content/feb_2026.strategy.ts
4017
+ node ${ENTRY_PATH} --pine ./math/feb_2026.pine --timeframe 15m --limit 500 --jsonl
4018
+ node ${ENTRY_PATH} --editor
4019
+ node ${ENTRY_PATH} --dump --symbol BTCUSDT --timeframe 15m --limit 500 --jsonl
4020
+ node ${ENTRY_PATH} --pnldebug --symbol BTCUSDT --priceopen 64069.50 --direction short --when "2025-02-25" --minutes 120
4021
+ node ${ENTRY_PATH} --pnldebug --priceopen 67956.73 --direction long --when 1772064000000 --minutes 60 --markdown
4022
+ node ${ENTRY_PATH} --brokerdebug --commit signal-open --symbol BTCUSDT
4023
+ node ${ENTRY_PATH} --brokerdebug --commit partial-profit --symbol ETHUSDT
4024
+ node ${ENTRY_PATH} --flush ./content/feb_2026.strategy/feb_2026.strategy.ts
4025
+ node ${ENTRY_PATH} --flush ./content/feb_2026.strategy/feb_2026.strategy.ts ./content/feb_2026.strategy/feb_2026.test.ts
4026
+ node ${ENTRY_PATH} --init --output my-trading-bot
4027
+ node ${ENTRY_PATH} --docker --output my-docker-workspace
3902
4028
  `.trimStart();
3903
4029
  const main$1 = async () => {
3904
4030
  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)))) {
@@ -3908,7 +4034,7 @@ const main$1 = async () => {
3908
4034
  if (!values.help) {
3909
4035
  return;
3910
4036
  }
3911
- process.stdout.write(`@backtest-kit/cli ${"8.4.2"}\n\n`);
4037
+ process.stdout.write(`@backtest-kit/cli ${"8.5.0"}\n\n`);
3912
4038
  process.stdout.write(HELP_TEXT);
3913
4039
  process.exit(0);
3914
4040
  };
@@ -3922,7 +4048,7 @@ const main = async () => {
3922
4048
  if (!values.version) {
3923
4049
  return;
3924
4050
  }
3925
- process.stdout.write(`@backtest-kit/cli ${"8.4.2"}\n`);
4051
+ process.stdout.write(`@backtest-kit/cli ${"8.5.0"}\n`);
3926
4052
  process.exit(0);
3927
4053
  };
3928
4054
  main();