@backtest-kit/cli 7.1.0 → 7.3.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 +119 -0
- package/build/index.cjs +376 -149
- package/build/index.mjs +379 -152
- package/config/notification.config.mjs +13 -0
- package/config/symbol.config.mjs +460 -0
- package/package.json +16 -15
- package/template/average-buy.mustache +2 -0
- package/template/breakeven.mustache +2 -0
- package/template/cancel-scheduled.mustache +1 -1
- package/template/cancelled.mustache +2 -0
- package/template/close-pending.mustache +2 -0
- package/template/closed.mustache +2 -0
- package/template/opened.mustache +2 -0
- package/template/partial-loss.mustache +2 -0
- package/template/partial-profit.mustache +2 -0
- package/template/project/package.mustache +7 -7
- package/template/scheduled.mustache +2 -0
- package/template/signal-close.mustache +2 -0
- package/template/signal-info.mustache +21 -0
- package/template/signal-open.mustache +2 -0
- package/template/trailing-stop.mustache +2 -0
- package/template/trailing-take.mustache +2 -0
- package/types.d.ts +149 -39
- /package/template/project/config/{symbol.config.cjs → symbol.config.ts} +0 -0
package/README.md
CHANGED
|
@@ -420,6 +420,89 @@ http://localhost:60050
|
|
|
420
420
|
|
|
421
421
|
Customize host/port via environment variables `CC_WWWROOT_HOST` and `CC_WWWROOT_PORT`.
|
|
422
422
|
|
|
423
|
+
#### Symbol List (`symbol.config`)
|
|
424
|
+
|
|
425
|
+
By default the UI shows all symbols from the exchange. To restrict or reorder the list, create a `config/symbol.config` file in your strategy directory (next to the entry point).
|
|
426
|
+
|
|
427
|
+
**Resolution order — first match wins:**
|
|
428
|
+
|
|
429
|
+
| Priority | Path | Notes |
|
|
430
|
+
|----------|------|-------|
|
|
431
|
+
| 1 | `{strategyDir}/config/symbol.config` | per-strategy override (cwd after `chdir`) |
|
|
432
|
+
| 2 | `{projectRoot}/config/symbol.config` | project-root override (cwd where `npx` was invoked) |
|
|
433
|
+
| 3 | `@backtest-kit/cli/config/symbol.config` | built-in default shipped with the package |
|
|
434
|
+
|
|
435
|
+
Supported file formats (`.ts`, `.cjs`, `.mjs`, `.js` tried automatically):
|
|
436
|
+
|
|
437
|
+
```ts
|
|
438
|
+
// config/symbol.config.ts
|
|
439
|
+
export const symbol_list = [
|
|
440
|
+
{
|
|
441
|
+
icon: "/icon/btc.png",
|
|
442
|
+
logo: "/icon/128/btc.png",
|
|
443
|
+
symbol: "BTCUSDT",
|
|
444
|
+
displayName: "Bitcoin",
|
|
445
|
+
color: "#F7931A",
|
|
446
|
+
priority: 50,
|
|
447
|
+
description: "Bitcoin - the first and most popular cryptocurrency",
|
|
448
|
+
},
|
|
449
|
+
{
|
|
450
|
+
icon: "/icon/eth.png",
|
|
451
|
+
logo: "/icon/128/eth.png",
|
|
452
|
+
symbol: "ETHUSDT",
|
|
453
|
+
displayName: "Ethereum",
|
|
454
|
+
color: "#6F42C1",
|
|
455
|
+
priority: 50,
|
|
456
|
+
description: "Ethereum - a blockchain platform for smart contracts",
|
|
457
|
+
},
|
|
458
|
+
];
|
|
459
|
+
```
|
|
460
|
+
|
|
461
|
+
#### Notification Filter (`notification.config`)
|
|
462
|
+
|
|
463
|
+
Controls which notification categories are shown in the UI dashboard. Create a `config/notification.config` file in your strategy directory to override the defaults.
|
|
464
|
+
|
|
465
|
+
**Resolution order — first match wins:**
|
|
466
|
+
|
|
467
|
+
| Priority | Path | Notes |
|
|
468
|
+
|----------|------|-------|
|
|
469
|
+
| 1 | `{strategyDir}/config/notification.config` | per-strategy override (cwd after `chdir`) |
|
|
470
|
+
| 2 | `{projectRoot}/config/notification.config` | project-root override (cwd where `npx` was invoked) |
|
|
471
|
+
| 3 | `@backtest-kit/cli/config/notification.config` | built-in default shipped with the package |
|
|
472
|
+
|
|
473
|
+
**Default values (built-in):**
|
|
474
|
+
|
|
475
|
+
| Key | Default | Description |
|
|
476
|
+
|-----|---------|-------------|
|
|
477
|
+
| `signal` | `true` | Signal lifecycle: opened, scheduled, closed, cancelled |
|
|
478
|
+
| `risk` | `true` | Risk manager rejection notifications |
|
|
479
|
+
| `info` | `true` | Informational messages attached to an active signal |
|
|
480
|
+
| `breakeven` | `true` | Breakeven level reached |
|
|
481
|
+
| `common_error` | `true` | Non-fatal runtime errors |
|
|
482
|
+
| `critical_error` | `true` | Fatal errors that terminate the session |
|
|
483
|
+
| `validation_error` | `true` | Strategy config / input validation errors |
|
|
484
|
+
| `strategy_commit` | `true` | All committed actions (partial close, DCA, trailing, etc.) |
|
|
485
|
+
| `partial_loss` | `false` | Partial loss level reached (before commit) |
|
|
486
|
+
| `partial_profit` | `false` | Partial profit level reached (before commit) |
|
|
487
|
+
| `signal_sync` | `false` | Live order fill / exit confirmations from exchange sync |
|
|
488
|
+
|
|
489
|
+
```js
|
|
490
|
+
// config/notification.config.ts
|
|
491
|
+
export default {
|
|
492
|
+
signal: true,
|
|
493
|
+
risk: true,
|
|
494
|
+
info: true,
|
|
495
|
+
breakeven: true,
|
|
496
|
+
common_error: true,
|
|
497
|
+
critical_error: true,
|
|
498
|
+
validation_error: true,
|
|
499
|
+
strategy_commit: true,
|
|
500
|
+
partial_loss: false,
|
|
501
|
+
partial_profit: false,
|
|
502
|
+
signal_sync: false,
|
|
503
|
+
};
|
|
504
|
+
```
|
|
505
|
+
|
|
423
506
|
### Telegram Notifications (`--telegram`)
|
|
424
507
|
|
|
425
508
|
Sends formatted HTML messages with 1m / 15m / 1h price charts to your Telegram channel for every position event: opened, closed, scheduled, cancelled, risk rejection, partial profit/loss, trailing stop/take, and breakeven.
|
|
@@ -514,6 +597,42 @@ Broker.useBrokerAdapter(MyBroker);
|
|
|
514
597
|
Broker.enable();
|
|
515
598
|
```
|
|
516
599
|
|
|
600
|
+
## 🔀 Import Aliases (`alias.module`)
|
|
601
|
+
|
|
602
|
+
`@backtest-kit/cli` lets you override any nodejs module import — without touching the strategy code. Drop a `config/alias.module` file in your project root and export a mapping from module name to replacement module.
|
|
603
|
+
|
|
604
|
+
The alias table is loaded once (on the first `import` call) from `{projectRoot}/config/alias.module` and applied globally to every subsequent module load via `require`/ `import`.
|
|
605
|
+
|
|
606
|
+
**Use cases:**
|
|
607
|
+
|
|
608
|
+
- Replace a heavy dependency with a lighter stub for backtesting
|
|
609
|
+
- Swap any external api for a mock during CI runs
|
|
610
|
+
|
|
611
|
+
```ts
|
|
612
|
+
// config/alias.module.ts — named export
|
|
613
|
+
export const ccxt = require("./stubs/ccxt.stub.cjs");
|
|
614
|
+
```
|
|
615
|
+
|
|
616
|
+
```js
|
|
617
|
+
// config/alias.module.cjs — default export
|
|
618
|
+
module.exports = {
|
|
619
|
+
ccxt: require("./stubs/ccxt.stub.cjs"),
|
|
620
|
+
};
|
|
621
|
+
```
|
|
622
|
+
|
|
623
|
+
```js
|
|
624
|
+
// config/alias.module.mjs — default export
|
|
625
|
+
import ccxtStub from "./stubs/ccxt.stub.mjs";
|
|
626
|
+
|
|
627
|
+
export default {
|
|
628
|
+
ccxt: ccxtStub,
|
|
629
|
+
};
|
|
630
|
+
```
|
|
631
|
+
|
|
632
|
+
**How it works:** when strategy code calls `require("ccxt")`, the loader checks `IMPORT_ALIAS` first. If a key matches, the mapped value is returned instead of the real module — no monkey-patching of `node_modules` needed.
|
|
633
|
+
|
|
634
|
+
**Important:** It is **not** per-strategy — it applies to all modules loaded in the current process.
|
|
635
|
+
|
|
517
636
|
## 📦 Supported Entry Point Formats
|
|
518
637
|
|
|
519
638
|
`@backtest-kit/cli` automatically detects the format of your strategy file and loads it with the appropriate runtime — no flags or configuration required.
|