@backtest-kit/cli 3.3.0 → 3.3.4

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 CHANGED
@@ -340,6 +340,10 @@ export default class {
340
340
  onBreakeven(event) {
341
341
  console.log('Breakeven triggered', event.symbol);
342
342
  }
343
+
344
+ onAverageBuy(event) {
345
+ console.log('Cost averaging (DCA)', event.symbol);
346
+ }
343
347
  }
344
348
  ```
345
349
 
@@ -356,6 +360,57 @@ export default class MyModule implements ILiveModule {
356
360
  }
357
361
  ```
358
362
 
363
+ ## 📦 Supported Entry Point Formats
364
+
365
+ `@backtest-kit/cli` automatically detects the format of your strategy file and loads it with the appropriate runtime — no flags or configuration required.
366
+
367
+ | Format | Extension | Runtime | Use Case |
368
+ |--------|-----------|---------|----------|
369
+ | **TypeScript** | `.ts` | [`tsx`](https://tsx.is/) via `tsImport()` | TypeScript strategies with cross-imports (ESM ↔ CJS) |
370
+ | **ES Module** | `.mjs` | Native `import()` | Modern JavaScript with top-level `await` and ESM syntax |
371
+ | **CommonJS** | `.cjs` | Native `require()` | Legacy or dual-package strategies |
372
+
373
+ ### TypeScript (`.ts`)
374
+
375
+ Run TypeScript strategy files directly — no `tsc` compilation step needed. Powered by `tsx`, which handles cross-format imports transparently:
376
+
377
+ ```json
378
+ {
379
+ "scripts": {
380
+ "backtest": "npx @backtest-kit/cli --backtest ./src/index.ts"
381
+ },
382
+ "dependencies": {
383
+ "@backtest-kit/cli": "latest",
384
+ "backtest-kit": "latest",
385
+ "tsx": "latest"
386
+ }
387
+ }
388
+ ```
389
+
390
+ ### ES Module (`.mjs`)
391
+
392
+ Standard ESM format. Supports top-level `await`, named exports, and `import` syntax:
393
+
394
+ ```json
395
+ {
396
+ "scripts": {
397
+ "backtest": "npx @backtest-kit/cli --backtest ./src/index.mjs"
398
+ }
399
+ }
400
+ ```
401
+
402
+ ### CommonJS (`.cjs`)
403
+
404
+ For projects that compile to or use CommonJS. Loaded via `require()`:
405
+
406
+ ```json
407
+ {
408
+ "scripts": {
409
+ "backtest": "npx @backtest-kit/cli --backtest ./dist/index.cjs"
410
+ }
411
+ }
412
+ ```
413
+
359
414
  ## 🌍 Environment Variables
360
415
 
361
416
  Create a `.env` file in your project root:
package/build/index.cjs CHANGED
@@ -249,7 +249,15 @@ const REQUIRE_ENTRY_FACTORY = (filePath) => {
249
249
  const IMPORT_ENTRY_FACTORY = async (filePath) => {
250
250
  await import(url.pathToFileURL(filePath).href);
251
251
  };
252
+ const TSX_ENTRY_FACTORY = async (filePath) => {
253
+ const { tsImport } = await import('tsx/esm/api');
254
+ await tsImport(url.pathToFileURL(filePath).href, (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)));
255
+ };
252
256
  const LOAD_ENTRY_FN = async (filePath) => {
257
+ if (filePath.endsWith('.ts') || filePath.endsWith('.tsx')) {
258
+ await TSX_ENTRY_FACTORY(filePath);
259
+ return;
260
+ }
253
261
  if (!REQUIRE_ENTRY_FACTORY(filePath)) {
254
262
  await IMPORT_ENTRY_FACTORY(filePath);
255
263
  }
package/build/index.mjs CHANGED
@@ -227,7 +227,15 @@ const REQUIRE_ENTRY_FACTORY = (filePath) => {
227
227
  const IMPORT_ENTRY_FACTORY = async (filePath) => {
228
228
  await import(pathToFileURL(filePath).href);
229
229
  };
230
+ const TSX_ENTRY_FACTORY = async (filePath) => {
231
+ const { tsImport } = await import('tsx/esm/api');
232
+ await tsImport(pathToFileURL(filePath).href, import.meta.url);
233
+ };
230
234
  const LOAD_ENTRY_FN = async (filePath) => {
235
+ if (filePath.endsWith('.ts') || filePath.endsWith('.tsx')) {
236
+ await TSX_ENTRY_FACTORY(filePath);
237
+ return;
238
+ }
231
239
  if (!REQUIRE_ENTRY_FACTORY(filePath)) {
232
240
  await IMPORT_ENTRY_FACTORY(filePath);
233
241
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backtest-kit/cli",
3
- "version": "3.3.0",
3
+ "version": "3.3.4",
4
4
  "description": "Zero-boilerplate CLI runner for backtest-kit strategies. Run backtests, paper trading, and live bots with candle cache warming, web dashboard, and Telegram notifications — no setup code required.",
5
5
  "author": {
6
6
  "name": "Petr Tripolsky",
@@ -58,7 +58,7 @@
58
58
  "default": "./build/index.cjs"
59
59
  },
60
60
  "devDependencies": {
61
- "@backtest-kit/ui": "3.3.0",
61
+ "@backtest-kit/ui": "3.3.2",
62
62
  "markdown-it": "14.1.1",
63
63
  "@rollup/plugin-typescript": "11.1.6",
64
64
  "@types/image-size": "0.7.0",
@@ -66,7 +66,7 @@
66
66
  "@types/mustache": "4.2.6",
67
67
  "@types/node": "22.9.0",
68
68
  "@types/stack-trace": "0.0.33",
69
- "backtest-kit": "3.3.1",
69
+ "backtest-kit": "3.3.2",
70
70
  "glob": "11.0.1",
71
71
  "rimraf": "6.0.1",
72
72
  "rollup": "3.29.5",
@@ -75,13 +75,15 @@
75
75
  "ts-morph": "27.0.2",
76
76
  "tslib": "2.7.0",
77
77
  "typedoc": "0.27.9",
78
+ "tsx": "4.19.3",
78
79
  "worker-testbed": "1.0.12"
79
80
  },
80
81
  "peerDependencies": {
81
82
  "typescript": "^5.0.0",
82
- "@backtest-kit/ui": "^3.3.0",
83
- "backtest-kit": "^3.3.1",
84
- "markdown-it": "^14.1.1"
83
+ "@backtest-kit/ui": "^3.3.2",
84
+ "backtest-kit": "^3.3.2",
85
+ "markdown-it": "^14.1.1",
86
+ "tsx": "^4.19.3"
85
87
  },
86
88
  "dependencies": {
87
89
  "ccxt": "4.5.39",
@@ -1,4 +1,4 @@
1
- **➗ Averaging Entry (DCA)**
1
+ **🪓 Averaging Entry (DCA)**
2
2
 
3
3
  **Symbol:** `{{symbol}}` ({{position}})
4
4