backtest-kit 1.4.12 → 1.4.14

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/types.d.ts CHANGED
@@ -4493,6 +4493,8 @@ interface PartialEvent {
4493
4493
  action: "profit" | "loss";
4494
4494
  /** Trading pair symbol */
4495
4495
  symbol: string;
4496
+ /** Strategy name */
4497
+ strategyName: string;
4496
4498
  /** Signal ID */
4497
4499
  signalId: string;
4498
4500
  /** Position type */
@@ -4511,7 +4513,7 @@ interface PartialEvent {
4511
4513
  *
4512
4514
  * @example
4513
4515
  * ```typescript
4514
- * const stats = await Partial.getData("my-strategy");
4516
+ * const stats = await Partial.getData("BTCUSDT", "my-strategy");
4515
4517
  *
4516
4518
  * console.log(`Total events: ${stats.totalEvents}`);
4517
4519
  * console.log(`Profit events: ${stats.totalProfit}`);
@@ -4533,10 +4535,10 @@ interface PartialStatistics {
4533
4535
  *
4534
4536
  * Features:
4535
4537
  * - Listens to partial profit and loss events via partialProfitSubject/partialLossSubject
4536
- * - Accumulates all events (profit, loss) per symbol
4538
+ * - Accumulates all events (profit, loss) per symbol-strategy pair
4537
4539
  * - Generates markdown tables with detailed event information
4538
4540
  * - Provides statistics (total profit/loss events)
4539
- * - Saves reports to disk in dump/partial/{symbol}.md
4541
+ * - Saves reports to disk in dump/partial/{symbol}_{strategyName}.md
4540
4542
  *
4541
4543
  * @example
4542
4544
  * ```typescript
@@ -4546,15 +4548,15 @@ interface PartialStatistics {
4546
4548
  * // No manual callback setup needed
4547
4549
  *
4548
4550
  * // Later: generate and save report
4549
- * await service.dump("BTCUSDT");
4551
+ * await service.dump("BTCUSDT", "my-strategy");
4550
4552
  * ```
4551
4553
  */
4552
4554
  declare class PartialMarkdownService {
4553
4555
  /** Logger service for debug output */
4554
4556
  private readonly loggerService;
4555
4557
  /**
4556
- * Memoized function to get or create ReportStorage for a symbol.
4557
- * Each symbol gets its own isolated storage instance.
4558
+ * Memoized function to get or create ReportStorage for a symbol-strategy pair.
4559
+ * Each symbol-strategy combination gets its own isolated storage instance.
4558
4560
  */
4559
4561
  private getStorage;
4560
4562
  /**
@@ -4584,74 +4586,80 @@ declare class PartialMarkdownService {
4584
4586
  */
4585
4587
  private tickLoss;
4586
4588
  /**
4587
- * Gets statistical data from all partial profit/loss events for a symbol.
4589
+ * Gets statistical data from all partial profit/loss events for a symbol-strategy pair.
4588
4590
  * Delegates to ReportStorage.getData().
4589
4591
  *
4590
4592
  * @param symbol - Trading pair symbol to get data for
4593
+ * @param strategyName - Strategy name to get data for
4591
4594
  * @returns Statistical data object with all metrics
4592
4595
  *
4593
4596
  * @example
4594
4597
  * ```typescript
4595
4598
  * const service = new PartialMarkdownService();
4596
- * const stats = await service.getData("BTCUSDT");
4599
+ * const stats = await service.getData("BTCUSDT", "my-strategy");
4597
4600
  * console.log(stats.totalProfit, stats.totalLoss);
4598
4601
  * ```
4599
4602
  */
4600
- getData: (symbol: string) => Promise<PartialStatistics>;
4603
+ getData: (symbol: string, strategyName: string) => Promise<PartialStatistics>;
4601
4604
  /**
4602
- * Generates markdown report with all partial events for a symbol.
4605
+ * Generates markdown report with all partial events for a symbol-strategy pair.
4603
4606
  * Delegates to ReportStorage.getReport().
4604
4607
  *
4605
4608
  * @param symbol - Trading pair symbol to generate report for
4609
+ * @param strategyName - Strategy name to generate report for
4606
4610
  * @returns Markdown formatted report string with table of all events
4607
4611
  *
4608
4612
  * @example
4609
4613
  * ```typescript
4610
4614
  * const service = new PartialMarkdownService();
4611
- * const markdown = await service.getReport("BTCUSDT");
4615
+ * const markdown = await service.getReport("BTCUSDT", "my-strategy");
4612
4616
  * console.log(markdown);
4613
4617
  * ```
4614
4618
  */
4615
- getReport: (symbol: string) => Promise<string>;
4619
+ getReport: (symbol: string, strategyName: string) => Promise<string>;
4616
4620
  /**
4617
- * Saves symbol report to disk.
4621
+ * Saves symbol-strategy report to disk.
4618
4622
  * Creates directory if it doesn't exist.
4619
4623
  * Delegates to ReportStorage.dump().
4620
4624
  *
4621
4625
  * @param symbol - Trading pair symbol to save report for
4626
+ * @param strategyName - Strategy name to save report for
4622
4627
  * @param path - Directory path to save report (default: "./dump/partial")
4623
4628
  *
4624
4629
  * @example
4625
4630
  * ```typescript
4626
4631
  * const service = new PartialMarkdownService();
4627
4632
  *
4628
- * // Save to default path: ./dump/partial/BTCUSDT.md
4629
- * await service.dump("BTCUSDT");
4633
+ * // Save to default path: ./dump/partial/BTCUSDT_my-strategy.md
4634
+ * await service.dump("BTCUSDT", "my-strategy");
4630
4635
  *
4631
- * // Save to custom path: ./custom/path/BTCUSDT.md
4632
- * await service.dump("BTCUSDT", "./custom/path");
4636
+ * // Save to custom path: ./custom/path/BTCUSDT_my-strategy.md
4637
+ * await service.dump("BTCUSDT", "my-strategy", "./custom/path");
4633
4638
  * ```
4634
4639
  */
4635
- dump: (symbol: string, path?: string) => Promise<void>;
4640
+ dump: (symbol: string, strategyName: string, path?: string) => Promise<void>;
4636
4641
  /**
4637
4642
  * Clears accumulated event data from storage.
4638
- * If symbol is provided, clears only that symbol's data.
4639
- * If symbol is omitted, clears all symbols' data.
4643
+ * If ctx is provided, clears only that specific symbol-strategy pair's data.
4644
+ * If nothing is provided, clears all data.
4640
4645
  *
4641
- * @param symbol - Optional symbol to clear specific symbol data
4646
+ * @param ctx - Optional context with symbol and strategyName
4642
4647
  *
4643
4648
  * @example
4644
4649
  * ```typescript
4645
4650
  * const service = new PartialMarkdownService();
4646
4651
  *
4647
- * // Clear specific symbol data
4648
- * await service.clear("BTCUSDT");
4652
+ * // Clear specific symbol-strategy pair
4653
+ * await service.clear({ symbol: "BTCUSDT", strategyName: "my-strategy" });
4649
4654
  *
4650
- * // Clear all symbols' data
4655
+ * // Clear all data
4651
4656
  * await service.clear();
4652
4657
  * ```
4653
4658
  */
4654
- clear: (symbol?: string) => Promise<void>;
4659
+ clear: (ctx?: {
4660
+ symbol: string;
4661
+ strategyName: string;
4662
+ }) => Promise<void>;
4655
4663
  /**
4656
4664
  * Initializes the service by subscribing to partial profit/loss events.
4657
4665
  * Uses singleshot to ensure initialization happens only once.
@@ -5205,19 +5213,20 @@ declare class BacktestUtils {
5205
5213
  /**
5206
5214
  * Saves strategy report to disk.
5207
5215
  *
5216
+ * @param symbol - Trading pair symbol
5208
5217
  * @param strategyName - Strategy name to save report for
5209
5218
  * @param path - Optional directory path to save report (default: "./dump/backtest")
5210
5219
  *
5211
5220
  * @example
5212
5221
  * ```typescript
5213
5222
  * // Save to default path: ./dump/backtest/my-strategy.md
5214
- * await Backtest.dump("my-strategy");
5223
+ * await Backtest.dump("BTCUSDT", "my-strategy");
5215
5224
  *
5216
5225
  * // Save to custom path: ./custom/path/my-strategy.md
5217
- * await Backtest.dump("my-strategy", "./custom/path");
5226
+ * await Backtest.dump("BTCUSDT", "my-strategy", "./custom/path");
5218
5227
  * ```
5219
5228
  */
5220
- dump: (strategyName: StrategyName, path?: string) => Promise<void>;
5229
+ dump: (symbol: string, strategyName: StrategyName, path?: string) => Promise<void>;
5221
5230
  }
5222
5231
  /**
5223
5232
  * Singleton instance of BacktestUtils for convenient backtest operations.
@@ -5339,19 +5348,20 @@ declare class LiveUtils {
5339
5348
  /**
5340
5349
  * Saves strategy report to disk.
5341
5350
  *
5351
+ * @param symbol - Trading pair symbol
5342
5352
  * @param strategyName - Strategy name to save report for
5343
5353
  * @param path - Optional directory path to save report (default: "./dump/live")
5344
5354
  *
5345
5355
  * @example
5346
5356
  * ```typescript
5347
5357
  * // Save to default path: ./dump/live/my-strategy.md
5348
- * await Live.dump("my-strategy");
5358
+ * await Live.dump("BTCUSDT", "my-strategy");
5349
5359
  *
5350
5360
  * // Save to custom path: ./custom/path/my-strategy.md
5351
- * await Live.dump("my-strategy", "./custom/path");
5361
+ * await Live.dump("BTCUSDT", "my-strategy", "./custom/path");
5352
5362
  * ```
5353
5363
  */
5354
- dump: (strategyName: StrategyName, path?: string) => Promise<void>;
5364
+ dump: (symbol: string, strategyName: StrategyName, path?: string) => Promise<void>;
5355
5365
  }
5356
5366
  /**
5357
5367
  * Singleton instance of LiveUtils for convenient live trading operations.
@@ -5427,19 +5437,20 @@ declare class ScheduleUtils {
5427
5437
  /**
5428
5438
  * Saves strategy report to disk.
5429
5439
  *
5440
+ * @param symbol - Trading pair symbol
5430
5441
  * @param strategyName - Strategy name to save report for
5431
5442
  * @param path - Optional directory path to save report (default: "./dump/schedule")
5432
5443
  *
5433
5444
  * @example
5434
5445
  * ```typescript
5435
5446
  * // Save to default path: ./dump/schedule/my-strategy.md
5436
- * await Schedule.dump("my-strategy");
5447
+ * await Schedule.dump("BTCUSDT", "my-strategy");
5437
5448
  *
5438
5449
  * // Save to custom path: ./custom/path/my-strategy.md
5439
- * await Schedule.dump("my-strategy", "./custom/path");
5450
+ * await Schedule.dump("BTCUSDT", "my-strategy", "./custom/path");
5440
5451
  * ```
5441
5452
  */
5442
- dump: (strategyName: StrategyName, path?: string) => Promise<void>;
5453
+ dump: (symbol: string, strategyName: StrategyName, path?: string) => Promise<void>;
5443
5454
  }
5444
5455
  /**
5445
5456
  * Singleton instance of ScheduleUtils for convenient scheduled signals reporting.
@@ -5545,19 +5556,20 @@ declare class Performance {
5545
5556
  * Creates directory if it doesn't exist.
5546
5557
  * Default path: ./dump/performance/{strategyName}.md
5547
5558
  *
5559
+ * @param symbol - Trading pair symbol
5548
5560
  * @param strategyName - Strategy name to save report for
5549
5561
  * @param path - Optional custom directory path
5550
5562
  *
5551
5563
  * @example
5552
5564
  * ```typescript
5553
5565
  * // Save to default path: ./dump/performance/my-strategy.md
5554
- * await Performance.dump("my-strategy");
5566
+ * await Performance.dump("BTCUSDT", "my-strategy");
5555
5567
  *
5556
5568
  * // Save to custom path: ./reports/perf/my-strategy.md
5557
- * await Performance.dump("my-strategy", "./reports/perf");
5569
+ * await Performance.dump("BTCUSDT", "my-strategy", "./reports/perf");
5558
5570
  * ```
5559
5571
  */
5560
- static dump(strategyName: string, path?: string): Promise<void>;
5572
+ static dump(symbol: string, strategyName: string, path?: string): Promise<void>;
5561
5573
  }
5562
5574
 
5563
5575
  /**
@@ -5972,26 +5984,26 @@ declare const Optimizer: OptimizerUtils;
5972
5984
  *
5973
5985
  * Data source:
5974
5986
  * - PartialMarkdownService listens to partialProfitSubject/partialLossSubject
5975
- * - Accumulates events in ReportStorage (max 250 events per symbol)
5976
- * - Events include: timestamp, action, symbol, signalId, position, level, price, mode
5987
+ * - Accumulates events in ReportStorage (max 250 events per symbol-strategy pair)
5988
+ * - Events include: timestamp, action, symbol, strategyName, signalId, position, level, price, mode
5977
5989
  *
5978
5990
  * @example
5979
5991
  * ```typescript
5980
5992
  * import { Partial } from "./classes/Partial";
5981
5993
  *
5982
- * // Get statistical data for BTCUSDT
5983
- * const stats = await Partial.getData("BTCUSDT");
5994
+ * // Get statistical data for BTCUSDT:my-strategy
5995
+ * const stats = await Partial.getData("BTCUSDT", "my-strategy");
5984
5996
  * console.log(`Total events: ${stats.totalEvents}`);
5985
5997
  * console.log(`Profit events: ${stats.totalProfit}`);
5986
5998
  * console.log(`Loss events: ${stats.totalLoss}`);
5987
5999
  *
5988
6000
  * // Generate markdown report
5989
- * const markdown = await Partial.getReport("BTCUSDT");
6001
+ * const markdown = await Partial.getReport("BTCUSDT", "my-strategy");
5990
6002
  * console.log(markdown); // Formatted table with all events
5991
6003
  *
5992
6004
  * // Export report to file
5993
- * await Partial.dump("BTCUSDT"); // Saves to ./dump/partial/BTCUSDT.md
5994
- * await Partial.dump("BTCUSDT", "./custom/path"); // Custom directory
6005
+ * await Partial.dump("BTCUSDT", "my-strategy"); // Saves to ./dump/partial/BTCUSDT_my-strategy.md
6006
+ * await Partial.dump("BTCUSDT", "my-strategy", "./custom/path"); // Custom directory
5995
6007
  * ```
5996
6008
  */
5997
6009
  declare class PartialUtils {
@@ -6002,11 +6014,12 @@ declare class PartialUtils {
6002
6014
  * Returns aggregated metrics calculated from all profit and loss events.
6003
6015
  *
6004
6016
  * @param symbol - Trading pair symbol (e.g., "BTCUSDT")
6017
+ * @param strategyName - Strategy name (e.g., "my-strategy")
6005
6018
  * @returns Promise resolving to PartialStatistics object with counts and event list
6006
6019
  *
6007
6020
  * @example
6008
6021
  * ```typescript
6009
- * const stats = await Partial.getData("BTCUSDT");
6022
+ * const stats = await Partial.getData("BTCUSDT", "my-strategy");
6010
6023
  *
6011
6024
  * console.log(`Total events: ${stats.totalEvents}`);
6012
6025
  * console.log(`Profit events: ${stats.totalProfit} (${(stats.totalProfit / stats.totalEvents * 100).toFixed(1)}%)`);
@@ -6018,13 +6031,14 @@ declare class PartialUtils {
6018
6031
  * }
6019
6032
  * ```
6020
6033
  */
6021
- getData: (symbol: string) => Promise<PartialStatistics>;
6034
+ getData: (symbol: string, strategyName: string) => Promise<PartialStatistics>;
6022
6035
  /**
6023
- * Generates markdown report with all partial profit/loss events for a symbol.
6036
+ * Generates markdown report with all partial profit/loss events for a symbol-strategy pair.
6024
6037
  *
6025
6038
  * Creates formatted table containing:
6026
6039
  * - Action (PROFIT/LOSS)
6027
6040
  * - Symbol
6041
+ * - Strategy
6028
6042
  * - Signal ID
6029
6043
  * - Position (LONG/SHORT)
6030
6044
  * - Level % (+10%, -20%, etc)
@@ -6035,32 +6049,33 @@ declare class PartialUtils {
6035
6049
  * Also includes summary statistics at the end.
6036
6050
  *
6037
6051
  * @param symbol - Trading pair symbol (e.g., "BTCUSDT")
6052
+ * @param strategyName - Strategy name (e.g., "my-strategy")
6038
6053
  * @returns Promise resolving to markdown formatted report string
6039
6054
  *
6040
6055
  * @example
6041
6056
  * ```typescript
6042
- * const markdown = await Partial.getReport("BTCUSDT");
6057
+ * const markdown = await Partial.getReport("BTCUSDT", "my-strategy");
6043
6058
  * console.log(markdown);
6044
6059
  *
6045
6060
  * // Output:
6046
- * // # Partial Profit/Loss Report: BTCUSDT
6061
+ * // # Partial Profit/Loss Report: BTCUSDT:my-strategy
6047
6062
  * //
6048
- * // | Action | Symbol | Signal ID | Position | Level % | Current Price | Timestamp | Mode |
6049
- * // | --- | --- | --- | --- | --- | --- | --- | --- |
6050
- * // | PROFIT | BTCUSDT | abc123 | LONG | +10% | 51500.00000000 USD | 2024-01-15T10:30:00.000Z | Backtest |
6051
- * // | LOSS | BTCUSDT | abc123 | LONG | -10% | 49000.00000000 USD | 2024-01-15T11:00:00.000Z | Backtest |
6063
+ * // | Action | Symbol | Strategy | Signal ID | Position | Level % | Current Price | Timestamp | Mode |
6064
+ * // | --- | --- | --- | --- | --- | --- | --- | --- | --- |
6065
+ * // | PROFIT | BTCUSDT | my-strategy | abc123 | LONG | +10% | 51500.00000000 USD | 2024-01-15T10:30:00.000Z | Backtest |
6066
+ * // | LOSS | BTCUSDT | my-strategy | abc123 | LONG | -10% | 49000.00000000 USD | 2024-01-15T11:00:00.000Z | Backtest |
6052
6067
  * //
6053
6068
  * // **Total events:** 2
6054
6069
  * // **Profit events:** 1
6055
6070
  * // **Loss events:** 1
6056
6071
  * ```
6057
6072
  */
6058
- getReport: (symbol: string) => Promise<string>;
6073
+ getReport: (symbol: string, strategyName: string) => Promise<string>;
6059
6074
  /**
6060
6075
  * Generates and saves markdown report to file.
6061
6076
  *
6062
6077
  * Creates directory if it doesn't exist.
6063
- * Filename format: {symbol}.md (e.g., "BTCUSDT.md")
6078
+ * Filename format: {symbol}_{strategyName}.md (e.g., "BTCUSDT_my-strategy.md")
6064
6079
  *
6065
6080
  * Delegates to PartialMarkdownService.dump() which:
6066
6081
  * 1. Generates markdown report via getReport()
@@ -6069,24 +6084,25 @@ declare class PartialUtils {
6069
6084
  * 4. Logs success/failure to console
6070
6085
  *
6071
6086
  * @param symbol - Trading pair symbol (e.g., "BTCUSDT")
6087
+ * @param strategyName - Strategy name (e.g., "my-strategy")
6072
6088
  * @param path - Output directory path (default: "./dump/partial")
6073
6089
  * @returns Promise that resolves when file is written
6074
6090
  *
6075
6091
  * @example
6076
6092
  * ```typescript
6077
- * // Save to default path: ./dump/partial/BTCUSDT.md
6078
- * await Partial.dump("BTCUSDT");
6093
+ * // Save to default path: ./dump/partial/BTCUSDT_my-strategy.md
6094
+ * await Partial.dump("BTCUSDT", "my-strategy");
6079
6095
  *
6080
- * // Save to custom path: ./reports/partial/BTCUSDT.md
6081
- * await Partial.dump("BTCUSDT", "./reports/partial");
6096
+ * // Save to custom path: ./reports/partial/BTCUSDT_my-strategy.md
6097
+ * await Partial.dump("BTCUSDT", "my-strategy", "./reports/partial");
6082
6098
  *
6083
6099
  * // After multiple symbols backtested, export all reports
6084
6100
  * for (const symbol of ["BTCUSDT", "ETHUSDT", "BNBUSDT"]) {
6085
- * await Partial.dump(symbol, "./backtest-results");
6101
+ * await Partial.dump(symbol, "my-strategy", "./backtest-results");
6086
6102
  * }
6087
6103
  * ```
6088
6104
  */
6089
- dump: (symbol: string, path?: string) => Promise<void>;
6105
+ dump: (symbol: string, strategyName: string, path?: string) => Promise<void>;
6090
6106
  }
6091
6107
  /**
6092
6108
  * Global singleton instance of PartialUtils.
@@ -6097,9 +6113,9 @@ declare class PartialUtils {
6097
6113
  * import { Partial } from "backtest-kit";
6098
6114
  *
6099
6115
  * // Usage same as PartialUtils methods
6100
- * const stats = await Partial.getData("BTCUSDT");
6101
- * const report = await Partial.getReport("BTCUSDT");
6102
- * await Partial.dump("BTCUSDT");
6116
+ * const stats = await Partial.getData("BTCUSDT", "my-strategy");
6117
+ * const report = await Partial.getReport("BTCUSDT", "my-strategy");
6118
+ * await Partial.dump("BTCUSDT", "my-strategy");
6103
6119
  * ```
6104
6120
  */
6105
6121
  declare const Partial$1: PartialUtils;