@backtest-kit/cli 8.5.0 → 9.0.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
@@ -681,6 +681,9 @@ const notifyFinish = functoolsKit.singleshot(() => {
681
681
  });
682
682
 
683
683
  const getEntry = (metaUrl) => {
684
+ if (!process.argv[1]) {
685
+ return "";
686
+ }
684
687
  const metaPath = url.fileURLToPath(metaUrl);
685
688
  const realArgv = fs.realpathSync(process.argv[1]);
686
689
  return path.resolve(realArgv) === path.resolve(metaPath);
@@ -3018,10 +3021,10 @@ init();
3018
3021
 
3019
3022
  const MODES = ["backtest", "walker", "paper", "live", "pine", "editor", "dump", "pnldebug", "brokerdebug", "flush", "init", "docker", "help", "version"];
3020
3023
  const ENTRY_PATH$1 = "./node_modules/@backtest-kit/cli/build/index.mjs";
3021
- const HELP_TEXT$1 = `
3022
- Example:
3023
-
3024
- node ${ENTRY_PATH$1} --help
3024
+ const HELP_TEXT$1 = `
3025
+ Example:
3026
+
3027
+ node ${ENTRY_PATH$1} --help
3025
3028
  `.trimStart();
3026
3029
  const main$g = async () => {
3027
3030
  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)))) {
@@ -3031,7 +3034,7 @@ const main$g = async () => {
3031
3034
  if (MODES.some((mode) => values[mode])) {
3032
3035
  return;
3033
3036
  }
3034
- process.stdout.write(`@backtest-kit/cli ${"8.5.0"}\n`);
3037
+ process.stdout.write(`@backtest-kit/cli ${"9.0.0"}\n`);
3035
3038
  process.stdout.write("\n");
3036
3039
  process.stdout.write(`Run with --help to see available commands.\n`);
3037
3040
  process.stdout.write("\n");
@@ -3848,183 +3851,183 @@ const main$2 = async () => {
3848
3851
  main$2();
3849
3852
 
3850
3853
  const ENTRY_PATH = "./node_modules/@backtest-kit/cli/build/index.mjs";
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
3854
+ const HELP_TEXT = `
3855
+ Usage:
3856
+ node index.mjs --<mode> [flags] [entry-point]
3857
+
3858
+ Modes:
3859
+
3860
+ --backtest <entry> Run strategy against historical candle data
3861
+ --walker <entry...> Run Walker A/B strategy comparison across multiple strategies
3862
+ --paper <entry> Paper trading (live prices, no real orders)
3863
+ --live <entry> Live trading with real orders
3864
+ --pine <entry> Execute a local .pine indicator file
3865
+ --editor Open the Pine Script visual editor in the browser
3866
+ --dump Fetch and save raw OHLCV candles
3867
+ --pnldebug Simulate PnL per minute for a given entry price and direction
3868
+ --brokerdebug Fire a single broker commit against the live broker adapter
3869
+ --flush <entry...> Delete report/log/markdown/agent folders from strategy dump dir
3870
+ --init Scaffold a new project in the current directory
3871
+ --docker Scaffold a Docker workspace for running strategies in a container
3872
+ --help Print this help message
3873
+
3874
+ Backtest flags:
3875
+
3876
+ --symbol <string> Trading pair (default: BTCUSDT)
3877
+ --strategy <string> Strategy name from addStrategySchema (default: first registered)
3878
+ --exchange <string> Exchange name from addExchangeSchema (default: first registered)
3879
+ --frame <string> Frame name from addFrameSchema (default: first registered)
3880
+ --cacheInterval <string> Comma-separated intervals to pre-cache (default: "1m, 15m, 30m, 4h")
3881
+ --noCache Skip candle cache warming before the run
3882
+ --noFlush Skip removing report/log/markdown/agent folders before backtest run
3883
+ --verbose Log every candle fetch to stdout
3884
+ --ui Start web dashboard at http://localhost:60050
3885
+ --telegram Send trade notifications to Telegram
3886
+
3887
+ Walker flags (--walker):
3888
+
3889
+ --symbol <string> Trading pair (default: BTCUSDT)
3890
+ --cacheInterval <string> Comma-separated intervals to pre-cache (default: "1m, 15m, 30m, 4h")
3891
+ --noCache Skip candle cache warming before the run
3892
+ --noFlush Skip removing report/log/markdown/agent folders before walker run
3893
+ --verbose Log every candle fetch to stdout
3894
+ --output <string> Output file base name (default: walker_{SYMBOL}_{TIMESTAMP})
3895
+ --json Save results as JSON to ./dump/<output>.json
3896
+ --markdown Save report as Markdown to ./dump/<output>.md
3897
+
3898
+ Each positional argument is a strategy entry point. All strategy files are loaded without
3899
+ changing process.cwd() — .env is read from the working directory only.
3900
+ addWalkerSchema is called automatically using the registered exchange and frame.
3901
+ After comparison completes the report is printed to stdout (or saved if --json/--markdown).
3902
+
3903
+ Module file ./modules/walker.module is loaded automatically if it exists.
3904
+
3905
+ Paper / Live flags:
3906
+
3907
+ --symbol <string> Trading pair (default: BTCUSDT)
3908
+ --strategy <string> Strategy name (default: first registered)
3909
+ --exchange <string> Exchange name (default: first registered)
3910
+ --verbose Log every candle fetch to stdout
3911
+ --ui Start web dashboard
3912
+ --telegram Send Telegram notifications
3913
+
3914
+ PineScript flags (--pine):
3915
+
3916
+ --symbol <string> Trading pair (default: BTCUSDT)
3917
+ --timeframe <string> Candle interval (default: 15m)
3918
+ --limit <string> Number of candles to fetch (default: 250)
3919
+ --when <string> End date — ISO 8601 or Unix ms (default: now)
3920
+ --exchange <string> Exchange name (default: first registered)
3921
+ --output <string> Output file base name without extension
3922
+ --json Save output as JSON array to <pine-dir>/dump/<output>.json
3923
+ --jsonl Save output as JSONL to <pine-dir>/dump/<output>.jsonl
3924
+ --markdown Save output as Markdown table to <pine-dir>/dump/<output>.md
3925
+
3926
+ Only plot() calls with display=display.data_window produce output columns.
3927
+ Module file ./modules/pine.module is loaded automatically if it exists.
3928
+
3929
+ Candle dump flags (--dump):
3930
+
3931
+ --symbol <string> Trading pair (default: BTCUSDT)
3932
+ --timeframe <string> Candle interval (default: 15m)
3933
+ --limit <string> Number of candles (default: 250)
3934
+ --when <string> End date — ISO 8601 or Unix ms (default: now)
3935
+ --exchange <string> Exchange name (default: first registered)
3936
+ --output <string> Output file base name (default: {SYMBOL}_{LIMIT}_{TIMEFRAME}_{TIMESTAMP})
3937
+ --json Save as JSON array to ./dump/<output>.json
3938
+ --jsonl Save as JSONL to ./dump/<output>.jsonl
3939
+
3940
+ Module file ./modules/dump.module is loaded automatically if it exists.
3941
+
3942
+ PnL debug flags (--pnldebug):
3943
+
3944
+ --symbol <string> Trading pair (default: BTCUSDT)
3945
+ --priceopen <number> Entry price (required)
3946
+ --direction <string> Position direction: long or short (default: long)
3947
+ --when <string> Start timestamp — ISO 8601 or Unix ms (default: now)
3948
+ --minutes <string> Number of 1m candles to simulate (default: 60)
3949
+ --exchange <string> Exchange name (default: first registered)
3950
+ --output <string> Output file base name (default: {SYMBOL}_{DIRECTION}_{PRICEOPEN}_{TIMESTAMP})
3951
+ --json Save as JSON array to ./dump/<output>.json
3952
+ --jsonl Save as JSONL to ./dump/<output>.jsonl
3953
+ --markdown Save as Markdown table to ./dump/<output>.md
3954
+
3955
+ Module file ./modules/pnldebug.module is loaded automatically if it exists.
3956
+
3957
+ Broker debug flags (--brokerdebug):
3958
+
3959
+ --symbol <string> Trading pair (default: BTCUSDT)
3960
+ --exchange <string> Exchange name (default: first registered)
3961
+ --commit <string> Commit type to fire: signal-open, signal-close, partial-profit,
3962
+ partial-loss, average-buy, trailing-stop, trailing-take, breakeven
3963
+ (default: signal-open)
3964
+
3965
+ Loads ./live.module, fetches the last candle for --symbol/--timeframe, and calls
3966
+ the selected broker commit with synthetic payload values derived from current price.
3967
+
3968
+ Flush flags (--flush):
3969
+
3970
+ One or more positional entry points. For each entry point the following
3971
+ subdirectories are removed from <entry-dir>/dump/:
3972
+
3973
+ report log markdown agent
3974
+
3975
+ Init flags (--init):
3976
+
3977
+ --output <string> Target directory name (default: backtest-kit-project)
3978
+
3979
+ Scaffolds a project and runs scripts/fetch_docs.mjs to download library docs.
3980
+
3981
+ Docker flags (--docker):
3982
+
3983
+ --output <string> Target directory name (default: backtest-kit-docker)
3984
+
3985
+ Scaffolds a Docker workspace: docker-compose.yaml, .env.example, package.json,
3986
+ tsconfig.json, and a sample strategy under content/. Run npm install then
3987
+ docker compose up to start the container.
3988
+
3989
+ Module hooks (loaded automatically by each mode):
3990
+
3991
+ modules/backtest.module --backtest Broker adapter for backtest
3992
+ modules/walker.module --walker Broker adapter for walker comparison
3993
+ modules/paper.module --paper Broker adapter for paper trading
3994
+ modules/live.module --live Broker adapter for live trading
3995
+ modules/pine.module --pine Exchange schema for PineScript runs
3996
+ modules/editor.module --editor Exchange schema for the visual Pine editor
3997
+ modules/dump.module --dump Exchange schema for candle dumps
3998
+ modules/pnldebug.module --pnldebug Exchange schema for PnL debug runs
3999
+ modules/brokerdebug.module --brokerdebug Broker adapter used for broker commit testing
4000
+
4001
+ --flush has no associated module. It only removes dump subdirectories.
4002
+
4003
+ Extensions .ts, .mjs, .cjs are tried automatically. Missing module = soft warning.
4004
+
4005
+ Environment variables:
4006
+
4007
+ CC_TELEGRAM_TOKEN Telegram bot token (required for --telegram)
4008
+ CC_TELEGRAM_CHANNEL Telegram channel or chat ID (required for --telegram)
4009
+ CC_WWWROOT_HOST UI server bind address (default: 0.0.0.0)
4010
+ CC_WWWROOT_PORT UI server port (default: 60050)
4011
+
4012
+ Examples:
4013
+
4014
+ node ${ENTRY_PATH} --backtest ./content/feb_2026.strategy.ts
4015
+ node ${ENTRY_PATH} --backtest --symbol BTCUSDT --noCache --noFlush --ui ./content/feb_2026.strategy.ts
4016
+ node ${ENTRY_PATH} --walker ./content/feb_2026_v1.strategy.ts ./content/feb_2026_v2.strategy.ts ./content/feb_2026_v3.strategy.ts
4017
+ node ${ENTRY_PATH} --walker --symbol BTCUSDT --noCache --noFlush --markdown ./content/feb_2026_v1.ts ./content/feb_2026_v2.ts
4018
+ node ${ENTRY_PATH} --paper --symbol ETHUSDT ./content/feb_2026.strategy.ts
4019
+ node ${ENTRY_PATH} --live --ui --telegram ./content/feb_2026.strategy.ts
4020
+ node ${ENTRY_PATH} --pine ./math/feb_2026.pine --timeframe 15m --limit 500 --jsonl
4021
+ node ${ENTRY_PATH} --editor
4022
+ node ${ENTRY_PATH} --dump --symbol BTCUSDT --timeframe 15m --limit 500 --jsonl
4023
+ node ${ENTRY_PATH} --pnldebug --symbol BTCUSDT --priceopen 64069.50 --direction short --when "2025-02-25" --minutes 120
4024
+ node ${ENTRY_PATH} --pnldebug --priceopen 67956.73 --direction long --when 1772064000000 --minutes 60 --markdown
4025
+ node ${ENTRY_PATH} --brokerdebug --commit signal-open --symbol BTCUSDT
4026
+ node ${ENTRY_PATH} --brokerdebug --commit partial-profit --symbol ETHUSDT
4027
+ node ${ENTRY_PATH} --flush ./content/feb_2026.strategy/feb_2026.strategy.ts
4028
+ node ${ENTRY_PATH} --flush ./content/feb_2026.strategy/feb_2026.strategy.ts ./content/feb_2026.strategy/feb_2026.test.ts
4029
+ node ${ENTRY_PATH} --init --output my-trading-bot
4030
+ node ${ENTRY_PATH} --docker --output my-docker-workspace
4028
4031
  `.trimStart();
4029
4032
  const main$1 = async () => {
4030
4033
  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)))) {
@@ -4034,7 +4037,7 @@ const main$1 = async () => {
4034
4037
  if (!values.help) {
4035
4038
  return;
4036
4039
  }
4037
- process.stdout.write(`@backtest-kit/cli ${"8.5.0"}\n\n`);
4040
+ process.stdout.write(`@backtest-kit/cli ${"9.0.0"}\n\n`);
4038
4041
  process.stdout.write(HELP_TEXT);
4039
4042
  process.exit(0);
4040
4043
  };
@@ -4048,7 +4051,7 @@ const main = async () => {
4048
4051
  if (!values.version) {
4049
4052
  return;
4050
4053
  }
4051
- process.stdout.write(`@backtest-kit/cli ${"8.5.0"}\n`);
4054
+ process.stdout.write(`@backtest-kit/cli ${"9.0.0"}\n`);
4052
4055
  process.exit(0);
4053
4056
  };
4054
4057
  main();