backtest-kit 6.7.0 → 6.8.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.
Files changed (4) hide show
  1. package/build/index.cjs +4180 -3993
  2. package/build/index.mjs +4180 -3993
  3. package/package.json +3 -2
  4. package/types.d.ts +978 -781
package/types.d.ts CHANGED
@@ -272,6 +272,8 @@ interface IRiskParams extends IRiskSchema {
272
272
  exchangeName: ExchangeName;
273
273
  /** Logger service for debug output */
274
274
  logger: ILogger;
275
+ /** Execution context service (symbol, when, backtest flag) */
276
+ execution: TExecutionContextService;
275
277
  /** True if backtest mode, false if live mode */
276
278
  backtest: boolean;
277
279
  /**
@@ -1321,6 +1323,47 @@ type SignalSyncContract = SignalOpenContract | SignalCloseContract;
1321
1323
  * ```
1322
1324
  */
1323
1325
  type TActionCtor = new (strategyName: StrategyName, frameName: FrameName, actionName: ActionName, backtest: boolean) => Partial<IPublicAction>;
1326
+ /**
1327
+ * Strategy query interface exposed to action handlers via IActionParams.strategy.
1328
+ *
1329
+ * Provides read-only access to the current signal state needed for
1330
+ * guard checks inside ActionProxy before invoking user callbacks.
1331
+ *
1332
+ * Used by:
1333
+ * - ActionProxy.breakevenAvailable — skips if no pending signal
1334
+ * - ActionProxy.partialProfitAvailable — skips if no pending signal
1335
+ * - ActionProxy.partialLossAvailable — skips if no pending signal
1336
+ * - ActionProxy.pingActive — skips if no pending signal
1337
+ * - ActionProxy.pingScheduled — skips if no scheduled signal
1338
+ */
1339
+ interface IActionStrategy {
1340
+ /**
1341
+ * Checks if there is an active pending signal (open position) for the symbol.
1342
+ *
1343
+ * @param backtest - Whether running in backtest mode
1344
+ * @param symbol - Trading pair symbol
1345
+ * @param context - Execution context with strategyName, exchangeName, frameName
1346
+ * @returns Promise resolving to true if a pending signal exists, false otherwise
1347
+ */
1348
+ hasPendingSignal(backtest: boolean, symbol: string, context: {
1349
+ strategyName: StrategyName;
1350
+ exchangeName: ExchangeName;
1351
+ frameName: FrameName;
1352
+ }): Promise<boolean>;
1353
+ /**
1354
+ * Checks if there is a waiting scheduled signal for the symbol.
1355
+ *
1356
+ * @param backtest - Whether running in backtest mode
1357
+ * @param symbol - Trading pair symbol
1358
+ * @param context - Execution context with strategyName, exchangeName, frameName
1359
+ * @returns Promise resolving to true if a scheduled signal exists, false otherwise
1360
+ */
1361
+ hasScheduledSignal(backtest: boolean, symbol: string, context: {
1362
+ strategyName: StrategyName;
1363
+ exchangeName: ExchangeName;
1364
+ frameName: FrameName;
1365
+ }): Promise<boolean>;
1366
+ }
1324
1367
  /**
1325
1368
  * Action parameters passed to ClientAction constructor.
1326
1369
  * Combines schema with runtime dependencies and execution context.
@@ -1355,6 +1398,8 @@ interface IActionParams extends IActionSchema {
1355
1398
  frameName: FrameName;
1356
1399
  /** Whether running in backtest mode */
1357
1400
  backtest: boolean;
1401
+ /** Strategy context object providing access to current signal and position state */
1402
+ strategy: IActionStrategy;
1358
1403
  }
1359
1404
  /**
1360
1405
  * Lifecycle and event callbacks for action handlers.
@@ -12151,10 +12196,199 @@ declare class PersistMemoryUtils {
12151
12196
  */
12152
12197
  declare const PersistMemoryAdapter: PersistMemoryUtils;
12153
12198
 
12154
- /** Symbol key for the singleshot waitForInit function on ReportBase instances. */
12155
- declare const WAIT_FOR_INIT_SYMBOL$1: unique symbol;
12156
- /** Symbol key for the timeout-protected write function on ReportBase instances. */
12157
- declare const WRITE_SAFE_SYMBOL$1: unique symbol;
12199
+ /**
12200
+ * Configuration interface for selective markdown service enablement.
12201
+ * Controls which markdown report services should be activated.
12202
+ */
12203
+ interface IMarkdownTarget {
12204
+ /** Enable strategy event tracking reports (entry/exit signals) */
12205
+ strategy: boolean;
12206
+ /** Enable risk rejection tracking reports (signals blocked by risk limits) */
12207
+ risk: boolean;
12208
+ /** Enable breakeven event tracking reports (when stop loss moves to entry) */
12209
+ breakeven: boolean;
12210
+ /** Enable partial profit/loss event tracking reports */
12211
+ partial: boolean;
12212
+ /** Enable portfolio heatmap analysis reports across all symbols */
12213
+ heat: boolean;
12214
+ /** Enable walker strategy comparison and optimization reports */
12215
+ walker: boolean;
12216
+ /** Enable performance metrics and bottleneck analysis reports */
12217
+ performance: boolean;
12218
+ /** Enable scheduled signal tracking reports (signals waiting for trigger) */
12219
+ schedule: boolean;
12220
+ /** Enable live trading event reports (all tick events) */
12221
+ live: boolean;
12222
+ /** Enable backtest markdown reports (main strategy results with full trade history) */
12223
+ backtest: boolean;
12224
+ /** Enable signal sync lifecycle reports (signal-open and signal-close events) */
12225
+ sync: boolean;
12226
+ /** Enable highest profit milestone tracking reports */
12227
+ highest_profit: boolean;
12228
+ /** Enable max drawdown milestone tracking reports */
12229
+ max_drawdown: boolean;
12230
+ }
12231
+ /** Symbol key for the singleshot waitForInit function on MarkdownFileBase instances. */
12232
+ declare const WAIT_FOR_INIT_SYMBOL: unique symbol;
12233
+ /** Symbol key for the timeout-protected write function on MarkdownFileBase instances. */
12234
+ declare const WRITE_SAFE_SYMBOL: unique symbol;
12235
+ /**
12236
+ * Union type of all valid markdown report names.
12237
+ * Used for type-safe identification of markdown services.
12238
+ */
12239
+ type MarkdownName = keyof IMarkdownTarget;
12240
+ /**
12241
+ * Options for markdown dump operations.
12242
+ * Contains path information and metadata for filtering.
12243
+ */
12244
+ interface IMarkdownDumpOptions {
12245
+ /** Directory path relative to process.cwd() */
12246
+ path: string;
12247
+ /** File name including extension */
12248
+ file: string;
12249
+ /** Trading pair symbol (e.g., "BTCUSDT") */
12250
+ symbol: string;
12251
+ /** Strategy name */
12252
+ strategyName: string;
12253
+ /** Exchange name */
12254
+ exchangeName: string;
12255
+ /** Frame name (timeframe identifier) */
12256
+ frameName: string;
12257
+ /** Signal unique identifier */
12258
+ signalId: string;
12259
+ }
12260
+ /**
12261
+ * Base interface for markdown storage adapters.
12262
+ * All markdown adapters must implement this interface.
12263
+ */
12264
+ type TMarkdownBase = {
12265
+ /**
12266
+ * Initialize markdown storage and prepare for writes.
12267
+ * Uses singleshot to ensure one-time execution.
12268
+ *
12269
+ * @param initial - Whether this is the first initialization
12270
+ * @returns Promise that resolves when initialization is complete
12271
+ */
12272
+ waitForInit(initial: boolean): Promise<void>;
12273
+ /**
12274
+ * Dump markdown content to storage.
12275
+ *
12276
+ * @param content - Markdown content to write
12277
+ * @param options - Metadata and path options for the dump
12278
+ * @returns Promise that resolves when write is complete
12279
+ * @throws Error if write fails or stream is not initialized
12280
+ */
12281
+ dump(content: string, options: IMarkdownDumpOptions): Promise<void>;
12282
+ };
12283
+ /**
12284
+ * Constructor type for markdown storage adapters.
12285
+ * Used for custom markdown storage implementations.
12286
+ */
12287
+ type TMarkdownBaseCtor = new (markdownName: MarkdownName) => TMarkdownBase;
12288
+ /**
12289
+ * JSONL-based markdown adapter with append-only writes.
12290
+ *
12291
+ * Features:
12292
+ * - Writes markdown reports as JSONL entries to a single file per markdown type
12293
+ * - Stream-based writes with backpressure handling
12294
+ * - 15-second timeout protection for write operations
12295
+ * - Automatic directory creation
12296
+ * - Error handling via exitEmitter
12297
+ * - Search metadata for filtering (symbol, strategy, exchange, frame, signalId)
12298
+ *
12299
+ * File format: ./dump/markdown/{markdownName}.jsonl
12300
+ * Each line contains: markdownName, data, symbol, strategyName, exchangeName, frameName, signalId, timestamp
12301
+ *
12302
+ * Use this adapter for centralized logging and post-processing with JSONL tools.
12303
+ */
12304
+ declare class MarkdownFileBase implements TMarkdownBase {
12305
+ readonly markdownName: MarkdownName;
12306
+ /** Absolute path to the JSONL file for this markdown type */
12307
+ _filePath: string;
12308
+ /** WriteStream instance for append-only writes, null until initialized */
12309
+ _stream: WriteStream | null;
12310
+ /** Base directory for all JSONL markdown files */
12311
+ _baseDir: string;
12312
+ /**
12313
+ * Creates a new JSONL markdown adapter instance.
12314
+ *
12315
+ * @param markdownName - Type of markdown report (backtest, live, walker, etc.)
12316
+ */
12317
+ constructor(markdownName: MarkdownName);
12318
+ /**
12319
+ * Singleshot initialization function that creates directory and stream.
12320
+ * Protected by singleshot to ensure one-time execution.
12321
+ * Sets up error handler that emits to exitEmitter.
12322
+ */
12323
+ [WAIT_FOR_INIT_SYMBOL]: (() => Promise<void>) & functools_kit.ISingleshotClearable;
12324
+ /**
12325
+ * Timeout-protected write function with backpressure handling.
12326
+ * Waits for drain event if write buffer is full.
12327
+ * Times out after 15 seconds and returns TIMEOUT_SYMBOL.
12328
+ */
12329
+ [WRITE_SAFE_SYMBOL]: (line: string) => Promise<symbol | void>;
12330
+ /**
12331
+ * Initializes the JSONL file and write stream.
12332
+ * Safe to call multiple times - singleshot ensures one-time execution.
12333
+ *
12334
+ * @returns Promise that resolves when initialization is complete
12335
+ */
12336
+ waitForInit(): Promise<void>;
12337
+ /**
12338
+ * Writes markdown content to JSONL file with metadata.
12339
+ * Appends a single line with JSON object containing:
12340
+ * - markdownName: Type of report
12341
+ * - data: Markdown content
12342
+ * - Search flags: symbol, strategyName, exchangeName, frameName, signalId
12343
+ * - timestamp: Current timestamp in milliseconds
12344
+ *
12345
+ * @param data - Markdown content to write
12346
+ * @param options - Path and metadata options
12347
+ * @throws Error if stream not initialized or write timeout exceeded
12348
+ */
12349
+ dump(data: string, options: IMarkdownDumpOptions): Promise<void>;
12350
+ }
12351
+ /**
12352
+ * Folder-based markdown adapter with separate files per report.
12353
+ *
12354
+ * Features:
12355
+ * - Writes each markdown report as a separate .md file
12356
+ * - File path based on options.path and options.file
12357
+ * - Automatic directory creation
12358
+ * - No stream management (direct writeFile)
12359
+ * - Suitable for human-readable report directories
12360
+ *
12361
+ * File format: {options.path}/{options.file}
12362
+ * Example: ./dump/backtest/BTCUSDT_my-strategy_binance_2024-Q1_backtest-1736601234567.md
12363
+ *
12364
+ * Use this adapter (default) for organized report directories and manual review.
12365
+ */
12366
+ declare class MarkdownFolderBase implements TMarkdownBase {
12367
+ readonly markdownName: MarkdownName;
12368
+ /**
12369
+ * Creates a new folder-based markdown adapter instance.
12370
+ *
12371
+ * @param markdownName - Type of markdown report (backtest, live, walker, etc.)
12372
+ */
12373
+ constructor(markdownName: MarkdownName);
12374
+ /**
12375
+ * No-op initialization for folder adapter.
12376
+ * This adapter doesn't need initialization since it uses direct writeFile.
12377
+ *
12378
+ * @returns Promise that resolves immediately
12379
+ */
12380
+ waitForInit(): Promise<void>;
12381
+ /**
12382
+ * Writes markdown content to a separate file.
12383
+ * Creates directory structure automatically.
12384
+ * File path is determined by options.path and options.file.
12385
+ *
12386
+ * @param content - Markdown content to write
12387
+ * @param options - Path and file options for the dump
12388
+ * @throws Error if directory creation or file write fails
12389
+ */
12390
+ dump(content: string, options: IMarkdownDumpOptions): Promise<void>;
12391
+ }
12158
12392
  /**
12159
12393
  * Configuration interface for selective report service enablement.
12160
12394
  * Controls which report services should be activated for JSONL event logging.
@@ -12273,13 +12507,13 @@ declare class ReportBase implements TReportBase {
12273
12507
  * Protected by singleshot to ensure one-time execution.
12274
12508
  * Sets up error handler that emits to exitEmitter.
12275
12509
  */
12276
- [WAIT_FOR_INIT_SYMBOL$1]: (() => Promise<void>) & functools_kit.ISingleshotClearable;
12510
+ [WAIT_FOR_INIT_SYMBOL]: (() => Promise<void>) & functools_kit.ISingleshotClearable;
12277
12511
  /**
12278
12512
  * Timeout-protected write function with backpressure handling.
12279
12513
  * Waits for drain event if write buffer is full.
12280
12514
  * Times out after 15 seconds and returns TIMEOUT_SYMBOL.
12281
12515
  */
12282
- [WRITE_SAFE_SYMBOL$1]: (line: string) => Promise<symbol | void>;
12516
+ [WRITE_SAFE_SYMBOL]: (line: string) => Promise<symbol | void>;
12283
12517
  /**
12284
12518
  * Initializes the JSONL file and write stream.
12285
12519
  * Safe to call multiple times - singleshot ensures one-time execution.
@@ -12302,6 +12536,7 @@ declare class ReportBase implements TReportBase {
12302
12536
  */
12303
12537
  write<T = any>(data: T, options: IReportDumpOptions): Promise<void>;
12304
12538
  }
12539
+
12305
12540
  /**
12306
12541
  * Utility class for managing report services.
12307
12542
  *
@@ -12389,19 +12624,6 @@ declare class ReportUtils {
12389
12624
  * Used for structured event logging and analytics pipelines.
12390
12625
  */
12391
12626
  declare class ReportAdapter extends ReportUtils {
12392
- /**
12393
- * Current report storage adapter constructor.
12394
- * Defaults to ReportBase for JSONL storage.
12395
- * Can be changed via useReportAdapter().
12396
- */
12397
- private ReportFactory;
12398
- /**
12399
- * Memoized storage instances cache.
12400
- * Key: reportName (backtest, live, walker, etc.)
12401
- * Value: TReportBase instance created with current ReportFactory.
12402
- * Ensures single instance per report type for the lifetime of the application.
12403
- */
12404
- private getReportStorage;
12405
12627
  /**
12406
12628
  * Sets the report storage adapter constructor.
12407
12629
  * All future report instances will use this adapter.
@@ -12409,19 +12631,6 @@ declare class ReportAdapter extends ReportUtils {
12409
12631
  * @param Ctor - Constructor for report storage adapter
12410
12632
  */
12411
12633
  useReportAdapter(Ctor: TReportBaseCtor): void;
12412
- /**
12413
- * Writes report data to storage using the configured adapter.
12414
- * Automatically initializes storage on first write for each report type.
12415
- *
12416
- * @param reportName - Type of report (backtest, live, walker, etc.)
12417
- * @param data - Event data object to write
12418
- * @param options - Metadata options for filtering and search
12419
- * @returns Promise that resolves when write is complete
12420
- * @throws Error if write fails or storage initialization fails
12421
- *
12422
- * @internal - Automatically called by report services, not for direct use
12423
- */
12424
- writeData: <T = any>(reportName: ReportName, data: T, options: IReportDumpOptions) => Promise<void>;
12425
12634
  /**
12426
12635
  * Clears the memoized storage cache.
12427
12636
  * Call this when process.cwd() changes between strategy iterations
@@ -12446,205 +12655,12 @@ declare class ReportAdapter extends ReportUtils {
12446
12655
  declare const Report: ReportAdapter;
12447
12656
 
12448
12657
  /**
12449
- * Configuration interface for selective markdown service enablement.
12450
- * Controls which markdown report services should be activated.
12451
- */
12452
- interface IMarkdownTarget {
12453
- /** Enable strategy event tracking reports (entry/exit signals) */
12454
- strategy: boolean;
12455
- /** Enable risk rejection tracking reports (signals blocked by risk limits) */
12456
- risk: boolean;
12457
- /** Enable breakeven event tracking reports (when stop loss moves to entry) */
12458
- breakeven: boolean;
12459
- /** Enable partial profit/loss event tracking reports */
12460
- partial: boolean;
12461
- /** Enable portfolio heatmap analysis reports across all symbols */
12462
- heat: boolean;
12463
- /** Enable walker strategy comparison and optimization reports */
12464
- walker: boolean;
12465
- /** Enable performance metrics and bottleneck analysis reports */
12466
- performance: boolean;
12467
- /** Enable scheduled signal tracking reports (signals waiting for trigger) */
12468
- schedule: boolean;
12469
- /** Enable live trading event reports (all tick events) */
12470
- live: boolean;
12471
- /** Enable backtest markdown reports (main strategy results with full trade history) */
12472
- backtest: boolean;
12473
- /** Enable signal sync lifecycle reports (signal-open and signal-close events) */
12474
- sync: boolean;
12475
- /** Enable highest profit milestone tracking reports */
12476
- highest_profit: boolean;
12477
- /** Enable max drawdown milestone tracking reports */
12478
- max_drawdown: boolean;
12479
- }
12480
- /** Symbol key for the singleshot waitForInit function on MarkdownFileBase instances. */
12481
- declare const WAIT_FOR_INIT_SYMBOL: unique symbol;
12482
- /** Symbol key for the timeout-protected write function on MarkdownFileBase instances. */
12483
- declare const WRITE_SAFE_SYMBOL: unique symbol;
12484
- /**
12485
- * Union type of all valid markdown report names.
12486
- * Used for type-safe identification of markdown services.
12487
- */
12488
- type MarkdownName = keyof IMarkdownTarget;
12489
- /**
12490
- * Options for markdown dump operations.
12491
- * Contains path information and metadata for filtering.
12492
- */
12493
- interface IMarkdownDumpOptions {
12494
- /** Directory path relative to process.cwd() */
12495
- path: string;
12496
- /** File name including extension */
12497
- file: string;
12498
- /** Trading pair symbol (e.g., "BTCUSDT") */
12499
- symbol: string;
12500
- /** Strategy name */
12501
- strategyName: string;
12502
- /** Exchange name */
12503
- exchangeName: string;
12504
- /** Frame name (timeframe identifier) */
12505
- frameName: string;
12506
- /** Signal unique identifier */
12507
- signalId: string;
12508
- }
12509
- /**
12510
- * Base interface for markdown storage adapters.
12511
- * All markdown adapters must implement this interface.
12512
- */
12513
- type TMarkdownBase = {
12514
- /**
12515
- * Initialize markdown storage and prepare for writes.
12516
- * Uses singleshot to ensure one-time execution.
12517
- *
12518
- * @param initial - Whether this is the first initialization
12519
- * @returns Promise that resolves when initialization is complete
12520
- */
12521
- waitForInit(initial: boolean): Promise<void>;
12522
- /**
12523
- * Dump markdown content to storage.
12524
- *
12525
- * @param content - Markdown content to write
12526
- * @param options - Metadata and path options for the dump
12527
- * @returns Promise that resolves when write is complete
12528
- * @throws Error if write fails or stream is not initialized
12529
- */
12530
- dump(content: string, options: IMarkdownDumpOptions): Promise<void>;
12531
- };
12532
- /**
12533
- * Constructor type for markdown storage adapters.
12534
- * Used for custom markdown storage implementations.
12535
- */
12536
- type TMarkdownBaseCtor = new (markdownName: MarkdownName) => TMarkdownBase;
12537
- /**
12538
- * JSONL-based markdown adapter with append-only writes.
12539
- *
12540
- * Features:
12541
- * - Writes markdown reports as JSONL entries to a single file per markdown type
12542
- * - Stream-based writes with backpressure handling
12543
- * - 15-second timeout protection for write operations
12544
- * - Automatic directory creation
12545
- * - Error handling via exitEmitter
12546
- * - Search metadata for filtering (symbol, strategy, exchange, frame, signalId)
12547
- *
12548
- * File format: ./dump/markdown/{markdownName}.jsonl
12549
- * Each line contains: markdownName, data, symbol, strategyName, exchangeName, frameName, signalId, timestamp
12550
- *
12551
- * Use this adapter for centralized logging and post-processing with JSONL tools.
12552
- */
12553
- declare class MarkdownFileBase implements TMarkdownBase {
12554
- readonly markdownName: MarkdownName;
12555
- /** Absolute path to the JSONL file for this markdown type */
12556
- _filePath: string;
12557
- /** WriteStream instance for append-only writes, null until initialized */
12558
- _stream: WriteStream | null;
12559
- /** Base directory for all JSONL markdown files */
12560
- _baseDir: string;
12561
- /**
12562
- * Creates a new JSONL markdown adapter instance.
12563
- *
12564
- * @param markdownName - Type of markdown report (backtest, live, walker, etc.)
12565
- */
12566
- constructor(markdownName: MarkdownName);
12567
- /**
12568
- * Singleshot initialization function that creates directory and stream.
12569
- * Protected by singleshot to ensure one-time execution.
12570
- * Sets up error handler that emits to exitEmitter.
12571
- */
12572
- [WAIT_FOR_INIT_SYMBOL]: (() => Promise<void>) & functools_kit.ISingleshotClearable;
12573
- /**
12574
- * Timeout-protected write function with backpressure handling.
12575
- * Waits for drain event if write buffer is full.
12576
- * Times out after 15 seconds and returns TIMEOUT_SYMBOL.
12577
- */
12578
- [WRITE_SAFE_SYMBOL]: (line: string) => Promise<symbol | void>;
12579
- /**
12580
- * Initializes the JSONL file and write stream.
12581
- * Safe to call multiple times - singleshot ensures one-time execution.
12582
- *
12583
- * @returns Promise that resolves when initialization is complete
12584
- */
12585
- waitForInit(): Promise<void>;
12586
- /**
12587
- * Writes markdown content to JSONL file with metadata.
12588
- * Appends a single line with JSON object containing:
12589
- * - markdownName: Type of report
12590
- * - data: Markdown content
12591
- * - Search flags: symbol, strategyName, exchangeName, frameName, signalId
12592
- * - timestamp: Current timestamp in milliseconds
12593
- *
12594
- * @param data - Markdown content to write
12595
- * @param options - Path and metadata options
12596
- * @throws Error if stream not initialized or write timeout exceeded
12597
- */
12598
- dump(data: string, options: IMarkdownDumpOptions): Promise<void>;
12599
- }
12600
- /**
12601
- * Folder-based markdown adapter with separate files per report.
12602
- *
12603
- * Features:
12604
- * - Writes each markdown report as a separate .md file
12605
- * - File path based on options.path and options.file
12606
- * - Automatic directory creation
12607
- * - No stream management (direct writeFile)
12608
- * - Suitable for human-readable report directories
12609
- *
12610
- * File format: {options.path}/{options.file}
12611
- * Example: ./dump/backtest/BTCUSDT_my-strategy_binance_2024-Q1_backtest-1736601234567.md
12612
- *
12613
- * Use this adapter (default) for organized report directories and manual review.
12614
- */
12615
- declare class MarkdownFolderBase implements TMarkdownBase {
12616
- readonly markdownName: MarkdownName;
12617
- /**
12618
- * Creates a new folder-based markdown adapter instance.
12619
- *
12620
- * @param markdownName - Type of markdown report (backtest, live, walker, etc.)
12621
- */
12622
- constructor(markdownName: MarkdownName);
12623
- /**
12624
- * No-op initialization for folder adapter.
12625
- * This adapter doesn't need initialization since it uses direct writeFile.
12626
- *
12627
- * @returns Promise that resolves immediately
12628
- */
12629
- waitForInit(): Promise<void>;
12630
- /**
12631
- * Writes markdown content to a separate file.
12632
- * Creates directory structure automatically.
12633
- * File path is determined by options.path and options.file.
12634
- *
12635
- * @param content - Markdown content to write
12636
- * @param options - Path and file options for the dump
12637
- * @throws Error if directory creation or file write fails
12638
- */
12639
- dump(content: string, options: IMarkdownDumpOptions): Promise<void>;
12640
- }
12641
- /**
12642
- * Utility class for managing markdown report services.
12643
- *
12644
- * Provides methods to enable/disable markdown report generation across
12645
- * different service types (backtest, live, walker, performance, etc.).
12646
- *
12647
- * Typically extended by MarkdownAdapter for additional functionality.
12658
+ * Utility class for managing markdown report services.
12659
+ *
12660
+ * Provides methods to enable/disable markdown report generation across
12661
+ * different service types (backtest, live, walker, performance, etc.).
12662
+ *
12663
+ * Typically extended by MarkdownAdapter for additional functionality.
12648
12664
  */
12649
12665
  declare class MarkdownUtils {
12650
12666
  /**
@@ -12725,19 +12741,6 @@ declare class MarkdownUtils {
12725
12741
  * - Convenience methods: useMd(), useJsonl()
12726
12742
  */
12727
12743
  declare class MarkdownAdapter extends MarkdownUtils {
12728
- /**
12729
- * Current markdown storage adapter constructor.
12730
- * Defaults to MarkdownFolderBase for separate file storage.
12731
- * Can be changed via useMarkdownAdapter().
12732
- */
12733
- private MarkdownFactory;
12734
- /**
12735
- * Memoized storage instances cache.
12736
- * Key: markdownName (backtest, live, walker, etc.)
12737
- * Value: TMarkdownBase instance created with current MarkdownFactory.
12738
- * Ensures single instance per markdown type for the lifetime of the application.
12739
- */
12740
- private getMarkdownStorage;
12741
12744
  /**
12742
12745
  * Sets the markdown storage adapter constructor.
12743
12746
  * All future markdown instances will use this adapter.
@@ -12745,19 +12748,6 @@ declare class MarkdownAdapter extends MarkdownUtils {
12745
12748
  * @param Ctor - Constructor for markdown storage adapter
12746
12749
  */
12747
12750
  useMarkdownAdapter(Ctor: TMarkdownBaseCtor): void;
12748
- /**
12749
- * Writes markdown data to storage using the configured adapter.
12750
- * Automatically initializes storage on first write for each markdown type.
12751
- *
12752
- * @param markdownName - Type of markdown report (backtest, live, walker, etc.)
12753
- * @param content - Markdown content to write
12754
- * @param options - Path, file, and metadata options
12755
- * @returns Promise that resolves when write is complete
12756
- * @throws Error if write fails or storage initialization fails
12757
- *
12758
- * @internal - Use service-specific dump methods instead (e.g., Backtest.dump)
12759
- */
12760
- writeData(markdownName: MarkdownName, content: string, options: IMarkdownDumpOptions): Promise<void>;
12761
12751
  /**
12762
12752
  * Switches to folder-based markdown storage (default).
12763
12753
  * Shorthand for useMarkdownAdapter(MarkdownFolderBase).
@@ -18296,7 +18286,7 @@ type Columns$2 = ColumnModel<SyncEvent>;
18296
18286
  * ```typescript
18297
18287
  * import { Markdown } from "backtest-kit";
18298
18288
  *
18299
- * const unsubscribe = Markdown.enable({ sync: true });
18289
+ * const unsubscribe = MarkdownWriter.enable({ sync: true });
18300
18290
  * // ... later
18301
18291
  * unsubscribe();
18302
18292
  * ```
@@ -20248,67 +20238,6 @@ declare class BreakevenUtils {
20248
20238
  */
20249
20239
  declare const Breakeven: BreakevenUtils;
20250
20240
 
20251
- /**
20252
- * Logger service with automatic context injection.
20253
- *
20254
- * Features:
20255
- * - Delegates to user-provided logger via setLogger()
20256
- * - Automatically appends method context (strategyName, exchangeName, frameName)
20257
- * - Automatically appends execution context (symbol, when, backtest)
20258
- * - Defaults to NOOP_LOGGER if no logger configured
20259
- *
20260
- * Used throughout the framework for consistent logging with context.
20261
- */
20262
- declare class LoggerService implements ILogger {
20263
- private readonly methodContextService;
20264
- private readonly executionContextService;
20265
- private _commonLogger;
20266
- /**
20267
- * Gets current method context if available.
20268
- * Contains strategyName, exchangeName, frameName from MethodContextService.
20269
- */
20270
- private get methodContext();
20271
- /**
20272
- * Gets current execution context if available.
20273
- * Contains symbol, when, backtest from ExecutionContextService.
20274
- */
20275
- private get executionContext();
20276
- /**
20277
- * Logs general-purpose message with automatic context injection.
20278
- *
20279
- * @param topic - Log topic/category
20280
- * @param args - Additional log arguments
20281
- */
20282
- log: (topic: string, ...args: any[]) => Promise<void>;
20283
- /**
20284
- * Logs debug-level message with automatic context injection.
20285
- *
20286
- * @param topic - Log topic/category
20287
- * @param args - Additional log arguments
20288
- */
20289
- debug: (topic: string, ...args: any[]) => Promise<void>;
20290
- /**
20291
- * Logs info-level message with automatic context injection.
20292
- *
20293
- * @param topic - Log topic/category
20294
- * @param args - Additional log arguments
20295
- */
20296
- info: (topic: string, ...args: any[]) => Promise<void>;
20297
- /**
20298
- * Logs warning-level message with automatic context injection.
20299
- *
20300
- * @param topic - Log topic/category
20301
- * @param args - Additional log arguments
20302
- */
20303
- warn: (topic: string, ...args: any[]) => Promise<void>;
20304
- /**
20305
- * Sets custom logger implementation.
20306
- *
20307
- * @param logger - Custom logger implementing ILogger interface
20308
- */
20309
- setLogger: (logger: ILogger) => void;
20310
- }
20311
-
20312
20241
  /**
20313
20242
  * Type alias for column configuration used in strategy markdown reports.
20314
20243
  *
@@ -20363,7 +20292,22 @@ type Columns = ColumnModel<StrategyEvent>;
20363
20292
  * @see Strategy for the high-level utility class that wraps this service
20364
20293
  */
20365
20294
  declare class StrategyMarkdownService {
20366
- readonly loggerService: LoggerService;
20295
+ readonly loggerService: {
20296
+ readonly methodContextService: {
20297
+ readonly context: IMethodContext;
20298
+ };
20299
+ readonly executionContextService: {
20300
+ readonly context: IExecutionContext;
20301
+ };
20302
+ _commonLogger: ILogger;
20303
+ readonly _methodContext: {};
20304
+ readonly _executionContext: {};
20305
+ log: (topic: string, ...args: any[]) => Promise<void>;
20306
+ debug: (topic: string, ...args: any[]) => Promise<void>;
20307
+ info: (topic: string, ...args: any[]) => Promise<void>;
20308
+ warn: (topic: string, ...args: any[]) => Promise<void>;
20309
+ setLogger: (logger: ILogger) => void;
20310
+ };
20367
20311
  /**
20368
20312
  * Memoized factory for ReportStorage instances.
20369
20313
  *
@@ -20599,7 +20543,7 @@ declare class StrategyMarkdownService {
20599
20543
  * Generates and saves a markdown report to disk.
20600
20544
  *
20601
20545
  * Creates the output directory if it doesn't exist and writes
20602
- * the report with a timestamped filename via Markdown.writeData().
20546
+ * the report with a timestamped filename via MarkdownWriter.writeData().
20603
20547
  *
20604
20548
  * Filename format: `{symbol}_{strategyName}_{exchangeName}[_{frameName}_backtest|_live]-{timestamp}.md`
20605
20549
  *
@@ -20819,228 +20763,27 @@ declare class StrategyUtils {
20819
20763
  declare const Strategy: StrategyUtils;
20820
20764
 
20821
20765
  /**
20822
- * Proxy wrapper for user-defined action handlers with automatic error capture.
20766
+ * Base class for custom action handlers.
20823
20767
  *
20824
- * Wraps all IPublicAction methods with trycatch to prevent user code errors from crashing the system.
20825
- * All errors are logged, sent to errorEmitter, and returned as null (non-breaking).
20768
+ * Provides default implementations for all IPublicAction methods that log events.
20769
+ * Extend this class to implement custom action handlers for:
20770
+ * - State management (Redux, Zustand, MobX)
20771
+ * - Real-time notifications (Telegram, Discord, Email)
20772
+ * - Event logging and monitoring
20773
+ * - Analytics and metrics collection
20774
+ * - Custom business logic triggers
20826
20775
  *
20827
20776
  * Key features:
20828
- * - Automatic error catching and logging for all action methods
20829
- * - Safe execution of partial user implementations (missing methods return null)
20830
- * - Consistent error capture across all action lifecycle events
20831
- * - Non-breaking failure mode (errors logged but execution continues)
20777
+ * - All methods have default implementations (no need to implement unused methods)
20778
+ * - Automatic logging of all events via LOGGER_SERVICE
20779
+ * - Access to strategy context (strategyName, frameName, actionName)
20780
+ * - Implements full IPublicAction interface
20832
20781
  *
20833
- * Architecture:
20834
- * - Private constructor enforces factory pattern via fromInstance()
20835
- * - Each method checks if target implements the method before calling
20836
- * - Errors caught with fallback handler (warn log + errorEmitter)
20837
- * - Returns null on error to prevent undefined behavior
20838
- *
20839
- * Used by:
20840
- * - ClientAction to wrap user-provided action handlers
20841
- * - ActionCoreService to safely invoke action callbacks
20842
- *
20843
- * @example
20844
- * ```typescript
20845
- * // Create proxy from user implementation
20846
- * const userAction = {
20847
- * signal: async (event) => {
20848
- * // User code that might throw
20849
- * throw new Error('User error');
20850
- * }
20851
- * };
20852
- *
20853
- * const proxy = ActionProxy.fromInstance(userAction);
20854
- *
20855
- * // Error is caught and logged, execution continues
20856
- * await proxy.signal(event); // Logs error, returns null
20857
- * await proxy.dispose(); // Safe call even though not implemented
20858
- * ```
20859
- *
20860
- * @example
20861
- * ```typescript
20862
- * // Partial implementation is safe
20863
- * const partialAction = {
20864
- * init: async () => console.log('Initialized'),
20865
- * // Other methods not implemented
20866
- * };
20867
- *
20868
- * const proxy = ActionProxy.fromInstance(partialAction);
20869
- * await proxy.init(); // Works
20870
- * await proxy.signal(event); // Returns null (not implemented)
20871
- * ```
20872
- */
20873
- declare class ActionProxy implements IPublicAction {
20874
- readonly _target: Partial<IPublicAction>;
20875
- /**
20876
- * Creates a new ActionProxy instance.
20877
- *
20878
- * @param _target - Partial action implementation to wrap with error capture
20879
- * @private Use ActionProxy.fromInstance() instead
20880
- */
20881
- private constructor();
20882
- /**
20883
- * Initializes the action handler with error capture.
20884
- *
20885
- * Wraps the user's init() method in trycatch to prevent initialization errors from crashing the system.
20886
- * If the target doesn't implement init(), this method safely returns undefined.
20887
- *
20888
- * @returns Promise resolving to user's init() result or undefined if not implemented
20889
- */
20890
- init(): Promise<any>;
20891
- /**
20892
- * Handles signal events from all modes with error capture.
20893
- *
20894
- * Wraps the user's signal() method to catch and log any errors.
20895
- * Called on every tick/candle when strategy is evaluated.
20896
- *
20897
- * @param event - Signal state result with action, state, signal data, and context
20898
- * @returns Promise resolving to user's signal() result or null on error
20899
- */
20900
- signal(event: IStrategyTickResult): Promise<any>;
20901
- /**
20902
- * Handles signal events from live trading only with error capture.
20903
- *
20904
- * Wraps the user's signalLive() method to catch and log any errors.
20905
- * Called every tick in live mode.
20906
- *
20907
- * @param event - Signal state result from live trading
20908
- * @returns Promise resolving to user's signalLive() result or null on error
20909
- */
20910
- signalLive(event: IStrategyTickResult): Promise<any>;
20911
- /**
20912
- * Handles signal events from backtest only with error capture.
20913
- *
20914
- * Wraps the user's signalBacktest() method to catch and log any errors.
20915
- * Called every candle in backtest mode.
20916
- *
20917
- * @param event - Signal state result from backtest
20918
- * @returns Promise resolving to user's signalBacktest() result or null on error
20919
- */
20920
- signalBacktest(event: IStrategyTickResult): Promise<any>;
20921
- /**
20922
- * Handles breakeven events with error capture.
20923
- *
20924
- * Wraps the user's breakevenAvailable() method to catch and log any errors.
20925
- * Called once per signal when stop-loss is moved to entry price.
20926
- *
20927
- * @param event - Breakeven milestone data with signal info, current price, timestamp
20928
- * @returns Promise resolving to user's breakevenAvailable() result or null on error
20929
- */
20930
- breakevenAvailable(event: BreakevenContract): Promise<any>;
20931
- /**
20932
- * Handles partial profit level events with error capture.
20933
- *
20934
- * Wraps the user's partialProfitAvailable() method to catch and log any errors.
20935
- * Called once per profit level per signal (10%, 20%, 30%, etc).
20936
- *
20937
- * @param event - Profit milestone data with signal info, level, price, timestamp
20938
- * @returns Promise resolving to user's partialProfitAvailable() result or null on error
20939
- */
20940
- partialProfitAvailable(event: PartialProfitContract): Promise<any>;
20941
- /**
20942
- * Handles partial loss level events with error capture.
20943
- *
20944
- * Wraps the user's partialLossAvailable() method to catch and log any errors.
20945
- * Called once per loss level per signal (-10%, -20%, -30%, etc).
20946
- *
20947
- * @param event - Loss milestone data with signal info, level, price, timestamp
20948
- * @returns Promise resolving to user's partialLossAvailable() result or null on error
20949
- */
20950
- partialLossAvailable(event: PartialLossContract): Promise<any>;
20951
- /**
20952
- * Handles scheduled ping events with error capture.
20953
- *
20954
- * Wraps the user's pingScheduled() method to catch and log any errors.
20955
- * Called every minute while a scheduled signal is waiting for activation.
20956
- *
20957
- * @param event - Scheduled signal monitoring data with symbol, strategy info, signal data, timestamp
20958
- * @returns Promise resolving to user's pingScheduled() result or null on error
20959
- */
20960
- pingScheduled(event: SchedulePingContract): Promise<any>;
20961
- /**
20962
- * Handles active ping events with error capture.
20963
- *
20964
- * Wraps the user's pingActive() method to catch and log any errors.
20965
- * Called every minute while a pending signal is active (position open).
20966
- *
20967
- * @param event - Active pending signal monitoring data with symbol, strategy info, signal data, timestamp
20968
- * @returns Promise resolving to user's pingActive() result or null on error
20969
- */
20970
- pingActive(event: ActivePingContract): Promise<any>;
20971
- /**
20972
- * Handles risk rejection events with error capture.
20973
- *
20974
- * Wraps the user's riskRejection() method to catch and log any errors.
20975
- * Called only when signal is rejected by risk management validation.
20976
- *
20977
- * @param event - Risk rejection data with symbol, pending signal, rejection reason, timestamp
20978
- * @returns Promise resolving to user's riskRejection() result or null on error
20979
- */
20980
- riskRejection(event: RiskContract): Promise<any>;
20981
- /**
20982
- * Gate for position open/close via limit order.
20983
- * NOT wrapped in trycatch — exceptions propagate to CREATE_SYNC_FN.
20984
- *
20985
- * @param event - Sync event with action "signal-open" or "signal-close"
20986
- */
20987
- signalSync(event: SignalSyncContract): Promise<void>;
20988
- /**
20989
- * Cleans up resources with error capture.
20990
- *
20991
- * Wraps the user's dispose() method to catch and log any errors.
20992
- * Called once when strategy execution ends.
20993
- *
20994
- * @returns Promise resolving to user's dispose() result or null on error
20995
- */
20996
- dispose(): Promise<any>;
20997
- /**
20998
- * Creates a new ActionProxy instance wrapping a user-provided action handler.
20999
- *
21000
- * Factory method enforcing the private constructor pattern.
21001
- * Wraps all methods of the provided instance with error capture.
21002
- *
21003
- * @param instance - Partial action implementation to wrap
21004
- * @returns New ActionProxy instance with error-safe method wrappers
21005
- *
21006
- * @example
21007
- * ```typescript
21008
- * const userAction = {
21009
- * signal: async (event) => {
21010
- * console.log('Signal received:', event);
21011
- * },
21012
- * dispose: async () => {
21013
- * console.log('Cleanup complete');
21014
- * }
21015
- * };
21016
- *
21017
- * const proxy = ActionProxy.fromInstance(userAction);
21018
- * ```
21019
- */
21020
- static fromInstance(instance: Partial<IPublicAction>): ActionProxy;
21021
- }
21022
- /**
21023
- * Base class for custom action handlers.
21024
- *
21025
- * Provides default implementations for all IPublicAction methods that log events.
21026
- * Extend this class to implement custom action handlers for:
21027
- * - State management (Redux, Zustand, MobX)
21028
- * - Real-time notifications (Telegram, Discord, Email)
21029
- * - Event logging and monitoring
21030
- * - Analytics and metrics collection
21031
- * - Custom business logic triggers
21032
- *
21033
- * Key features:
21034
- * - All methods have default implementations (no need to implement unused methods)
21035
- * - Automatic logging of all events via backtest.loggerService
21036
- * - Access to strategy context (strategyName, frameName, actionName)
21037
- * - Implements full IPublicAction interface
21038
- *
21039
- * Lifecycle:
21040
- * 1. Constructor called with (strategyName, frameName, actionName)
21041
- * 2. init() called once for async initialization
21042
- * 3. Event methods called as strategy executes (signal, breakeven, partialProfit, etc.)
21043
- * 4. dispose() called once for cleanup
20782
+ * Lifecycle:
20783
+ * 1. Constructor called with (strategyName, frameName, actionName)
20784
+ * 2. init() called once for async initialization
20785
+ * 3. Event methods called as strategy executes (signal, breakeven, partialProfit, etc.)
20786
+ * 4. dispose() called once for cleanup
21044
20787
  *
21045
20788
  * Event flow:
21046
20789
  * - signal() - Called on every tick/candle (all modes)
@@ -23256,7 +22999,22 @@ declare class ExchangeConnectionService implements IExchange {
23256
22999
  * Strategies are registered via addStrategy() and retrieved by name.
23257
23000
  */
23258
23001
  declare class StrategySchemaService {
23259
- readonly loggerService: LoggerService;
23002
+ readonly loggerService: {
23003
+ readonly methodContextService: {
23004
+ readonly context: IMethodContext;
23005
+ };
23006
+ readonly executionContextService: {
23007
+ readonly context: IExecutionContext;
23008
+ };
23009
+ _commonLogger: ILogger;
23010
+ readonly _methodContext: {};
23011
+ readonly _executionContext: {};
23012
+ log: (topic: string, ...args: any[]) => Promise<void>;
23013
+ debug: (topic: string, ...args: any[]) => Promise<void>;
23014
+ info: (topic: string, ...args: any[]) => Promise<void>;
23015
+ warn: (topic: string, ...args: any[]) => Promise<void>;
23016
+ setLogger: (logger: ILogger) => void;
23017
+ };
23260
23018
  private _registry;
23261
23019
  /**
23262
23020
  * Registers a new strategy schema.
@@ -23382,6 +23140,67 @@ declare class ClientRisk implements IRisk {
23382
23140
  checkSignal: (params: IRiskCheckArgs) => Promise<boolean>;
23383
23141
  }
23384
23142
 
23143
+ /**
23144
+ * Service for managing risk schema registry.
23145
+ *
23146
+ * Uses ToolRegistry from functools-kit for type-safe schema storage.
23147
+ * Risk profiles are registered via addRisk() and retrieved by name.
23148
+ */
23149
+ declare class RiskSchemaService {
23150
+ readonly loggerService: {
23151
+ readonly methodContextService: {
23152
+ readonly context: IMethodContext;
23153
+ };
23154
+ readonly executionContextService: {
23155
+ readonly context: IExecutionContext;
23156
+ };
23157
+ _commonLogger: ILogger;
23158
+ readonly _methodContext: {};
23159
+ readonly _executionContext: {};
23160
+ log: (topic: string, ...args: any[]) => Promise<void>;
23161
+ debug: (topic: string, ...args: any[]) => Promise<void>;
23162
+ info: (topic: string, ...args: any[]) => Promise<void>;
23163
+ warn: (topic: string, ...args: any[]) => Promise<void>;
23164
+ setLogger: (logger: ILogger) => void;
23165
+ };
23166
+ private _registry;
23167
+ /**
23168
+ * Registers a new risk schema.
23169
+ *
23170
+ * @param key - Unique risk profile name
23171
+ * @param value - Risk schema configuration
23172
+ * @throws Error if risk name already exists
23173
+ */
23174
+ register: (key: RiskName, value: IRiskSchema) => void;
23175
+ /**
23176
+ * Validates risk schema structure for required properties.
23177
+ *
23178
+ * Performs shallow validation to ensure all required properties exist
23179
+ * and have correct types before registration in the registry.
23180
+ *
23181
+ * @param riskSchema - Risk schema to validate
23182
+ * @throws Error if riskName is missing or not a string
23183
+ */
23184
+ private validateShallow;
23185
+ /**
23186
+ * Overrides an existing risk schema with partial updates.
23187
+ *
23188
+ * @param key - Risk name to override
23189
+ * @param value - Partial schema updates
23190
+ * @returns Updated risk schema
23191
+ * @throws Error if risk name doesn't exist
23192
+ */
23193
+ override: (key: RiskName, value: Partial<IRiskSchema>) => IRiskSchema;
23194
+ /**
23195
+ * Retrieves a risk schema by name.
23196
+ *
23197
+ * @param key - Risk name
23198
+ * @returns Risk schema configuration
23199
+ * @throws Error if risk name doesn't exist
23200
+ */
23201
+ get: (key: RiskName) => IRiskSchema;
23202
+ }
23203
+
23385
23204
  /**
23386
23205
  * Type definition for action methods.
23387
23206
  * Maps all keys of IAction to any type.
@@ -23668,10 +23487,28 @@ type TRisk$1 = {
23668
23487
  * ```
23669
23488
  */
23670
23489
  declare class RiskConnectionService implements TRisk$1 {
23671
- private readonly loggerService;
23672
- private readonly riskSchemaService;
23673
- /**
23674
- * Action core service injected from DI container.
23490
+ readonly loggerService: {
23491
+ readonly methodContextService: {
23492
+ readonly context: IMethodContext;
23493
+ };
23494
+ readonly executionContextService: {
23495
+ readonly context: IExecutionContext;
23496
+ };
23497
+ _commonLogger: ILogger;
23498
+ readonly _methodContext: {};
23499
+ readonly _executionContext: {};
23500
+ log: (topic: string, ...args: any[]) => Promise<void>;
23501
+ debug: (topic: string, ...args: any[]) => Promise<void>;
23502
+ info: (topic: string, ...args: any[]) => Promise<void>;
23503
+ warn: (topic: string, ...args: any[]) => Promise<void>;
23504
+ setLogger: (logger: ILogger) => void;
23505
+ };
23506
+ readonly riskSchemaService: RiskSchemaService;
23507
+ readonly executionContextService: {
23508
+ readonly context: IExecutionContext;
23509
+ };
23510
+ /**
23511
+ * Action core service injected from DI container.
23675
23512
  */
23676
23513
  readonly actionCoreService: ActionCoreService;
23677
23514
  /**
@@ -23789,7 +23626,22 @@ declare class PartialConnectionService implements IPartial {
23789
23626
  /**
23790
23627
  * Logger service injected from DI container.
23791
23628
  */
23792
- private readonly loggerService;
23629
+ readonly loggerService: {
23630
+ readonly methodContextService: {
23631
+ readonly context: IMethodContext;
23632
+ };
23633
+ readonly executionContextService: {
23634
+ readonly context: IExecutionContext;
23635
+ };
23636
+ _commonLogger: ILogger;
23637
+ readonly _methodContext: {};
23638
+ readonly _executionContext: {};
23639
+ log: (topic: string, ...args: any[]) => Promise<void>;
23640
+ debug: (topic: string, ...args: any[]) => Promise<void>;
23641
+ info: (topic: string, ...args: any[]) => Promise<void>;
23642
+ warn: (topic: string, ...args: any[]) => Promise<void>;
23643
+ setLogger: (logger: ILogger) => void;
23644
+ };
23793
23645
  /**
23794
23646
  * Action core service injected from DI container.
23795
23647
  */
@@ -23890,7 +23742,22 @@ declare class BreakevenConnectionService implements IBreakeven {
23890
23742
  /**
23891
23743
  * Logger service injected from DI container.
23892
23744
  */
23893
- private readonly loggerService;
23745
+ readonly loggerService: {
23746
+ readonly methodContextService: {
23747
+ readonly context: IMethodContext;
23748
+ };
23749
+ readonly executionContextService: {
23750
+ readonly context: IExecutionContext;
23751
+ };
23752
+ _commonLogger: ILogger;
23753
+ readonly _methodContext: {};
23754
+ readonly _executionContext: {};
23755
+ log: (topic: string, ...args: any[]) => Promise<void>;
23756
+ debug: (topic: string, ...args: any[]) => Promise<void>;
23757
+ info: (topic: string, ...args: any[]) => Promise<void>;
23758
+ warn: (topic: string, ...args: any[]) => Promise<void>;
23759
+ setLogger: (logger: ILogger) => void;
23760
+ };
23894
23761
  /**
23895
23762
  * Action core service injected from DI container.
23896
23763
  */
@@ -24147,7 +24014,22 @@ type TStrategy$1 = {
24147
24014
  * ```
24148
24015
  */
24149
24016
  declare class StrategyConnectionService implements TStrategy$1 {
24150
- readonly loggerService: LoggerService;
24017
+ readonly loggerService: {
24018
+ readonly methodContextService: {
24019
+ readonly context: IMethodContext;
24020
+ };
24021
+ readonly executionContextService: {
24022
+ readonly context: IExecutionContext;
24023
+ };
24024
+ _commonLogger: ILogger;
24025
+ readonly _methodContext: {};
24026
+ readonly _executionContext: {};
24027
+ log: (topic: string, ...args: any[]) => Promise<void>;
24028
+ debug: (topic: string, ...args: any[]) => Promise<void>;
24029
+ info: (topic: string, ...args: any[]) => Promise<void>;
24030
+ warn: (topic: string, ...args: any[]) => Promise<void>;
24031
+ setLogger: (logger: ILogger) => void;
24032
+ };
24151
24033
  readonly executionContextService: {
24152
24034
  readonly context: IExecutionContext;
24153
24035
  };
@@ -25306,6 +25188,209 @@ declare class SizingConnectionService implements TSizing$1 {
25306
25188
  }) => Promise<number>;
25307
25189
  }
25308
25190
 
25191
+ /**
25192
+ * Proxy wrapper for user-defined action handlers with automatic error capture.
25193
+ *
25194
+ * Wraps all IPublicAction methods with trycatch to prevent user code errors from crashing the system.
25195
+ * All errors are logged, sent to errorEmitter, and returned as null (non-breaking).
25196
+ *
25197
+ * Key features:
25198
+ * - Automatic error catching and logging for all action methods
25199
+ * - Safe execution of partial user implementations (missing methods return null)
25200
+ * - Consistent error capture across all action lifecycle events
25201
+ * - Non-breaking failure mode (errors logged but execution continues)
25202
+ *
25203
+ * Architecture:
25204
+ * - Private constructor enforces factory pattern via fromInstance()
25205
+ * - Each method checks if target implements the method before calling
25206
+ * - Errors caught with fallback handler (warn log + errorEmitter)
25207
+ * - Returns null on error to prevent undefined behavior
25208
+ *
25209
+ * Used by:
25210
+ * - ClientAction to wrap user-provided action handlers
25211
+ * - ActionCoreService to safely invoke action callbacks
25212
+ *
25213
+ * @example
25214
+ * ```typescript
25215
+ * // Create proxy from user implementation
25216
+ * const userAction = {
25217
+ * signal: async (event) => {
25218
+ * // User code that might throw
25219
+ * throw new Error('User error');
25220
+ * }
25221
+ * };
25222
+ *
25223
+ * const proxy = ActionProxy.fromInstance(userAction);
25224
+ *
25225
+ * // Error is caught and logged, execution continues
25226
+ * await proxy.signal(event); // Logs error, returns null
25227
+ * await proxy.dispose(); // Safe call even though not implemented
25228
+ * ```
25229
+ *
25230
+ * @example
25231
+ * ```typescript
25232
+ * // Partial implementation is safe
25233
+ * const partialAction = {
25234
+ * init: async () => console.log('Initialized'),
25235
+ * // Other methods not implemented
25236
+ * };
25237
+ *
25238
+ * const proxy = ActionProxy.fromInstance(partialAction);
25239
+ * await proxy.init(); // Works
25240
+ * await proxy.signal(event); // Returns null (not implemented)
25241
+ * ```
25242
+ */
25243
+ declare class ActionProxy implements IPublicAction {
25244
+ readonly _target: Partial<IPublicAction>;
25245
+ readonly params: IActionParams;
25246
+ /**
25247
+ * Creates a new ActionProxy instance.
25248
+ *
25249
+ * @param _target - Partial action implementation to wrap with error capture
25250
+ * @private Use ActionProxy.fromInstance() instead
25251
+ */
25252
+ private constructor();
25253
+ /**
25254
+ * Initializes the action handler with error capture.
25255
+ *
25256
+ * Wraps the user's init() method in trycatch to prevent initialization errors from crashing the system.
25257
+ * If the target doesn't implement init(), this method safely returns undefined.
25258
+ *
25259
+ * @returns Promise resolving to user's init() result or undefined if not implemented
25260
+ */
25261
+ init(): Promise<any>;
25262
+ /**
25263
+ * Handles signal events from all modes with error capture.
25264
+ *
25265
+ * Wraps the user's signal() method to catch and log any errors.
25266
+ * Called on every tick/candle when strategy is evaluated.
25267
+ *
25268
+ * @param event - Signal state result with action, state, signal data, and context
25269
+ * @returns Promise resolving to user's signal() result or null on error
25270
+ */
25271
+ signal(event: IStrategyTickResult): Promise<any>;
25272
+ /**
25273
+ * Handles signal events from live trading only with error capture.
25274
+ *
25275
+ * Wraps the user's signalLive() method to catch and log any errors.
25276
+ * Called every tick in live mode.
25277
+ *
25278
+ * @param event - Signal state result from live trading
25279
+ * @returns Promise resolving to user's signalLive() result or null on error
25280
+ */
25281
+ signalLive(event: IStrategyTickResult): Promise<any>;
25282
+ /**
25283
+ * Handles signal events from backtest only with error capture.
25284
+ *
25285
+ * Wraps the user's signalBacktest() method to catch and log any errors.
25286
+ * Called every candle in backtest mode.
25287
+ *
25288
+ * @param event - Signal state result from backtest
25289
+ * @returns Promise resolving to user's signalBacktest() result or null on error
25290
+ */
25291
+ signalBacktest(event: IStrategyTickResult): Promise<any>;
25292
+ /**
25293
+ * Handles breakeven events with error capture.
25294
+ *
25295
+ * Wraps the user's breakevenAvailable() method to catch and log any errors.
25296
+ * Called once per signal when stop-loss is moved to entry price.
25297
+ *
25298
+ * @param event - Breakeven milestone data with signal info, current price, timestamp
25299
+ * @returns Promise resolving to user's breakevenAvailable() result or null on error
25300
+ */
25301
+ breakevenAvailable(event: BreakevenContract): Promise<any>;
25302
+ /**
25303
+ * Handles partial profit level events with error capture.
25304
+ *
25305
+ * Wraps the user's partialProfitAvailable() method to catch and log any errors.
25306
+ * Called once per profit level per signal (10%, 20%, 30%, etc).
25307
+ *
25308
+ * @param event - Profit milestone data with signal info, level, price, timestamp
25309
+ * @returns Promise resolving to user's partialProfitAvailable() result or null on error
25310
+ */
25311
+ partialProfitAvailable(event: PartialProfitContract): Promise<any>;
25312
+ /**
25313
+ * Handles partial loss level events with error capture.
25314
+ *
25315
+ * Wraps the user's partialLossAvailable() method to catch and log any errors.
25316
+ * Called once per loss level per signal (-10%, -20%, -30%, etc).
25317
+ *
25318
+ * @param event - Loss milestone data with signal info, level, price, timestamp
25319
+ * @returns Promise resolving to user's partialLossAvailable() result or null on error
25320
+ */
25321
+ partialLossAvailable(event: PartialLossContract): Promise<any>;
25322
+ /**
25323
+ * Handles scheduled ping events with error capture.
25324
+ *
25325
+ * Wraps the user's pingScheduled() method to catch and log any errors.
25326
+ * Called every minute while a scheduled signal is waiting for activation.
25327
+ *
25328
+ * @param event - Scheduled signal monitoring data with symbol, strategy info, signal data, timestamp
25329
+ * @returns Promise resolving to user's pingScheduled() result or null on error
25330
+ */
25331
+ pingScheduled(event: SchedulePingContract): Promise<any>;
25332
+ /**
25333
+ * Handles active ping events with error capture.
25334
+ *
25335
+ * Wraps the user's pingActive() method to catch and log any errors.
25336
+ * Called every minute while a pending signal is active (position open).
25337
+ *
25338
+ * @param event - Active pending signal monitoring data with symbol, strategy info, signal data, timestamp
25339
+ * @returns Promise resolving to user's pingActive() result or null on error
25340
+ */
25341
+ pingActive(event: ActivePingContract): Promise<any>;
25342
+ /**
25343
+ * Handles risk rejection events with error capture.
25344
+ *
25345
+ * Wraps the user's riskRejection() method to catch and log any errors.
25346
+ * Called only when signal is rejected by risk management validation.
25347
+ *
25348
+ * @param event - Risk rejection data with symbol, pending signal, rejection reason, timestamp
25349
+ * @returns Promise resolving to user's riskRejection() result or null on error
25350
+ */
25351
+ riskRejection(event: RiskContract): Promise<any>;
25352
+ /**
25353
+ * Gate for position open/close via limit order.
25354
+ * NOT wrapped in trycatch — exceptions propagate to CREATE_SYNC_FN.
25355
+ *
25356
+ * @param event - Sync event with action "signal-open" or "signal-close"
25357
+ */
25358
+ signalSync(event: SignalSyncContract): Promise<void>;
25359
+ /**
25360
+ * Cleans up resources with error capture.
25361
+ *
25362
+ * Wraps the user's dispose() method to catch and log any errors.
25363
+ * Called once when strategy execution ends.
25364
+ *
25365
+ * @returns Promise resolving to user's dispose() result or null on error
25366
+ */
25367
+ dispose(): Promise<any>;
25368
+ /**
25369
+ * Creates a new ActionProxy instance wrapping a user-provided action handler.
25370
+ *
25371
+ * Factory method enforcing the private constructor pattern.
25372
+ * Wraps all methods of the provided instance with error capture.
25373
+ *
25374
+ * @param instance - Partial action implementation to wrap
25375
+ * @returns New ActionProxy instance with error-safe method wrappers
25376
+ *
25377
+ * @example
25378
+ * ```typescript
25379
+ * const userAction = {
25380
+ * signal: async (event) => {
25381
+ * console.log('Signal received:', event);
25382
+ * },
25383
+ * dispose: async () => {
25384
+ * console.log('Cleanup complete');
25385
+ * }
25386
+ * };
25387
+ *
25388
+ * const proxy = ActionProxy.fromInstance(userAction);
25389
+ * ```
25390
+ */
25391
+ static fromInstance(instance: Partial<IPublicAction>, params: IActionParams): ActionProxy;
25392
+ }
25393
+
25309
25394
  /**
25310
25395
  * ClientAction implementation for action handler execution.
25311
25396
  *
@@ -25463,6 +25548,7 @@ type TAction = {
25463
25548
  declare class ActionConnectionService implements TAction {
25464
25549
  private readonly loggerService;
25465
25550
  private readonly actionSchemaService;
25551
+ private readonly strategyCoreService;
25466
25552
  /**
25467
25553
  * Retrieves memoized ClientAction instance for given action name, strategy, exchange, frame and backtest mode.
25468
25554
  *
@@ -26887,28 +26973,225 @@ declare class RiskGlobalService implements TRisk {
26887
26973
  }
26888
26974
 
26889
26975
  /**
26890
- * Private service for walker orchestration (strategy comparison).
26976
+ * Private service for backtest orchestration using async generators.
26891
26977
  *
26892
26978
  * Flow:
26893
- * 1. Yields progress updates as each strategy completes
26894
- * 2. Tracks best metric in real-time
26895
- * 3. Returns final results with all strategies ranked
26979
+ * 1. Get timeframes from frame service
26980
+ * 2. Iterate through timeframes calling tick()
26981
+ * 3. When signal opens: fetch candles and call backtest()
26982
+ * 4. Skip timeframes until signal closes
26983
+ * 5. Yield closed result and continue
26896
26984
  *
26897
- * Uses BacktestLogicPublicService internally for each strategy.
26985
+ * Memory efficient: streams results without array accumulation.
26986
+ * Supports early termination via break in consumer.
26898
26987
  */
26899
- declare class WalkerLogicPrivateService {
26900
- private readonly loggerService;
26901
- private readonly backtestLogicPublicService;
26902
- private readonly backtestMarkdownService;
26903
- private readonly walkerSchemaService;
26988
+ declare class BacktestLogicPrivateService {
26989
+ readonly loggerService: {
26990
+ readonly methodContextService: {
26991
+ readonly context: IMethodContext;
26992
+ };
26993
+ readonly executionContextService: {
26994
+ readonly context: IExecutionContext;
26995
+ };
26996
+ _commonLogger: ILogger;
26997
+ readonly _methodContext: {};
26998
+ readonly _executionContext: {};
26999
+ log: (topic: string, ...args: any[]) => Promise<void>;
27000
+ debug: (topic: string, ...args: any[]) => Promise<void>;
27001
+ info: (topic: string, ...args: any[]) => Promise<void>;
27002
+ warn: (topic: string, ...args: any[]) => Promise<void>;
27003
+ setLogger: (logger: ILogger) => void;
27004
+ };
27005
+ readonly strategyCoreService: StrategyCoreService;
27006
+ readonly exchangeCoreService: ExchangeCoreService;
27007
+ readonly frameCoreService: FrameCoreService;
27008
+ readonly methodContextService: {
27009
+ readonly context: IMethodContext;
27010
+ };
27011
+ readonly actionCoreService: ActionCoreService;
26904
27012
  /**
26905
- * Runs walker comparison for a symbol.
26906
- *
26907
- * Executes backtest for each strategy sequentially.
26908
- * Yields WalkerContract after each strategy completes.
27013
+ * Runs backtest for a symbol, streaming closed signals as async generator.
26909
27014
  *
26910
27015
  * @param symbol - Trading pair symbol (e.g., "BTCUSDT")
26911
- * @param strategies - List of strategy names to compare
27016
+ * @yields Closed signal results with PNL
27017
+ *
27018
+ * @example
27019
+ * ```typescript
27020
+ * for await (const result of backtestLogic.run("BTCUSDT")) {
27021
+ * console.log(result.closeReason, result.pnl.pnlPercentage);
27022
+ * if (result.pnl.pnlPercentage < -10) break; // Early termination
27023
+ * }
27024
+ * ```
27025
+ */
27026
+ run(symbol: string): AsyncGenerator<IStrategyTickResultScheduled | IStrategyTickResultOpened | IStrategyTickResultClosed | IStrategyTickResultCancelled, void, any>;
27027
+ }
27028
+
27029
+ /**
27030
+ * Type definition for public BacktestLogic service.
27031
+ * Omits private dependencies from BacktestLogicPrivateService.
27032
+ */
27033
+ type IBacktestLogicPrivateService = Omit<BacktestLogicPrivateService, keyof {
27034
+ loggerService: never;
27035
+ strategyCoreService: never;
27036
+ exchangeCoreService: never;
27037
+ frameCoreService: never;
27038
+ actionCoreService: never;
27039
+ methodContextService: never;
27040
+ }>;
27041
+ /**
27042
+ * Type definition for BacktestLogicPublicService.
27043
+ * Maps all keys of IBacktestLogicPrivateService to any type.
27044
+ */
27045
+ type TBacktestLogicPrivateService = {
27046
+ [key in keyof IBacktestLogicPrivateService]: any;
27047
+ };
27048
+ /**
27049
+ * Public service for backtest orchestration with context management.
27050
+ *
27051
+ * Wraps BacktestLogicPrivateService with MethodContextService to provide
27052
+ * implicit context propagation for strategyName, exchangeName, and frameName.
27053
+ *
27054
+ * This allows getCandles(), getSignal(), and other functions to work without
27055
+ * explicit context parameters.
27056
+ *
27057
+ * @example
27058
+ * ```typescript
27059
+ * const backtestLogicPublicService = inject(TYPES.backtestLogicPublicService);
27060
+ *
27061
+ * for await (const result of backtestLogicPublicService.run("BTCUSDT", {
27062
+ * strategyName: "my-strategy",
27063
+ * exchangeName: "my-exchange",
27064
+ * frameName: "1d-backtest",
27065
+ * })) {
27066
+ * if (result.action === "closed") {
27067
+ * console.log("PNL:", result.pnl.profit);
27068
+ * }
27069
+ * }
27070
+ * ```
27071
+ */
27072
+ declare class BacktestLogicPublicService implements TBacktestLogicPrivateService {
27073
+ private readonly loggerService;
27074
+ private readonly backtestLogicPrivateService;
27075
+ /**
27076
+ * Runs backtest for a symbol with context propagation.
27077
+ *
27078
+ * Streams closed signals as async generator. Context is automatically
27079
+ * injected into all framework functions called during iteration.
27080
+ *
27081
+ * @param symbol - Trading pair symbol (e.g., "BTCUSDT")
27082
+ * @param context - Execution context with strategy, exchange, and frame names
27083
+ * @returns Async generator yielding closed signals with PNL
27084
+ */
27085
+ run: (symbol: string, context: {
27086
+ strategyName: StrategyName;
27087
+ exchangeName: ExchangeName;
27088
+ frameName: FrameName;
27089
+ }) => AsyncGenerator<IStrategyTickResultScheduled | IStrategyTickResultOpened | IStrategyTickResultClosed | IStrategyTickResultCancelled, void, any>;
27090
+ }
27091
+
27092
+ /**
27093
+ * Service for managing walker schema registry.
27094
+ *
27095
+ * Uses ToolRegistry from functools-kit for type-safe schema storage.
27096
+ * Walkers are registered via addWalker() and retrieved by name.
27097
+ */
27098
+ declare class WalkerSchemaService {
27099
+ readonly loggerService: {
27100
+ readonly methodContextService: {
27101
+ readonly context: IMethodContext;
27102
+ };
27103
+ readonly executionContextService: {
27104
+ readonly context: IExecutionContext;
27105
+ };
27106
+ _commonLogger: ILogger;
27107
+ readonly _methodContext: {};
27108
+ readonly _executionContext: {};
27109
+ log: (topic: string, ...args: any[]) => Promise<void>;
27110
+ debug: (topic: string, ...args: any[]) => Promise<void>;
27111
+ info: (topic: string, ...args: any[]) => Promise<void>;
27112
+ warn: (topic: string, ...args: any[]) => Promise<void>;
27113
+ setLogger: (logger: ILogger) => void;
27114
+ };
27115
+ private _registry;
27116
+ /**
27117
+ * Registers a new walker schema.
27118
+ *
27119
+ * @param key - Unique walker name
27120
+ * @param value - Walker schema configuration
27121
+ * @throws Error if walker name already exists
27122
+ */
27123
+ register: (key: WalkerName, value: IWalkerSchema) => void;
27124
+ /**
27125
+ * Validates walker schema structure for required properties.
27126
+ *
27127
+ * Performs shallow validation to ensure all required properties exist
27128
+ * and have correct types before registration in the registry.
27129
+ *
27130
+ * @param walkerSchema - Walker schema to validate
27131
+ * @throws Error if walkerName is missing or not a string
27132
+ * @throws Error if exchangeName is missing or not a string
27133
+ * @throws Error if frameName is missing or not a string
27134
+ * @throws Error if strategies is missing or not an array
27135
+ * @throws Error if strategies array is empty
27136
+ */
27137
+ private validateShallow;
27138
+ /**
27139
+ * Overrides an existing walker schema with partial updates.
27140
+ *
27141
+ * @param key - Walker name to override
27142
+ * @param value - Partial schema updates
27143
+ * @returns Updated walker schema
27144
+ * @throws Error if walker name doesn't exist
27145
+ */
27146
+ override: (key: WalkerName, value: Partial<IWalkerSchema>) => IWalkerSchema;
27147
+ /**
27148
+ * Retrieves a walker schema by name.
27149
+ *
27150
+ * @param key - Walker name
27151
+ * @returns Walker schema configuration
27152
+ * @throws Error if walker name doesn't exist
27153
+ */
27154
+ get: (key: WalkerName) => IWalkerSchema;
27155
+ }
27156
+
27157
+ /**
27158
+ * Private service for walker orchestration (strategy comparison).
27159
+ *
27160
+ * Flow:
27161
+ * 1. Yields progress updates as each strategy completes
27162
+ * 2. Tracks best metric in real-time
27163
+ * 3. Returns final results with all strategies ranked
27164
+ *
27165
+ * Uses BacktestLogicPublicService internally for each strategy.
27166
+ */
27167
+ declare class WalkerLogicPrivateService {
27168
+ readonly loggerService: {
27169
+ readonly methodContextService: {
27170
+ readonly context: IMethodContext;
27171
+ };
27172
+ readonly executionContextService: {
27173
+ readonly context: IExecutionContext;
27174
+ };
27175
+ _commonLogger: ILogger;
27176
+ readonly _methodContext: {};
27177
+ readonly _executionContext: {};
27178
+ log: (topic: string, ...args: any[]) => Promise<void>;
27179
+ debug: (topic: string, ...args: any[]) => Promise<void>;
27180
+ info: (topic: string, ...args: any[]) => Promise<void>;
27181
+ warn: (topic: string, ...args: any[]) => Promise<void>;
27182
+ setLogger: (logger: ILogger) => void;
27183
+ };
27184
+ readonly backtestLogicPublicService: BacktestLogicPublicService;
27185
+ readonly backtestMarkdownService: BacktestMarkdownService;
27186
+ readonly walkerSchemaService: WalkerSchemaService;
27187
+ /**
27188
+ * Runs walker comparison for a symbol.
27189
+ *
27190
+ * Executes backtest for each strategy sequentially.
27191
+ * Yields WalkerContract after each strategy completes.
27192
+ *
27193
+ * @param symbol - Trading pair symbol (e.g., "BTCUSDT")
27194
+ * @param strategies - List of strategy names to compare
26912
27195
  * @param metric - Metric to use for comparison
26913
27196
  * @param context - Walker context with exchangeName, frameName, walkerName
26914
27197
  * @yields WalkerContract with progress after each strategy
@@ -27037,7 +27320,22 @@ declare class WalkerCommandService implements TWalkerLogicPublicService {
27037
27320
  * Exchanges are registered via addExchange() and retrieved by name.
27038
27321
  */
27039
27322
  declare class ExchangeSchemaService {
27040
- readonly loggerService: LoggerService;
27323
+ readonly loggerService: {
27324
+ readonly methodContextService: {
27325
+ readonly context: IMethodContext;
27326
+ };
27327
+ readonly executionContextService: {
27328
+ readonly context: IExecutionContext;
27329
+ };
27330
+ _commonLogger: ILogger;
27331
+ readonly _methodContext: {};
27332
+ readonly _executionContext: {};
27333
+ log: (topic: string, ...args: any[]) => Promise<void>;
27334
+ debug: (topic: string, ...args: any[]) => Promise<void>;
27335
+ info: (topic: string, ...args: any[]) => Promise<void>;
27336
+ warn: (topic: string, ...args: any[]) => Promise<void>;
27337
+ setLogger: (logger: ILogger) => void;
27338
+ };
27041
27339
  private _registry;
27042
27340
  /**
27043
27341
  * Registers a new exchange schema.
@@ -27086,7 +27384,22 @@ declare class ExchangeSchemaService {
27086
27384
  * Frames are registered via addFrame() and retrieved by name.
27087
27385
  */
27088
27386
  declare class FrameSchemaService {
27089
- readonly loggerService: LoggerService;
27387
+ readonly loggerService: {
27388
+ readonly methodContextService: {
27389
+ readonly context: IMethodContext;
27390
+ };
27391
+ readonly executionContextService: {
27392
+ readonly context: IExecutionContext;
27393
+ };
27394
+ _commonLogger: ILogger;
27395
+ readonly _methodContext: {};
27396
+ readonly _executionContext: {};
27397
+ log: (topic: string, ...args: any[]) => Promise<void>;
27398
+ debug: (topic: string, ...args: any[]) => Promise<void>;
27399
+ info: (topic: string, ...args: any[]) => Promise<void>;
27400
+ warn: (topic: string, ...args: any[]) => Promise<void>;
27401
+ setLogger: (logger: ILogger) => void;
27402
+ };
27090
27403
  private _registry;
27091
27404
  /**
27092
27405
  * Registers a new frame schema.
@@ -27134,7 +27447,22 @@ declare class FrameSchemaService {
27134
27447
  * Sizing schemas are registered via addSizing() and retrieved by name.
27135
27448
  */
27136
27449
  declare class SizingSchemaService {
27137
- readonly loggerService: LoggerService;
27450
+ readonly loggerService: {
27451
+ readonly methodContextService: {
27452
+ readonly context: IMethodContext;
27453
+ };
27454
+ readonly executionContextService: {
27455
+ readonly context: IExecutionContext;
27456
+ };
27457
+ _commonLogger: ILogger;
27458
+ readonly _methodContext: {};
27459
+ readonly _executionContext: {};
27460
+ log: (topic: string, ...args: any[]) => Promise<void>;
27461
+ debug: (topic: string, ...args: any[]) => Promise<void>;
27462
+ info: (topic: string, ...args: any[]) => Promise<void>;
27463
+ warn: (topic: string, ...args: any[]) => Promise<void>;
27464
+ setLogger: (logger: ILogger) => void;
27465
+ };
27138
27466
  private _registry;
27139
27467
  /**
27140
27468
  * Registers a new sizing schema.
@@ -27174,52 +27502,6 @@ declare class SizingSchemaService {
27174
27502
  get(key: SizingName): ISizingSchema;
27175
27503
  }
27176
27504
 
27177
- /**
27178
- * Service for managing risk schema registry.
27179
- *
27180
- * Uses ToolRegistry from functools-kit for type-safe schema storage.
27181
- * Risk profiles are registered via addRisk() and retrieved by name.
27182
- */
27183
- declare class RiskSchemaService {
27184
- readonly loggerService: LoggerService;
27185
- private _registry;
27186
- /**
27187
- * Registers a new risk schema.
27188
- *
27189
- * @param key - Unique risk profile name
27190
- * @param value - Risk schema configuration
27191
- * @throws Error if risk name already exists
27192
- */
27193
- register: (key: RiskName, value: IRiskSchema) => void;
27194
- /**
27195
- * Validates risk schema structure for required properties.
27196
- *
27197
- * Performs shallow validation to ensure all required properties exist
27198
- * and have correct types before registration in the registry.
27199
- *
27200
- * @param riskSchema - Risk schema to validate
27201
- * @throws Error if riskName is missing or not a string
27202
- */
27203
- private validateShallow;
27204
- /**
27205
- * Overrides an existing risk schema with partial updates.
27206
- *
27207
- * @param key - Risk name to override
27208
- * @param value - Partial schema updates
27209
- * @returns Updated risk schema
27210
- * @throws Error if risk name doesn't exist
27211
- */
27212
- override: (key: RiskName, value: Partial<IRiskSchema>) => IRiskSchema;
27213
- /**
27214
- * Retrieves a risk schema by name.
27215
- *
27216
- * @param key - Risk name
27217
- * @returns Risk schema configuration
27218
- * @throws Error if risk name doesn't exist
27219
- */
27220
- get: (key: RiskName) => IRiskSchema;
27221
- }
27222
-
27223
27505
  /**
27224
27506
  * Service for managing action schema registry.
27225
27507
  *
@@ -27254,7 +27536,22 @@ declare class RiskSchemaService {
27254
27536
  * ```
27255
27537
  */
27256
27538
  declare class ActionSchemaService {
27257
- readonly loggerService: LoggerService;
27539
+ readonly loggerService: {
27540
+ readonly methodContextService: {
27541
+ readonly context: IMethodContext;
27542
+ };
27543
+ readonly executionContextService: {
27544
+ readonly context: IExecutionContext;
27545
+ };
27546
+ _commonLogger: ILogger;
27547
+ readonly _methodContext: {};
27548
+ readonly _executionContext: {};
27549
+ log: (topic: string, ...args: any[]) => Promise<void>;
27550
+ debug: (topic: string, ...args: any[]) => Promise<void>;
27551
+ info: (topic: string, ...args: any[]) => Promise<void>;
27552
+ warn: (topic: string, ...args: any[]) => Promise<void>;
27553
+ setLogger: (logger: ILogger) => void;
27554
+ };
27258
27555
  private _registry;
27259
27556
  /**
27260
27557
  * Registers a new action schema.
@@ -27307,95 +27604,6 @@ declare class ActionSchemaService {
27307
27604
  get: (key: ActionName) => IActionSchema;
27308
27605
  }
27309
27606
 
27310
- /**
27311
- * Service for managing walker schema registry.
27312
- *
27313
- * Uses ToolRegistry from functools-kit for type-safe schema storage.
27314
- * Walkers are registered via addWalker() and retrieved by name.
27315
- */
27316
- declare class WalkerSchemaService {
27317
- readonly loggerService: LoggerService;
27318
- private _registry;
27319
- /**
27320
- * Registers a new walker schema.
27321
- *
27322
- * @param key - Unique walker name
27323
- * @param value - Walker schema configuration
27324
- * @throws Error if walker name already exists
27325
- */
27326
- register: (key: WalkerName, value: IWalkerSchema) => void;
27327
- /**
27328
- * Validates walker schema structure for required properties.
27329
- *
27330
- * Performs shallow validation to ensure all required properties exist
27331
- * and have correct types before registration in the registry.
27332
- *
27333
- * @param walkerSchema - Walker schema to validate
27334
- * @throws Error if walkerName is missing or not a string
27335
- * @throws Error if exchangeName is missing or not a string
27336
- * @throws Error if frameName is missing or not a string
27337
- * @throws Error if strategies is missing or not an array
27338
- * @throws Error if strategies array is empty
27339
- */
27340
- private validateShallow;
27341
- /**
27342
- * Overrides an existing walker schema with partial updates.
27343
- *
27344
- * @param key - Walker name to override
27345
- * @param value - Partial schema updates
27346
- * @returns Updated walker schema
27347
- * @throws Error if walker name doesn't exist
27348
- */
27349
- override: (key: WalkerName, value: Partial<IWalkerSchema>) => IWalkerSchema;
27350
- /**
27351
- * Retrieves a walker schema by name.
27352
- *
27353
- * @param key - Walker name
27354
- * @returns Walker schema configuration
27355
- * @throws Error if walker name doesn't exist
27356
- */
27357
- get: (key: WalkerName) => IWalkerSchema;
27358
- }
27359
-
27360
- /**
27361
- * Private service for backtest orchestration using async generators.
27362
- *
27363
- * Flow:
27364
- * 1. Get timeframes from frame service
27365
- * 2. Iterate through timeframes calling tick()
27366
- * 3. When signal opens: fetch candles and call backtest()
27367
- * 4. Skip timeframes until signal closes
27368
- * 5. Yield closed result and continue
27369
- *
27370
- * Memory efficient: streams results without array accumulation.
27371
- * Supports early termination via break in consumer.
27372
- */
27373
- declare class BacktestLogicPrivateService {
27374
- readonly loggerService: LoggerService;
27375
- readonly strategyCoreService: StrategyCoreService;
27376
- readonly exchangeCoreService: ExchangeCoreService;
27377
- readonly frameCoreService: FrameCoreService;
27378
- readonly methodContextService: {
27379
- readonly context: IMethodContext;
27380
- };
27381
- readonly actionCoreService: ActionCoreService;
27382
- /**
27383
- * Runs backtest for a symbol, streaming closed signals as async generator.
27384
- *
27385
- * @param symbol - Trading pair symbol (e.g., "BTCUSDT")
27386
- * @yields Closed signal results with PNL
27387
- *
27388
- * @example
27389
- * ```typescript
27390
- * for await (const result of backtestLogic.run("BTCUSDT")) {
27391
- * console.log(result.closeReason, result.pnl.pnlPercentage);
27392
- * if (result.pnl.pnlPercentage < -10) break; // Early termination
27393
- * }
27394
- * ```
27395
- */
27396
- run(symbol: string): AsyncGenerator<IStrategyTickResultScheduled | IStrategyTickResultOpened | IStrategyTickResultClosed | IStrategyTickResultCancelled, void, any>;
27397
- }
27398
-
27399
27607
  /**
27400
27608
  * Private service for live trading orchestration using async generators.
27401
27609
  *
@@ -27441,69 +27649,6 @@ declare class LiveLogicPrivateService {
27441
27649
  run(symbol: string): AsyncGenerator<IStrategyTickResultOpened | IStrategyTickResultClosed | IStrategyTickResultCancelled, void, unknown>;
27442
27650
  }
27443
27651
 
27444
- /**
27445
- * Type definition for public BacktestLogic service.
27446
- * Omits private dependencies from BacktestLogicPrivateService.
27447
- */
27448
- type IBacktestLogicPrivateService = Omit<BacktestLogicPrivateService, keyof {
27449
- loggerService: never;
27450
- strategyCoreService: never;
27451
- exchangeCoreService: never;
27452
- frameCoreService: never;
27453
- actionCoreService: never;
27454
- methodContextService: never;
27455
- }>;
27456
- /**
27457
- * Type definition for BacktestLogicPublicService.
27458
- * Maps all keys of IBacktestLogicPrivateService to any type.
27459
- */
27460
- type TBacktestLogicPrivateService = {
27461
- [key in keyof IBacktestLogicPrivateService]: any;
27462
- };
27463
- /**
27464
- * Public service for backtest orchestration with context management.
27465
- *
27466
- * Wraps BacktestLogicPrivateService with MethodContextService to provide
27467
- * implicit context propagation for strategyName, exchangeName, and frameName.
27468
- *
27469
- * This allows getCandles(), getSignal(), and other functions to work without
27470
- * explicit context parameters.
27471
- *
27472
- * @example
27473
- * ```typescript
27474
- * const backtestLogicPublicService = inject(TYPES.backtestLogicPublicService);
27475
- *
27476
- * for await (const result of backtestLogicPublicService.run("BTCUSDT", {
27477
- * strategyName: "my-strategy",
27478
- * exchangeName: "my-exchange",
27479
- * frameName: "1d-backtest",
27480
- * })) {
27481
- * if (result.action === "closed") {
27482
- * console.log("PNL:", result.pnl.profit);
27483
- * }
27484
- * }
27485
- * ```
27486
- */
27487
- declare class BacktestLogicPublicService implements TBacktestLogicPrivateService {
27488
- private readonly loggerService;
27489
- private readonly backtestLogicPrivateService;
27490
- /**
27491
- * Runs backtest for a symbol with context propagation.
27492
- *
27493
- * Streams closed signals as async generator. Context is automatically
27494
- * injected into all framework functions called during iteration.
27495
- *
27496
- * @param symbol - Trading pair symbol (e.g., "BTCUSDT")
27497
- * @param context - Execution context with strategy, exchange, and frame names
27498
- * @returns Async generator yielding closed signals with PNL
27499
- */
27500
- run: (symbol: string, context: {
27501
- strategyName: StrategyName;
27502
- exchangeName: ExchangeName;
27503
- frameName: FrameName;
27504
- }) => AsyncGenerator<IStrategyTickResultScheduled | IStrategyTickResultOpened | IStrategyTickResultClosed | IStrategyTickResultCancelled, void, any>;
27505
- }
27506
-
27507
27652
  /**
27508
27653
  * Type definition for public LiveLogic service.
27509
27654
  * Omits private dependencies from LiveLogicPrivateService.
@@ -28387,7 +28532,7 @@ declare class ColumnValidationService {
28387
28532
  * Features:
28388
28533
  * - Listens to backtest signal events via signalBacktestEmitter
28389
28534
  * - Logs all tick event types with full signal details
28390
- * - Stores events in Report.writeData() for persistence
28535
+ * - Stores events in ReportWriter.writeData() for persistence
28391
28536
  * - Protected against multiple subscriptions using singleshot
28392
28537
  *
28393
28538
  * @example
@@ -28459,7 +28604,7 @@ declare class BacktestReportService {
28459
28604
  * Features:
28460
28605
  * - Listens to live signal events via signalLiveEmitter
28461
28606
  * - Logs all tick event types with full signal details
28462
- * - Stores events in Report.writeData() for persistence
28607
+ * - Stores events in ReportWriter.writeData() for persistence
28463
28608
  * - Protected against multiple subscriptions using singleshot
28464
28609
  *
28465
28610
  * @example
@@ -28532,7 +28677,7 @@ declare class LiveReportService {
28532
28677
  * - Listens to signal events via signalEmitter
28533
28678
  * - Logs scheduled, opened (from scheduled), and cancelled events
28534
28679
  * - Calculates duration between scheduling and execution/cancellation
28535
- * - Stores events in Report.writeData() for schedule tracking
28680
+ * - Stores events in ReportWriter.writeData() for schedule tracking
28536
28681
  * - Protected against multiple subscriptions using singleshot
28537
28682
  *
28538
28683
  * @example
@@ -28604,7 +28749,7 @@ declare class ScheduleReportService {
28604
28749
  * Features:
28605
28750
  * - Listens to performance events via performanceEmitter
28606
28751
  * - Logs all timing metrics with duration and metadata
28607
- * - Stores events in Report.writeData() for performance analysis
28752
+ * - Stores events in ReportWriter.writeData() for performance analysis
28608
28753
  * - Protected against multiple subscriptions using singleshot
28609
28754
  *
28610
28755
  * @example
@@ -28676,7 +28821,7 @@ declare class PerformanceReportService {
28676
28821
  * - Listens to walker events via walkerEmitter
28677
28822
  * - Logs each strategy test result with metrics and statistics
28678
28823
  * - Tracks best strategy and optimization progress
28679
- * - Stores events in Report.writeData() for optimization analysis
28824
+ * - Stores events in ReportWriter.writeData() for optimization analysis
28680
28825
  * - Protected against multiple subscriptions using singleshot
28681
28826
  *
28682
28827
  * @example
@@ -28747,7 +28892,7 @@ declare class WalkerReportService {
28747
28892
  * Features:
28748
28893
  * - Listens to signal events via signalEmitter
28749
28894
  * - Logs only closed signals with PNL data
28750
- * - Stores events in Report.writeData() for heatmap generation
28895
+ * - Stores events in ReportWriter.writeData() for heatmap generation
28751
28896
  * - Protected against multiple subscriptions using singleshot
28752
28897
  *
28753
28898
  * @example
@@ -28820,7 +28965,7 @@ declare class HeatReportService {
28820
28965
  * - Listens to partial profit events via partialProfitSubject
28821
28966
  * - Listens to partial loss events via partialLossSubject
28822
28967
  * - Logs all partial exit events with level and price information
28823
- * - Stores events in Report.writeData() for persistence
28968
+ * - Stores events in ReportWriter.writeData() for persistence
28824
28969
  * - Protected against multiple subscriptions using singleshot
28825
28970
  *
28826
28971
  * @example
@@ -28899,7 +29044,7 @@ declare class PartialReportService {
28899
29044
  * Features:
28900
29045
  * - Listens to breakeven events via breakevenSubject
28901
29046
  * - Logs all breakeven achievements with full signal details
28902
- * - Stores events in Report.writeData() for persistence
29047
+ * - Stores events in ReportWriter.writeData() for persistence
28903
29048
  * - Protected against multiple subscriptions using singleshot
28904
29049
  *
28905
29050
  * @example
@@ -28970,7 +29115,7 @@ declare class BreakevenReportService {
28970
29115
  * Features:
28971
29116
  * - Listens to risk rejection events via riskSubject
28972
29117
  * - Logs all rejected signals with reason and pending signal details
28973
- * - Stores events in Report.writeData() for risk tracking
29118
+ * - Stores events in ReportWriter.writeData() for risk tracking
28974
29119
  * - Protected against multiple subscriptions using singleshot
28975
29120
  *
28976
29121
  * @example
@@ -29044,14 +29189,29 @@ declare class RiskReportService {
29044
29189
  *
29045
29190
  * Lifecycle:
29046
29191
  * - Call subscribe() to enable event logging
29047
- * - Events are written via Report.writeData() with "strategy" category
29192
+ * - Events are written via ReportWriter.writeData() with "strategy" category
29048
29193
  * - Call unsubscribe() to disable event logging
29049
29194
  *
29050
29195
  * @see StrategyMarkdownService for in-memory event accumulation and markdown report generation
29051
29196
  * @see Report for the underlying persistence mechanism
29052
29197
  */
29053
29198
  declare class StrategyReportService {
29054
- readonly loggerService: LoggerService;
29199
+ readonly loggerService: {
29200
+ readonly methodContextService: {
29201
+ readonly context: IMethodContext;
29202
+ };
29203
+ readonly executionContextService: {
29204
+ readonly context: IExecutionContext;
29205
+ };
29206
+ _commonLogger: ILogger;
29207
+ readonly _methodContext: {};
29208
+ readonly _executionContext: {};
29209
+ log: (topic: string, ...args: any[]) => Promise<void>;
29210
+ debug: (topic: string, ...args: any[]) => Promise<void>;
29211
+ info: (topic: string, ...args: any[]) => Promise<void>;
29212
+ warn: (topic: string, ...args: any[]) => Promise<void>;
29213
+ setLogger: (logger: ILogger) => void;
29214
+ };
29055
29215
  /**
29056
29216
  * Logs a cancel-scheduled event when a scheduled signal is cancelled.
29057
29217
  */
@@ -29152,7 +29312,7 @@ declare class StrategyReportService {
29152
29312
  * - Listens to sync events via syncSubject
29153
29313
  * - Logs signal-open events (scheduled limit order filled) with full signal details
29154
29314
  * - Logs signal-close events (position exited) with PNL and close reason
29155
- * - Stores events in Report.writeData() for persistence
29315
+ * - Stores events in ReportWriter.writeData() for persistence
29156
29316
  * - Protected against multiple subscriptions using singleshot
29157
29317
  *
29158
29318
  * @example
@@ -29219,7 +29379,7 @@ declare class SyncReportService {
29219
29379
  * Service for logging highest profit events to the JSONL report database.
29220
29380
  *
29221
29381
  * Listens to highestProfitSubject and writes each new price record to
29222
- * Report.writeData() for persistence and analytics.
29382
+ * ReportWriter.writeData() for persistence and analytics.
29223
29383
  */
29224
29384
  declare class HighestProfitReportService {
29225
29385
  private readonly loggerService;
@@ -29227,7 +29387,7 @@ declare class HighestProfitReportService {
29227
29387
  * Handles a single `HighestProfitContract` event emitted by `highestProfitSubject`.
29228
29388
  *
29229
29389
  * Writes a JSONL record to the `"highest_profit"` report database via
29230
- * `Report.writeData`, capturing the full signal snapshot at the moment
29390
+ * `ReportWriter.writeData`, capturing the full signal snapshot at the moment
29231
29391
  * the new profit record was set:
29232
29392
  * - `timestamp`, `symbol`, `strategyName`, `exchangeName`, `frameName`, `backtest`
29233
29393
  * - `signalId`, `position`, `currentPrice`
@@ -29281,7 +29441,7 @@ declare class HighestProfitReportService {
29281
29441
  * Service for logging max drawdown events to the JSONL report database.
29282
29442
  *
29283
29443
  * Listens to maxDrawdownSubject and writes each new drawdown record to
29284
- * Report.writeData() for persistence and analytics.
29444
+ * ReportWriter.writeData() for persistence and analytics.
29285
29445
  */
29286
29446
  declare class MaxDrawdownReportService {
29287
29447
  private readonly loggerService;
@@ -29289,7 +29449,7 @@ declare class MaxDrawdownReportService {
29289
29449
  * Handles a single `MaxDrawdownContract` event emitted by `maxDrawdownSubject`.
29290
29450
  *
29291
29451
  * Writes a JSONL record to the `"max_drawdown"` report database via
29292
- * `Report.writeData`, capturing the full signal snapshot at the moment
29452
+ * `ReportWriter.writeData`, capturing the full signal snapshot at the moment
29293
29453
  * the new drawdown record was set:
29294
29454
  * - `timestamp`, `symbol`, `strategyName`, `exchangeName`, `frameName`, `backtest`
29295
29455
  * - `signalId`, `position`, `currentPrice`
@@ -29374,6 +29534,28 @@ declare const backtest: {
29374
29534
  breakevenGlobalService: BreakevenGlobalService;
29375
29535
  timeMetaService: TimeMetaService;
29376
29536
  priceMetaService: PriceMetaService;
29537
+ contextMetaService: {
29538
+ readonly loggerService: {
29539
+ readonly methodContextService: {
29540
+ readonly context: IMethodContext;
29541
+ };
29542
+ readonly executionContextService: {
29543
+ readonly context: IExecutionContext;
29544
+ };
29545
+ _commonLogger: ILogger;
29546
+ readonly _methodContext: {};
29547
+ readonly _executionContext: {};
29548
+ log: (topic: string, ...args: any[]) => Promise<void>;
29549
+ debug: (topic: string, ...args: any[]) => Promise<void>;
29550
+ info: (topic: string, ...args: any[]) => Promise<void>;
29551
+ warn: (topic: string, ...args: any[]) => Promise<void>;
29552
+ setLogger: (logger: ILogger) => void;
29553
+ };
29554
+ readonly executionContextService: {
29555
+ readonly context: IExecutionContext;
29556
+ };
29557
+ getContextTimestamp: () => number;
29558
+ };
29377
29559
  exchangeCoreService: ExchangeCoreService;
29378
29560
  strategyCoreService: StrategyCoreService;
29379
29561
  actionCoreService: ActionCoreService;
@@ -29399,7 +29581,22 @@ declare const backtest: {
29399
29581
  methodContextService: {
29400
29582
  readonly context: IMethodContext;
29401
29583
  };
29402
- loggerService: LoggerService;
29584
+ loggerService: {
29585
+ readonly methodContextService: {
29586
+ readonly context: IMethodContext;
29587
+ };
29588
+ readonly executionContextService: {
29589
+ readonly context: IExecutionContext;
29590
+ };
29591
+ _commonLogger: ILogger;
29592
+ readonly _methodContext: {};
29593
+ readonly _executionContext: {};
29594
+ log: (topic: string, ...args: any[]) => Promise<void>;
29595
+ debug: (topic: string, ...args: any[]) => Promise<void>;
29596
+ info: (topic: string, ...args: any[]) => Promise<void>;
29597
+ warn: (topic: string, ...args: any[]) => Promise<void>;
29598
+ setLogger: (logger: ILogger) => void;
29599
+ };
29403
29600
  };
29404
29601
 
29405
29602
  interface Signal$2 extends ISignalDto {