backtest-kit 1.1.9 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/types.d.ts CHANGED
@@ -2,6 +2,41 @@ import * as di_scoped from 'di-scoped';
2
2
  import * as functools_kit from 'functools-kit';
3
3
  import { Subject } from 'functools-kit';
4
4
 
5
+ declare const GLOBAL_CONFIG: {
6
+ /**
7
+ * Time to wait for scheduled signal to activate (in minutes)
8
+ * If signal does not activate within this time, it will be cancelled.
9
+ */
10
+ CC_SCHEDULE_AWAIT_MINUTES: number;
11
+ /**
12
+ * Number of candles to use for average price calculation (VWAP)
13
+ * Default: 5 candles (last 5 minutes when using 1m interval)
14
+ */
15
+ CC_AVG_PRICE_CANDLES_COUNT: number;
16
+ /**
17
+ * Minimum TakeProfit distance from priceOpen (percentage)
18
+ * Must be greater than trading fees to ensure profitable trades
19
+ * Default: 0.3% (covers 2×0.1% fees + minimum profit margin)
20
+ */
21
+ CC_MIN_TAKEPROFIT_DISTANCE_PERCENT: number;
22
+ /**
23
+ * Maximum StopLoss distance from priceOpen (percentage)
24
+ * Prevents catastrophic losses from extreme StopLoss values
25
+ * Default: 20% (one signal cannot lose more than 20% of position)
26
+ */
27
+ CC_MAX_STOPLOSS_DISTANCE_PERCENT: number;
28
+ /**
29
+ * Maximum signal lifetime in minutes
30
+ * Prevents eternal signals that block risk limits for weeks/months
31
+ * Default: 1440 minutes (1 day)
32
+ */
33
+ CC_MAX_SIGNAL_LIFETIME_MINUTES: number;
34
+ };
35
+ /**
36
+ * Type for global configuration object.
37
+ */
38
+ type GlobalConfig = typeof GLOBAL_CONFIG;
39
+
5
40
  /**
6
41
  * Interface representing a logging mechanism for the swarm system.
7
42
  * Provides methods to record messages at different severity levels, used across components like agents, sessions, states, storage, swarms, history, embeddings, completions, and policies.
@@ -48,6 +83,18 @@ interface ILogger {
48
83
  * ```
49
84
  */
50
85
  declare function setLogger(logger: ILogger): Promise<void>;
86
+ /**
87
+ * Sets global configuration parameters for the framework.
88
+ * @param config - Partial configuration object to override default settings
89
+ *
90
+ * @example
91
+ * ```typescript
92
+ * setConfig({
93
+ * CC_SCHEDULE_AWAIT_MINUTES: 90,
94
+ * });
95
+ * ```
96
+ */
97
+ declare function setConfig(config: Partial<GlobalConfig>): Promise<void>;
51
98
 
52
99
  /**
53
100
  * Execution context containing runtime parameters for strategy/exchange operations.
@@ -304,7 +351,7 @@ interface IFrame {
304
351
  * @param symbol - Trading pair symbol (unused, for API consistency)
305
352
  * @returns Promise resolving to array of Date objects
306
353
  */
307
- getTimeframe: (symbol: string) => Promise<Date[]>;
354
+ getTimeframe: (symbol: string, frameName: FrameName) => Promise<Date[]>;
308
355
  }
309
356
  /**
310
357
  * Unique identifier for a frame schema.
@@ -523,14 +570,28 @@ interface ISignalRow extends ISignalDto {
523
570
  exchangeName: ExchangeName;
524
571
  /** Unique strategy identifier for execution */
525
572
  strategyName: StrategyName;
526
- /** Signal creation timestamp in milliseconds */
527
- timestamp: number;
573
+ /** Signal creation timestamp in milliseconds (when signal was first created/scheduled) */
574
+ scheduledAt: number;
575
+ /** Pending timestamp in milliseconds (when position became pending/active at priceOpen) */
576
+ pendingAt: number;
528
577
  /** Trading pair symbol (e.g., "BTCUSDT") */
529
578
  symbol: string;
579
+ /** Internal runtime marker for scheduled signals */
580
+ _isScheduled: boolean;
581
+ }
582
+ /**
583
+ * Scheduled signal row for delayed entry at specific price.
584
+ * Inherits from ISignalRow - represents a signal waiting for price to reach priceOpen.
585
+ * Once price reaches priceOpen, will be converted to regular _pendingSignal.
586
+ * Note: pendingAt will be set to scheduledAt until activation, then updated to actual pending time.
587
+ */
588
+ interface IScheduledSignalRow extends ISignalRow {
589
+ /** Entry price for the position */
590
+ priceOpen: number;
530
591
  }
531
592
  /**
532
593
  * Optional lifecycle callbacks for signal events.
533
- * Called when signals are opened, active, idle, or closed.
594
+ * Called when signals are opened, active, idle, closed, scheduled, or cancelled.
534
595
  */
535
596
  interface IStrategyCallbacks {
536
597
  /** Called on every tick with the result */
@@ -543,6 +604,10 @@ interface IStrategyCallbacks {
543
604
  onIdle: (symbol: string, currentPrice: number, backtest: boolean) => void;
544
605
  /** Called when signal is closed with final price */
545
606
  onClose: (symbol: string, data: ISignalRow, priceClose: number, backtest: boolean) => void;
607
+ /** Called when scheduled signal is created (delayed entry) */
608
+ onSchedule: (symbol: string, data: IScheduledSignalRow, currentPrice: number, backtest: boolean) => void;
609
+ /** Called when scheduled signal is cancelled without opening position */
610
+ onCancel: (symbol: string, data: IScheduledSignalRow, currentPrice: number, backtest: boolean) => void;
546
611
  }
547
612
  /**
548
613
  * Strategy schema registered via addStrategy().
@@ -555,7 +620,11 @@ interface IStrategySchema {
555
620
  note?: string;
556
621
  /** Minimum interval between getSignal calls (throttling) */
557
622
  interval: SignalInterval;
558
- /** Signal generation function (returns null if no signal, validated DTO if signal) */
623
+ /**
624
+ * Signal generation function (returns null if no signal, validated DTO if signal).
625
+ * If priceOpen is provided - becomes scheduled signal waiting for price to reach entry point.
626
+ * If priceOpen is omitted - opens immediately at current price.
627
+ */
559
628
  getSignal: (symbol: string) => Promise<ISignalDto | null>;
560
629
  /** Optional lifecycle event callbacks (onOpen, onClose) */
561
630
  callbacks?: Partial<IStrategyCallbacks>;
@@ -596,6 +665,24 @@ interface IStrategyTickResultIdle {
596
665
  /** Current VWAP price during idle state */
597
666
  currentPrice: number;
598
667
  }
668
+ /**
669
+ * Tick result: scheduled signal created, waiting for price to reach entry point.
670
+ * Triggered when getSignal returns signal with priceOpen specified.
671
+ */
672
+ interface IStrategyTickResultScheduled {
673
+ /** Discriminator for type-safe union */
674
+ action: "scheduled";
675
+ /** Scheduled signal waiting for activation */
676
+ signal: IScheduledSignalRow;
677
+ /** Strategy name for tracking */
678
+ strategyName: StrategyName;
679
+ /** Exchange name for tracking */
680
+ exchangeName: ExchangeName;
681
+ /** Trading pair symbol (e.g., "BTCUSDT") */
682
+ symbol: string;
683
+ /** Current VWAP price when scheduled signal created */
684
+ currentPrice: number;
685
+ }
599
686
  /**
600
687
  * Tick result: new signal just created.
601
688
  * Triggered after getSignal validation and persistence.
@@ -656,15 +743,35 @@ interface IStrategyTickResultClosed {
656
743
  /** Trading pair symbol (e.g., "BTCUSDT") */
657
744
  symbol: string;
658
745
  }
746
+ /**
747
+ * Tick result: scheduled signal cancelled without opening position.
748
+ * Occurs when scheduled signal doesn't activate or hits stop loss before entry.
749
+ */
750
+ interface IStrategyTickResultCancelled {
751
+ /** Discriminator for type-safe union */
752
+ action: "cancelled";
753
+ /** Cancelled scheduled signal */
754
+ signal: IScheduledSignalRow;
755
+ /** Final VWAP price at cancellation */
756
+ currentPrice: number;
757
+ /** Unix timestamp in milliseconds when signal cancelled */
758
+ closeTimestamp: number;
759
+ /** Strategy name for tracking */
760
+ strategyName: StrategyName;
761
+ /** Exchange name for tracking */
762
+ exchangeName: ExchangeName;
763
+ /** Trading pair symbol (e.g., "BTCUSDT") */
764
+ symbol: string;
765
+ }
659
766
  /**
660
767
  * Discriminated union of all tick results.
661
768
  * Use type guards: `result.action === "closed"` for type safety.
662
769
  */
663
- type IStrategyTickResult = IStrategyTickResultIdle | IStrategyTickResultOpened | IStrategyTickResultActive | IStrategyTickResultClosed;
770
+ type IStrategyTickResult = IStrategyTickResultIdle | IStrategyTickResultScheduled | IStrategyTickResultOpened | IStrategyTickResultActive | IStrategyTickResultClosed | IStrategyTickResultCancelled;
664
771
  /**
665
- * Backtest always returns closed result (TP/SL or time_expired).
772
+ * Backtest returns closed result (TP/SL or time_expired) or cancelled result (scheduled signal never activated).
666
773
  */
667
- type IStrategyBacktestResult = IStrategyTickResultClosed;
774
+ type IStrategyBacktestResult = IStrategyTickResultClosed | IStrategyTickResultCancelled;
668
775
  /**
669
776
  * Strategy interface implemented by ClientStrategy.
670
777
  * Defines core strategy execution methods.
@@ -682,6 +789,9 @@ interface IStrategy {
682
789
  * Fast backtest using historical candles.
683
790
  * Iterates through candles, calculates VWAP, checks TP/SL on each candle.
684
791
  *
792
+ * For scheduled signals: first monitors activation/cancellation,
793
+ * then if activated continues with TP/SL monitoring.
794
+ *
685
795
  * @param candles - Array of historical candle data
686
796
  * @returns Promise resolving to closed result (always completes signal)
687
797
  */
@@ -2437,7 +2547,7 @@ interface IHeatmapStatistics {
2437
2547
  * Contains all information about a tick event regardless of action type.
2438
2548
  */
2439
2549
  interface TickEvent {
2440
- /** Event timestamp in milliseconds */
2550
+ /** Event timestamp in milliseconds (pendingAt for opened/closed events) */
2441
2551
  timestamp: number;
2442
2552
  /** Event action type */
2443
2553
  action: "idle" | "opened" | "active" | "closed";
@@ -2658,6 +2768,199 @@ declare class LiveMarkdownService {
2658
2768
  protected init: (() => Promise<void>) & functools_kit.ISingleshotClearable;
2659
2769
  }
2660
2770
 
2771
+ /**
2772
+ * Unified scheduled signal event data for report generation.
2773
+ * Contains all information about scheduled and cancelled events.
2774
+ */
2775
+ interface ScheduledEvent {
2776
+ /** Event timestamp in milliseconds (scheduledAt for scheduled/cancelled events) */
2777
+ timestamp: number;
2778
+ /** Event action type */
2779
+ action: "scheduled" | "cancelled";
2780
+ /** Trading pair symbol */
2781
+ symbol: string;
2782
+ /** Signal ID */
2783
+ signalId: string;
2784
+ /** Position type */
2785
+ position: string;
2786
+ /** Signal note */
2787
+ note?: string;
2788
+ /** Current market price */
2789
+ currentPrice: number;
2790
+ /** Scheduled entry price */
2791
+ priceOpen: number;
2792
+ /** Take profit price */
2793
+ takeProfit: number;
2794
+ /** Stop loss price */
2795
+ stopLoss: number;
2796
+ /** Close timestamp (only for cancelled) */
2797
+ closeTimestamp?: number;
2798
+ /** Duration in minutes (only for cancelled) */
2799
+ duration?: number;
2800
+ }
2801
+ /**
2802
+ * Statistical data calculated from scheduled signals.
2803
+ *
2804
+ * Provides metrics for scheduled signal tracking and cancellation analysis.
2805
+ *
2806
+ * @example
2807
+ * ```typescript
2808
+ * const stats = await Schedule.getData("my-strategy");
2809
+ *
2810
+ * console.log(`Total events: ${stats.totalEvents}`);
2811
+ * console.log(`Scheduled signals: ${stats.totalScheduled}`);
2812
+ * console.log(`Cancelled signals: ${stats.totalCancelled}`);
2813
+ * console.log(`Cancellation rate: ${stats.cancellationRate}%`);
2814
+ *
2815
+ * // Access raw event data (includes scheduled, cancelled)
2816
+ * stats.eventList.forEach(event => {
2817
+ * if (event.action === "cancelled") {
2818
+ * console.log(`Cancelled signal: ${event.signalId}`);
2819
+ * }
2820
+ * });
2821
+ * ```
2822
+ */
2823
+ interface ScheduleStatistics {
2824
+ /** Array of all scheduled/cancelled events with full details */
2825
+ eventList: ScheduledEvent[];
2826
+ /** Total number of all events (includes scheduled, cancelled) */
2827
+ totalEvents: number;
2828
+ /** Total number of scheduled signals */
2829
+ totalScheduled: number;
2830
+ /** Total number of cancelled signals */
2831
+ totalCancelled: number;
2832
+ /** Cancellation rate as percentage (0-100), null if no scheduled signals. Lower is better. */
2833
+ cancellationRate: number | null;
2834
+ /** Average waiting time for cancelled signals in minutes, null if no cancelled signals */
2835
+ avgWaitTime: number | null;
2836
+ }
2837
+ /**
2838
+ * Service for generating and saving scheduled signals markdown reports.
2839
+ *
2840
+ * Features:
2841
+ * - Listens to scheduled and cancelled signal events via signalLiveEmitter
2842
+ * - Accumulates all events (scheduled, cancelled) per strategy
2843
+ * - Generates markdown tables with detailed event information
2844
+ * - Provides statistics (cancellation rate, average wait time)
2845
+ * - Saves reports to disk in logs/schedule/{strategyName}.md
2846
+ *
2847
+ * @example
2848
+ * ```typescript
2849
+ * const service = new ScheduleMarkdownService();
2850
+ *
2851
+ * // Service automatically subscribes to signalLiveEmitter on init
2852
+ * // No manual callback setup needed
2853
+ *
2854
+ * // Later: generate and save report
2855
+ * await service.dump("my-strategy");
2856
+ * ```
2857
+ */
2858
+ declare class ScheduleMarkdownService {
2859
+ /** Logger service for debug output */
2860
+ private readonly loggerService;
2861
+ /**
2862
+ * Memoized function to get or create ReportStorage for a strategy.
2863
+ * Each strategy gets its own isolated storage instance.
2864
+ */
2865
+ private getStorage;
2866
+ /**
2867
+ * Processes tick events and accumulates scheduled/cancelled events.
2868
+ * Should be called from signalLiveEmitter subscription.
2869
+ *
2870
+ * Processes only scheduled and cancelled event types.
2871
+ *
2872
+ * @param data - Tick result from strategy execution
2873
+ *
2874
+ * @example
2875
+ * ```typescript
2876
+ * const service = new ScheduleMarkdownService();
2877
+ * // Service automatically subscribes in init()
2878
+ * ```
2879
+ */
2880
+ private tick;
2881
+ /**
2882
+ * Gets statistical data from all scheduled signal events for a strategy.
2883
+ * Delegates to ReportStorage.getData().
2884
+ *
2885
+ * @param strategyName - Strategy name to get data for
2886
+ * @returns Statistical data object with all metrics
2887
+ *
2888
+ * @example
2889
+ * ```typescript
2890
+ * const service = new ScheduleMarkdownService();
2891
+ * const stats = await service.getData("my-strategy");
2892
+ * console.log(stats.cancellationRate, stats.avgWaitTime);
2893
+ * ```
2894
+ */
2895
+ getData: (strategyName: StrategyName) => Promise<ScheduleStatistics>;
2896
+ /**
2897
+ * Generates markdown report with all scheduled events for a strategy.
2898
+ * Delegates to ReportStorage.getReport().
2899
+ *
2900
+ * @param strategyName - Strategy name to generate report for
2901
+ * @returns Markdown formatted report string with table of all events
2902
+ *
2903
+ * @example
2904
+ * ```typescript
2905
+ * const service = new ScheduleMarkdownService();
2906
+ * const markdown = await service.getReport("my-strategy");
2907
+ * console.log(markdown);
2908
+ * ```
2909
+ */
2910
+ getReport: (strategyName: StrategyName) => Promise<string>;
2911
+ /**
2912
+ * Saves strategy report to disk.
2913
+ * Creates directory if it doesn't exist.
2914
+ * Delegates to ReportStorage.dump().
2915
+ *
2916
+ * @param strategyName - Strategy name to save report for
2917
+ * @param path - Directory path to save report (default: "./logs/schedule")
2918
+ *
2919
+ * @example
2920
+ * ```typescript
2921
+ * const service = new ScheduleMarkdownService();
2922
+ *
2923
+ * // Save to default path: ./logs/schedule/my-strategy.md
2924
+ * await service.dump("my-strategy");
2925
+ *
2926
+ * // Save to custom path: ./custom/path/my-strategy.md
2927
+ * await service.dump("my-strategy", "./custom/path");
2928
+ * ```
2929
+ */
2930
+ dump: (strategyName: StrategyName, path?: string) => Promise<void>;
2931
+ /**
2932
+ * Clears accumulated event data from storage.
2933
+ * If strategyName is provided, clears only that strategy's data.
2934
+ * If strategyName is omitted, clears all strategies' data.
2935
+ *
2936
+ * @param strategyName - Optional strategy name to clear specific strategy data
2937
+ *
2938
+ * @example
2939
+ * ```typescript
2940
+ * const service = new ScheduleMarkdownService();
2941
+ *
2942
+ * // Clear specific strategy data
2943
+ * await service.clear("my-strategy");
2944
+ *
2945
+ * // Clear all strategies' data
2946
+ * await service.clear();
2947
+ * ```
2948
+ */
2949
+ clear: (strategyName?: StrategyName) => Promise<void>;
2950
+ /**
2951
+ * Initializes the service by subscribing to live signal events.
2952
+ * Uses singleshot to ensure initialization happens only once.
2953
+ * Automatically called on first use.
2954
+ *
2955
+ * @example
2956
+ * ```typescript
2957
+ * const service = new ScheduleMarkdownService();
2958
+ * await service.init(); // Subscribe to live events
2959
+ * ```
2960
+ */
2961
+ protected init: (() => Promise<void>) & functools_kit.ISingleshotClearable;
2962
+ }
2963
+
2661
2964
  /**
2662
2965
  * Aggregated statistics for a specific metric type.
2663
2966
  */
@@ -3280,7 +3583,7 @@ declare class BacktestUtils {
3280
3583
  strategyName: string;
3281
3584
  exchangeName: string;
3282
3585
  frameName: string;
3283
- }) => AsyncGenerator<IStrategyTickResultClosed, void, unknown>;
3586
+ }) => AsyncGenerator<IStrategyBacktestResult, void, unknown>;
3284
3587
  /**
3285
3588
  * Runs backtest in background without yielding results.
3286
3589
  *
@@ -3413,7 +3716,7 @@ declare class LiveUtils {
3413
3716
  run: (symbol: string, context: {
3414
3717
  strategyName: string;
3415
3718
  exchangeName: string;
3416
- }) => AsyncGenerator<IStrategyTickResultOpened | IStrategyTickResultClosed, void, unknown>;
3719
+ }) => AsyncGenerator<IStrategyTickResultOpened | IStrategyTickResultClosed | IStrategyTickResultCancelled, void, unknown>;
3417
3720
  /**
3418
3721
  * Runs live trading in background without yielding results.
3419
3722
  *
@@ -3499,6 +3802,105 @@ declare class LiveUtils {
3499
3802
  */
3500
3803
  declare const Live: LiveUtils;
3501
3804
 
3805
+ /**
3806
+ * Utility class for scheduled signals reporting operations.
3807
+ *
3808
+ * Provides simplified access to scheduleMarkdownService with logging.
3809
+ * Exported as singleton instance for convenient usage.
3810
+ *
3811
+ * Features:
3812
+ * - Track scheduled signals in queue
3813
+ * - Track cancelled signals
3814
+ * - Calculate cancellation rate and average wait time
3815
+ * - Generate markdown reports
3816
+ *
3817
+ * @example
3818
+ * ```typescript
3819
+ * import { Schedule } from "./classes/Schedule";
3820
+ *
3821
+ * // Get scheduled signals statistics
3822
+ * const stats = await Schedule.getData("my-strategy");
3823
+ * console.log(`Cancellation rate: ${stats.cancellationRate}%`);
3824
+ * console.log(`Average wait time: ${stats.avgWaitTime} minutes`);
3825
+ *
3826
+ * // Generate and save report
3827
+ * await Schedule.dump("my-strategy");
3828
+ * ```
3829
+ */
3830
+ declare class ScheduleUtils {
3831
+ /**
3832
+ * Gets statistical data from all scheduled signal events for a strategy.
3833
+ *
3834
+ * @param strategyName - Strategy name to get data for
3835
+ * @returns Promise resolving to statistical data object
3836
+ *
3837
+ * @example
3838
+ * ```typescript
3839
+ * const stats = await Schedule.getData("my-strategy");
3840
+ * console.log(stats.cancellationRate, stats.avgWaitTime);
3841
+ * ```
3842
+ */
3843
+ getData: (strategyName: StrategyName) => Promise<ScheduleStatistics>;
3844
+ /**
3845
+ * Generates markdown report with all scheduled events for a strategy.
3846
+ *
3847
+ * @param strategyName - Strategy name to generate report for
3848
+ * @returns Promise resolving to markdown formatted report string
3849
+ *
3850
+ * @example
3851
+ * ```typescript
3852
+ * const markdown = await Schedule.getReport("my-strategy");
3853
+ * console.log(markdown);
3854
+ * ```
3855
+ */
3856
+ getReport: (strategyName: StrategyName) => Promise<string>;
3857
+ /**
3858
+ * Saves strategy report to disk.
3859
+ *
3860
+ * @param strategyName - Strategy name to save report for
3861
+ * @param path - Optional directory path to save report (default: "./logs/schedule")
3862
+ *
3863
+ * @example
3864
+ * ```typescript
3865
+ * // Save to default path: ./logs/schedule/my-strategy.md
3866
+ * await Schedule.dump("my-strategy");
3867
+ *
3868
+ * // Save to custom path: ./custom/path/my-strategy.md
3869
+ * await Schedule.dump("my-strategy", "./custom/path");
3870
+ * ```
3871
+ */
3872
+ dump: (strategyName: StrategyName, path?: string) => Promise<void>;
3873
+ /**
3874
+ * Clears accumulated scheduled signal data from storage.
3875
+ * If strategyName is provided, clears only that strategy's data.
3876
+ * If strategyName is omitted, clears all strategies' data.
3877
+ *
3878
+ * @param strategyName - Optional strategy name to clear specific strategy data
3879
+ *
3880
+ * @example
3881
+ * ```typescript
3882
+ * // Clear specific strategy data
3883
+ * await Schedule.clear("my-strategy");
3884
+ *
3885
+ * // Clear all strategies' data
3886
+ * await Schedule.clear();
3887
+ * ```
3888
+ */
3889
+ clear: (strategyName?: StrategyName) => Promise<void>;
3890
+ }
3891
+ /**
3892
+ * Singleton instance of ScheduleUtils for convenient scheduled signals reporting.
3893
+ *
3894
+ * @example
3895
+ * ```typescript
3896
+ * import { Schedule } from "./classes/Schedule";
3897
+ *
3898
+ * const stats = await Schedule.getData("my-strategy");
3899
+ * console.log("Cancellation rate:", stats.cancellationRate);
3900
+ * ```
3901
+ */
3902
+ declare const Schedule: ScheduleUtils;
3903
+
3502
3904
  /**
3503
3905
  * Performance class provides static methods for performance metrics analysis.
3504
3906
  *
@@ -4128,7 +4530,8 @@ declare class ClientExchange implements IExchange {
4128
4530
  */
4129
4531
  getNextCandles(symbol: string, interval: CandleInterval, limit: number): Promise<ICandleData[]>;
4130
4532
  /**
4131
- * Calculates VWAP (Volume Weighted Average Price) from last 5 1m candles.
4533
+ * Calculates VWAP (Volume Weighted Average Price) from last N 1m candles.
4534
+ * The number of candles is configurable via GLOBAL_CONFIG.CC_AVG_PRICE_CANDLES_COUNT.
4132
4535
  *
4133
4536
  * Formula:
4134
4537
  * - Typical Price = (high + low + close) / 3
@@ -4385,7 +4788,7 @@ declare class FrameConnectionService implements IFrame {
4385
4788
  * @param symbol - Trading pair symbol (e.g., "BTCUSDT")
4386
4789
  * @returns Promise resolving to { startDate: Date, endDate: Date }
4387
4790
  */
4388
- getTimeframe: (symbol: string) => Promise<Date[]>;
4791
+ getTimeframe: (symbol: string, frameName: string) => Promise<Date[]>;
4389
4792
  }
4390
4793
 
4391
4794
  /**
@@ -4616,6 +5019,12 @@ declare class RiskConnectionService {
4616
5019
  strategyName: string;
4617
5020
  riskName: RiskName;
4618
5021
  }) => Promise<void>;
5022
+ /**
5023
+ * Clears the cached ClientRisk instance for the given risk name.
5024
+ *
5025
+ * @param riskName - Name of the risk schema to clear from cache
5026
+ */
5027
+ clear: (riskName?: RiskName) => Promise<void>;
4619
5028
  }
4620
5029
 
4621
5030
  /**
@@ -4629,6 +5038,16 @@ declare class RiskConnectionService {
4629
5038
  declare class ExchangeGlobalService {
4630
5039
  private readonly loggerService;
4631
5040
  private readonly exchangeConnectionService;
5041
+ private readonly methodContextService;
5042
+ private readonly exchangeValidationService;
5043
+ /**
5044
+ * Validates exchange configuration.
5045
+ * Memoized to avoid redundant validations for the same exchange.
5046
+ * Logs validation activity.
5047
+ * @param exchangeName - Name of the exchange to validate
5048
+ * @returns Promise that resolves when validation is complete
5049
+ */
5050
+ private validate;
4632
5051
  /**
4633
5052
  * Fetches historical candles with execution context.
4634
5053
  *
@@ -4693,6 +5112,19 @@ declare class ExchangeGlobalService {
4693
5112
  declare class StrategyGlobalService {
4694
5113
  private readonly loggerService;
4695
5114
  private readonly strategyConnectionService;
5115
+ private readonly strategySchemaService;
5116
+ private readonly riskValidationService;
5117
+ private readonly strategyValidationService;
5118
+ private readonly methodContextService;
5119
+ /**
5120
+ * Validates strategy and associated risk configuration.
5121
+ *
5122
+ * Memoized to avoid redundant validations for the same strategy.
5123
+ * Logs validation activity.
5124
+ * @param strategyName - Name of the strategy to validate
5125
+ * @returns Promise that resolves when validation is complete
5126
+ */
5127
+ private validate;
4696
5128
  /**
4697
5129
  * Checks signal status at a specific timestamp.
4698
5130
  *
@@ -4736,7 +5168,7 @@ declare class StrategyGlobalService {
4736
5168
  *
4737
5169
  * @param strategyName - Name of strategy to clear from cache
4738
5170
  */
4739
- clear: (strategyName: StrategyName) => Promise<void>;
5171
+ clear: (strategyName?: StrategyName) => Promise<void>;
4740
5172
  }
4741
5173
 
4742
5174
  /**
@@ -4748,13 +5180,14 @@ declare class StrategyGlobalService {
4748
5180
  declare class FrameGlobalService {
4749
5181
  private readonly loggerService;
4750
5182
  private readonly frameConnectionService;
5183
+ private readonly frameValidationService;
4751
5184
  /**
4752
5185
  * Generates timeframe array for backtest iteration.
4753
5186
  *
4754
- * @param symbol - Trading pair symbol
5187
+ * @param frameName - Target frame name (e.g., "1m", "1h")
4755
5188
  * @returns Promise resolving to array of Date objects
4756
5189
  */
4757
- getTimeframe: (symbol: string) => Promise<Date[]>;
5190
+ getTimeframe: (symbol: string, frameName: string) => Promise<Date[]>;
4758
5191
  }
4759
5192
 
4760
5193
  /**
@@ -4766,6 +5199,7 @@ declare class FrameGlobalService {
4766
5199
  declare class SizingGlobalService {
4767
5200
  private readonly loggerService;
4768
5201
  private readonly sizingConnectionService;
5202
+ private readonly sizingValidationService;
4769
5203
  /**
4770
5204
  * Calculates position size based on risk parameters.
4771
5205
  *
@@ -4787,6 +5221,15 @@ declare class SizingGlobalService {
4787
5221
  declare class RiskGlobalService {
4788
5222
  private readonly loggerService;
4789
5223
  private readonly riskConnectionService;
5224
+ private readonly riskValidationService;
5225
+ /**
5226
+ * Validates risk configuration.
5227
+ * Memoized to avoid redundant validations for the same risk instance.
5228
+ * Logs validation activity.
5229
+ * @param riskName - Name of the risk instance to validate
5230
+ * @returns Promise that resolves when validation is complete
5231
+ */
5232
+ private validate;
4790
5233
  /**
4791
5234
  * Checks if a signal should be allowed based on risk limits.
4792
5235
  *
@@ -4817,6 +5260,13 @@ declare class RiskGlobalService {
4817
5260
  strategyName: string;
4818
5261
  riskName: RiskName;
4819
5262
  }) => Promise<void>;
5263
+ /**
5264
+ * Clears risk data.
5265
+ * If riskName is provided, clears data for that specific risk instance.
5266
+ * If no riskName is provided, clears all risk data.
5267
+ * @param riskName - Optional name of the risk instance to clear
5268
+ */
5269
+ clear: (riskName?: RiskName) => Promise<void>;
4820
5270
  }
4821
5271
 
4822
5272
  /**
@@ -4828,6 +5278,13 @@ declare class RiskGlobalService {
4828
5278
  declare class WalkerGlobalService {
4829
5279
  private readonly loggerService;
4830
5280
  private readonly walkerLogicPublicService;
5281
+ private readonly walkerSchemaService;
5282
+ private readonly strategyValidationService;
5283
+ private readonly exchangeValidationService;
5284
+ private readonly frameValidationService;
5285
+ private readonly walkerValidationService;
5286
+ private readonly strategySchemaService;
5287
+ private readonly riskValidationService;
4831
5288
  /**
4832
5289
  * Runs walker comparison for a symbol with context propagation.
4833
5290
  *
@@ -5162,7 +5619,7 @@ declare class BacktestLogicPrivateService {
5162
5619
  * }
5163
5620
  * ```
5164
5621
  */
5165
- run(symbol: string): AsyncGenerator<IStrategyTickResultClosed, void, unknown>;
5622
+ run(symbol: string): AsyncGenerator<IStrategyBacktestResult, void, unknown>;
5166
5623
  }
5167
5624
 
5168
5625
  /**
@@ -5207,7 +5664,7 @@ declare class LiveLogicPrivateService {
5207
5664
  * }
5208
5665
  * ```
5209
5666
  */
5210
- run(symbol: string): AsyncGenerator<IStrategyTickResultOpened | IStrategyTickResultClosed, void, unknown>;
5667
+ run(symbol: string): AsyncGenerator<IStrategyTickResultOpened | IStrategyTickResultClosed | IStrategyTickResultCancelled, void, unknown>;
5211
5668
  }
5212
5669
 
5213
5670
  /**
@@ -5301,7 +5758,7 @@ declare class BacktestLogicPublicService {
5301
5758
  strategyName: string;
5302
5759
  exchangeName: string;
5303
5760
  frameName: string;
5304
- }) => AsyncGenerator<IStrategyTickResultClosed, void, unknown>;
5761
+ }) => AsyncGenerator<IStrategyBacktestResult, void, unknown>;
5305
5762
  }
5306
5763
 
5307
5764
  /**
@@ -5352,7 +5809,7 @@ declare class LiveLogicPublicService {
5352
5809
  run: (symbol: string, context: {
5353
5810
  strategyName: string;
5354
5811
  exchangeName: string;
5355
- }) => AsyncGenerator<IStrategyTickResultOpened | IStrategyTickResultClosed, void, unknown>;
5812
+ }) => AsyncGenerator<IStrategyTickResultOpened | IStrategyTickResultClosed | IStrategyTickResultCancelled, void, unknown>;
5356
5813
  }
5357
5814
 
5358
5815
  /**
@@ -5406,6 +5863,8 @@ declare class LiveGlobalService {
5406
5863
  private readonly liveLogicPublicService;
5407
5864
  private readonly strategyValidationService;
5408
5865
  private readonly exchangeValidationService;
5866
+ private readonly strategySchemaService;
5867
+ private readonly riskValidationService;
5409
5868
  /**
5410
5869
  * Runs live trading for a symbol with context propagation.
5411
5870
  *
@@ -5418,7 +5877,7 @@ declare class LiveGlobalService {
5418
5877
  run: (symbol: string, context: {
5419
5878
  strategyName: string;
5420
5879
  exchangeName: string;
5421
- }) => AsyncGenerator<IStrategyTickResultOpened | IStrategyTickResultClosed, void, unknown>;
5880
+ }) => AsyncGenerator<IStrategyTickResultOpened | IStrategyTickResultClosed | IStrategyTickResultCancelled, void, unknown>;
5422
5881
  }
5423
5882
 
5424
5883
  /**
@@ -5429,6 +5888,8 @@ declare class LiveGlobalService {
5429
5888
  */
5430
5889
  declare class BacktestGlobalService {
5431
5890
  private readonly loggerService;
5891
+ private readonly strategySchemaService;
5892
+ private readonly riskValidationService;
5432
5893
  private readonly backtestLogicPublicService;
5433
5894
  private readonly strategyValidationService;
5434
5895
  private readonly exchangeValidationService;
@@ -5444,7 +5905,7 @@ declare class BacktestGlobalService {
5444
5905
  strategyName: string;
5445
5906
  exchangeName: string;
5446
5907
  frameName: string;
5447
- }) => AsyncGenerator<IStrategyTickResultClosed, void, unknown>;
5908
+ }) => AsyncGenerator<IStrategyBacktestResult, void, unknown>;
5448
5909
  }
5449
5910
 
5450
5911
  /**
@@ -5827,6 +6288,7 @@ declare const backtest: {
5827
6288
  riskValidationService: RiskValidationService;
5828
6289
  backtestMarkdownService: BacktestMarkdownService;
5829
6290
  liveMarkdownService: LiveMarkdownService;
6291
+ scheduleMarkdownService: ScheduleMarkdownService;
5830
6292
  performanceMarkdownService: PerformanceMarkdownService;
5831
6293
  walkerMarkdownService: WalkerMarkdownService;
5832
6294
  heatMarkdownService: HeatMarkdownService;
@@ -5864,4 +6326,4 @@ declare const backtest: {
5864
6326
  loggerService: LoggerService;
5865
6327
  };
5866
6328
 
5867
- export { Backtest, type BacktestStatistics, type CandleInterval, type DoneContract, type EntityId, ExecutionContextService, type FrameInterval, Heat, type ICandleData, type IExchangeSchema, type IFrameSchema, type IHeatmapRow, type IHeatmapStatistics, type IPersistBase, type IPositionSizeATRParams, type IPositionSizeFixedPercentageParams, type IPositionSizeKellyParams, type IRiskActivePosition, type IRiskCheckArgs, type IRiskSchema, type IRiskValidation, type IRiskValidationFn, type IRiskValidationPayload, type ISignalDto, type ISignalRow, type ISizingCalculateParams, type ISizingCalculateParamsATR, type ISizingCalculateParamsFixedPercentage, type ISizingCalculateParamsKelly, type ISizingSchema, type ISizingSchemaATR, type ISizingSchemaFixedPercentage, type ISizingSchemaKelly, type IStrategyPnL, type IStrategySchema, type IStrategyTickResult, type IStrategyTickResultActive, type IStrategyTickResultClosed, type IStrategyTickResultIdle, type IStrategyTickResultOpened, type IWalkerResults, type IWalkerSchema, type IWalkerStrategyResult, Live, type LiveStatistics, MethodContextService, Performance, type PerformanceContract, type PerformanceMetricType, type PerformanceStatistics, PersistBase, PersistRiskAdapter, PersistSignalAdaper, PositionSize, type ProgressContract, type RiskData, type SignalData, type SignalInterval, type TPersistBase, type TPersistBaseCtor, Walker, type WalkerMetric, type WalkerStatistics, addExchange, addFrame, addRisk, addSizing, addStrategy, addWalker, emitters, formatPrice, formatQuantity, getAveragePrice, getCandles, getDate, getMode, backtest as lib, listExchanges, listFrames, listRisks, listSizings, listStrategies, listWalkers, listenDoneBacktest, listenDoneBacktestOnce, listenDoneLive, listenDoneLiveOnce, listenDoneWalker, listenDoneWalkerOnce, listenError, listenPerformance, listenProgress, listenSignal, listenSignalBacktest, listenSignalBacktestOnce, listenSignalLive, listenSignalLiveOnce, listenSignalOnce, listenValidation, listenWalker, listenWalkerComplete, listenWalkerOnce, setLogger };
6329
+ export { Backtest, type BacktestStatistics, type CandleInterval, type DoneContract, type EntityId, ExecutionContextService, type FrameInterval, type GlobalConfig, Heat, type ICandleData, type IExchangeSchema, type IFrameSchema, type IHeatmapRow, type IHeatmapStatistics, type IPersistBase, type IPositionSizeATRParams, type IPositionSizeFixedPercentageParams, type IPositionSizeKellyParams, type IRiskActivePosition, type IRiskCheckArgs, type IRiskSchema, type IRiskValidation, type IRiskValidationFn, type IRiskValidationPayload, type IScheduledSignalRow, type ISignalDto, type ISignalRow, type ISizingCalculateParams, type ISizingCalculateParamsATR, type ISizingCalculateParamsFixedPercentage, type ISizingCalculateParamsKelly, type ISizingSchema, type ISizingSchemaATR, type ISizingSchemaFixedPercentage, type ISizingSchemaKelly, type IStrategyPnL, type IStrategySchema, type IStrategyTickResult, type IStrategyTickResultActive, type IStrategyTickResultCancelled, type IStrategyTickResultClosed, type IStrategyTickResultIdle, type IStrategyTickResultOpened, type IStrategyTickResultScheduled, type IWalkerResults, type IWalkerSchema, type IWalkerStrategyResult, Live, type LiveStatistics, MethodContextService, Performance, type PerformanceContract, type PerformanceMetricType, type PerformanceStatistics, PersistBase, PersistRiskAdapter, PersistSignalAdaper, PositionSize, type ProgressContract, type RiskData, Schedule, type ScheduleStatistics, type SignalData, type SignalInterval, type TPersistBase, type TPersistBaseCtor, Walker, type WalkerMetric, type WalkerStatistics, addExchange, addFrame, addRisk, addSizing, addStrategy, addWalker, emitters, formatPrice, formatQuantity, getAveragePrice, getCandles, getDate, getMode, backtest as lib, listExchanges, listFrames, listRisks, listSizings, listStrategies, listWalkers, listenDoneBacktest, listenDoneBacktestOnce, listenDoneLive, listenDoneLiveOnce, listenDoneWalker, listenDoneWalkerOnce, listenError, listenPerformance, listenProgress, listenSignal, listenSignalBacktest, listenSignalBacktestOnce, listenSignalLive, listenSignalLiveOnce, listenSignalOnce, listenValidation, listenWalker, listenWalkerComplete, listenWalkerOnce, setConfig, setLogger };