@backtest-kit/cli 8.4.3 → 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/README.md +1692 -1615
- package/build/index.cjs +324 -195
- package/build/index.mjs +324 -195
- package/config/notification.config.mjs +13 -13
- package/config/symbol.config.mjs +460 -460
- package/docker/.env.example +2 -2
- package/docker/content/feb_2026/feb_2026.strategy.ts +11 -11
- package/docker/content/feb_2026/modules/backtest.module.ts +83 -83
- package/docker/docker-compose.yaml +45 -44
- package/docker/package.json +38 -38
- package/docker/tsconfig.json +36 -36
- package/package.json +126 -126
- package/template/average-buy.mustache +22 -22
- package/template/breakeven.mustache +21 -21
- package/template/cancel-scheduled.mustache +14 -14
- package/template/cancelled.mustache +21 -21
- package/template/close-pending.mustache +16 -16
- package/template/closed.mustache +23 -23
- package/template/opened.mustache +22 -22
- package/template/partial-loss.mustache +22 -22
- package/template/partial-profit.mustache +22 -22
- package/template/project/config/symbol.config.ts +460 -460
- package/template/project/package.mustache +28 -28
- package/template/risk.mustache +19 -19
- package/template/scheduled.mustache +22 -22
- package/template/signal-close.mustache +22 -22
- package/template/signal-info.mustache +20 -20
- package/template/signal-open.mustache +22 -22
- package/template/source/CLAUDE.md +160 -160
- package/template/trailing-stop.mustache +21 -21
- package/template/trailing-take.mustache +21 -21
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",
|
|
@@ -677,6 +681,9 @@ const notifyFinish = functoolsKit.singleshot(() => {
|
|
|
677
681
|
});
|
|
678
682
|
|
|
679
683
|
const getEntry = (metaUrl) => {
|
|
684
|
+
if (!process.argv[1]) {
|
|
685
|
+
return "";
|
|
686
|
+
}
|
|
680
687
|
const metaPath = url.fileURLToPath(metaUrl);
|
|
681
688
|
const realArgv = fs.realpathSync(process.argv[1]);
|
|
682
689
|
return path.resolve(realArgv) === path.resolve(metaPath);
|
|
@@ -3014,12 +3021,12 @@ init();
|
|
|
3014
3021
|
|
|
3015
3022
|
const MODES = ["backtest", "walker", "paper", "live", "pine", "editor", "dump", "pnldebug", "brokerdebug", "flush", "init", "docker", "help", "version"];
|
|
3016
3023
|
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
|
|
3024
|
+
const HELP_TEXT$1 = `
|
|
3025
|
+
Example:
|
|
3026
|
+
|
|
3027
|
+
node ${ENTRY_PATH$1} --help
|
|
3021
3028
|
`.trimStart();
|
|
3022
|
-
const main$
|
|
3029
|
+
const main$g = async () => {
|
|
3023
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)))) {
|
|
3024
3031
|
return;
|
|
3025
3032
|
}
|
|
@@ -3027,14 +3034,14 @@ const main$f = async () => {
|
|
|
3027
3034
|
if (MODES.some((mode) => values[mode])) {
|
|
3028
3035
|
return;
|
|
3029
3036
|
}
|
|
3030
|
-
process.stdout.write(`@backtest-kit/cli ${"
|
|
3037
|
+
process.stdout.write(`@backtest-kit/cli ${"9.0.0"}\n`);
|
|
3031
3038
|
process.stdout.write("\n");
|
|
3032
3039
|
process.stdout.write(`Run with --help to see available commands.\n`);
|
|
3033
3040
|
process.stdout.write("\n");
|
|
3034
3041
|
process.stdout.write(HELP_TEXT$1);
|
|
3035
3042
|
process.exit(0);
|
|
3036
3043
|
};
|
|
3037
|
-
main$
|
|
3044
|
+
main$g();
|
|
3038
3045
|
|
|
3039
3046
|
const notifyShutdown = functoolsKit.singleshot(async () => {
|
|
3040
3047
|
console.log("Graceful shutdown initiated. Press Ctrl+C again to force quit.");
|
|
@@ -3050,7 +3057,7 @@ const flush = async (entryPoint) => {
|
|
|
3050
3057
|
console.log(`Removed: ${target}`);
|
|
3051
3058
|
}
|
|
3052
3059
|
};
|
|
3053
|
-
const main$
|
|
3060
|
+
const main$f = async () => {
|
|
3054
3061
|
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
3062
|
return;
|
|
3056
3063
|
}
|
|
@@ -3067,7 +3074,7 @@ const main$e = async () => {
|
|
|
3067
3074
|
}
|
|
3068
3075
|
process.exit(0);
|
|
3069
3076
|
};
|
|
3070
|
-
main$
|
|
3077
|
+
main$f();
|
|
3071
3078
|
|
|
3072
3079
|
const BEFORE_EXIT_FN$5 = functoolsKit.singleshot(async () => {
|
|
3073
3080
|
process.off("SIGINT", BEFORE_EXIT_FN$5);
|
|
@@ -3089,7 +3096,7 @@ const BEFORE_EXIT_FN$5 = functoolsKit.singleshot(async () => {
|
|
|
3089
3096
|
const listenGracefulShutdown$5 = functoolsKit.singleshot(() => {
|
|
3090
3097
|
process.on("SIGINT", BEFORE_EXIT_FN$5);
|
|
3091
3098
|
});
|
|
3092
|
-
const main$
|
|
3099
|
+
const main$e = async () => {
|
|
3093
3100
|
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
3101
|
return;
|
|
3095
3102
|
}
|
|
@@ -3097,6 +3104,9 @@ const main$d = async () => {
|
|
|
3097
3104
|
if (!values.backtest) {
|
|
3098
3105
|
return;
|
|
3099
3106
|
}
|
|
3107
|
+
if (values.entry) {
|
|
3108
|
+
return;
|
|
3109
|
+
}
|
|
3100
3110
|
if (!values.noFlush) {
|
|
3101
3111
|
const [entryPoint = null] = getPositionals();
|
|
3102
3112
|
entryPoint && await flush(entryPoint);
|
|
@@ -3104,7 +3114,7 @@ const main$d = async () => {
|
|
|
3104
3114
|
await cli.backtestMainService.connect();
|
|
3105
3115
|
listenGracefulShutdown$5();
|
|
3106
3116
|
};
|
|
3107
|
-
main$
|
|
3117
|
+
main$e();
|
|
3108
3118
|
|
|
3109
3119
|
const BEFORE_EXIT_FN$4 = functoolsKit.singleshot(async () => {
|
|
3110
3120
|
process.off("SIGINT", BEFORE_EXIT_FN$4);
|
|
@@ -3122,7 +3132,7 @@ const BEFORE_EXIT_FN$4 = functoolsKit.singleshot(async () => {
|
|
|
3122
3132
|
const listenGracefulShutdown$4 = functoolsKit.singleshot(() => {
|
|
3123
3133
|
process.on("SIGINT", BEFORE_EXIT_FN$4);
|
|
3124
3134
|
});
|
|
3125
|
-
const main$
|
|
3135
|
+
const main$d = async () => {
|
|
3126
3136
|
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
3137
|
return;
|
|
3128
3138
|
}
|
|
@@ -3130,6 +3140,9 @@ const main$c = async () => {
|
|
|
3130
3140
|
if (!values.walker) {
|
|
3131
3141
|
return;
|
|
3132
3142
|
}
|
|
3143
|
+
if (values.entry) {
|
|
3144
|
+
return;
|
|
3145
|
+
}
|
|
3133
3146
|
if (!values.noFlush) {
|
|
3134
3147
|
for (const entryPoint of getPositionals()) {
|
|
3135
3148
|
await flush(entryPoint);
|
|
@@ -3138,7 +3151,7 @@ const main$c = async () => {
|
|
|
3138
3151
|
listenGracefulShutdown$4();
|
|
3139
3152
|
await cli.walkerMainService.connect();
|
|
3140
3153
|
};
|
|
3141
|
-
main$
|
|
3154
|
+
main$d();
|
|
3142
3155
|
|
|
3143
3156
|
const BEFORE_EXIT_FN$3 = functoolsKit.singleshot(async () => {
|
|
3144
3157
|
process.off("SIGINT", BEFORE_EXIT_FN$3);
|
|
@@ -3159,7 +3172,7 @@ const BEFORE_EXIT_FN$3 = functoolsKit.singleshot(async () => {
|
|
|
3159
3172
|
const listenGracefulShutdown$3 = functoolsKit.singleshot(() => {
|
|
3160
3173
|
process.on("SIGINT", BEFORE_EXIT_FN$3);
|
|
3161
3174
|
});
|
|
3162
|
-
const main$
|
|
3175
|
+
const main$c = async () => {
|
|
3163
3176
|
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
3177
|
return;
|
|
3165
3178
|
}
|
|
@@ -3167,10 +3180,13 @@ const main$b = async () => {
|
|
|
3167
3180
|
if (!values.paper) {
|
|
3168
3181
|
return;
|
|
3169
3182
|
}
|
|
3183
|
+
if (values.entry) {
|
|
3184
|
+
return;
|
|
3185
|
+
}
|
|
3170
3186
|
cli.paperMainService.connect();
|
|
3171
3187
|
listenGracefulShutdown$3();
|
|
3172
3188
|
};
|
|
3173
|
-
main$
|
|
3189
|
+
main$c();
|
|
3174
3190
|
|
|
3175
3191
|
const BEFORE_EXIT_FN$2 = functoolsKit.singleshot(async () => {
|
|
3176
3192
|
process.off("SIGINT", BEFORE_EXIT_FN$2);
|
|
@@ -3191,7 +3207,7 @@ const BEFORE_EXIT_FN$2 = functoolsKit.singleshot(async () => {
|
|
|
3191
3207
|
const listenGracefulShutdown$2 = functoolsKit.singleshot(() => {
|
|
3192
3208
|
process.on("SIGINT", BEFORE_EXIT_FN$2);
|
|
3193
3209
|
});
|
|
3194
|
-
const main$
|
|
3210
|
+
const main$b = async () => {
|
|
3195
3211
|
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
3212
|
return;
|
|
3197
3213
|
}
|
|
@@ -3199,9 +3215,122 @@ const main$a = async () => {
|
|
|
3199
3215
|
if (!values.live) {
|
|
3200
3216
|
return;
|
|
3201
3217
|
}
|
|
3218
|
+
if (values.entry) {
|
|
3219
|
+
return;
|
|
3220
|
+
}
|
|
3202
3221
|
await cli.liveMainService.connect();
|
|
3203
3222
|
listenGracefulShutdown$2();
|
|
3204
3223
|
};
|
|
3224
|
+
main$b();
|
|
3225
|
+
|
|
3226
|
+
const MODE_MODULE = {
|
|
3227
|
+
backtest: "./backtest.module",
|
|
3228
|
+
live: "./live.module",
|
|
3229
|
+
paper: "./paper.module",
|
|
3230
|
+
walker: "./walker.module",
|
|
3231
|
+
};
|
|
3232
|
+
const resolveMode = (values) => {
|
|
3233
|
+
const enabled = ["backtest", "live", "paper", "walker"].filter((mode) => Boolean(values[mode]));
|
|
3234
|
+
if (enabled.length !== 1) {
|
|
3235
|
+
return null;
|
|
3236
|
+
}
|
|
3237
|
+
return enabled[0];
|
|
3238
|
+
};
|
|
3239
|
+
const stopBacktestList = async () => {
|
|
3240
|
+
for (const item of await BacktestKit.Backtest.list()) {
|
|
3241
|
+
if (item.status === "fulfilled") {
|
|
3242
|
+
continue;
|
|
3243
|
+
}
|
|
3244
|
+
BacktestKit.Backtest.stop(item.symbol, {
|
|
3245
|
+
exchangeName: item.exchangeName,
|
|
3246
|
+
strategyName: item.strategyName,
|
|
3247
|
+
frameName: item.frameName,
|
|
3248
|
+
});
|
|
3249
|
+
}
|
|
3250
|
+
};
|
|
3251
|
+
const stopLiveList = async () => {
|
|
3252
|
+
for (const item of await BacktestKit.Live.list()) {
|
|
3253
|
+
if (item.status === "fulfilled") {
|
|
3254
|
+
continue;
|
|
3255
|
+
}
|
|
3256
|
+
BacktestKit.Live.stop(item.symbol, {
|
|
3257
|
+
exchangeName: item.exchangeName,
|
|
3258
|
+
strategyName: item.strategyName,
|
|
3259
|
+
});
|
|
3260
|
+
}
|
|
3261
|
+
};
|
|
3262
|
+
const stopWalkerList = async () => {
|
|
3263
|
+
for (const item of await BacktestKit.Walker.list()) {
|
|
3264
|
+
if (item.status === "fulfilled") {
|
|
3265
|
+
continue;
|
|
3266
|
+
}
|
|
3267
|
+
BacktestKit.Walker.stop(item.symbol, { walkerName: item.walkerName });
|
|
3268
|
+
}
|
|
3269
|
+
};
|
|
3270
|
+
const MODE_STOP = {
|
|
3271
|
+
backtest: stopBacktestList,
|
|
3272
|
+
live: stopLiveList,
|
|
3273
|
+
paper: stopLiveList,
|
|
3274
|
+
walker: stopWalkerList,
|
|
3275
|
+
};
|
|
3276
|
+
const listenFinish = functoolsKit.singleshot(() => {
|
|
3277
|
+
let disposeRef;
|
|
3278
|
+
const unBacktest = BacktestKit.listenDoneBacktest(() => {
|
|
3279
|
+
console.log("Backtest trading finished");
|
|
3280
|
+
disposeRef && disposeRef();
|
|
3281
|
+
});
|
|
3282
|
+
const unLive = BacktestKit.listenDoneLive(() => {
|
|
3283
|
+
console.log("Live trading finished");
|
|
3284
|
+
disposeRef && disposeRef();
|
|
3285
|
+
});
|
|
3286
|
+
const unWalker = BacktestKit.listenDoneWalker(() => {
|
|
3287
|
+
console.log("Walker comparison finished");
|
|
3288
|
+
disposeRef && disposeRef();
|
|
3289
|
+
});
|
|
3290
|
+
disposeRef = functoolsKit.compose(() => unBacktest(), () => unLive(), () => unWalker());
|
|
3291
|
+
BacktestKit.shutdown();
|
|
3292
|
+
});
|
|
3293
|
+
const createGracefulShutdown = (mode) => {
|
|
3294
|
+
const stop = MODE_STOP[mode];
|
|
3295
|
+
const handler = functoolsKit.singleshot(async () => {
|
|
3296
|
+
process.off("SIGINT", handler);
|
|
3297
|
+
notifyShutdown();
|
|
3298
|
+
await stop();
|
|
3299
|
+
});
|
|
3300
|
+
return functoolsKit.singleshot(() => {
|
|
3301
|
+
process.on("SIGINT", handler);
|
|
3302
|
+
});
|
|
3303
|
+
};
|
|
3304
|
+
const main$a = async () => {
|
|
3305
|
+
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)))) {
|
|
3306
|
+
return;
|
|
3307
|
+
}
|
|
3308
|
+
const { values } = getArgs();
|
|
3309
|
+
if (!values.entry) {
|
|
3310
|
+
return;
|
|
3311
|
+
}
|
|
3312
|
+
const mode = resolveMode(values);
|
|
3313
|
+
if (!mode) {
|
|
3314
|
+
console.error("--entry requires exactly one of --backtest, --live, --paper, --walker");
|
|
3315
|
+
process.exit(1);
|
|
3316
|
+
return;
|
|
3317
|
+
}
|
|
3318
|
+
const [entryPoint = null] = getPositionals();
|
|
3319
|
+
if (!entryPoint) {
|
|
3320
|
+
throw new Error("Entry point is required");
|
|
3321
|
+
}
|
|
3322
|
+
if (!values.noFlush) {
|
|
3323
|
+
await flush(entryPoint);
|
|
3324
|
+
}
|
|
3325
|
+
await cli.configService.waitForInit();
|
|
3326
|
+
Setup.enable();
|
|
3327
|
+
cli.frontendProviderService.connect();
|
|
3328
|
+
cli.telegramProviderService.connect();
|
|
3329
|
+
await cli.moduleConnectionService.loadModule(MODE_MODULE[mode]);
|
|
3330
|
+
listenFinish();
|
|
3331
|
+
createGracefulShutdown(mode)();
|
|
3332
|
+
await cli.resolveService.attachJavascript(entryPoint);
|
|
3333
|
+
};
|
|
3205
3334
|
main$a();
|
|
3206
3335
|
|
|
3207
3336
|
const BEFORE_EXIT_FN$1 = functoolsKit.singleshot(async () => {
|
|
@@ -3722,183 +3851,183 @@ const main$2 = async () => {
|
|
|
3722
3851
|
main$2();
|
|
3723
3852
|
|
|
3724
3853
|
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
|
|
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
|
|
3902
4031
|
`.trimStart();
|
|
3903
4032
|
const main$1 = async () => {
|
|
3904
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)))) {
|
|
@@ -3908,7 +4037,7 @@ const main$1 = async () => {
|
|
|
3908
4037
|
if (!values.help) {
|
|
3909
4038
|
return;
|
|
3910
4039
|
}
|
|
3911
|
-
process.stdout.write(`@backtest-kit/cli ${"
|
|
4040
|
+
process.stdout.write(`@backtest-kit/cli ${"9.0.0"}\n\n`);
|
|
3912
4041
|
process.stdout.write(HELP_TEXT);
|
|
3913
4042
|
process.exit(0);
|
|
3914
4043
|
};
|
|
@@ -3922,7 +4051,7 @@ const main = async () => {
|
|
|
3922
4051
|
if (!values.version) {
|
|
3923
4052
|
return;
|
|
3924
4053
|
}
|
|
3925
|
-
process.stdout.write(`@backtest-kit/cli ${"
|
|
4054
|
+
process.stdout.write(`@backtest-kit/cli ${"9.0.0"}\n`);
|
|
3926
4055
|
process.exit(0);
|
|
3927
4056
|
};
|
|
3928
4057
|
main();
|