backtest-kit 2.2.1 → 2.2.3

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 (5) hide show
  1. package/README.md +32 -10
  2. package/build/index.cjs +1891 -132
  3. package/build/index.mjs +1890 -134
  4. package/package.json +2 -1
  5. package/types.d.ts +1709 -865
package/types.d.ts CHANGED
@@ -3839,6 +3839,8 @@ declare const COLUMN_CONFIG: {
3839
3839
  risk_columns: ColumnModel<RiskEvent>[];
3840
3840
  /** Columns for scheduled report output */
3841
3841
  schedule_columns: ColumnModel<ScheduledEvent>[];
3842
+ /** Columns for strategy management events */
3843
+ strategy_columns: ColumnModel<StrategyEvent>[];
3842
3844
  /** Walker: PnL summary columns */
3843
3845
  walker_pnl_columns: ColumnModel<SignalData$1>[];
3844
3846
  /** Walker: strategy-level summary columns */
@@ -3997,6 +3999,7 @@ declare function getColumns(): {
3997
3999
  performance_columns: ColumnModel<MetricStats>[];
3998
4000
  risk_columns: ColumnModel<RiskEvent>[];
3999
4001
  schedule_columns: ColumnModel<ScheduledEvent>[];
4002
+ strategy_columns: ColumnModel<StrategyEvent>[];
4000
4003
  walker_pnl_columns: ColumnModel<SignalData$1>[];
4001
4004
  walker_strategy_columns: ColumnModel<IStrategyResult>[];
4002
4005
  };
@@ -4023,6 +4026,7 @@ declare function getDefaultColumns(): Readonly<{
4023
4026
  performance_columns: ColumnModel<MetricStats>[];
4024
4027
  risk_columns: ColumnModel<RiskEvent>[];
4025
4028
  schedule_columns: ColumnModel<ScheduledEvent>[];
4029
+ strategy_columns: ColumnModel<StrategyEvent>[];
4026
4030
  walker_pnl_columns: ColumnModel<SignalData$1>[];
4027
4031
  walker_strategy_columns: ColumnModel<IStrategyResult>[];
4028
4032
  }>;
@@ -5071,6 +5075,84 @@ interface WalkerContract {
5071
5075
  totalStrategies: number;
5072
5076
  }
5073
5077
 
5078
+ /**
5079
+ * Base fields for all signal commit events.
5080
+ */
5081
+ interface SignalCommitBase {
5082
+ symbol: string;
5083
+ strategyName: StrategyName;
5084
+ exchangeName: ExchangeName;
5085
+ frameName: FrameName;
5086
+ backtest: boolean;
5087
+ }
5088
+ /**
5089
+ * Cancel scheduled signal event.
5090
+ */
5091
+ interface CancelScheduledCommit extends SignalCommitBase {
5092
+ action: "cancel-scheduled";
5093
+ cancelId?: string;
5094
+ }
5095
+ /**
5096
+ * Close pending signal event.
5097
+ */
5098
+ interface ClosePendingCommit extends SignalCommitBase {
5099
+ action: "close-pending";
5100
+ closeId?: string;
5101
+ }
5102
+ /**
5103
+ * Partial profit event.
5104
+ */
5105
+ interface PartialProfitCommit extends SignalCommitBase {
5106
+ action: "partial-profit";
5107
+ percentToClose: number;
5108
+ currentPrice: number;
5109
+ }
5110
+ /**
5111
+ * Partial loss event.
5112
+ */
5113
+ interface PartialLossCommit extends SignalCommitBase {
5114
+ action: "partial-loss";
5115
+ percentToClose: number;
5116
+ currentPrice: number;
5117
+ }
5118
+ /**
5119
+ * Trailing stop event.
5120
+ */
5121
+ interface TrailingStopCommit extends SignalCommitBase {
5122
+ action: "trailing-stop";
5123
+ percentShift: number;
5124
+ currentPrice: number;
5125
+ }
5126
+ /**
5127
+ * Trailing take event.
5128
+ */
5129
+ interface TrailingTakeCommit extends SignalCommitBase {
5130
+ action: "trailing-take";
5131
+ percentShift: number;
5132
+ currentPrice: number;
5133
+ }
5134
+ /**
5135
+ * Breakeven event.
5136
+ */
5137
+ interface BreakevenCommit extends SignalCommitBase {
5138
+ action: "breakeven";
5139
+ currentPrice: number;
5140
+ }
5141
+ /**
5142
+ * Discriminated union for strategy management signal events.
5143
+ *
5144
+ * Emitted by strategyCommitSubject when strategy management actions are executed.
5145
+ *
5146
+ * Consumers:
5147
+ * - StrategyReportService: Persists events to JSON files
5148
+ * - StrategyMarkdownService: Accumulates events for markdown reports
5149
+ *
5150
+ * Note: Signal data (IPublicSignalRow) is NOT included in this contract.
5151
+ * Consumers must retrieve signal data from StrategyCoreService using
5152
+ * getPendingSignal() or getScheduledSignal() methods.
5153
+ */
5154
+ type StrategyCommitContract = CancelScheduledCommit | ClosePendingCommit | PartialProfitCommit | PartialLossCommit | TrailingStopCommit | TrailingTakeCommit | BreakevenCommit;
5155
+
5074
5156
  /**
5075
5157
  * Subscribes to all signal events with queued async processing.
5076
5158
  *
@@ -6001,6 +6083,72 @@ declare function listenActivePing(fn: (event: ActivePingContract) => void): () =
6001
6083
  * ```
6002
6084
  */
6003
6085
  declare function listenActivePingOnce(filterFn: (event: ActivePingContract) => boolean, fn: (event: ActivePingContract) => void): () => void;
6086
+ /**
6087
+ * Subscribes to strategy management events with queued async processing.
6088
+ *
6089
+ * Emits when strategy management actions are executed:
6090
+ * - cancel-scheduled: Scheduled signal cancelled
6091
+ * - close-pending: Pending signal closed
6092
+ * - partial-profit: Partial close at profit level
6093
+ * - partial-loss: Partial close at loss level
6094
+ * - trailing-stop: Stop-loss adjusted
6095
+ * - trailing-take: Take-profit adjusted
6096
+ * - breakeven: Stop-loss moved to entry price
6097
+ *
6098
+ * Events are processed sequentially in order received, even if callback is async.
6099
+ * Uses queued wrapper to prevent concurrent execution of the callback.
6100
+ *
6101
+ * @param fn - Callback function to handle strategy commit events
6102
+ * @returns Unsubscribe function to stop listening
6103
+ *
6104
+ * @example
6105
+ * ```typescript
6106
+ * import { listenStrategyCommit } from "./function/event";
6107
+ *
6108
+ * const unsubscribe = listenStrategyCommit((event) => {
6109
+ * console.log(`[${event.action}] ${event.symbol}`);
6110
+ * console.log(`Strategy: ${event.strategyName}, Exchange: ${event.exchangeName}`);
6111
+ * if (event.action === "partial-profit") {
6112
+ * console.log(`Closed ${event.percentToClose}% at ${event.currentPrice}`);
6113
+ * }
6114
+ * });
6115
+ *
6116
+ * // Later: stop listening
6117
+ * unsubscribe();
6118
+ * ```
6119
+ */
6120
+ declare function listenStrategyCommit(fn: (event: StrategyCommitContract) => void): () => void;
6121
+ /**
6122
+ * Subscribes to filtered strategy management events with one-time execution.
6123
+ *
6124
+ * Listens for events matching the filter predicate, then executes callback once
6125
+ * and automatically unsubscribes. Useful for waiting for specific strategy actions.
6126
+ *
6127
+ * @param filterFn - Predicate to filter which events trigger the callback
6128
+ * @param fn - Callback function to handle the filtered event (called only once)
6129
+ * @returns Unsubscribe function to cancel the listener before it fires
6130
+ *
6131
+ * @example
6132
+ * ```typescript
6133
+ * import { listenStrategyCommitOnce } from "./function/event";
6134
+ *
6135
+ * // Wait for first trailing stop adjustment
6136
+ * listenStrategyCommitOnce(
6137
+ * (event) => event.action === "trailing-stop",
6138
+ * (event) => console.log("Trailing stop adjusted:", event.symbol)
6139
+ * );
6140
+ *
6141
+ * // Wait for breakeven on BTCUSDT
6142
+ * const cancel = listenStrategyCommitOnce(
6143
+ * (event) => event.action === "breakeven" && event.symbol === "BTCUSDT",
6144
+ * (event) => console.log("BTCUSDT moved to breakeven at", event.currentPrice)
6145
+ * );
6146
+ *
6147
+ * // Cancel if needed before event fires
6148
+ * cancel();
6149
+ * ```
6150
+ */
6151
+ declare function listenStrategyCommitOnce(filterFn: (event: StrategyCommitContract) => boolean, fn: (event: StrategyCommitContract) => void): () => void;
6004
6152
 
6005
6153
  /**
6006
6154
  * Checks if trade context is active (execution and method contexts).
@@ -6923,6 +7071,79 @@ interface RiskStatisticsModel {
6923
7071
  byStrategy: Record<string, number>;
6924
7072
  }
6925
7073
 
7074
+ /**
7075
+ * Action types for strategy events.
7076
+ * Represents all possible strategy management actions.
7077
+ */
7078
+ type StrategyActionType = "cancel-scheduled" | "close-pending" | "partial-profit" | "partial-loss" | "trailing-stop" | "trailing-take" | "breakeven";
7079
+ /**
7080
+ * Unified strategy event data for markdown report generation.
7081
+ * Contains all information about strategy management actions.
7082
+ */
7083
+ interface StrategyEvent {
7084
+ /** Event timestamp in milliseconds */
7085
+ timestamp: number;
7086
+ /** Trading pair symbol */
7087
+ symbol: string;
7088
+ /** Strategy name */
7089
+ strategyName: StrategyName;
7090
+ /** Exchange name */
7091
+ exchangeName: ExchangeName;
7092
+ /** Frame name (empty for live) */
7093
+ frameName: FrameName;
7094
+ /** Signal ID */
7095
+ signalId: string;
7096
+ /** Action type */
7097
+ action: StrategyActionType;
7098
+ /** Current market price when action was executed */
7099
+ currentPrice?: number;
7100
+ /** Percent to close for partial profit/loss */
7101
+ percentToClose?: number;
7102
+ /** Percent shift for trailing stop/take */
7103
+ percentShift?: number;
7104
+ /** Cancel ID for cancel-scheduled action */
7105
+ cancelId?: string;
7106
+ /** Close ID for close-pending action */
7107
+ closeId?: string;
7108
+ /** ISO timestamp string when action was created */
7109
+ createdAt: string;
7110
+ /** True if backtest mode, false if live mode */
7111
+ backtest: boolean;
7112
+ }
7113
+ /**
7114
+ * Statistical data calculated from strategy events.
7115
+ *
7116
+ * Provides metrics for strategy action tracking.
7117
+ *
7118
+ * @example
7119
+ * ```typescript
7120
+ * const stats = await Strategy.getData("BTCUSDT", "my-strategy");
7121
+ *
7122
+ * console.log(`Total events: ${stats.totalEvents}`);
7123
+ * console.log(`Cancel scheduled: ${stats.cancelScheduledCount}`);
7124
+ * ```
7125
+ */
7126
+ interface StrategyStatisticsModel {
7127
+ /** Array of all strategy events with full details */
7128
+ eventList: StrategyEvent[];
7129
+ /** Total number of strategy events */
7130
+ totalEvents: number;
7131
+ /** Count of cancel-scheduled events */
7132
+ cancelScheduledCount: number;
7133
+ /** Count of close-pending events */
7134
+ closePendingCount: number;
7135
+ /** Count of partial-profit events */
7136
+ partialProfitCount: number;
7137
+ /** Count of partial-loss events */
7138
+ partialLossCount: number;
7139
+ /** Count of trailing-stop events */
7140
+ trailingStopCount: number;
7141
+ /** Count of trailing-take events */
7142
+ trailingTakeCount: number;
7143
+ /** Count of breakeven events */
7144
+ breakevenCount: number;
7145
+ }
7146
+
6926
7147
  declare const BASE_WAIT_FOR_INIT_SYMBOL: unique symbol;
6927
7148
  /**
6928
7149
  * Signal data stored in persistence layer.
@@ -7602,6 +7823,8 @@ declare const WRITE_SAFE_SYMBOL$1: unique symbol;
7602
7823
  * Controls which report services should be activated for JSONL event logging.
7603
7824
  */
7604
7825
  interface IReportTarget {
7826
+ /** Enable strategy commit actions */
7827
+ strategy: boolean;
7605
7828
  /** Enable risk rejection event logging */
7606
7829
  risk: boolean;
7607
7830
  /** Enable breakeven event logging */
@@ -7771,7 +7994,7 @@ declare class ReportUtils {
7771
7994
  *
7772
7995
  * @returns Cleanup function that unsubscribes from all enabled services
7773
7996
  */
7774
- enable: ({ backtest: bt, breakeven, heat, live, partial, performance, risk, schedule, walker, }?: Partial<IReportTarget>) => (...args: any[]) => any;
7997
+ enable: ({ backtest: bt, breakeven, heat, live, partial, performance, risk, schedule, walker, strategy, }?: Partial<IReportTarget>) => (...args: any[]) => any;
7775
7998
  /**
7776
7999
  * Disables report services selectively.
7777
8000
  *
@@ -7808,7 +8031,7 @@ declare class ReportUtils {
7808
8031
  * Report.disable();
7809
8032
  * ```
7810
8033
  */
7811
- disable: ({ backtest: bt, breakeven, heat, live, partial, performance, risk, schedule, walker, }?: Partial<IReportTarget>) => void;
8034
+ disable: ({ backtest: bt, breakeven, heat, live, partial, performance, risk, schedule, walker, strategy, }?: Partial<IReportTarget>) => void;
7812
8035
  }
7813
8036
  /**
7814
8037
  * Report adapter with pluggable storage backend and instance memoization.
@@ -7878,6 +8101,8 @@ declare const Report: ReportAdapter;
7878
8101
  * Controls which markdown report services should be activated.
7879
8102
  */
7880
8103
  interface IMarkdownTarget {
8104
+ /** Enable strategy event tracking reports (entry/exit signals) */
8105
+ strategy: boolean;
7881
8106
  /** Enable risk rejection tracking reports (signals blocked by risk limits) */
7882
8107
  risk: boolean;
7883
8108
  /** Enable breakeven event tracking reports (when stop loss moves to entry) */
@@ -8091,7 +8316,7 @@ declare class MarkdownUtils {
8091
8316
  *
8092
8317
  * @returns Cleanup function that unsubscribes from all enabled services
8093
8318
  */
8094
- enable: ({ backtest: bt, breakeven, heat, live, partial, performance, risk, schedule, walker, }?: Partial<IMarkdownTarget>) => (...args: any[]) => any;
8319
+ enable: ({ backtest: bt, breakeven, heat, live, partial, performance, strategy, risk, schedule, walker, }?: Partial<IMarkdownTarget>) => (...args: any[]) => any;
8095
8320
  /**
8096
8321
  * Disables markdown report services selectively.
8097
8322
  *
@@ -8129,7 +8354,7 @@ declare class MarkdownUtils {
8129
8354
  * Markdown.disable();
8130
8355
  * ```
8131
8356
  */
8132
- disable: ({ backtest: bt, breakeven, heat, live, partial, performance, risk, schedule, walker, }?: Partial<IMarkdownTarget>) => void;
8357
+ disable: ({ backtest: bt, breakeven, heat, live, partial, performance, risk, strategy, schedule, walker, }?: Partial<IMarkdownTarget>) => void;
8133
8358
  }
8134
8359
  /**
8135
8360
  * Markdown adapter with pluggable storage backend and instance memoization.
@@ -8231,7 +8456,7 @@ declare const Markdown: MarkdownAdapter;
8231
8456
  * @see ColumnModel for the base interface
8232
8457
  * @see IStrategyTickResultClosed for the signal data structure
8233
8458
  */
8234
- type Columns$7 = ColumnModel<IStrategyTickResultClosed>;
8459
+ type Columns$8 = ColumnModel<IStrategyTickResultClosed>;
8235
8460
  /**
8236
8461
  * Service for generating and saving backtest markdown reports.
8237
8462
  *
@@ -8325,7 +8550,7 @@ declare class BacktestMarkdownService {
8325
8550
  * console.log(markdown);
8326
8551
  * ```
8327
8552
  */
8328
- getReport: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, columns?: Columns$7[]) => Promise<string>;
8553
+ getReport: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, columns?: Columns$8[]) => Promise<string>;
8329
8554
  /**
8330
8555
  * Saves symbol-strategy report to disk.
8331
8556
  * Creates directory if it doesn't exist.
@@ -8350,7 +8575,7 @@ declare class BacktestMarkdownService {
8350
8575
  * await service.dump("BTCUSDT", "my-strategy", "binance", "1h", true, "./custom/path");
8351
8576
  * ```
8352
8577
  */
8353
- dump: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, path?: string, columns?: Columns$7[]) => Promise<void>;
8578
+ dump: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, path?: string, columns?: Columns$8[]) => Promise<void>;
8354
8579
  /**
8355
8580
  * Clears accumulated signal data from storage.
8356
8581
  * If payload is provided, clears only that specific symbol-strategy-exchange-frame-backtest combination's data.
@@ -8860,7 +9085,7 @@ declare class BacktestUtils {
8860
9085
  strategyName: StrategyName;
8861
9086
  exchangeName: ExchangeName;
8862
9087
  frameName: FrameName;
8863
- }, columns?: Columns$7[]) => Promise<string>;
9088
+ }, columns?: Columns$8[]) => Promise<string>;
8864
9089
  /**
8865
9090
  * Saves strategy report to disk.
8866
9091
  *
@@ -8891,7 +9116,7 @@ declare class BacktestUtils {
8891
9116
  strategyName: StrategyName;
8892
9117
  exchangeName: ExchangeName;
8893
9118
  frameName: FrameName;
8894
- }, path?: string, columns?: Columns$7[]) => Promise<void>;
9119
+ }, path?: string, columns?: Columns$8[]) => Promise<void>;
8895
9120
  /**
8896
9121
  * Lists all active backtest instances with their current status.
8897
9122
  *
@@ -8965,7 +9190,7 @@ declare const Backtest: BacktestUtils;
8965
9190
  * @see ColumnModel for the base interface
8966
9191
  * @see TickEvent for the event data structure
8967
9192
  */
8968
- type Columns$6 = ColumnModel<TickEvent>;
9193
+ type Columns$7 = ColumnModel<TickEvent>;
8969
9194
  /**
8970
9195
  * Service for generating and saving live trading markdown reports.
8971
9196
  *
@@ -9092,7 +9317,7 @@ declare class LiveMarkdownService {
9092
9317
  * console.log(markdown);
9093
9318
  * ```
9094
9319
  */
9095
- getReport: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, columns?: Columns$6[]) => Promise<string>;
9320
+ getReport: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, columns?: Columns$7[]) => Promise<string>;
9096
9321
  /**
9097
9322
  * Saves symbol-strategy report to disk.
9098
9323
  * Creates directory if it doesn't exist.
@@ -9117,7 +9342,7 @@ declare class LiveMarkdownService {
9117
9342
  * await service.dump("BTCUSDT", "my-strategy", "binance", "1h", false, "./custom/path");
9118
9343
  * ```
9119
9344
  */
9120
- dump: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, path?: string, columns?: Columns$6[]) => Promise<void>;
9345
+ dump: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, path?: string, columns?: Columns$7[]) => Promise<void>;
9121
9346
  /**
9122
9347
  * Clears accumulated event data from storage.
9123
9348
  * If payload is provided, clears only that specific symbol-strategy-exchange-frame-backtest combination's data.
@@ -9586,7 +9811,7 @@ declare class LiveUtils {
9586
9811
  getReport: (symbol: string, context: {
9587
9812
  strategyName: StrategyName;
9588
9813
  exchangeName: ExchangeName;
9589
- }, columns?: Columns$6[]) => Promise<string>;
9814
+ }, columns?: Columns$7[]) => Promise<string>;
9590
9815
  /**
9591
9816
  * Saves strategy report to disk.
9592
9817
  *
@@ -9616,7 +9841,7 @@ declare class LiveUtils {
9616
9841
  dump: (symbol: string, context: {
9617
9842
  strategyName: StrategyName;
9618
9843
  exchangeName: ExchangeName;
9619
- }, path?: string, columns?: Columns$6[]) => Promise<void>;
9844
+ }, path?: string, columns?: Columns$7[]) => Promise<void>;
9620
9845
  /**
9621
9846
  * Lists all active live trading instances with their current status.
9622
9847
  *
@@ -9686,7 +9911,7 @@ declare const Live: LiveUtils;
9686
9911
  * @see ColumnModel for the base interface
9687
9912
  * @see ScheduledEvent for the event data structure
9688
9913
  */
9689
- type Columns$5 = ColumnModel<ScheduledEvent>;
9914
+ type Columns$6 = ColumnModel<ScheduledEvent>;
9690
9915
  /**
9691
9916
  * Service for generating and saving scheduled signals markdown reports.
9692
9917
  *
@@ -9797,7 +10022,7 @@ declare class ScheduleMarkdownService {
9797
10022
  * console.log(markdown);
9798
10023
  * ```
9799
10024
  */
9800
- getReport: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, columns?: Columns$5[]) => Promise<string>;
10025
+ getReport: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, columns?: Columns$6[]) => Promise<string>;
9801
10026
  /**
9802
10027
  * Saves symbol-strategy report to disk.
9803
10028
  * Creates directory if it doesn't exist.
@@ -9822,7 +10047,7 @@ declare class ScheduleMarkdownService {
9822
10047
  * await service.dump("BTCUSDT", "my-strategy", "binance", "1h", false, "./custom/path");
9823
10048
  * ```
9824
10049
  */
9825
- dump: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, path?: string, columns?: Columns$5[]) => Promise<void>;
10050
+ dump: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, path?: string, columns?: Columns$6[]) => Promise<void>;
9826
10051
  /**
9827
10052
  * Clears accumulated event data from storage.
9828
10053
  * If payload is provided, clears only that specific symbol-strategy-exchange-frame-backtest combination's data.
@@ -9912,7 +10137,7 @@ declare class ScheduleUtils {
9912
10137
  strategyName: StrategyName;
9913
10138
  exchangeName: ExchangeName;
9914
10139
  frameName: FrameName;
9915
- }, backtest?: boolean, columns?: Columns$5[]) => Promise<string>;
10140
+ }, backtest?: boolean, columns?: Columns$6[]) => Promise<string>;
9916
10141
  /**
9917
10142
  * Saves strategy report to disk.
9918
10143
  *
@@ -9934,7 +10159,7 @@ declare class ScheduleUtils {
9934
10159
  strategyName: StrategyName;
9935
10160
  exchangeName: ExchangeName;
9936
10161
  frameName: FrameName;
9937
- }, backtest?: boolean, path?: string, columns?: Columns$5[]) => Promise<void>;
10162
+ }, backtest?: boolean, path?: string, columns?: Columns$6[]) => Promise<void>;
9938
10163
  }
9939
10164
  /**
9940
10165
  * Singleton instance of ScheduleUtils for convenient scheduled signals reporting.
@@ -9980,7 +10205,7 @@ declare const Schedule: ScheduleUtils;
9980
10205
  * @see ColumnModel for the base interface
9981
10206
  * @see MetricStats for the metric data structure
9982
10207
  */
9983
- type Columns$4 = ColumnModel<MetricStats>;
10208
+ type Columns$5 = ColumnModel<MetricStats>;
9984
10209
  /**
9985
10210
  * Service for collecting and analyzing performance metrics.
9986
10211
  *
@@ -10087,7 +10312,7 @@ declare class PerformanceMarkdownService {
10087
10312
  * console.log(markdown);
10088
10313
  * ```
10089
10314
  */
10090
- getReport: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, columns?: Columns$4[]) => Promise<string>;
10315
+ getReport: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, columns?: Columns$5[]) => Promise<string>;
10091
10316
  /**
10092
10317
  * Saves performance report to disk.
10093
10318
  *
@@ -10108,7 +10333,7 @@ declare class PerformanceMarkdownService {
10108
10333
  * await performanceService.dump("BTCUSDT", "my-strategy", "binance", "1h", false, "./custom/path");
10109
10334
  * ```
10110
10335
  */
10111
- dump: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, path?: string, columns?: Columns$4[]) => Promise<void>;
10336
+ dump: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, path?: string, columns?: Columns$5[]) => Promise<void>;
10112
10337
  /**
10113
10338
  * Clears accumulated performance data from storage.
10114
10339
  *
@@ -10216,7 +10441,7 @@ declare class Performance {
10216
10441
  strategyName: StrategyName;
10217
10442
  exchangeName: ExchangeName;
10218
10443
  frameName: FrameName;
10219
- }, backtest?: boolean, columns?: Columns$4[]): Promise<string>;
10444
+ }, backtest?: boolean, columns?: Columns$5[]): Promise<string>;
10220
10445
  /**
10221
10446
  * Saves performance report to disk.
10222
10447
  *
@@ -10241,7 +10466,7 @@ declare class Performance {
10241
10466
  strategyName: StrategyName;
10242
10467
  exchangeName: ExchangeName;
10243
10468
  frameName: FrameName;
10244
- }, backtest?: boolean, path?: string, columns?: Columns$4[]): Promise<void>;
10469
+ }, backtest?: boolean, path?: string, columns?: Columns$5[]): Promise<void>;
10245
10470
  }
10246
10471
 
10247
10472
  /**
@@ -10672,7 +10897,7 @@ declare const Walker: WalkerUtils;
10672
10897
  * @see ColumnModel for the base interface
10673
10898
  * @see IHeatmapRow for the row data structure
10674
10899
  */
10675
- type Columns$3 = ColumnModel<IHeatmapRow>;
10900
+ type Columns$4 = ColumnModel<IHeatmapRow>;
10676
10901
  /**
10677
10902
  * Portfolio Heatmap Markdown Service.
10678
10903
  *
@@ -10793,7 +11018,7 @@ declare class HeatMarkdownService {
10793
11018
  * // ...
10794
11019
  * ```
10795
11020
  */
10796
- getReport: (strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, columns?: Columns$3[]) => Promise<string>;
11021
+ getReport: (strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, columns?: Columns$4[]) => Promise<string>;
10797
11022
  /**
10798
11023
  * Saves heatmap report to disk.
10799
11024
  *
@@ -10818,7 +11043,7 @@ declare class HeatMarkdownService {
10818
11043
  * await service.dump("my-strategy", "binance", "frame1", true, "./reports");
10819
11044
  * ```
10820
11045
  */
10821
- dump: (strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, path?: string, columns?: Columns$3[]) => Promise<void>;
11046
+ dump: (strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, path?: string, columns?: Columns$4[]) => Promise<void>;
10822
11047
  /**
10823
11048
  * Clears accumulated heatmap data from storage.
10824
11049
  * If payload is provided, clears only that exchangeName+frameName+backtest combination's data.
@@ -10948,7 +11173,7 @@ declare class HeatUtils {
10948
11173
  strategyName: StrategyName;
10949
11174
  exchangeName: ExchangeName;
10950
11175
  frameName: FrameName;
10951
- }, backtest?: boolean, columns?: Columns$3[]) => Promise<string>;
11176
+ }, backtest?: boolean, columns?: Columns$4[]) => Promise<string>;
10952
11177
  /**
10953
11178
  * Saves heatmap report to disk for a strategy.
10954
11179
  *
@@ -10981,7 +11206,7 @@ declare class HeatUtils {
10981
11206
  strategyName: StrategyName;
10982
11207
  exchangeName: ExchangeName;
10983
11208
  frameName: FrameName;
10984
- }, backtest?: boolean, path?: string, columns?: Columns$3[]) => Promise<void>;
11209
+ }, backtest?: boolean, path?: string, columns?: Columns$4[]) => Promise<void>;
10985
11210
  }
10986
11211
  /**
10987
11212
  * Singleton instance of HeatUtils for convenient heatmap operations.
@@ -11135,7 +11360,7 @@ declare const PositionSize: typeof PositionSizeUtils;
11135
11360
  * @see ColumnModel for the base interface
11136
11361
  * @see PartialEvent for the event data structure
11137
11362
  */
11138
- type Columns$2 = ColumnModel<PartialEvent>;
11363
+ type Columns$3 = ColumnModel<PartialEvent>;
11139
11364
  /**
11140
11365
  * Service for generating and saving partial profit/loss markdown reports.
11141
11366
  *
@@ -11257,7 +11482,7 @@ declare class PartialMarkdownService {
11257
11482
  * console.log(markdown);
11258
11483
  * ```
11259
11484
  */
11260
- getReport: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, columns?: Columns$2[]) => Promise<string>;
11485
+ getReport: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, columns?: Columns$3[]) => Promise<string>;
11261
11486
  /**
11262
11487
  * Saves symbol-strategy report to disk.
11263
11488
  * Creates directory if it doesn't exist.
@@ -11282,7 +11507,7 @@ declare class PartialMarkdownService {
11282
11507
  * await service.dump("BTCUSDT", "my-strategy", "binance", "1h", false, "./custom/path");
11283
11508
  * ```
11284
11509
  */
11285
- dump: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, path?: string, columns?: Columns$2[]) => Promise<void>;
11510
+ dump: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, path?: string, columns?: Columns$3[]) => Promise<void>;
11286
11511
  /**
11287
11512
  * Clears accumulated event data from storage.
11288
11513
  * If payload is provided, clears only that specific symbol-strategy-exchange-frame-backtest combination's data.
@@ -11418,7 +11643,7 @@ declare class PartialUtils {
11418
11643
  strategyName: StrategyName;
11419
11644
  exchangeName: ExchangeName;
11420
11645
  frameName: FrameName;
11421
- }, backtest?: boolean, columns?: Columns$2[]) => Promise<string>;
11646
+ }, backtest?: boolean, columns?: Columns$3[]) => Promise<string>;
11422
11647
  /**
11423
11648
  * Generates and saves markdown report to file.
11424
11649
  *
@@ -11455,7 +11680,7 @@ declare class PartialUtils {
11455
11680
  strategyName: StrategyName;
11456
11681
  exchangeName: ExchangeName;
11457
11682
  frameName: FrameName;
11458
- }, backtest?: boolean, path?: string, columns?: Columns$2[]) => Promise<void>;
11683
+ }, backtest?: boolean, path?: string, columns?: Columns$3[]) => Promise<void>;
11459
11684
  }
11460
11685
  /**
11461
11686
  * Global singleton instance of PartialUtils.
@@ -11583,7 +11808,7 @@ declare const Constant: ConstantUtils;
11583
11808
  * @see ColumnModel for the base interface
11584
11809
  * @see RiskEvent for the event data structure
11585
11810
  */
11586
- type Columns$1 = ColumnModel<RiskEvent>;
11811
+ type Columns$2 = ColumnModel<RiskEvent>;
11587
11812
  /**
11588
11813
  * Service for generating and saving risk rejection markdown reports.
11589
11814
  *
@@ -11692,7 +11917,7 @@ declare class RiskMarkdownService {
11692
11917
  * console.log(markdown);
11693
11918
  * ```
11694
11919
  */
11695
- getReport: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, columns?: Columns$1[]) => Promise<string>;
11920
+ getReport: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, columns?: Columns$2[]) => Promise<string>;
11696
11921
  /**
11697
11922
  * Saves symbol-strategy report to disk.
11698
11923
  * Creates directory if it doesn't exist.
@@ -11717,7 +11942,7 @@ declare class RiskMarkdownService {
11717
11942
  * await service.dump("BTCUSDT", "my-strategy", "binance", "1h", false, "./custom/path");
11718
11943
  * ```
11719
11944
  */
11720
- dump: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, path?: string, columns?: Columns$1[]) => Promise<void>;
11945
+ dump: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, path?: string, columns?: Columns$2[]) => Promise<void>;
11721
11946
  /**
11722
11947
  * Clears accumulated event data from storage.
11723
11948
  * If payload is provided, clears only that specific symbol-strategy-exchange-frame-backtest combination's data.
@@ -11855,7 +12080,7 @@ declare class RiskUtils {
11855
12080
  strategyName: StrategyName;
11856
12081
  exchangeName: ExchangeName;
11857
12082
  frameName: FrameName;
11858
- }, backtest?: boolean, columns?: Columns$1[]) => Promise<string>;
12083
+ }, backtest?: boolean, columns?: Columns$2[]) => Promise<string>;
11859
12084
  /**
11860
12085
  * Generates and saves markdown report to file.
11861
12086
  *
@@ -11892,7 +12117,7 @@ declare class RiskUtils {
11892
12117
  strategyName: StrategyName;
11893
12118
  exchangeName: ExchangeName;
11894
12119
  frameName: FrameName;
11895
- }, backtest?: boolean, path?: string, columns?: Columns$1[]) => Promise<void>;
12120
+ }, backtest?: boolean, path?: string, columns?: Columns$2[]) => Promise<void>;
11896
12121
  }
11897
12122
  /**
11898
12123
  * Global singleton instance of RiskUtils.
@@ -12321,7 +12546,7 @@ declare const Notification: NotificationUtils;
12321
12546
  * @see ColumnModel for the base interface
12322
12547
  * @see BreakevenEvent for the event data structure
12323
12548
  */
12324
- type Columns = ColumnModel<BreakevenEvent>;
12549
+ type Columns$1 = ColumnModel<BreakevenEvent>;
12325
12550
  /**
12326
12551
  * Service for generating and saving breakeven markdown reports.
12327
12552
  *
@@ -12430,7 +12655,7 @@ declare class BreakevenMarkdownService {
12430
12655
  * console.log(markdown);
12431
12656
  * ```
12432
12657
  */
12433
- getReport: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, columns?: Columns[]) => Promise<string>;
12658
+ getReport: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, columns?: Columns$1[]) => Promise<string>;
12434
12659
  /**
12435
12660
  * Saves symbol-strategy report to disk.
12436
12661
  * Creates directory if it doesn't exist.
@@ -12455,7 +12680,7 @@ declare class BreakevenMarkdownService {
12455
12680
  * await service.dump("BTCUSDT", "my-strategy", "binance", "1h", false, "./custom/path");
12456
12681
  * ```
12457
12682
  */
12458
- dump: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, path?: string, columns?: Columns[]) => Promise<void>;
12683
+ dump: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, path?: string, columns?: Columns$1[]) => Promise<void>;
12459
12684
  /**
12460
12685
  * Clears accumulated event data from storage.
12461
12686
  * If payload is provided, clears only that specific symbol-strategy-exchange-frame-backtest combination's data.
@@ -12583,7 +12808,7 @@ declare class BreakevenUtils {
12583
12808
  strategyName: StrategyName;
12584
12809
  exchangeName: ExchangeName;
12585
12810
  frameName: FrameName;
12586
- }, backtest?: boolean, columns?: Columns[]) => Promise<string>;
12811
+ }, backtest?: boolean, columns?: Columns$1[]) => Promise<string>;
12587
12812
  /**
12588
12813
  * Generates and saves markdown report to file.
12589
12814
  *
@@ -12620,7 +12845,7 @@ declare class BreakevenUtils {
12620
12845
  strategyName: StrategyName;
12621
12846
  exchangeName: ExchangeName;
12622
12847
  frameName: FrameName;
12623
- }, backtest?: boolean, path?: string, columns?: Columns[]) => Promise<void>;
12848
+ }, backtest?: boolean, path?: string, columns?: Columns$1[]) => Promise<void>;
12624
12849
  }
12625
12850
  /**
12626
12851
  * Global singleton instance of BreakevenUtils.
@@ -12639,97 +12864,988 @@ declare class BreakevenUtils {
12639
12864
  declare const Breakeven: BreakevenUtils;
12640
12865
 
12641
12866
  /**
12642
- * Proxy wrapper for user-defined action handlers with automatic error capture.
12643
- *
12644
- * Wraps all IPublicAction methods with trycatch to prevent user code errors from crashing the system.
12645
- * All errors are logged, sent to errorEmitter, and returned as null (non-breaking).
12646
- *
12647
- * Key features:
12648
- * - Automatic error catching and logging for all action methods
12649
- * - Safe execution of partial user implementations (missing methods return null)
12650
- * - Consistent error capture across all action lifecycle events
12651
- * - Non-breaking failure mode (errors logged but execution continues)
12652
- *
12653
- * Architecture:
12654
- * - Private constructor enforces factory pattern via fromInstance()
12655
- * - Each method checks if target implements the method before calling
12656
- * - Errors caught with fallback handler (warn log + errorEmitter)
12657
- * - Returns null on error to prevent undefined behavior
12658
- *
12659
- * Used by:
12660
- * - ClientAction to wrap user-provided action handlers
12661
- * - ActionCoreService to safely invoke action callbacks
12662
- *
12663
- * @example
12664
- * ```typescript
12665
- * // Create proxy from user implementation
12666
- * const userAction = {
12667
- * signal: async (event) => {
12668
- * // User code that might throw
12669
- * throw new Error('User error');
12670
- * }
12671
- * };
12672
- *
12673
- * const proxy = ActionProxy.fromInstance(userAction);
12674
- *
12675
- * // Error is caught and logged, execution continues
12676
- * await proxy.signal(event); // Logs error, returns null
12677
- * await proxy.dispose(); // Safe call even though not implemented
12678
- * ```
12867
+ * Logger service with automatic context injection.
12679
12868
  *
12680
- * @example
12681
- * ```typescript
12682
- * // Partial implementation is safe
12683
- * const partialAction = {
12684
- * init: async () => console.log('Initialized'),
12685
- * // Other methods not implemented
12686
- * };
12869
+ * Features:
12870
+ * - Delegates to user-provided logger via setLogger()
12871
+ * - Automatically appends method context (strategyName, exchangeName, frameName)
12872
+ * - Automatically appends execution context (symbol, when, backtest)
12873
+ * - Defaults to NOOP_LOGGER if no logger configured
12687
12874
  *
12688
- * const proxy = ActionProxy.fromInstance(partialAction);
12689
- * await proxy.init(); // Works
12690
- * await proxy.signal(event); // Returns null (not implemented)
12691
- * ```
12875
+ * Used throughout the framework for consistent logging with context.
12692
12876
  */
12693
- declare class ActionProxy implements IPublicAction {
12694
- readonly _target: Partial<IPublicAction>;
12877
+ declare class LoggerService implements ILogger {
12878
+ private readonly methodContextService;
12879
+ private readonly executionContextService;
12880
+ private _commonLogger;
12695
12881
  /**
12696
- * Creates a new ActionProxy instance.
12697
- *
12698
- * @param _target - Partial action implementation to wrap with error capture
12699
- * @private Use ActionProxy.fromInstance() instead
12882
+ * Gets current method context if available.
12883
+ * Contains strategyName, exchangeName, frameName from MethodContextService.
12700
12884
  */
12701
- private constructor();
12885
+ private get methodContext();
12702
12886
  /**
12703
- * Initializes the action handler with error capture.
12704
- *
12705
- * Wraps the user's init() method in trycatch to prevent initialization errors from crashing the system.
12706
- * If the target doesn't implement init(), this method safely returns undefined.
12707
- *
12708
- * @returns Promise resolving to user's init() result or undefined if not implemented
12887
+ * Gets current execution context if available.
12888
+ * Contains symbol, when, backtest from ExecutionContextService.
12709
12889
  */
12710
- init(): Promise<any>;
12890
+ private get executionContext();
12711
12891
  /**
12712
- * Handles signal events from all modes with error capture.
12713
- *
12714
- * Wraps the user's signal() method to catch and log any errors.
12715
- * Called on every tick/candle when strategy is evaluated.
12892
+ * Logs general-purpose message with automatic context injection.
12716
12893
  *
12717
- * @param event - Signal state result with action, state, signal data, and context
12718
- * @returns Promise resolving to user's signal() result or null on error
12894
+ * @param topic - Log topic/category
12895
+ * @param args - Additional log arguments
12719
12896
  */
12720
- signal(event: IStrategyTickResult): Promise<any>;
12897
+ log: (topic: string, ...args: any[]) => Promise<void>;
12721
12898
  /**
12722
- * Handles signal events from live trading only with error capture.
12723
- *
12724
- * Wraps the user's signalLive() method to catch and log any errors.
12725
- * Called every tick in live mode.
12899
+ * Logs debug-level message with automatic context injection.
12726
12900
  *
12727
- * @param event - Signal state result from live trading
12728
- * @returns Promise resolving to user's signalLive() result or null on error
12901
+ * @param topic - Log topic/category
12902
+ * @param args - Additional log arguments
12729
12903
  */
12730
- signalLive(event: IStrategyTickResult): Promise<any>;
12904
+ debug: (topic: string, ...args: any[]) => Promise<void>;
12731
12905
  /**
12732
- * Handles signal events from backtest only with error capture.
12906
+ * Logs info-level message with automatic context injection.
12907
+ *
12908
+ * @param topic - Log topic/category
12909
+ * @param args - Additional log arguments
12910
+ */
12911
+ info: (topic: string, ...args: any[]) => Promise<void>;
12912
+ /**
12913
+ * Logs warning-level message with automatic context injection.
12914
+ *
12915
+ * @param topic - Log topic/category
12916
+ * @param args - Additional log arguments
12917
+ */
12918
+ warn: (topic: string, ...args: any[]) => Promise<void>;
12919
+ /**
12920
+ * Sets custom logger implementation.
12921
+ *
12922
+ * @param logger - Custom logger implementing ILogger interface
12923
+ */
12924
+ setLogger: (logger: ILogger) => void;
12925
+ }
12926
+
12927
+ /**
12928
+ * Type definition for strategy methods.
12929
+ * Maps all keys of IStrategy to any type.
12930
+ * Used for dynamic method routing in StrategyCoreService.
12931
+ */
12932
+ type TStrategy$1 = {
12933
+ [key in keyof IStrategy]: any;
12934
+ };
12935
+ /**
12936
+ * Global service for strategy operations with execution context injection.
12937
+ *
12938
+ * Wraps StrategyConnectionService with ExecutionContextService to inject
12939
+ * symbol, when, and backtest parameters into the execution context.
12940
+ *
12941
+ * Used internally by BacktestLogicPrivateService and LiveLogicPrivateService.
12942
+ */
12943
+ declare class StrategyCoreService implements TStrategy$1 {
12944
+ private readonly loggerService;
12945
+ private readonly strategyConnectionService;
12946
+ private readonly strategySchemaService;
12947
+ private readonly riskValidationService;
12948
+ private readonly strategyValidationService;
12949
+ private readonly exchangeValidationService;
12950
+ private readonly frameValidationService;
12951
+ /**
12952
+ * Validates strategy and associated risk configuration.
12953
+ *
12954
+ * Memoized to avoid redundant validations for the same symbol-strategy-exchange-frame combination.
12955
+ * Logs validation activity.
12956
+ * @param symbol - Trading pair symbol
12957
+ * @param context - Execution context with strategyName, exchangeName, frameName
12958
+ * @returns Promise that resolves when validation is complete
12959
+ */
12960
+ private validate;
12961
+ /**
12962
+ * Retrieves the currently active pending signal for the symbol.
12963
+ * If no active signal exists, returns null.
12964
+ * Used internally for monitoring TP/SL and time expiration.
12965
+ *
12966
+ * @param backtest - Whether running in backtest mode
12967
+ * @param symbol - Trading pair symbol
12968
+ * @param context - Execution context with strategyName, exchangeName, frameName
12969
+ * @returns Promise resolving to pending signal or null
12970
+ */
12971
+ getPendingSignal: (backtest: boolean, symbol: string, context: {
12972
+ strategyName: StrategyName;
12973
+ exchangeName: ExchangeName;
12974
+ frameName: FrameName;
12975
+ }) => Promise<ISignalRow | null>;
12976
+ /**
12977
+ * Retrieves the currently active scheduled signal for the symbol.
12978
+ * If no scheduled signal exists, returns null.
12979
+ * Used internally for monitoring scheduled signal activation.
12980
+ *
12981
+ * @param backtest - Whether running in backtest mode
12982
+ * @param symbol - Trading pair symbol
12983
+ * @param context - Execution context with strategyName, exchangeName, frameName
12984
+ * @returns Promise resolving to scheduled signal or null
12985
+ */
12986
+ getScheduledSignal: (backtest: boolean, symbol: string, context: {
12987
+ strategyName: StrategyName;
12988
+ exchangeName: ExchangeName;
12989
+ frameName: FrameName;
12990
+ }) => Promise<IScheduledSignalRow | null>;
12991
+ /**
12992
+ * Checks if breakeven threshold has been reached for the current pending signal.
12993
+ *
12994
+ * Validates strategy existence and delegates to connection service
12995
+ * to check if price has moved far enough to cover transaction costs.
12996
+ *
12997
+ * Does not require execution context as this is a state query operation.
12998
+ *
12999
+ * @param backtest - Whether running in backtest mode
13000
+ * @param symbol - Trading pair symbol
13001
+ * @param currentPrice - Current market price to check against threshold
13002
+ * @param context - Execution context with strategyName, exchangeName, frameName
13003
+ * @returns Promise<boolean> - true if breakeven threshold reached, false otherwise
13004
+ *
13005
+ * @example
13006
+ * ```typescript
13007
+ * // Check if breakeven is available for LONG position (entry=100, threshold=0.4%)
13008
+ * const canBreakeven = await strategyCoreService.getBreakeven(
13009
+ * false,
13010
+ * "BTCUSDT",
13011
+ * 100.5,
13012
+ * { strategyName: "my-strategy", exchangeName: "binance", frameName: "" }
13013
+ * );
13014
+ * // Returns true (price >= 100.4)
13015
+ *
13016
+ * if (canBreakeven) {
13017
+ * await strategyCoreService.breakeven(false, "BTCUSDT", 100.5, context);
13018
+ * }
13019
+ * ```
13020
+ */
13021
+ getBreakeven: (backtest: boolean, symbol: string, currentPrice: number, context: {
13022
+ strategyName: StrategyName;
13023
+ exchangeName: ExchangeName;
13024
+ frameName: FrameName;
13025
+ }) => Promise<boolean>;
13026
+ /**
13027
+ * Checks if the strategy has been stopped.
13028
+ *
13029
+ * Validates strategy existence and delegates to connection service
13030
+ * to retrieve the stopped state from the strategy instance.
13031
+ *
13032
+ * @param backtest - Whether running in backtest mode
13033
+ * @param symbol - Trading pair symbol
13034
+ * @param context - Execution context with strategyName, exchangeName, frameName
13035
+ * @returns Promise resolving to true if strategy is stopped, false otherwise
13036
+ */
13037
+ getStopped: (backtest: boolean, symbol: string, context: {
13038
+ strategyName: StrategyName;
13039
+ exchangeName: ExchangeName;
13040
+ frameName: FrameName;
13041
+ }) => Promise<boolean>;
13042
+ /**
13043
+ * Checks signal status at a specific timestamp.
13044
+ *
13045
+ * Wraps strategy tick() with execution context containing symbol, timestamp,
13046
+ * and backtest mode flag.
13047
+ *
13048
+ * @param symbol - Trading pair symbol
13049
+ * @param when - Timestamp for tick evaluation
13050
+ * @param backtest - Whether running in backtest mode
13051
+ * @param context - Execution context with strategyName, exchangeName, frameName
13052
+ * @returns Discriminated union of tick result (idle, opened, active, closed)
13053
+ */
13054
+ tick: (symbol: string, when: Date, backtest: boolean, context: {
13055
+ strategyName: StrategyName;
13056
+ exchangeName: ExchangeName;
13057
+ frameName: FrameName;
13058
+ }) => Promise<IStrategyTickResult>;
13059
+ /**
13060
+ * Runs fast backtest against candle array.
13061
+ *
13062
+ * Wraps strategy backtest() with execution context containing symbol,
13063
+ * timestamp, and backtest mode flag.
13064
+ *
13065
+ * @param symbol - Trading pair symbol
13066
+ * @param candles - Array of historical candles to test against
13067
+ * @param when - Starting timestamp for backtest
13068
+ * @param backtest - Whether running in backtest mode (typically true)
13069
+ * @param context - Execution context with strategyName, exchangeName, frameName
13070
+ * @returns Closed signal result with PNL
13071
+ */
13072
+ backtest: (symbol: string, candles: ICandleData[], when: Date, backtest: boolean, context: {
13073
+ strategyName: StrategyName;
13074
+ exchangeName: ExchangeName;
13075
+ frameName: FrameName;
13076
+ }) => Promise<IStrategyBacktestResult>;
13077
+ /**
13078
+ * Stops the strategy from generating new signals.
13079
+ *
13080
+ * Delegates to StrategyConnectionService.stop() to set internal flag.
13081
+ * Does not require execution context.
13082
+ *
13083
+ * @param backtest - Whether running in backtest mode
13084
+ * @param symbol - Trading pair symbol
13085
+ * @param ctx - Context with strategyName, exchangeName, frameName
13086
+ * @returns Promise that resolves when stop flag is set
13087
+ */
13088
+ stopStrategy: (backtest: boolean, symbol: string, context: {
13089
+ strategyName: StrategyName;
13090
+ exchangeName: ExchangeName;
13091
+ frameName: FrameName;
13092
+ }) => Promise<void>;
13093
+ /**
13094
+ * Cancels the scheduled signal without stopping the strategy.
13095
+ *
13096
+ * Delegates to StrategyConnectionService.cancelScheduled() to clear scheduled signal
13097
+ * and emit cancelled event through emitters.
13098
+ * Does not require execution context.
13099
+ *
13100
+ * @param backtest - Whether running in backtest mode
13101
+ * @param symbol - Trading pair symbol
13102
+ * @param ctx - Context with strategyName, exchangeName, frameName
13103
+ * @param cancelId - Optional cancellation ID for user-initiated cancellations
13104
+ * @returns Promise that resolves when scheduled signal is cancelled
13105
+ */
13106
+ cancelScheduled: (backtest: boolean, symbol: string, context: {
13107
+ strategyName: StrategyName;
13108
+ exchangeName: ExchangeName;
13109
+ frameName: FrameName;
13110
+ }, cancelId?: string) => Promise<void>;
13111
+ /**
13112
+ * Closes the pending signal without stopping the strategy.
13113
+ *
13114
+ * Clears the pending signal (active position).
13115
+ * Does NOT affect scheduled signals or strategy operation.
13116
+ * Does NOT set stop flag - strategy can continue generating new signals.
13117
+ *
13118
+ * Delegates to StrategyConnectionService.closePending() to clear pending signal
13119
+ * and emit closed event through emitters.
13120
+ * Does not require execution context.
13121
+ *
13122
+ * @param backtest - Whether running in backtest mode
13123
+ * @param symbol - Trading pair symbol
13124
+ * @param context - Context with strategyName, exchangeName, frameName
13125
+ * @param closeId - Optional close ID for user-initiated closes
13126
+ * @returns Promise that resolves when pending signal is closed
13127
+ */
13128
+ closePending: (backtest: boolean, symbol: string, context: {
13129
+ strategyName: StrategyName;
13130
+ exchangeName: ExchangeName;
13131
+ frameName: FrameName;
13132
+ }, closeId?: string) => Promise<void>;
13133
+ /**
13134
+ * Disposes the ClientStrategy instance for the given context.
13135
+ *
13136
+ * Calls dispose on the strategy instance to clean up resources,
13137
+ * then removes it from cache.
13138
+ *
13139
+ * @param backtest - Whether running in backtest mode
13140
+ * @param symbol - Trading pair symbol
13141
+ * @param context - Execution context with strategyName, exchangeName, frameName
13142
+ */
13143
+ dispose: (backtest: boolean, symbol: string, context: {
13144
+ strategyName: StrategyName;
13145
+ exchangeName: ExchangeName;
13146
+ frameName: FrameName;
13147
+ }) => Promise<void>;
13148
+ /**
13149
+ * Clears the memoized ClientStrategy instance from cache.
13150
+ *
13151
+ * Delegates to StrategyConnectionService.dispose() if payload provided,
13152
+ * otherwise clears all strategy instances.
13153
+ *
13154
+ * @param payload - Optional payload with symbol, context and backtest flag (clears all if not provided)
13155
+ */
13156
+ clear: (payload?: {
13157
+ symbol: string;
13158
+ strategyName: StrategyName;
13159
+ exchangeName: ExchangeName;
13160
+ frameName: FrameName;
13161
+ backtest: boolean;
13162
+ }) => Promise<void>;
13163
+ /**
13164
+ * Executes partial close at profit level (moving toward TP).
13165
+ *
13166
+ * Validates strategy existence and delegates to connection service
13167
+ * to close a percentage of the pending position at profit.
13168
+ *
13169
+ * Does not require execution context as this is a direct state mutation.
13170
+ *
13171
+ * @param backtest - Whether running in backtest mode
13172
+ * @param symbol - Trading pair symbol
13173
+ * @param percentToClose - Percentage of position to close (0-100, absolute value)
13174
+ * @param currentPrice - Current market price for this partial close (must be in profit direction)
13175
+ * @param context - Execution context with strategyName, exchangeName, frameName
13176
+ * @returns Promise<boolean> - true if partial close executed, false if skipped
13177
+ *
13178
+ * @example
13179
+ * ```typescript
13180
+ * // Close 30% of position at profit
13181
+ * const success = await strategyCoreService.partialProfit(
13182
+ * false,
13183
+ * "BTCUSDT",
13184
+ * 30,
13185
+ * 45000,
13186
+ * { strategyName: "my-strategy", exchangeName: "binance", frameName: "" }
13187
+ * );
13188
+ * if (success) {
13189
+ * console.log('Partial profit executed');
13190
+ * }
13191
+ * ```
13192
+ */
13193
+ partialProfit: (backtest: boolean, symbol: string, percentToClose: number, currentPrice: number, context: {
13194
+ strategyName: StrategyName;
13195
+ exchangeName: ExchangeName;
13196
+ frameName: FrameName;
13197
+ }) => Promise<boolean>;
13198
+ /**
13199
+ * Executes partial close at loss level (moving toward SL).
13200
+ *
13201
+ * Validates strategy existence and delegates to connection service
13202
+ * to close a percentage of the pending position at loss.
13203
+ *
13204
+ * Does not require execution context as this is a direct state mutation.
13205
+ *
13206
+ * @param backtest - Whether running in backtest mode
13207
+ * @param symbol - Trading pair symbol
13208
+ * @param percentToClose - Percentage of position to close (0-100, absolute value)
13209
+ * @param currentPrice - Current market price for this partial close (must be in loss direction)
13210
+ * @param context - Execution context with strategyName, exchangeName, frameName
13211
+ * @returns Promise<boolean> - true if partial close executed, false if skipped
13212
+ *
13213
+ * @example
13214
+ * ```typescript
13215
+ * // Close 40% of position at loss
13216
+ * const success = await strategyCoreService.partialLoss(
13217
+ * false,
13218
+ * "BTCUSDT",
13219
+ * 40,
13220
+ * 38000,
13221
+ * { strategyName: "my-strategy", exchangeName: "binance", frameName: "" }
13222
+ * );
13223
+ * if (success) {
13224
+ * console.log('Partial loss executed');
13225
+ * }
13226
+ * ```
13227
+ */
13228
+ partialLoss: (backtest: boolean, symbol: string, percentToClose: number, currentPrice: number, context: {
13229
+ strategyName: StrategyName;
13230
+ exchangeName: ExchangeName;
13231
+ frameName: FrameName;
13232
+ }) => Promise<boolean>;
13233
+ /**
13234
+ * Adjusts the trailing stop-loss distance for an active pending signal.
13235
+ *
13236
+ * Validates strategy existence and delegates to connection service
13237
+ * to update the stop-loss distance by a percentage adjustment.
13238
+ *
13239
+ * Does not require execution context as this is a direct state mutation.
13240
+ *
13241
+ * @param backtest - Whether running in backtest mode
13242
+ * @param symbol - Trading pair symbol
13243
+ * @param percentShift - Percentage adjustment to SL distance (-100 to 100)
13244
+ * @param currentPrice - Current market price to check for intrusion
13245
+ * @param context - Execution context with strategyName, exchangeName, frameName
13246
+ * @returns Promise that resolves when trailing SL is updated
13247
+ *
13248
+ * @example
13249
+ * ```typescript
13250
+ * // LONG: entry=100, originalSL=90, distance=10%, currentPrice=102
13251
+ * // Tighten stop by 50%: newSL = 100 - 5% = 95
13252
+ * await strategyCoreService.trailingStop(
13253
+ * false,
13254
+ * "BTCUSDT",
13255
+ * -50,
13256
+ * 102,
13257
+ * { strategyName: "my-strategy", exchangeName: "binance", frameName: "" }
13258
+ * );
13259
+ * ```
13260
+ */
13261
+ trailingStop: (backtest: boolean, symbol: string, percentShift: number, currentPrice: number, context: {
13262
+ strategyName: StrategyName;
13263
+ exchangeName: ExchangeName;
13264
+ frameName: FrameName;
13265
+ }) => Promise<boolean>;
13266
+ /**
13267
+ * Adjusts the trailing take-profit distance for an active pending signal.
13268
+ * Validates context and delegates to StrategyConnectionService.
13269
+ *
13270
+ * @param backtest - Whether running in backtest mode
13271
+ * @param symbol - Trading pair symbol
13272
+ * @param percentShift - Percentage adjustment to TP distance (-100 to 100)
13273
+ * @param currentPrice - Current market price to check for intrusion
13274
+ * @param context - Strategy context with strategyName, exchangeName, frameName
13275
+ * @returns Promise that resolves when trailing TP is updated
13276
+ *
13277
+ * @example
13278
+ * ```typescript
13279
+ * // LONG: entry=100, originalTP=110, distance=10%, currentPrice=102
13280
+ * // Move TP further by 50%: newTP = 100 + 15% = 115
13281
+ * await strategyCoreService.trailingTake(
13282
+ * false,
13283
+ * "BTCUSDT",
13284
+ * 50,
13285
+ * 102,
13286
+ * { strategyName: "my-strategy", exchangeName: "binance", frameName: "" }
13287
+ * );
13288
+ * ```
13289
+ */
13290
+ trailingTake: (backtest: boolean, symbol: string, percentShift: number, currentPrice: number, context: {
13291
+ strategyName: StrategyName;
13292
+ exchangeName: ExchangeName;
13293
+ frameName: FrameName;
13294
+ }) => Promise<boolean>;
13295
+ /**
13296
+ * Moves stop-loss to breakeven when price reaches threshold.
13297
+ * Validates context and delegates to StrategyConnectionService.
13298
+ *
13299
+ * @param backtest - Whether running in backtest mode
13300
+ * @param symbol - Trading pair symbol
13301
+ * @param currentPrice - Current market price to check threshold
13302
+ * @param context - Strategy context with strategyName, exchangeName, frameName
13303
+ * @returns Promise<boolean> - true if breakeven was set, false otherwise
13304
+ *
13305
+ * @example
13306
+ * ```typescript
13307
+ * const moved = await strategyCoreService.breakeven(
13308
+ * false,
13309
+ * "BTCUSDT",
13310
+ * 112,
13311
+ * { strategyName: "my-strategy", exchangeName: "binance", frameName: "" }
13312
+ * );
13313
+ * ```
13314
+ */
13315
+ breakeven: (backtest: boolean, symbol: string, currentPrice: number, context: {
13316
+ strategyName: StrategyName;
13317
+ exchangeName: ExchangeName;
13318
+ frameName: FrameName;
13319
+ }) => Promise<boolean>;
13320
+ }
13321
+
13322
+ /**
13323
+ * Type alias for column configuration used in strategy markdown reports.
13324
+ *
13325
+ * @see ColumnModel for the base interface
13326
+ * @see StrategyEvent for the event data structure
13327
+ */
13328
+ type Columns = ColumnModel<StrategyEvent>;
13329
+ /**
13330
+ * Service for accumulating strategy management events and generating markdown reports.
13331
+ *
13332
+ * Collects strategy actions (cancel-scheduled, close-pending, partial-profit,
13333
+ * partial-loss, trailing-stop, trailing-take, breakeven) in memory and provides
13334
+ * methods to retrieve statistics, generate reports, and export to files.
13335
+ *
13336
+ * Unlike StrategyReportService which writes each event to disk immediately,
13337
+ * this service accumulates events in ReportStorage instances (max 250 per
13338
+ * symbol-strategy pair) for batch reporting.
13339
+ *
13340
+ * Features:
13341
+ * - In-memory event accumulation with memoized storage per symbol-strategy pair
13342
+ * - Statistical data extraction (event counts by action type)
13343
+ * - Markdown report generation with configurable columns
13344
+ * - File export with timestamped filenames
13345
+ * - Selective or full cache clearing
13346
+ *
13347
+ * Lifecycle:
13348
+ * - Call subscribe() to enable event collection
13349
+ * - Events are collected automatically via cancelScheduled, closePending, etc.
13350
+ * - Use getData(), getReport(), or dump() to retrieve accumulated data
13351
+ * - Call unsubscribe() to disable collection and clear all data
13352
+ *
13353
+ * @example
13354
+ * ```typescript
13355
+ * strategyMarkdownService.subscribe();
13356
+ *
13357
+ * // Events are collected automatically during strategy execution
13358
+ * // ...
13359
+ *
13360
+ * // Get statistics
13361
+ * const stats = await strategyMarkdownService.getData("BTCUSDT", "my-strategy", "binance", "1h", true);
13362
+ *
13363
+ * // Generate markdown report
13364
+ * const report = await strategyMarkdownService.getReport("BTCUSDT", "my-strategy", "binance", "1h", true);
13365
+ *
13366
+ * // Export to file
13367
+ * await strategyMarkdownService.dump("BTCUSDT", "my-strategy", "binance", "1h", true);
13368
+ *
13369
+ * strategyMarkdownService.unsubscribe();
13370
+ * ```
13371
+ *
13372
+ * @see StrategyReportService for immediate event persistence to JSON files
13373
+ * @see Strategy for the high-level utility class that wraps this service
13374
+ */
13375
+ declare class StrategyMarkdownService {
13376
+ readonly loggerService: LoggerService;
13377
+ readonly executionContextService: {
13378
+ readonly context: IExecutionContext;
13379
+ };
13380
+ readonly strategyCoreService: StrategyCoreService;
13381
+ /**
13382
+ * Memoized factory for ReportStorage instances.
13383
+ *
13384
+ * Creates and caches ReportStorage per unique symbol-strategy-exchange-frame-backtest combination.
13385
+ * Uses CREATE_KEY_FN for cache key generation.
13386
+ *
13387
+ * @internal
13388
+ */
13389
+ private getStorage;
13390
+ /**
13391
+ * Records a cancel-scheduled event when a scheduled signal is cancelled.
13392
+ *
13393
+ * Retrieves the scheduled signal from StrategyCoreService and stores
13394
+ * the cancellation event in the appropriate ReportStorage.
13395
+ *
13396
+ * @param symbol - Trading pair symbol (e.g., "BTCUSDT")
13397
+ * @param isBacktest - Whether this is a backtest or live trading event
13398
+ * @param context - Strategy context with strategyName, exchangeName, frameName
13399
+ * @param cancelId - Optional identifier for the cancellation reason
13400
+ */
13401
+ cancelScheduled: (symbol: string, isBacktest: boolean, context: {
13402
+ strategyName: StrategyName;
13403
+ exchangeName: ExchangeName;
13404
+ frameName: FrameName;
13405
+ }, cancelId?: string) => Promise<void>;
13406
+ /**
13407
+ * Records a close-pending event when a pending signal is closed.
13408
+ *
13409
+ * Retrieves the pending signal from StrategyCoreService and stores
13410
+ * the close event in the appropriate ReportStorage.
13411
+ *
13412
+ * @param symbol - Trading pair symbol (e.g., "BTCUSDT")
13413
+ * @param isBacktest - Whether this is a backtest or live trading event
13414
+ * @param context - Strategy context with strategyName, exchangeName, frameName
13415
+ * @param closeId - Optional identifier for the close reason
13416
+ */
13417
+ closePending: (symbol: string, isBacktest: boolean, context: {
13418
+ strategyName: StrategyName;
13419
+ exchangeName: ExchangeName;
13420
+ frameName: FrameName;
13421
+ }, closeId?: string) => Promise<void>;
13422
+ /**
13423
+ * Records a partial-profit event when a portion of the position is closed at profit.
13424
+ *
13425
+ * Stores the percentage closed and current price when partial profit-taking occurs.
13426
+ *
13427
+ * @param symbol - Trading pair symbol (e.g., "BTCUSDT")
13428
+ * @param percentToClose - Percentage of position to close (0-100)
13429
+ * @param currentPrice - Current market price at time of partial close
13430
+ * @param isBacktest - Whether this is a backtest or live trading event
13431
+ * @param context - Strategy context with strategyName, exchangeName, frameName
13432
+ */
13433
+ partialProfit: (symbol: string, percentToClose: number, currentPrice: number, isBacktest: boolean, context: {
13434
+ strategyName: StrategyName;
13435
+ exchangeName: ExchangeName;
13436
+ frameName: FrameName;
13437
+ }) => Promise<void>;
13438
+ /**
13439
+ * Records a partial-loss event when a portion of the position is closed at loss.
13440
+ *
13441
+ * Stores the percentage closed and current price when partial loss-cutting occurs.
13442
+ *
13443
+ * @param symbol - Trading pair symbol (e.g., "BTCUSDT")
13444
+ * @param percentToClose - Percentage of position to close (0-100)
13445
+ * @param currentPrice - Current market price at time of partial close
13446
+ * @param isBacktest - Whether this is a backtest or live trading event
13447
+ * @param context - Strategy context with strategyName, exchangeName, frameName
13448
+ */
13449
+ partialLoss: (symbol: string, percentToClose: number, currentPrice: number, isBacktest: boolean, context: {
13450
+ strategyName: StrategyName;
13451
+ exchangeName: ExchangeName;
13452
+ frameName: FrameName;
13453
+ }) => Promise<void>;
13454
+ /**
13455
+ * Records a trailing-stop event when the stop-loss is adjusted.
13456
+ *
13457
+ * Stores the percentage shift and current price when trailing stop moves.
13458
+ *
13459
+ * @param symbol - Trading pair symbol (e.g., "BTCUSDT")
13460
+ * @param percentShift - Percentage the stop-loss was shifted
13461
+ * @param currentPrice - Current market price at time of adjustment
13462
+ * @param isBacktest - Whether this is a backtest or live trading event
13463
+ * @param context - Strategy context with strategyName, exchangeName, frameName
13464
+ */
13465
+ trailingStop: (symbol: string, percentShift: number, currentPrice: number, isBacktest: boolean, context: {
13466
+ strategyName: StrategyName;
13467
+ exchangeName: ExchangeName;
13468
+ frameName: FrameName;
13469
+ }) => Promise<void>;
13470
+ /**
13471
+ * Records a trailing-take event when the take-profit is adjusted.
13472
+ *
13473
+ * Stores the percentage shift and current price when trailing take-profit moves.
13474
+ *
13475
+ * @param symbol - Trading pair symbol (e.g., "BTCUSDT")
13476
+ * @param percentShift - Percentage the take-profit was shifted
13477
+ * @param currentPrice - Current market price at time of adjustment
13478
+ * @param isBacktest - Whether this is a backtest or live trading event
13479
+ * @param context - Strategy context with strategyName, exchangeName, frameName
13480
+ */
13481
+ trailingTake: (symbol: string, percentShift: number, currentPrice: number, isBacktest: boolean, context: {
13482
+ strategyName: StrategyName;
13483
+ exchangeName: ExchangeName;
13484
+ frameName: FrameName;
13485
+ }) => Promise<void>;
13486
+ /**
13487
+ * Records a breakeven event when the stop-loss is moved to entry price.
13488
+ *
13489
+ * Stores the current price when breakeven protection is activated.
13490
+ *
13491
+ * @param symbol - Trading pair symbol (e.g., "BTCUSDT")
13492
+ * @param currentPrice - Current market price at time of breakeven activation
13493
+ * @param isBacktest - Whether this is a backtest or live trading event
13494
+ * @param context - Strategy context with strategyName, exchangeName, frameName
13495
+ */
13496
+ breakeven: (symbol: string, currentPrice: number, isBacktest: boolean, context: {
13497
+ strategyName: StrategyName;
13498
+ exchangeName: ExchangeName;
13499
+ frameName: FrameName;
13500
+ }) => Promise<void>;
13501
+ /**
13502
+ * Retrieves aggregated statistics from accumulated strategy events.
13503
+ *
13504
+ * Returns counts for each action type and the full event list from the
13505
+ * ReportStorage for the specified symbol-strategy pair.
13506
+ *
13507
+ * @param symbol - Trading pair symbol (e.g., "BTCUSDT")
13508
+ * @param strategyName - Name of the trading strategy
13509
+ * @param exchangeName - Name of the exchange
13510
+ * @param frameName - Timeframe name for backtest identification
13511
+ * @param backtest - Whether to get backtest or live data
13512
+ * @returns Promise resolving to StrategyStatisticsModel with event list and counts
13513
+ * @throws Error if service not initialized (subscribe() not called)
13514
+ */
13515
+ getData: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean) => Promise<StrategyStatisticsModel>;
13516
+ /**
13517
+ * Generates a markdown report from accumulated strategy events.
13518
+ *
13519
+ * Creates a formatted markdown document containing:
13520
+ * - Header with symbol and strategy name
13521
+ * - Table of all events with configurable columns
13522
+ * - Summary statistics with counts by action type
13523
+ *
13524
+ * @param symbol - Trading pair symbol (e.g., "BTCUSDT")
13525
+ * @param strategyName - Name of the trading strategy
13526
+ * @param exchangeName - Name of the exchange
13527
+ * @param frameName - Timeframe name for backtest identification
13528
+ * @param backtest - Whether to get backtest or live data
13529
+ * @param columns - Column configuration for the event table
13530
+ * @returns Promise resolving to formatted markdown string
13531
+ * @throws Error if service not initialized (subscribe() not called)
13532
+ */
13533
+ getReport: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, columns?: Columns[]) => Promise<string>;
13534
+ /**
13535
+ * Generates and saves a markdown report to disk.
13536
+ *
13537
+ * Creates the output directory if it doesn't exist and writes
13538
+ * the report with a timestamped filename via Markdown.writeData().
13539
+ *
13540
+ * Filename format: `{symbol}_{strategyName}_{exchangeName}[_{frameName}_backtest|_live]-{timestamp}.md`
13541
+ *
13542
+ * @param symbol - Trading pair symbol (e.g., "BTCUSDT")
13543
+ * @param strategyName - Name of the trading strategy
13544
+ * @param exchangeName - Name of the exchange
13545
+ * @param frameName - Timeframe name for backtest identification
13546
+ * @param backtest - Whether to dump backtest or live data
13547
+ * @param path - Output directory path (default: "./dump/strategy")
13548
+ * @param columns - Column configuration for the event table
13549
+ * @returns Promise that resolves when file is written
13550
+ * @throws Error if service not initialized (subscribe() not called)
13551
+ */
13552
+ dump: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, path?: string, columns?: Columns[]) => Promise<void>;
13553
+ /**
13554
+ * Clears accumulated events from storage.
13555
+ *
13556
+ * Can clear either a specific symbol-strategy pair or all stored data.
13557
+ *
13558
+ * @param payload - Optional filter to clear specific storage. If omitted, clears all.
13559
+ * @param payload.symbol - Trading pair symbol
13560
+ * @param payload.strategyName - Strategy name
13561
+ * @param payload.exchangeName - Exchange name
13562
+ * @param payload.frameName - Frame name
13563
+ * @param payload.backtest - Backtest mode flag
13564
+ */
13565
+ clear: (payload?: {
13566
+ symbol: string;
13567
+ strategyName: StrategyName;
13568
+ exchangeName: ExchangeName;
13569
+ frameName: FrameName;
13570
+ backtest: boolean;
13571
+ }) => Promise<void>;
13572
+ /**
13573
+ * Initializes the service for event collection.
13574
+ *
13575
+ * Must be called before any events can be collected or reports generated.
13576
+ * Uses singleshot pattern to ensure only one subscription exists at a time.
13577
+ *
13578
+ * @returns Cleanup function that clears the subscription and all accumulated data
13579
+ */
13580
+ subscribe: (() => () => void) & functools_kit.ISingleshotClearable;
13581
+ /**
13582
+ * Stops event collection and clears all accumulated data.
13583
+ *
13584
+ * Invokes the cleanup function returned by subscribe(), which clears
13585
+ * both the subscription and all ReportStorage instances.
13586
+ * Safe to call multiple times - only acts if subscription exists.
13587
+ */
13588
+ unsubscribe: () => Promise<void>;
13589
+ }
13590
+
13591
+ /**
13592
+ * Utility class for accessing strategy management reports and statistics.
13593
+ *
13594
+ * Provides static-like methods (via singleton instance) to retrieve data
13595
+ * accumulated by StrategyMarkdownService from strategy management events.
13596
+ *
13597
+ * Features:
13598
+ * - Statistical data extraction (event counts by action type)
13599
+ * - Markdown report generation with event tables
13600
+ * - File export to disk
13601
+ *
13602
+ * Data source:
13603
+ * - StrategyMarkdownService receives events via direct method calls
13604
+ * - Accumulates events in ReportStorage (max 250 events per symbol-strategy pair)
13605
+ * - Events include: cancel-scheduled, close-pending, partial-profit, partial-loss,
13606
+ * trailing-stop, trailing-take, breakeven
13607
+ *
13608
+ * @example
13609
+ * ```typescript
13610
+ * import { Strategy } from "./classes/Strategy";
13611
+ *
13612
+ * // Get statistical data for BTCUSDT:my-strategy
13613
+ * const stats = await Strategy.getData("BTCUSDT", { strategyName: "my-strategy", exchangeName: "binance", frameName: "1h" });
13614
+ * console.log(`Total events: ${stats.totalEvents}`);
13615
+ * console.log(`Partial profit events: ${stats.partialProfitCount}`);
13616
+ *
13617
+ * // Generate markdown report
13618
+ * const markdown = await Strategy.getReport("BTCUSDT", { strategyName: "my-strategy", exchangeName: "binance", frameName: "1h" });
13619
+ * console.log(markdown); // Formatted table with all events
13620
+ *
13621
+ * // Export report to file
13622
+ * await Strategy.dump("BTCUSDT", { strategyName: "my-strategy", exchangeName: "binance", frameName: "1h" }); // Saves to ./dump/strategy/
13623
+ * ```
13624
+ */
13625
+ declare class StrategyUtils {
13626
+ /**
13627
+ * Retrieves statistical data from accumulated strategy events.
13628
+ *
13629
+ * Delegates to StrategyMarkdownService.getData() which reads from ReportStorage.
13630
+ * Returns aggregated metrics calculated from all strategy events.
13631
+ *
13632
+ * @param symbol - Trading pair symbol (e.g., "BTCUSDT")
13633
+ * @param context - Strategy context with strategyName, exchangeName, frameName
13634
+ * @param backtest - Whether to get backtest data (default: false)
13635
+ * @returns Promise resolving to StrategyStatisticsModel object with counts and event list
13636
+ *
13637
+ * @example
13638
+ * ```typescript
13639
+ * const stats = await Strategy.getData("BTCUSDT", { strategyName: "my-strategy", exchangeName: "binance", frameName: "1h" });
13640
+ *
13641
+ * console.log(`Total events: ${stats.totalEvents}`);
13642
+ * console.log(`Partial profit: ${stats.partialProfitCount}`);
13643
+ * console.log(`Trailing stop: ${stats.trailingStopCount}`);
13644
+ *
13645
+ * // Iterate through all events
13646
+ * for (const event of stats.eventList) {
13647
+ * console.log(`Signal ${event.signalId}: ${event.action} at ${event.currentPrice}`);
13648
+ * }
13649
+ * ```
13650
+ */
13651
+ getData: (symbol: string, context: {
13652
+ strategyName: StrategyName;
13653
+ exchangeName: ExchangeName;
13654
+ frameName: FrameName;
13655
+ }, backtest?: boolean) => Promise<StrategyStatisticsModel>;
13656
+ /**
13657
+ * Generates markdown report with all strategy events for a symbol-strategy pair.
13658
+ *
13659
+ * Creates formatted table containing:
13660
+ * - Symbol
13661
+ * - Strategy
13662
+ * - Signal ID
13663
+ * - Action (cancel-scheduled, close-pending, partial-profit, etc.)
13664
+ * - Price
13665
+ * - Percent values (% To Close, % Shift)
13666
+ * - Cancel/Close IDs
13667
+ * - Timestamp (ISO 8601)
13668
+ * - Mode (Backtest/Live)
13669
+ *
13670
+ * Also includes summary statistics at the end with counts by action type.
13671
+ *
13672
+ * @param symbol - Trading pair symbol (e.g., "BTCUSDT")
13673
+ * @param context - Strategy context with strategyName, exchangeName, frameName
13674
+ * @param backtest - Whether to get backtest data (default: false)
13675
+ * @param columns - Optional columns configuration for the report
13676
+ * @returns Promise resolving to markdown formatted report string
13677
+ *
13678
+ * @example
13679
+ * ```typescript
13680
+ * const markdown = await Strategy.getReport("BTCUSDT", { strategyName: "my-strategy", exchangeName: "binance", frameName: "1h" });
13681
+ * console.log(markdown);
13682
+ *
13683
+ * // Output:
13684
+ * // # Strategy Report: BTCUSDT:my-strategy
13685
+ * //
13686
+ * // | Symbol | Strategy | Signal ID | Action | Price | ... |
13687
+ * // | --- | --- | --- | --- | --- | ... |
13688
+ * // | BTCUSDT | my-strategy | abc123 | partial-profit | 50100.00000000 USD | ... |
13689
+ * //
13690
+ * // **Total events:** 5
13691
+ * // - Cancel scheduled: 0
13692
+ * // - Close pending: 1
13693
+ * // - Partial profit: 2
13694
+ * // ...
13695
+ * ```
13696
+ */
13697
+ getReport: (symbol: string, context: {
13698
+ strategyName: StrategyName;
13699
+ exchangeName: ExchangeName;
13700
+ frameName: FrameName;
13701
+ }, backtest?: boolean, columns?: Columns[]) => Promise<string>;
13702
+ /**
13703
+ * Generates and saves markdown report to file.
13704
+ *
13705
+ * Creates directory if it doesn't exist.
13706
+ * Filename format: {symbol}_{strategyName}_{exchangeName}_{frameName|live}-{timestamp}.md
13707
+ *
13708
+ * Delegates to StrategyMarkdownService.dump() which:
13709
+ * 1. Generates markdown report via getReport()
13710
+ * 2. Creates output directory (recursive mkdir)
13711
+ * 3. Writes file with UTF-8 encoding
13712
+ * 4. Logs success/failure to console
13713
+ *
13714
+ * @param symbol - Trading pair symbol (e.g., "BTCUSDT")
13715
+ * @param context - Strategy context with strategyName, exchangeName, frameName
13716
+ * @param backtest - Whether to dump backtest data (default: false)
13717
+ * @param path - Output directory path (default: "./dump/strategy")
13718
+ * @param columns - Optional columns configuration for the report
13719
+ * @returns Promise that resolves when file is written
13720
+ *
13721
+ * @example
13722
+ * ```typescript
13723
+ * // Save to default path: ./dump/strategy/BTCUSDT_my-strategy_binance_1h_backtest-{timestamp}.md
13724
+ * await Strategy.dump("BTCUSDT", { strategyName: "my-strategy", exchangeName: "binance", frameName: "1h" }, true);
13725
+ *
13726
+ * // Save to custom path
13727
+ * await Strategy.dump("BTCUSDT", { strategyName: "my-strategy", exchangeName: "binance", frameName: "1h" }, true, "./reports/strategy");
13728
+ *
13729
+ * // After multiple symbols backtested, export all reports
13730
+ * for (const symbol of ["BTCUSDT", "ETHUSDT", "BNBUSDT"]) {
13731
+ * await Strategy.dump(symbol, { strategyName: "my-strategy", exchangeName: "binance", frameName: "1h" }, true, "./backtest-results");
13732
+ * }
13733
+ * ```
13734
+ */
13735
+ dump: (symbol: string, context: {
13736
+ strategyName: StrategyName;
13737
+ exchangeName: ExchangeName;
13738
+ frameName: FrameName;
13739
+ }, backtest?: boolean, path?: string, columns?: Columns[]) => Promise<void>;
13740
+ }
13741
+ /**
13742
+ * Global singleton instance of StrategyUtils.
13743
+ * Provides static-like access to strategy management reporting methods.
13744
+ *
13745
+ * @example
13746
+ * ```typescript
13747
+ * import { Strategy } from "backtest-kit";
13748
+ *
13749
+ * // Usage same as StrategyUtils methods
13750
+ * const stats = await Strategy.getData("BTCUSDT", { strategyName: "my-strategy", exchangeName: "binance", frameName: "1h" });
13751
+ * const report = await Strategy.getReport("BTCUSDT", { strategyName: "my-strategy", exchangeName: "binance", frameName: "1h" });
13752
+ * await Strategy.dump("BTCUSDT", { strategyName: "my-strategy", exchangeName: "binance", frameName: "1h" });
13753
+ * ```
13754
+ */
13755
+ declare const Strategy: StrategyUtils;
13756
+
13757
+ /**
13758
+ * Proxy wrapper for user-defined action handlers with automatic error capture.
13759
+ *
13760
+ * Wraps all IPublicAction methods with trycatch to prevent user code errors from crashing the system.
13761
+ * All errors are logged, sent to errorEmitter, and returned as null (non-breaking).
13762
+ *
13763
+ * Key features:
13764
+ * - Automatic error catching and logging for all action methods
13765
+ * - Safe execution of partial user implementations (missing methods return null)
13766
+ * - Consistent error capture across all action lifecycle events
13767
+ * - Non-breaking failure mode (errors logged but execution continues)
13768
+ *
13769
+ * Architecture:
13770
+ * - Private constructor enforces factory pattern via fromInstance()
13771
+ * - Each method checks if target implements the method before calling
13772
+ * - Errors caught with fallback handler (warn log + errorEmitter)
13773
+ * - Returns null on error to prevent undefined behavior
13774
+ *
13775
+ * Used by:
13776
+ * - ClientAction to wrap user-provided action handlers
13777
+ * - ActionCoreService to safely invoke action callbacks
13778
+ *
13779
+ * @example
13780
+ * ```typescript
13781
+ * // Create proxy from user implementation
13782
+ * const userAction = {
13783
+ * signal: async (event) => {
13784
+ * // User code that might throw
13785
+ * throw new Error('User error');
13786
+ * }
13787
+ * };
13788
+ *
13789
+ * const proxy = ActionProxy.fromInstance(userAction);
13790
+ *
13791
+ * // Error is caught and logged, execution continues
13792
+ * await proxy.signal(event); // Logs error, returns null
13793
+ * await proxy.dispose(); // Safe call even though not implemented
13794
+ * ```
13795
+ *
13796
+ * @example
13797
+ * ```typescript
13798
+ * // Partial implementation is safe
13799
+ * const partialAction = {
13800
+ * init: async () => console.log('Initialized'),
13801
+ * // Other methods not implemented
13802
+ * };
13803
+ *
13804
+ * const proxy = ActionProxy.fromInstance(partialAction);
13805
+ * await proxy.init(); // Works
13806
+ * await proxy.signal(event); // Returns null (not implemented)
13807
+ * ```
13808
+ */
13809
+ declare class ActionProxy implements IPublicAction {
13810
+ readonly _target: Partial<IPublicAction>;
13811
+ /**
13812
+ * Creates a new ActionProxy instance.
13813
+ *
13814
+ * @param _target - Partial action implementation to wrap with error capture
13815
+ * @private Use ActionProxy.fromInstance() instead
13816
+ */
13817
+ private constructor();
13818
+ /**
13819
+ * Initializes the action handler with error capture.
13820
+ *
13821
+ * Wraps the user's init() method in trycatch to prevent initialization errors from crashing the system.
13822
+ * If the target doesn't implement init(), this method safely returns undefined.
13823
+ *
13824
+ * @returns Promise resolving to user's init() result or undefined if not implemented
13825
+ */
13826
+ init(): Promise<any>;
13827
+ /**
13828
+ * Handles signal events from all modes with error capture.
13829
+ *
13830
+ * Wraps the user's signal() method to catch and log any errors.
13831
+ * Called on every tick/candle when strategy is evaluated.
13832
+ *
13833
+ * @param event - Signal state result with action, state, signal data, and context
13834
+ * @returns Promise resolving to user's signal() result or null on error
13835
+ */
13836
+ signal(event: IStrategyTickResult): Promise<any>;
13837
+ /**
13838
+ * Handles signal events from live trading only with error capture.
13839
+ *
13840
+ * Wraps the user's signalLive() method to catch and log any errors.
13841
+ * Called every tick in live mode.
13842
+ *
13843
+ * @param event - Signal state result from live trading
13844
+ * @returns Promise resolving to user's signalLive() result or null on error
13845
+ */
13846
+ signalLive(event: IStrategyTickResult): Promise<any>;
13847
+ /**
13848
+ * Handles signal events from backtest only with error capture.
12733
13849
  *
12734
13850
  * Wraps the user's signalBacktest() method to catch and log any errors.
12735
13851
  * Called every candle in backtest mode.
@@ -13372,6 +14488,20 @@ declare const schedulePingSubject: Subject<SchedulePingContract>;
13372
14488
  * Allows users to track active signal lifecycle and implement custom dynamic management logic.
13373
14489
  */
13374
14490
  declare const activePingSubject: Subject<ActivePingContract>;
14491
+ /**
14492
+ * Strategy management signal emitter.
14493
+ * Emits when strategy management actions are executed:
14494
+ * - cancel-scheduled: Scheduled signal cancelled
14495
+ * - close-pending: Pending signal closed
14496
+ * - partial-profit: Partial close at profit level
14497
+ * - partial-loss: Partial close at loss level
14498
+ * - trailing-stop: Stop-loss adjusted
14499
+ * - trailing-take: Take-profit adjusted
14500
+ * - breakeven: Stop-loss moved to entry price
14501
+ *
14502
+ * Used by StrategyReportService and StrategyMarkdownService for event logging and reporting.
14503
+ */
14504
+ declare const strategyCommitSubject: Subject<StrategyCommitContract>;
13375
14505
 
13376
14506
  declare const emitters_activePingSubject: typeof activePingSubject;
13377
14507
  declare const emitters_breakevenSubject: typeof breakevenSubject;
@@ -13390,12 +14520,13 @@ declare const emitters_schedulePingSubject: typeof schedulePingSubject;
13390
14520
  declare const emitters_signalBacktestEmitter: typeof signalBacktestEmitter;
13391
14521
  declare const emitters_signalEmitter: typeof signalEmitter;
13392
14522
  declare const emitters_signalLiveEmitter: typeof signalLiveEmitter;
14523
+ declare const emitters_strategyCommitSubject: typeof strategyCommitSubject;
13393
14524
  declare const emitters_validationSubject: typeof validationSubject;
13394
14525
  declare const emitters_walkerCompleteSubject: typeof walkerCompleteSubject;
13395
14526
  declare const emitters_walkerEmitter: typeof walkerEmitter;
13396
14527
  declare const emitters_walkerStopSubject: typeof walkerStopSubject;
13397
14528
  declare namespace emitters {
13398
- export { emitters_activePingSubject as activePingSubject, emitters_breakevenSubject as breakevenSubject, emitters_doneBacktestSubject as doneBacktestSubject, emitters_doneLiveSubject as doneLiveSubject, emitters_doneWalkerSubject as doneWalkerSubject, emitters_errorEmitter as errorEmitter, emitters_exitEmitter as exitEmitter, emitters_partialLossSubject as partialLossSubject, emitters_partialProfitSubject as partialProfitSubject, emitters_performanceEmitter as performanceEmitter, emitters_progressBacktestEmitter as progressBacktestEmitter, emitters_progressWalkerEmitter as progressWalkerEmitter, emitters_riskSubject as riskSubject, emitters_schedulePingSubject as schedulePingSubject, emitters_signalBacktestEmitter as signalBacktestEmitter, emitters_signalEmitter as signalEmitter, emitters_signalLiveEmitter as signalLiveEmitter, emitters_validationSubject as validationSubject, emitters_walkerCompleteSubject as walkerCompleteSubject, emitters_walkerEmitter as walkerEmitter, emitters_walkerStopSubject as walkerStopSubject };
14529
+ export { emitters_activePingSubject as activePingSubject, emitters_breakevenSubject as breakevenSubject, emitters_doneBacktestSubject as doneBacktestSubject, emitters_doneLiveSubject as doneLiveSubject, emitters_doneWalkerSubject as doneWalkerSubject, emitters_errorEmitter as errorEmitter, emitters_exitEmitter as exitEmitter, emitters_partialLossSubject as partialLossSubject, emitters_partialProfitSubject as partialProfitSubject, emitters_performanceEmitter as performanceEmitter, emitters_progressBacktestEmitter as progressBacktestEmitter, emitters_progressWalkerEmitter as progressWalkerEmitter, emitters_riskSubject as riskSubject, emitters_schedulePingSubject as schedulePingSubject, emitters_signalBacktestEmitter as signalBacktestEmitter, emitters_signalEmitter as signalEmitter, emitters_signalLiveEmitter as signalLiveEmitter, emitters_strategyCommitSubject as strategyCommitSubject, emitters_validationSubject as validationSubject, emitters_walkerCompleteSubject as walkerCompleteSubject, emitters_walkerEmitter as walkerEmitter, emitters_walkerStopSubject as walkerStopSubject };
13399
14530
  }
13400
14531
 
13401
14532
  /**
@@ -13453,109 +14584,48 @@ interface IParseArgsResult extends IParseArgsParams {
13453
14584
  * - --backtest: Enable backtest mode (boolean flag)
13454
14585
  * - --paper: Enable paper trading mode (boolean flag)
13455
14586
  * - --live: Enable live trading mode (boolean flag)
13456
- *
13457
- * @param params - Optional default values for parameters
13458
- * @param params.symbol - Default trading pair symbol
13459
- * @param params.strategyName - Default strategy name
13460
- * @param params.exchangeName - Default exchange name
13461
- * @param params.frameName - Default timeframe
13462
- * @returns Parsed configuration with all parameters and mode flags
13463
- *
13464
- * @example
13465
- * ```typescript
13466
- * // Parse args with defaults
13467
- * const config = parseArgs({
13468
- * symbol: "BTCUSDT",
13469
- * strategyName: "rsi_divergence",
13470
- * exchangeName: "binance",
13471
- * frameName: "1h"
13472
- * });
13473
- *
13474
- * // Command: node app.js --backtest
13475
- * // Result: { symbol: "BTCUSDT", ..., backtest: true, paper: false, live: false }
13476
- * ```
13477
- */
13478
- declare const parseArgs: ({ symbol, strategyName, exchangeName, frameName, }?: Partial<IParseArgsParams>) => IParseArgsResult;
13479
-
13480
- /**
13481
- * Retrieves a value from an object using a given path.
13482
- *
13483
- * @param object - The object from which to retrieve the value.
13484
- * @param path - The path to the desired value, either as an array or dot-separated string.
13485
- * @returns - The value at the specified path, or undefined if it does not exist.
13486
- */
13487
- declare const get: (object: any, path: any) => any;
13488
-
13489
- /**
13490
- * Updates the value of a nested object property using a specific path.
13491
- *
13492
- * @param object - The object to update.
13493
- * @param path - The path to the property. Can be either a dot-separated string or an array of strings.
13494
- * @param value - The new value to set for the property.
13495
- * @returns - Returns true if the property was successfully updated, false otherwise.
13496
- */
13497
- declare const set: (object: any, path: any, value: any) => boolean;
13498
-
13499
- /**
13500
- * Logger service with automatic context injection.
13501
- *
13502
- * Features:
13503
- * - Delegates to user-provided logger via setLogger()
13504
- * - Automatically appends method context (strategyName, exchangeName, frameName)
13505
- * - Automatically appends execution context (symbol, when, backtest)
13506
- * - Defaults to NOOP_LOGGER if no logger configured
13507
- *
13508
- * Used throughout the framework for consistent logging with context.
13509
- */
13510
- declare class LoggerService implements ILogger {
13511
- private readonly methodContextService;
13512
- private readonly executionContextService;
13513
- private _commonLogger;
13514
- /**
13515
- * Gets current method context if available.
13516
- * Contains strategyName, exchangeName, frameName from MethodContextService.
13517
- */
13518
- private get methodContext();
13519
- /**
13520
- * Gets current execution context if available.
13521
- * Contains symbol, when, backtest from ExecutionContextService.
13522
- */
13523
- private get executionContext();
13524
- /**
13525
- * Logs general-purpose message with automatic context injection.
13526
- *
13527
- * @param topic - Log topic/category
13528
- * @param args - Additional log arguments
13529
- */
13530
- log: (topic: string, ...args: any[]) => Promise<void>;
13531
- /**
13532
- * Logs debug-level message with automatic context injection.
13533
- *
13534
- * @param topic - Log topic/category
13535
- * @param args - Additional log arguments
13536
- */
13537
- debug: (topic: string, ...args: any[]) => Promise<void>;
13538
- /**
13539
- * Logs info-level message with automatic context injection.
13540
- *
13541
- * @param topic - Log topic/category
13542
- * @param args - Additional log arguments
13543
- */
13544
- info: (topic: string, ...args: any[]) => Promise<void>;
13545
- /**
13546
- * Logs warning-level message with automatic context injection.
13547
- *
13548
- * @param topic - Log topic/category
13549
- * @param args - Additional log arguments
13550
- */
13551
- warn: (topic: string, ...args: any[]) => Promise<void>;
13552
- /**
13553
- * Sets custom logger implementation.
13554
- *
13555
- * @param logger - Custom logger implementing ILogger interface
13556
- */
13557
- setLogger: (logger: ILogger) => void;
13558
- }
14587
+ *
14588
+ * @param params - Optional default values for parameters
14589
+ * @param params.symbol - Default trading pair symbol
14590
+ * @param params.strategyName - Default strategy name
14591
+ * @param params.exchangeName - Default exchange name
14592
+ * @param params.frameName - Default timeframe
14593
+ * @returns Parsed configuration with all parameters and mode flags
14594
+ *
14595
+ * @example
14596
+ * ```typescript
14597
+ * // Parse args with defaults
14598
+ * const config = parseArgs({
14599
+ * symbol: "BTCUSDT",
14600
+ * strategyName: "rsi_divergence",
14601
+ * exchangeName: "binance",
14602
+ * frameName: "1h"
14603
+ * });
14604
+ *
14605
+ * // Command: node app.js --backtest
14606
+ * // Result: { symbol: "BTCUSDT", ..., backtest: true, paper: false, live: false }
14607
+ * ```
14608
+ */
14609
+ declare const parseArgs: ({ symbol, strategyName, exchangeName, frameName, }?: Partial<IParseArgsParams>) => IParseArgsResult;
14610
+
14611
+ /**
14612
+ * Retrieves a value from an object using a given path.
14613
+ *
14614
+ * @param object - The object from which to retrieve the value.
14615
+ * @param path - The path to the desired value, either as an array or dot-separated string.
14616
+ * @returns - The value at the specified path, or undefined if it does not exist.
14617
+ */
14618
+ declare const get: (object: any, path: any) => any;
14619
+
14620
+ /**
14621
+ * Updates the value of a nested object property using a specific path.
14622
+ *
14623
+ * @param object - The object to update.
14624
+ * @param path - The path to the property. Can be either a dot-separated string or an array of strings.
14625
+ * @param value - The new value to set for the property.
14626
+ * @returns - Returns true if the property was successfully updated, false otherwise.
14627
+ */
14628
+ declare const set: (object: any, path: any, value: any) => boolean;
13559
14629
 
13560
14630
  /**
13561
14631
  * Client implementation for exchange data access.
@@ -14479,7 +15549,7 @@ declare class BreakevenConnectionService implements IBreakeven {
14479
15549
  * Maps all keys of IStrategy to any type.
14480
15550
  * Used for dynamic method routing in StrategyConnectionService.
14481
15551
  */
14482
- type TStrategy$1 = {
15552
+ type TStrategy = {
14483
15553
  [key in keyof IStrategy]: any;
14484
15554
  };
14485
15555
  /**
@@ -14502,7 +15572,7 @@ type TStrategy$1 = {
14502
15572
  * // Routes to correct strategy instance for symbol-strategy pair
14503
15573
  * ```
14504
15574
  */
14505
- declare class StrategyConnectionService implements TStrategy$1 {
15575
+ declare class StrategyConnectionService implements TStrategy {
14506
15576
  readonly loggerService: LoggerService;
14507
15577
  readonly executionContextService: {
14508
15578
  readonly context: IExecutionContext;
@@ -15105,783 +16175,388 @@ declare class ClientAction implements IAction {
15105
16175
  * onSignal: (event, actionName, strategyName, frameName, backtest) => {
15106
16176
  * console.log(`Signal: ${event.action}`);
15107
16177
  * }
15108
- * },
15109
- * logger: loggerService,
15110
- * strategyName: "rsi_divergence",
15111
- * exchangeName: "binance",
15112
- * frameName: "1h",
15113
- * backtest: false
15114
- * });
15115
- *
15116
- * await actionClient.signal({
15117
- * action: 'opened',
15118
- * signal: { id: '123', side: 'long' },
15119
- * backtest: false
15120
- * });
15121
- *
15122
- * await actionClient.dispose();
15123
- * ```
15124
- */
15125
- constructor(params: IActionParams);
15126
- /**
15127
- * Initializes handler instance using singleshot pattern.
15128
- * Ensures initialization happens exactly once.
15129
- */
15130
- waitForInit: (() => Promise<void>) & functools_kit.ISingleshotClearable;
15131
- /**
15132
- * Handles signal events from all modes (live + backtest).
15133
- */
15134
- signal(event: IStrategyTickResult): Promise<void>;
15135
- /**
15136
- * Handles signal events from live trading only.
15137
- */
15138
- signalLive(event: IStrategyTickResult): Promise<void>;
15139
- /**
15140
- * Handles signal events from backtest only.
15141
- */
15142
- signalBacktest(event: IStrategyTickResult): Promise<void>;
15143
- /**
15144
- * Handles breakeven events when stop-loss is moved to entry price.
15145
- */
15146
- breakevenAvailable(event: BreakevenContract): Promise<void>;
15147
- /**
15148
- * Handles partial profit level events (10%, 20%, 30%, etc).
15149
- */
15150
- partialProfitAvailable(event: PartialProfitContract): Promise<void>;
15151
- /**
15152
- * Handles partial loss level events (-10%, -20%, -30%, etc).
15153
- */
15154
- partialLossAvailable(event: PartialLossContract): Promise<void>;
15155
- /**
15156
- * Handles scheduled ping events during scheduled signal monitoring.
15157
- */
15158
- pingScheduled(event: SchedulePingContract): Promise<void>;
15159
- /**
15160
- * Handles active ping events during active pending signal monitoring.
15161
- */
15162
- pingActive(event: ActivePingContract): Promise<void>;
15163
- /**
15164
- * Handles risk rejection events when signals fail risk validation.
15165
- */
15166
- riskRejection(event: RiskContract): Promise<void>;
15167
- /**
15168
- * Cleans up resources and subscriptions when action handler is no longer needed.
15169
- * Uses singleshot pattern to ensure cleanup happens exactly once.
15170
- */
15171
- dispose: (() => Promise<void>) & functools_kit.ISingleshotClearable;
15172
- }
15173
-
15174
- /**
15175
- * Type definition for action methods.
15176
- * Maps all keys of IAction to any type.
15177
- * Used for dynamic method routing in ActionConnectionService.
15178
- */
15179
- type TAction = {
15180
- [key in keyof IAction]: any;
15181
- };
15182
- /**
15183
- * Connection service routing action operations to correct ClientAction instance.
15184
- *
15185
- * Routes action calls to the appropriate action implementation
15186
- * based on the provided actionName parameter. Uses memoization to cache
15187
- * ClientAction instances for performance.
15188
- *
15189
- * Key features:
15190
- * - Explicit action routing via actionName parameter
15191
- * - Memoized ClientAction instances by actionName, strategyName, frameName
15192
- * - Event routing to action handlers
15193
- *
15194
- * @example
15195
- * ```typescript
15196
- * // Used internally by framework
15197
- * await actionConnectionService.signal(
15198
- * event,
15199
- * {
15200
- * actionName: "telegram-notifier",
15201
- * strategyName: "rsi_divergence",
15202
- * exchangeName: "binance",
15203
- * frameName: "1h",
15204
- * backtest: false
15205
- * }
15206
- * );
15207
- * ```
15208
- */
15209
- declare class ActionConnectionService implements TAction {
15210
- private readonly loggerService;
15211
- private readonly actionSchemaService;
15212
- /**
15213
- * Retrieves memoized ClientAction instance for given action name, strategy, exchange, frame and backtest mode.
15214
- *
15215
- * Creates ClientAction on first call, returns cached instance on subsequent calls.
15216
- * Cache key includes strategyName, exchangeName and frameName to isolate action per strategy-frame pair.
15217
- *
15218
- * @param actionName - Name of registered action schema
15219
- * @param strategyName - Strategy name
15220
- * @param exchangeName - Exchange name
15221
- * @param frameName - Frame name (empty string for live)
15222
- * @param backtest - True if backtest mode, false if live mode
15223
- * @returns Configured ClientAction instance
15224
- */
15225
- getAction: ((actionName: ActionName, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean) => ClientAction) & functools_kit.IClearableMemoize<string> & functools_kit.IControlMemoize<string, ClientAction>;
15226
- /**
15227
- * Initializes the ClientAction instance for the given action name.
15228
- *
15229
- * Calls waitForInit() on the action instance to load persisted state.
15230
- *
15231
- * @param backtest - Whether running in backtest mode
15232
- * @param context - Execution context with action name, strategy name, exchange name, frame name
15233
- */
15234
- initFn: (backtest: boolean, context: {
15235
- actionName: ActionName;
15236
- strategyName: StrategyName;
15237
- exchangeName: ExchangeName;
15238
- frameName: FrameName;
15239
- }) => Promise<void>;
15240
- /**
15241
- * Routes signal event to appropriate ClientAction instance.
15242
- *
15243
- * @param event - Signal event data
15244
- * @param backtest - Whether running in backtest mode
15245
- * @param context - Execution context with action name, strategy name, exchange name, frame name
15246
- */
15247
- signal: (event: IStrategyTickResult, backtest: boolean, context: {
15248
- actionName: ActionName;
15249
- strategyName: StrategyName;
15250
- exchangeName: ExchangeName;
15251
- frameName: FrameName;
15252
- }) => Promise<void>;
15253
- /**
15254
- * Routes signalLive event to appropriate ClientAction instance.
15255
- *
15256
- * @param event - Signal event data from live trading
15257
- * @param backtest - Whether running in backtest mode
15258
- * @param context - Execution context with action name, strategy name, exchange name, frame name
15259
- */
15260
- signalLive: (event: IStrategyTickResult, backtest: boolean, context: {
15261
- actionName: ActionName;
15262
- strategyName: StrategyName;
15263
- exchangeName: ExchangeName;
15264
- frameName: FrameName;
15265
- }) => Promise<void>;
15266
- /**
15267
- * Routes signalBacktest event to appropriate ClientAction instance.
15268
- *
15269
- * @param event - Signal event data from backtest
15270
- * @param backtest - Whether running in backtest mode
15271
- * @param context - Execution context with action name, strategy name, exchange name, frame name
15272
- */
15273
- signalBacktest: (event: IStrategyTickResult, backtest: boolean, context: {
15274
- actionName: ActionName;
15275
- strategyName: StrategyName;
15276
- exchangeName: ExchangeName;
15277
- frameName: FrameName;
15278
- }) => Promise<void>;
15279
- /**
15280
- * Routes breakeven event to appropriate ClientAction instance.
15281
- *
15282
- * @param event - Breakeven event data
15283
- * @param backtest - Whether running in backtest mode
15284
- * @param context - Execution context with action name, strategy name, exchange name, frame name
15285
- */
15286
- breakevenAvailable: (event: BreakevenContract, backtest: boolean, context: {
15287
- actionName: ActionName;
15288
- strategyName: StrategyName;
15289
- exchangeName: ExchangeName;
15290
- frameName: FrameName;
15291
- }) => Promise<void>;
15292
- /**
15293
- * Routes partialProfit event to appropriate ClientAction instance.
15294
- *
15295
- * @param event - Partial profit event data
15296
- * @param backtest - Whether running in backtest mode
15297
- * @param context - Execution context with action name, strategy name, exchange name, frame name
15298
- */
15299
- partialProfitAvailable: (event: PartialProfitContract, backtest: boolean, context: {
15300
- actionName: ActionName;
15301
- strategyName: StrategyName;
15302
- exchangeName: ExchangeName;
15303
- frameName: FrameName;
15304
- }) => Promise<void>;
15305
- /**
15306
- * Routes partialLoss event to appropriate ClientAction instance.
15307
- *
15308
- * @param event - Partial loss event data
15309
- * @param backtest - Whether running in backtest mode
15310
- * @param context - Execution context with action name, strategy name, exchange name, frame name
15311
- */
15312
- partialLossAvailable: (event: PartialLossContract, backtest: boolean, context: {
15313
- actionName: ActionName;
15314
- strategyName: StrategyName;
15315
- exchangeName: ExchangeName;
15316
- frameName: FrameName;
15317
- }) => Promise<void>;
15318
- /**
15319
- * Routes scheduled ping event to appropriate ClientAction instance.
16178
+ * },
16179
+ * logger: loggerService,
16180
+ * strategyName: "rsi_divergence",
16181
+ * exchangeName: "binance",
16182
+ * frameName: "1h",
16183
+ * backtest: false
16184
+ * });
15320
16185
  *
15321
- * @param event - Scheduled ping event data
15322
- * @param backtest - Whether running in backtest mode
15323
- * @param context - Execution context with action name, strategy name, exchange name, frame name
15324
- */
15325
- pingScheduled: (event: SchedulePingContract, backtest: boolean, context: {
15326
- actionName: ActionName;
15327
- strategyName: StrategyName;
15328
- exchangeName: ExchangeName;
15329
- frameName: FrameName;
15330
- }) => Promise<void>;
15331
- /**
15332
- * Routes active ping event to appropriate ClientAction instance.
16186
+ * await actionClient.signal({
16187
+ * action: 'opened',
16188
+ * signal: { id: '123', side: 'long' },
16189
+ * backtest: false
16190
+ * });
15333
16191
  *
15334
- * @param event - Active ping event data
15335
- * @param backtest - Whether running in backtest mode
15336
- * @param context - Execution context with action name, strategy name, exchange name, frame name
16192
+ * await actionClient.dispose();
16193
+ * ```
15337
16194
  */
15338
- pingActive: (event: ActivePingContract, backtest: boolean, context: {
15339
- actionName: ActionName;
15340
- strategyName: StrategyName;
15341
- exchangeName: ExchangeName;
15342
- frameName: FrameName;
15343
- }) => Promise<void>;
16195
+ constructor(params: IActionParams);
15344
16196
  /**
15345
- * Routes riskRejection event to appropriate ClientAction instance.
15346
- *
15347
- * @param event - Risk rejection event data
15348
- * @param backtest - Whether running in backtest mode
15349
- * @param context - Execution context with action name, strategy name, exchange name, frame name
16197
+ * Initializes handler instance using singleshot pattern.
16198
+ * Ensures initialization happens exactly once.
15350
16199
  */
15351
- riskRejection: (event: RiskContract, backtest: boolean, context: {
15352
- actionName: ActionName;
15353
- strategyName: StrategyName;
15354
- exchangeName: ExchangeName;
15355
- frameName: FrameName;
15356
- }) => Promise<void>;
16200
+ waitForInit: (() => Promise<void>) & functools_kit.ISingleshotClearable;
15357
16201
  /**
15358
- * Disposes the ClientAction instance for the given action name.
15359
- *
15360
- * @param backtest - Whether running in backtest mode
15361
- * @param context - Execution context with action name, strategy name, exchange name, frame name
16202
+ * Handles signal events from all modes (live + backtest).
15362
16203
  */
15363
- dispose: (backtest: boolean, context: {
15364
- actionName: ActionName;
15365
- strategyName: StrategyName;
15366
- exchangeName: ExchangeName;
15367
- frameName: FrameName;
15368
- }) => Promise<void>;
16204
+ signal(event: IStrategyTickResult): Promise<void>;
15369
16205
  /**
15370
- * Clears the cached ClientAction instance for the given action name.
15371
- *
15372
- * @param payload - Optional payload with actionName, strategyName, exchangeName, frameName, backtest (clears all if not provided)
16206
+ * Handles signal events from live trading only.
15373
16207
  */
15374
- clear: (payload?: {
15375
- actionName: ActionName;
15376
- strategyName: StrategyName;
15377
- exchangeName: ExchangeName;
15378
- frameName: FrameName;
15379
- backtest: boolean;
15380
- }) => Promise<void>;
15381
- }
15382
-
15383
- /**
15384
- * Type definition for exchange methods.
15385
- * Maps all keys of IExchange to any type.
15386
- * Used for dynamic method routing in ExchangeCoreService.
15387
- */
15388
- type TExchange = {
15389
- [key in keyof IExchange]: any;
15390
- };
15391
- /**
15392
- * Global service for exchange operations with execution context injection.
15393
- *
15394
- * Wraps ExchangeConnectionService with ExecutionContextService to inject
15395
- * symbol, when, and backtest parameters into the execution context.
15396
- *
15397
- * Used internally by BacktestLogicPrivateService and LiveLogicPrivateService.
15398
- */
15399
- declare class ExchangeCoreService implements TExchange {
15400
- private readonly loggerService;
15401
- private readonly exchangeConnectionService;
15402
- private readonly methodContextService;
15403
- private readonly exchangeValidationService;
16208
+ signalLive(event: IStrategyTickResult): Promise<void>;
15404
16209
  /**
15405
- * Validates exchange configuration.
15406
- * Memoized to avoid redundant validations for the same exchange.
15407
- * Logs validation activity.
15408
- * @param exchangeName - Name of the exchange to validate
15409
- * @returns Promise that resolves when validation is complete
16210
+ * Handles signal events from backtest only.
15410
16211
  */
15411
- private validate;
16212
+ signalBacktest(event: IStrategyTickResult): Promise<void>;
15412
16213
  /**
15413
- * Fetches historical candles with execution context.
15414
- *
15415
- * @param symbol - Trading pair symbol
15416
- * @param interval - Candle interval (e.g., "1m", "1h")
15417
- * @param limit - Maximum number of candles to fetch
15418
- * @param when - Timestamp for context (used in backtest mode)
15419
- * @param backtest - Whether running in backtest mode
15420
- * @returns Promise resolving to array of candles
16214
+ * Handles breakeven events when stop-loss is moved to entry price.
15421
16215
  */
15422
- getCandles: (symbol: string, interval: CandleInterval, limit: number, when: Date, backtest: boolean) => Promise<ICandleData[]>;
16216
+ breakevenAvailable(event: BreakevenContract): Promise<void>;
15423
16217
  /**
15424
- * Fetches future candles (backtest mode only) with execution context.
15425
- *
15426
- * @param symbol - Trading pair symbol
15427
- * @param interval - Candle interval
15428
- * @param limit - Maximum number of candles to fetch
15429
- * @param when - Timestamp for context
15430
- * @param backtest - Whether running in backtest mode (must be true)
15431
- * @returns Promise resolving to array of future candles
16218
+ * Handles partial profit level events (10%, 20%, 30%, etc).
15432
16219
  */
15433
- getNextCandles: (symbol: string, interval: CandleInterval, limit: number, when: Date, backtest: boolean) => Promise<ICandleData[]>;
16220
+ partialProfitAvailable(event: PartialProfitContract): Promise<void>;
15434
16221
  /**
15435
- * Calculates VWAP with execution context.
15436
- *
15437
- * @param symbol - Trading pair symbol
15438
- * @param when - Timestamp for context
15439
- * @param backtest - Whether running in backtest mode
15440
- * @returns Promise resolving to VWAP price
16222
+ * Handles partial loss level events (-10%, -20%, -30%, etc).
15441
16223
  */
15442
- getAveragePrice: (symbol: string, when: Date, backtest: boolean) => Promise<number>;
16224
+ partialLossAvailable(event: PartialLossContract): Promise<void>;
15443
16225
  /**
15444
- * Formats price with execution context.
15445
- *
15446
- * @param symbol - Trading pair symbol
15447
- * @param price - Price to format
15448
- * @param when - Timestamp for context
15449
- * @param backtest - Whether running in backtest mode
15450
- * @returns Promise resolving to formatted price string
16226
+ * Handles scheduled ping events during scheduled signal monitoring.
15451
16227
  */
15452
- formatPrice: (symbol: string, price: number, when: Date, backtest: boolean) => Promise<string>;
16228
+ pingScheduled(event: SchedulePingContract): Promise<void>;
15453
16229
  /**
15454
- * Formats quantity with execution context.
15455
- *
15456
- * @param symbol - Trading pair symbol
15457
- * @param quantity - Quantity to format
15458
- * @param when - Timestamp for context
15459
- * @param backtest - Whether running in backtest mode
15460
- * @returns Promise resolving to formatted quantity string
16230
+ * Handles active ping events during active pending signal monitoring.
15461
16231
  */
15462
- formatQuantity: (symbol: string, quantity: number, when: Date, backtest: boolean) => Promise<string>;
16232
+ pingActive(event: ActivePingContract): Promise<void>;
15463
16233
  /**
15464
- * Fetches order book with execution context.
15465
- *
15466
- * Sets up execution context with the provided when/backtest parameters.
15467
- * The exchange implementation will receive time range parameters but may
15468
- * choose to use them (backtest) or ignore them (live).
15469
- *
15470
- * @param symbol - Trading pair symbol
15471
- * @param when - Timestamp for context
15472
- * @param backtest - Whether running in backtest mode
15473
- * @param depth - Maximum depth levels (default: CC_ORDER_BOOK_MAX_DEPTH_LEVELS)
15474
- * @returns Promise resolving to order book data
16234
+ * Handles risk rejection events when signals fail risk validation.
15475
16235
  */
15476
- getOrderBook: (symbol: string, when: Date, backtest: boolean, depth?: number) => Promise<IOrderBookData>;
16236
+ riskRejection(event: RiskContract): Promise<void>;
15477
16237
  /**
15478
- * Fetches raw candles with flexible date/limit parameters and execution context.
15479
- *
15480
- * @param symbol - Trading pair symbol
15481
- * @param interval - Candle interval (e.g., "1m", "1h")
15482
- * @param when - Timestamp for context (used in backtest mode)
15483
- * @param backtest - Whether running in backtest mode
15484
- * @param limit - Optional number of candles to fetch
15485
- * @param sDate - Optional start date in milliseconds
15486
- * @param eDate - Optional end date in milliseconds
15487
- * @returns Promise resolving to array of candles
16238
+ * Cleans up resources and subscriptions when action handler is no longer needed.
16239
+ * Uses singleshot pattern to ensure cleanup happens exactly once.
15488
16240
  */
15489
- getRawCandles: (symbol: string, interval: CandleInterval, when: Date, backtest: boolean, limit?: number, sDate?: number, eDate?: number) => Promise<ICandleData[]>;
16241
+ dispose: (() => Promise<void>) & functools_kit.ISingleshotClearable;
15490
16242
  }
15491
16243
 
15492
16244
  /**
15493
- * Type definition for strategy methods.
15494
- * Maps all keys of IStrategy to any type.
15495
- * Used for dynamic method routing in StrategyCoreService.
16245
+ * Type definition for action methods.
16246
+ * Maps all keys of IAction to any type.
16247
+ * Used for dynamic method routing in ActionConnectionService.
15496
16248
  */
15497
- type TStrategy = {
15498
- [key in keyof IStrategy]: any;
16249
+ type TAction = {
16250
+ [key in keyof IAction]: any;
15499
16251
  };
15500
16252
  /**
15501
- * Global service for strategy operations with execution context injection.
16253
+ * Connection service routing action operations to correct ClientAction instance.
15502
16254
  *
15503
- * Wraps StrategyConnectionService with ExecutionContextService to inject
15504
- * symbol, when, and backtest parameters into the execution context.
16255
+ * Routes action calls to the appropriate action implementation
16256
+ * based on the provided actionName parameter. Uses memoization to cache
16257
+ * ClientAction instances for performance.
15505
16258
  *
15506
- * Used internally by BacktestLogicPrivateService and LiveLogicPrivateService.
16259
+ * Key features:
16260
+ * - Explicit action routing via actionName parameter
16261
+ * - Memoized ClientAction instances by actionName, strategyName, frameName
16262
+ * - Event routing to action handlers
16263
+ *
16264
+ * @example
16265
+ * ```typescript
16266
+ * // Used internally by framework
16267
+ * await actionConnectionService.signal(
16268
+ * event,
16269
+ * {
16270
+ * actionName: "telegram-notifier",
16271
+ * strategyName: "rsi_divergence",
16272
+ * exchangeName: "binance",
16273
+ * frameName: "1h",
16274
+ * backtest: false
16275
+ * }
16276
+ * );
16277
+ * ```
15507
16278
  */
15508
- declare class StrategyCoreService implements TStrategy {
16279
+ declare class ActionConnectionService implements TAction {
15509
16280
  private readonly loggerService;
15510
- private readonly strategyConnectionService;
15511
- private readonly strategySchemaService;
15512
- private readonly riskValidationService;
15513
- private readonly strategyValidationService;
15514
- private readonly exchangeValidationService;
15515
- private readonly frameValidationService;
16281
+ private readonly actionSchemaService;
15516
16282
  /**
15517
- * Validates strategy and associated risk configuration.
16283
+ * Retrieves memoized ClientAction instance for given action name, strategy, exchange, frame and backtest mode.
15518
16284
  *
15519
- * Memoized to avoid redundant validations for the same symbol-strategy-exchange-frame combination.
15520
- * Logs validation activity.
15521
- * @param symbol - Trading pair symbol
15522
- * @param context - Execution context with strategyName, exchangeName, frameName
15523
- * @returns Promise that resolves when validation is complete
16285
+ * Creates ClientAction on first call, returns cached instance on subsequent calls.
16286
+ * Cache key includes strategyName, exchangeName and frameName to isolate action per strategy-frame pair.
16287
+ *
16288
+ * @param actionName - Name of registered action schema
16289
+ * @param strategyName - Strategy name
16290
+ * @param exchangeName - Exchange name
16291
+ * @param frameName - Frame name (empty string for live)
16292
+ * @param backtest - True if backtest mode, false if live mode
16293
+ * @returns Configured ClientAction instance
15524
16294
  */
15525
- private validate;
16295
+ getAction: ((actionName: ActionName, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean) => ClientAction) & functools_kit.IClearableMemoize<string> & functools_kit.IControlMemoize<string, ClientAction>;
16296
+ /**
16297
+ * Initializes the ClientAction instance for the given action name.
16298
+ *
16299
+ * Calls waitForInit() on the action instance to load persisted state.
16300
+ *
16301
+ * @param backtest - Whether running in backtest mode
16302
+ * @param context - Execution context with action name, strategy name, exchange name, frame name
16303
+ */
16304
+ initFn: (backtest: boolean, context: {
16305
+ actionName: ActionName;
16306
+ strategyName: StrategyName;
16307
+ exchangeName: ExchangeName;
16308
+ frameName: FrameName;
16309
+ }) => Promise<void>;
15526
16310
  /**
15527
- * Retrieves the currently active pending signal for the symbol.
15528
- * If no active signal exists, returns null.
15529
- * Used internally for monitoring TP/SL and time expiration.
16311
+ * Routes signal event to appropriate ClientAction instance.
15530
16312
  *
16313
+ * @param event - Signal event data
15531
16314
  * @param backtest - Whether running in backtest mode
15532
- * @param symbol - Trading pair symbol
15533
- * @param context - Execution context with strategyName, exchangeName, frameName
15534
- * @returns Promise resolving to pending signal or null
16315
+ * @param context - Execution context with action name, strategy name, exchange name, frame name
15535
16316
  */
15536
- getPendingSignal: (backtest: boolean, symbol: string, context: {
16317
+ signal: (event: IStrategyTickResult, backtest: boolean, context: {
16318
+ actionName: ActionName;
15537
16319
  strategyName: StrategyName;
15538
16320
  exchangeName: ExchangeName;
15539
16321
  frameName: FrameName;
15540
- }) => Promise<ISignalRow | null>;
16322
+ }) => Promise<void>;
15541
16323
  /**
15542
- * Retrieves the currently active scheduled signal for the symbol.
15543
- * If no scheduled signal exists, returns null.
15544
- * Used internally for monitoring scheduled signal activation.
16324
+ * Routes signalLive event to appropriate ClientAction instance.
15545
16325
  *
16326
+ * @param event - Signal event data from live trading
15546
16327
  * @param backtest - Whether running in backtest mode
15547
- * @param symbol - Trading pair symbol
15548
- * @param context - Execution context with strategyName, exchangeName, frameName
15549
- * @returns Promise resolving to scheduled signal or null
16328
+ * @param context - Execution context with action name, strategy name, exchange name, frame name
15550
16329
  */
15551
- getScheduledSignal: (backtest: boolean, symbol: string, context: {
16330
+ signalLive: (event: IStrategyTickResult, backtest: boolean, context: {
16331
+ actionName: ActionName;
15552
16332
  strategyName: StrategyName;
15553
16333
  exchangeName: ExchangeName;
15554
16334
  frameName: FrameName;
15555
- }) => Promise<IScheduledSignalRow | null>;
16335
+ }) => Promise<void>;
15556
16336
  /**
15557
- * Checks if breakeven threshold has been reached for the current pending signal.
15558
- *
15559
- * Validates strategy existence and delegates to connection service
15560
- * to check if price has moved far enough to cover transaction costs.
15561
- *
15562
- * Does not require execution context as this is a state query operation.
16337
+ * Routes signalBacktest event to appropriate ClientAction instance.
15563
16338
  *
16339
+ * @param event - Signal event data from backtest
15564
16340
  * @param backtest - Whether running in backtest mode
15565
- * @param symbol - Trading pair symbol
15566
- * @param currentPrice - Current market price to check against threshold
15567
- * @param context - Execution context with strategyName, exchangeName, frameName
15568
- * @returns Promise<boolean> - true if breakeven threshold reached, false otherwise
15569
- *
15570
- * @example
15571
- * ```typescript
15572
- * // Check if breakeven is available for LONG position (entry=100, threshold=0.4%)
15573
- * const canBreakeven = await strategyCoreService.getBreakeven(
15574
- * false,
15575
- * "BTCUSDT",
15576
- * 100.5,
15577
- * { strategyName: "my-strategy", exchangeName: "binance", frameName: "" }
15578
- * );
15579
- * // Returns true (price >= 100.4)
15580
- *
15581
- * if (canBreakeven) {
15582
- * await strategyCoreService.breakeven(false, "BTCUSDT", 100.5, context);
15583
- * }
15584
- * ```
16341
+ * @param context - Execution context with action name, strategy name, exchange name, frame name
15585
16342
  */
15586
- getBreakeven: (backtest: boolean, symbol: string, currentPrice: number, context: {
16343
+ signalBacktest: (event: IStrategyTickResult, backtest: boolean, context: {
16344
+ actionName: ActionName;
15587
16345
  strategyName: StrategyName;
15588
16346
  exchangeName: ExchangeName;
15589
16347
  frameName: FrameName;
15590
- }) => Promise<boolean>;
16348
+ }) => Promise<void>;
15591
16349
  /**
15592
- * Checks if the strategy has been stopped.
15593
- *
15594
- * Validates strategy existence and delegates to connection service
15595
- * to retrieve the stopped state from the strategy instance.
16350
+ * Routes breakeven event to appropriate ClientAction instance.
15596
16351
  *
16352
+ * @param event - Breakeven event data
15597
16353
  * @param backtest - Whether running in backtest mode
15598
- * @param symbol - Trading pair symbol
15599
- * @param context - Execution context with strategyName, exchangeName, frameName
15600
- * @returns Promise resolving to true if strategy is stopped, false otherwise
16354
+ * @param context - Execution context with action name, strategy name, exchange name, frame name
15601
16355
  */
15602
- getStopped: (backtest: boolean, symbol: string, context: {
16356
+ breakevenAvailable: (event: BreakevenContract, backtest: boolean, context: {
16357
+ actionName: ActionName;
15603
16358
  strategyName: StrategyName;
15604
16359
  exchangeName: ExchangeName;
15605
16360
  frameName: FrameName;
15606
- }) => Promise<boolean>;
16361
+ }) => Promise<void>;
15607
16362
  /**
15608
- * Checks signal status at a specific timestamp.
15609
- *
15610
- * Wraps strategy tick() with execution context containing symbol, timestamp,
15611
- * and backtest mode flag.
16363
+ * Routes partialProfit event to appropriate ClientAction instance.
15612
16364
  *
15613
- * @param symbol - Trading pair symbol
15614
- * @param when - Timestamp for tick evaluation
16365
+ * @param event - Partial profit event data
15615
16366
  * @param backtest - Whether running in backtest mode
15616
- * @param context - Execution context with strategyName, exchangeName, frameName
15617
- * @returns Discriminated union of tick result (idle, opened, active, closed)
16367
+ * @param context - Execution context with action name, strategy name, exchange name, frame name
15618
16368
  */
15619
- tick: (symbol: string, when: Date, backtest: boolean, context: {
16369
+ partialProfitAvailable: (event: PartialProfitContract, backtest: boolean, context: {
16370
+ actionName: ActionName;
15620
16371
  strategyName: StrategyName;
15621
16372
  exchangeName: ExchangeName;
15622
16373
  frameName: FrameName;
15623
- }) => Promise<IStrategyTickResult>;
16374
+ }) => Promise<void>;
15624
16375
  /**
15625
- * Runs fast backtest against candle array.
15626
- *
15627
- * Wraps strategy backtest() with execution context containing symbol,
15628
- * timestamp, and backtest mode flag.
16376
+ * Routes partialLoss event to appropriate ClientAction instance.
15629
16377
  *
15630
- * @param symbol - Trading pair symbol
15631
- * @param candles - Array of historical candles to test against
15632
- * @param when - Starting timestamp for backtest
15633
- * @param backtest - Whether running in backtest mode (typically true)
15634
- * @param context - Execution context with strategyName, exchangeName, frameName
15635
- * @returns Closed signal result with PNL
16378
+ * @param event - Partial loss event data
16379
+ * @param backtest - Whether running in backtest mode
16380
+ * @param context - Execution context with action name, strategy name, exchange name, frame name
15636
16381
  */
15637
- backtest: (symbol: string, candles: ICandleData[], when: Date, backtest: boolean, context: {
16382
+ partialLossAvailable: (event: PartialLossContract, backtest: boolean, context: {
16383
+ actionName: ActionName;
15638
16384
  strategyName: StrategyName;
15639
16385
  exchangeName: ExchangeName;
15640
16386
  frameName: FrameName;
15641
- }) => Promise<IStrategyBacktestResult>;
16387
+ }) => Promise<void>;
15642
16388
  /**
15643
- * Stops the strategy from generating new signals.
15644
- *
15645
- * Delegates to StrategyConnectionService.stop() to set internal flag.
15646
- * Does not require execution context.
16389
+ * Routes scheduled ping event to appropriate ClientAction instance.
15647
16390
  *
16391
+ * @param event - Scheduled ping event data
15648
16392
  * @param backtest - Whether running in backtest mode
15649
- * @param symbol - Trading pair symbol
15650
- * @param ctx - Context with strategyName, exchangeName, frameName
15651
- * @returns Promise that resolves when stop flag is set
16393
+ * @param context - Execution context with action name, strategy name, exchange name, frame name
15652
16394
  */
15653
- stopStrategy: (backtest: boolean, symbol: string, context: {
16395
+ pingScheduled: (event: SchedulePingContract, backtest: boolean, context: {
16396
+ actionName: ActionName;
15654
16397
  strategyName: StrategyName;
15655
16398
  exchangeName: ExchangeName;
15656
16399
  frameName: FrameName;
15657
16400
  }) => Promise<void>;
15658
16401
  /**
15659
- * Cancels the scheduled signal without stopping the strategy.
15660
- *
15661
- * Delegates to StrategyConnectionService.cancelScheduled() to clear scheduled signal
15662
- * and emit cancelled event through emitters.
15663
- * Does not require execution context.
16402
+ * Routes active ping event to appropriate ClientAction instance.
15664
16403
  *
16404
+ * @param event - Active ping event data
15665
16405
  * @param backtest - Whether running in backtest mode
15666
- * @param symbol - Trading pair symbol
15667
- * @param ctx - Context with strategyName, exchangeName, frameName
15668
- * @param cancelId - Optional cancellation ID for user-initiated cancellations
15669
- * @returns Promise that resolves when scheduled signal is cancelled
16406
+ * @param context - Execution context with action name, strategy name, exchange name, frame name
15670
16407
  */
15671
- cancelScheduled: (backtest: boolean, symbol: string, context: {
16408
+ pingActive: (event: ActivePingContract, backtest: boolean, context: {
16409
+ actionName: ActionName;
15672
16410
  strategyName: StrategyName;
15673
16411
  exchangeName: ExchangeName;
15674
16412
  frameName: FrameName;
15675
- }, cancelId?: string) => Promise<void>;
16413
+ }) => Promise<void>;
15676
16414
  /**
15677
- * Closes the pending signal without stopping the strategy.
15678
- *
15679
- * Clears the pending signal (active position).
15680
- * Does NOT affect scheduled signals or strategy operation.
15681
- * Does NOT set stop flag - strategy can continue generating new signals.
15682
- *
15683
- * Delegates to StrategyConnectionService.closePending() to clear pending signal
15684
- * and emit closed event through emitters.
15685
- * Does not require execution context.
16415
+ * Routes riskRejection event to appropriate ClientAction instance.
15686
16416
  *
16417
+ * @param event - Risk rejection event data
15687
16418
  * @param backtest - Whether running in backtest mode
15688
- * @param symbol - Trading pair symbol
15689
- * @param context - Context with strategyName, exchangeName, frameName
15690
- * @param closeId - Optional close ID for user-initiated closes
15691
- * @returns Promise that resolves when pending signal is closed
16419
+ * @param context - Execution context with action name, strategy name, exchange name, frame name
15692
16420
  */
15693
- closePending: (backtest: boolean, symbol: string, context: {
16421
+ riskRejection: (event: RiskContract, backtest: boolean, context: {
16422
+ actionName: ActionName;
15694
16423
  strategyName: StrategyName;
15695
16424
  exchangeName: ExchangeName;
15696
16425
  frameName: FrameName;
15697
- }, closeId?: string) => Promise<void>;
16426
+ }) => Promise<void>;
15698
16427
  /**
15699
- * Disposes the ClientStrategy instance for the given context.
15700
- *
15701
- * Calls dispose on the strategy instance to clean up resources,
15702
- * then removes it from cache.
16428
+ * Disposes the ClientAction instance for the given action name.
15703
16429
  *
15704
16430
  * @param backtest - Whether running in backtest mode
15705
- * @param symbol - Trading pair symbol
15706
- * @param context - Execution context with strategyName, exchangeName, frameName
16431
+ * @param context - Execution context with action name, strategy name, exchange name, frame name
15707
16432
  */
15708
- dispose: (backtest: boolean, symbol: string, context: {
16433
+ dispose: (backtest: boolean, context: {
16434
+ actionName: ActionName;
15709
16435
  strategyName: StrategyName;
15710
16436
  exchangeName: ExchangeName;
15711
16437
  frameName: FrameName;
15712
16438
  }) => Promise<void>;
15713
16439
  /**
15714
- * Clears the memoized ClientStrategy instance from cache.
15715
- *
15716
- * Delegates to StrategyConnectionService.dispose() if payload provided,
15717
- * otherwise clears all strategy instances.
16440
+ * Clears the cached ClientAction instance for the given action name.
15718
16441
  *
15719
- * @param payload - Optional payload with symbol, context and backtest flag (clears all if not provided)
16442
+ * @param payload - Optional payload with actionName, strategyName, exchangeName, frameName, backtest (clears all if not provided)
15720
16443
  */
15721
16444
  clear: (payload?: {
15722
- symbol: string;
16445
+ actionName: ActionName;
15723
16446
  strategyName: StrategyName;
15724
16447
  exchangeName: ExchangeName;
15725
16448
  frameName: FrameName;
15726
16449
  backtest: boolean;
15727
16450
  }) => Promise<void>;
16451
+ }
16452
+
16453
+ /**
16454
+ * Type definition for exchange methods.
16455
+ * Maps all keys of IExchange to any type.
16456
+ * Used for dynamic method routing in ExchangeCoreService.
16457
+ */
16458
+ type TExchange = {
16459
+ [key in keyof IExchange]: any;
16460
+ };
16461
+ /**
16462
+ * Global service for exchange operations with execution context injection.
16463
+ *
16464
+ * Wraps ExchangeConnectionService with ExecutionContextService to inject
16465
+ * symbol, when, and backtest parameters into the execution context.
16466
+ *
16467
+ * Used internally by BacktestLogicPrivateService and LiveLogicPrivateService.
16468
+ */
16469
+ declare class ExchangeCoreService implements TExchange {
16470
+ private readonly loggerService;
16471
+ private readonly exchangeConnectionService;
16472
+ private readonly methodContextService;
16473
+ private readonly exchangeValidationService;
15728
16474
  /**
15729
- * Executes partial close at profit level (moving toward TP).
15730
- *
15731
- * Validates strategy existence and delegates to connection service
15732
- * to close a percentage of the pending position at profit.
15733
- *
15734
- * Does not require execution context as this is a direct state mutation.
16475
+ * Validates exchange configuration.
16476
+ * Memoized to avoid redundant validations for the same exchange.
16477
+ * Logs validation activity.
16478
+ * @param exchangeName - Name of the exchange to validate
16479
+ * @returns Promise that resolves when validation is complete
16480
+ */
16481
+ private validate;
16482
+ /**
16483
+ * Fetches historical candles with execution context.
15735
16484
  *
15736
- * @param backtest - Whether running in backtest mode
15737
16485
  * @param symbol - Trading pair symbol
15738
- * @param percentToClose - Percentage of position to close (0-100, absolute value)
15739
- * @param currentPrice - Current market price for this partial close (must be in profit direction)
15740
- * @param context - Execution context with strategyName, exchangeName, frameName
15741
- * @returns Promise<boolean> - true if partial close executed, false if skipped
15742
- *
15743
- * @example
15744
- * ```typescript
15745
- * // Close 30% of position at profit
15746
- * const success = await strategyCoreService.partialProfit(
15747
- * false,
15748
- * "BTCUSDT",
15749
- * 30,
15750
- * 45000,
15751
- * { strategyName: "my-strategy", exchangeName: "binance", frameName: "" }
15752
- * );
15753
- * if (success) {
15754
- * console.log('Partial profit executed');
15755
- * }
15756
- * ```
16486
+ * @param interval - Candle interval (e.g., "1m", "1h")
16487
+ * @param limit - Maximum number of candles to fetch
16488
+ * @param when - Timestamp for context (used in backtest mode)
16489
+ * @param backtest - Whether running in backtest mode
16490
+ * @returns Promise resolving to array of candles
15757
16491
  */
15758
- partialProfit: (backtest: boolean, symbol: string, percentToClose: number, currentPrice: number, context: {
15759
- strategyName: StrategyName;
15760
- exchangeName: ExchangeName;
15761
- frameName: FrameName;
15762
- }) => Promise<boolean>;
16492
+ getCandles: (symbol: string, interval: CandleInterval, limit: number, when: Date, backtest: boolean) => Promise<ICandleData[]>;
15763
16493
  /**
15764
- * Executes partial close at loss level (moving toward SL).
15765
- *
15766
- * Validates strategy existence and delegates to connection service
15767
- * to close a percentage of the pending position at loss.
15768
- *
15769
- * Does not require execution context as this is a direct state mutation.
16494
+ * Fetches future candles (backtest mode only) with execution context.
15770
16495
  *
15771
- * @param backtest - Whether running in backtest mode
15772
16496
  * @param symbol - Trading pair symbol
15773
- * @param percentToClose - Percentage of position to close (0-100, absolute value)
15774
- * @param currentPrice - Current market price for this partial close (must be in loss direction)
15775
- * @param context - Execution context with strategyName, exchangeName, frameName
15776
- * @returns Promise<boolean> - true if partial close executed, false if skipped
15777
- *
15778
- * @example
15779
- * ```typescript
15780
- * // Close 40% of position at loss
15781
- * const success = await strategyCoreService.partialLoss(
15782
- * false,
15783
- * "BTCUSDT",
15784
- * 40,
15785
- * 38000,
15786
- * { strategyName: "my-strategy", exchangeName: "binance", frameName: "" }
15787
- * );
15788
- * if (success) {
15789
- * console.log('Partial loss executed');
15790
- * }
15791
- * ```
16497
+ * @param interval - Candle interval
16498
+ * @param limit - Maximum number of candles to fetch
16499
+ * @param when - Timestamp for context
16500
+ * @param backtest - Whether running in backtest mode (must be true)
16501
+ * @returns Promise resolving to array of future candles
15792
16502
  */
15793
- partialLoss: (backtest: boolean, symbol: string, percentToClose: number, currentPrice: number, context: {
15794
- strategyName: StrategyName;
15795
- exchangeName: ExchangeName;
15796
- frameName: FrameName;
15797
- }) => Promise<boolean>;
16503
+ getNextCandles: (symbol: string, interval: CandleInterval, limit: number, when: Date, backtest: boolean) => Promise<ICandleData[]>;
15798
16504
  /**
15799
- * Adjusts the trailing stop-loss distance for an active pending signal.
15800
- *
15801
- * Validates strategy existence and delegates to connection service
15802
- * to update the stop-loss distance by a percentage adjustment.
15803
- *
15804
- * Does not require execution context as this is a direct state mutation.
16505
+ * Calculates VWAP with execution context.
15805
16506
  *
15806
- * @param backtest - Whether running in backtest mode
15807
16507
  * @param symbol - Trading pair symbol
15808
- * @param percentShift - Percentage adjustment to SL distance (-100 to 100)
15809
- * @param currentPrice - Current market price to check for intrusion
15810
- * @param context - Execution context with strategyName, exchangeName, frameName
15811
- * @returns Promise that resolves when trailing SL is updated
15812
- *
15813
- * @example
15814
- * ```typescript
15815
- * // LONG: entry=100, originalSL=90, distance=10%, currentPrice=102
15816
- * // Tighten stop by 50%: newSL = 100 - 5% = 95
15817
- * await strategyCoreService.trailingStop(
15818
- * false,
15819
- * "BTCUSDT",
15820
- * -50,
15821
- * 102,
15822
- * { strategyName: "my-strategy", exchangeName: "binance", frameName: "" }
15823
- * );
15824
- * ```
16508
+ * @param when - Timestamp for context
16509
+ * @param backtest - Whether running in backtest mode
16510
+ * @returns Promise resolving to VWAP price
15825
16511
  */
15826
- trailingStop: (backtest: boolean, symbol: string, percentShift: number, currentPrice: number, context: {
15827
- strategyName: StrategyName;
15828
- exchangeName: ExchangeName;
15829
- frameName: FrameName;
15830
- }) => Promise<boolean>;
16512
+ getAveragePrice: (symbol: string, when: Date, backtest: boolean) => Promise<number>;
15831
16513
  /**
15832
- * Adjusts the trailing take-profit distance for an active pending signal.
15833
- * Validates context and delegates to StrategyConnectionService.
16514
+ * Formats price with execution context.
15834
16515
  *
15835
- * @param backtest - Whether running in backtest mode
15836
16516
  * @param symbol - Trading pair symbol
15837
- * @param percentShift - Percentage adjustment to TP distance (-100 to 100)
15838
- * @param currentPrice - Current market price to check for intrusion
15839
- * @param context - Strategy context with strategyName, exchangeName, frameName
15840
- * @returns Promise that resolves when trailing TP is updated
15841
- *
15842
- * @example
15843
- * ```typescript
15844
- * // LONG: entry=100, originalTP=110, distance=10%, currentPrice=102
15845
- * // Move TP further by 50%: newTP = 100 + 15% = 115
15846
- * await strategyCoreService.trailingTake(
15847
- * false,
15848
- * "BTCUSDT",
15849
- * 50,
15850
- * 102,
15851
- * { strategyName: "my-strategy", exchangeName: "binance", frameName: "" }
15852
- * );
15853
- * ```
16517
+ * @param price - Price to format
16518
+ * @param when - Timestamp for context
16519
+ * @param backtest - Whether running in backtest mode
16520
+ * @returns Promise resolving to formatted price string
15854
16521
  */
15855
- trailingTake: (backtest: boolean, symbol: string, percentShift: number, currentPrice: number, context: {
15856
- strategyName: StrategyName;
15857
- exchangeName: ExchangeName;
15858
- frameName: FrameName;
15859
- }) => Promise<boolean>;
16522
+ formatPrice: (symbol: string, price: number, when: Date, backtest: boolean) => Promise<string>;
15860
16523
  /**
15861
- * Moves stop-loss to breakeven when price reaches threshold.
15862
- * Validates context and delegates to StrategyConnectionService.
16524
+ * Formats quantity with execution context.
15863
16525
  *
16526
+ * @param symbol - Trading pair symbol
16527
+ * @param quantity - Quantity to format
16528
+ * @param when - Timestamp for context
15864
16529
  * @param backtest - Whether running in backtest mode
16530
+ * @returns Promise resolving to formatted quantity string
16531
+ */
16532
+ formatQuantity: (symbol: string, quantity: number, when: Date, backtest: boolean) => Promise<string>;
16533
+ /**
16534
+ * Fetches order book with execution context.
16535
+ *
16536
+ * Sets up execution context with the provided when/backtest parameters.
16537
+ * The exchange implementation will receive time range parameters but may
16538
+ * choose to use them (backtest) or ignore them (live).
16539
+ *
15865
16540
  * @param symbol - Trading pair symbol
15866
- * @param currentPrice - Current market price to check threshold
15867
- * @param context - Strategy context with strategyName, exchangeName, frameName
15868
- * @returns Promise<boolean> - true if breakeven was set, false otherwise
16541
+ * @param when - Timestamp for context
16542
+ * @param backtest - Whether running in backtest mode
16543
+ * @param depth - Maximum depth levels (default: CC_ORDER_BOOK_MAX_DEPTH_LEVELS)
16544
+ * @returns Promise resolving to order book data
16545
+ */
16546
+ getOrderBook: (symbol: string, when: Date, backtest: boolean, depth?: number) => Promise<IOrderBookData>;
16547
+ /**
16548
+ * Fetches raw candles with flexible date/limit parameters and execution context.
15869
16549
  *
15870
- * @example
15871
- * ```typescript
15872
- * const moved = await strategyCoreService.breakeven(
15873
- * false,
15874
- * "BTCUSDT",
15875
- * 112,
15876
- * { strategyName: "my-strategy", exchangeName: "binance", frameName: "" }
15877
- * );
15878
- * ```
16550
+ * @param symbol - Trading pair symbol
16551
+ * @param interval - Candle interval (e.g., "1m", "1h")
16552
+ * @param when - Timestamp for context (used in backtest mode)
16553
+ * @param backtest - Whether running in backtest mode
16554
+ * @param limit - Optional number of candles to fetch
16555
+ * @param sDate - Optional start date in milliseconds
16556
+ * @param eDate - Optional end date in milliseconds
16557
+ * @returns Promise resolving to array of candles
15879
16558
  */
15880
- breakeven: (backtest: boolean, symbol: string, currentPrice: number, context: {
15881
- strategyName: StrategyName;
15882
- exchangeName: ExchangeName;
15883
- frameName: FrameName;
15884
- }) => Promise<boolean>;
16559
+ getRawCandles: (symbol: string, interval: CandleInterval, when: Date, backtest: boolean, limit?: number, sDate?: number, eDate?: number) => Promise<ICandleData[]>;
15885
16560
  }
15886
16561
 
15887
16562
  /**
@@ -18172,6 +18847,173 @@ declare class RiskReportService {
18172
18847
  unsubscribe: () => Promise<void>;
18173
18848
  }
18174
18849
 
18850
+ /**
18851
+ * Service for persisting strategy management events to JSON report files.
18852
+ *
18853
+ * Handles logging of strategy actions (cancel-scheduled, close-pending, partial-profit,
18854
+ * partial-loss, trailing-stop, trailing-take, breakeven) to persistent storage via
18855
+ * the Report class. Each event is written as a separate JSON record.
18856
+ *
18857
+ * Unlike StrategyMarkdownService which accumulates events in memory for markdown reports,
18858
+ * this service writes each event immediately to disk for audit trail purposes.
18859
+ *
18860
+ * Lifecycle:
18861
+ * - Call subscribe() to enable event logging
18862
+ * - Events are written via Report.writeData() with "strategy" category
18863
+ * - Call unsubscribe() to disable event logging
18864
+ *
18865
+ * @example
18866
+ * ```typescript
18867
+ * // Service is typically used internally by strategy management classes
18868
+ * strategyReportService.subscribe();
18869
+ *
18870
+ * // Events are logged automatically when strategy actions occur
18871
+ * await strategyReportService.partialProfit("BTCUSDT", 50, 50100, false, {
18872
+ * strategyName: "my-strategy",
18873
+ * exchangeName: "binance",
18874
+ * frameName: "1h"
18875
+ * });
18876
+ *
18877
+ * strategyReportService.unsubscribe();
18878
+ * ```
18879
+ *
18880
+ * @see StrategyMarkdownService for in-memory event accumulation and markdown report generation
18881
+ * @see Report for the underlying persistence mechanism
18882
+ */
18883
+ declare class StrategyReportService {
18884
+ readonly loggerService: LoggerService;
18885
+ readonly executionContextService: {
18886
+ readonly context: IExecutionContext;
18887
+ };
18888
+ readonly strategyCoreService: StrategyCoreService;
18889
+ /**
18890
+ * Logs a cancel-scheduled event when a scheduled signal is cancelled.
18891
+ *
18892
+ * Retrieves the scheduled signal from StrategyCoreService and writes
18893
+ * the cancellation event to the report file.
18894
+ *
18895
+ * @param symbol - Trading pair symbol (e.g., "BTCUSDT")
18896
+ * @param isBacktest - Whether this is a backtest or live trading event
18897
+ * @param context - Strategy context with strategyName, exchangeName, frameName
18898
+ * @param cancelId - Optional identifier for the cancellation reason
18899
+ */
18900
+ cancelScheduled: (symbol: string, isBacktest: boolean, context: {
18901
+ strategyName: StrategyName;
18902
+ exchangeName: ExchangeName;
18903
+ frameName: FrameName;
18904
+ }, cancelId?: string) => Promise<void>;
18905
+ /**
18906
+ * Logs a close-pending event when a pending signal is closed.
18907
+ *
18908
+ * Retrieves the pending signal from StrategyCoreService and writes
18909
+ * the close event to the report file.
18910
+ *
18911
+ * @param symbol - Trading pair symbol (e.g., "BTCUSDT")
18912
+ * @param isBacktest - Whether this is a backtest or live trading event
18913
+ * @param context - Strategy context with strategyName, exchangeName, frameName
18914
+ * @param closeId - Optional identifier for the close reason
18915
+ */
18916
+ closePending: (symbol: string, isBacktest: boolean, context: {
18917
+ strategyName: StrategyName;
18918
+ exchangeName: ExchangeName;
18919
+ frameName: FrameName;
18920
+ }, closeId?: string) => Promise<void>;
18921
+ /**
18922
+ * Logs a partial-profit event when a portion of the position is closed at profit.
18923
+ *
18924
+ * Records the percentage closed and current price when partial profit-taking occurs.
18925
+ *
18926
+ * @param symbol - Trading pair symbol (e.g., "BTCUSDT")
18927
+ * @param percentToClose - Percentage of position to close (0-100)
18928
+ * @param currentPrice - Current market price at time of partial close
18929
+ * @param isBacktest - Whether this is a backtest or live trading event
18930
+ * @param context - Strategy context with strategyName, exchangeName, frameName
18931
+ */
18932
+ partialProfit: (symbol: string, percentToClose: number, currentPrice: number, isBacktest: boolean, context: {
18933
+ strategyName: StrategyName;
18934
+ exchangeName: ExchangeName;
18935
+ frameName: FrameName;
18936
+ }) => Promise<void>;
18937
+ /**
18938
+ * Logs a partial-loss event when a portion of the position is closed at loss.
18939
+ *
18940
+ * Records the percentage closed and current price when partial loss-cutting occurs.
18941
+ *
18942
+ * @param symbol - Trading pair symbol (e.g., "BTCUSDT")
18943
+ * @param percentToClose - Percentage of position to close (0-100)
18944
+ * @param currentPrice - Current market price at time of partial close
18945
+ * @param isBacktest - Whether this is a backtest or live trading event
18946
+ * @param context - Strategy context with strategyName, exchangeName, frameName
18947
+ */
18948
+ partialLoss: (symbol: string, percentToClose: number, currentPrice: number, isBacktest: boolean, context: {
18949
+ strategyName: StrategyName;
18950
+ exchangeName: ExchangeName;
18951
+ frameName: FrameName;
18952
+ }) => Promise<void>;
18953
+ /**
18954
+ * Logs a trailing-stop event when the stop-loss is adjusted.
18955
+ *
18956
+ * Records the percentage shift and current price when trailing stop moves.
18957
+ *
18958
+ * @param symbol - Trading pair symbol (e.g., "BTCUSDT")
18959
+ * @param percentShift - Percentage the stop-loss was shifted
18960
+ * @param currentPrice - Current market price at time of adjustment
18961
+ * @param isBacktest - Whether this is a backtest or live trading event
18962
+ * @param context - Strategy context with strategyName, exchangeName, frameName
18963
+ */
18964
+ trailingStop: (symbol: string, percentShift: number, currentPrice: number, isBacktest: boolean, context: {
18965
+ strategyName: StrategyName;
18966
+ exchangeName: ExchangeName;
18967
+ frameName: FrameName;
18968
+ }) => Promise<void>;
18969
+ /**
18970
+ * Logs a trailing-take event when the take-profit is adjusted.
18971
+ *
18972
+ * Records the percentage shift and current price when trailing take-profit moves.
18973
+ *
18974
+ * @param symbol - Trading pair symbol (e.g., "BTCUSDT")
18975
+ * @param percentShift - Percentage the take-profit was shifted
18976
+ * @param currentPrice - Current market price at time of adjustment
18977
+ * @param isBacktest - Whether this is a backtest or live trading event
18978
+ * @param context - Strategy context with strategyName, exchangeName, frameName
18979
+ */
18980
+ trailingTake: (symbol: string, percentShift: number, currentPrice: number, isBacktest: boolean, context: {
18981
+ strategyName: StrategyName;
18982
+ exchangeName: ExchangeName;
18983
+ frameName: FrameName;
18984
+ }) => Promise<void>;
18985
+ /**
18986
+ * Logs a breakeven event when the stop-loss is moved to entry price.
18987
+ *
18988
+ * Records the current price when breakeven protection is activated.
18989
+ *
18990
+ * @param symbol - Trading pair symbol (e.g., "BTCUSDT")
18991
+ * @param currentPrice - Current market price at time of breakeven activation
18992
+ * @param isBacktest - Whether this is a backtest or live trading event
18993
+ * @param context - Strategy context with strategyName, exchangeName, frameName
18994
+ */
18995
+ breakeven: (symbol: string, currentPrice: number, isBacktest: boolean, context: {
18996
+ strategyName: StrategyName;
18997
+ exchangeName: ExchangeName;
18998
+ frameName: FrameName;
18999
+ }) => Promise<void>;
19000
+ /**
19001
+ * Initializes the service for event logging.
19002
+ *
19003
+ * Must be called before any events can be logged. Uses singleshot pattern
19004
+ * to ensure only one subscription exists at a time.
19005
+ *
19006
+ * @returns Cleanup function that clears the subscription when called
19007
+ */
19008
+ subscribe: (() => () => void) & functools_kit.ISingleshotClearable;
19009
+ /**
19010
+ * Stops event logging and cleans up the subscription.
19011
+ *
19012
+ * Safe to call multiple times - only clears if subscription exists.
19013
+ */
19014
+ unsubscribe: () => Promise<void>;
19015
+ }
19016
+
18175
19017
  declare const backtest: {
18176
19018
  exchangeValidationService: ExchangeValidationService;
18177
19019
  strategyValidationService: StrategyValidationService;
@@ -18191,6 +19033,7 @@ declare const backtest: {
18191
19033
  partialReportService: PartialReportService;
18192
19034
  breakevenReportService: BreakevenReportService;
18193
19035
  riskReportService: RiskReportService;
19036
+ strategyReportService: StrategyReportService;
18194
19037
  backtestMarkdownService: BacktestMarkdownService;
18195
19038
  liveMarkdownService: LiveMarkdownService;
18196
19039
  scheduleMarkdownService: ScheduleMarkdownService;
@@ -18200,6 +19043,7 @@ declare const backtest: {
18200
19043
  partialMarkdownService: PartialMarkdownService;
18201
19044
  breakevenMarkdownService: BreakevenMarkdownService;
18202
19045
  riskMarkdownService: RiskMarkdownService;
19046
+ strategyMarkdownService: StrategyMarkdownService;
18203
19047
  backtestLogicPublicService: BacktestLogicPublicService;
18204
19048
  liveLogicPublicService: LiveLogicPublicService;
18205
19049
  walkerLogicPublicService: WalkerLogicPublicService;
@@ -18241,4 +19085,4 @@ declare const backtest: {
18241
19085
  loggerService: LoggerService;
18242
19086
  };
18243
19087
 
18244
- export { ActionBase, type ActivePingContract, Backtest, type BacktestDoneNotification, type BacktestStatisticsModel, Breakeven, type BreakevenContract, type BreakevenData, Cache, type CandleData, type CandleInterval, type ColumnConfig, type ColumnModel, Constant, type CriticalErrorNotification, type DoneContract, type EntityId, Exchange, ExecutionContextService, type FrameInterval, type GlobalConfig, Heat, type HeatmapStatisticsModel, type IBidData, type ICandleData, type IExchangeSchema, type IFrameSchema, type IHeatmapRow, type IMarkdownDumpOptions, type IOrderBookData, type IPersistBase, type IPositionSizeATRParams, type IPositionSizeFixedPercentageParams, type IPositionSizeKellyParams, type IPublicSignalRow, type IReportDumpOptions, type IRiskActivePosition, type IRiskCheckArgs, type IRiskSchema, type IRiskValidation, type IRiskValidationFn, type IRiskValidationPayload, type IScheduledSignalCancelRow, 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 IStrategyResult, type IStrategySchema, type IStrategyTickResult, type IStrategyTickResultActive, type IStrategyTickResultCancelled, type IStrategyTickResultClosed, type IStrategyTickResultIdle, type IStrategyTickResultOpened, type IStrategyTickResultScheduled, type IWalkerResults, type IWalkerSchema, type IWalkerStrategyResult, type InfoErrorNotification, Live, type LiveDoneNotification, type LiveStatisticsModel, Markdown, MarkdownFileBase, MarkdownFolderBase, type MarkdownName, MethodContextService, type MetricStats, Notification, type NotificationModel, Partial$1 as Partial, type PartialData, type PartialEvent, type PartialLossContract, type PartialLossNotification, type PartialProfitContract, type PartialProfitNotification, type PartialStatisticsModel, Performance, type PerformanceContract, type PerformanceMetricType, type PerformanceStatisticsModel, PersistBase, PersistBreakevenAdapter, PersistCandleAdapter, PersistPartialAdapter, PersistRiskAdapter, PersistScheduleAdapter, PersistSignalAdapter, PositionSize, type ProgressBacktestContract, type ProgressBacktestNotification, type ProgressWalkerContract, Report, ReportBase, type ReportName, Risk, type RiskContract, type RiskData, type RiskEvent, type RiskRejectionNotification, type RiskStatisticsModel, Schedule, type ScheduleData, type SchedulePingContract, type ScheduleStatisticsModel, type ScheduledEvent, type SignalCancelledNotification, type SignalClosedNotification, type SignalData, type SignalInterval, type SignalOpenedNotification, type SignalScheduledNotification, type TMarkdownBase, type TPersistBase, type TPersistBaseCtor, type TReportBase, type TickEvent, type ValidationErrorNotification, Walker, type WalkerCompleteContract, type WalkerContract, type WalkerMetric, type SignalData$1 as WalkerSignalData, type WalkerStatisticsModel, addActionSchema, addExchangeSchema, addFrameSchema, addRiskSchema, addSizingSchema, addStrategySchema, addWalkerSchema, commitBreakeven, commitCancelScheduled, commitClosePending, commitPartialLoss, commitPartialProfit, commitTrailingStop, commitTrailingTake, emitters, formatPrice, formatQuantity, get, getActionSchema, getAveragePrice, getBacktestTimeframe, getCandles, getColumns, getConfig, getContext, getDate, getDefaultColumns, getDefaultConfig, getExchangeSchema, getFrameSchema, getMode, getOrderBook, getRawCandles, getRiskSchema, getSizingSchema, getStrategySchema, getSymbol, getWalkerSchema, hasTradeContext, backtest as lib, listExchangeSchema, listFrameSchema, listRiskSchema, listSizingSchema, listStrategySchema, listWalkerSchema, listenActivePing, listenActivePingOnce, listenBacktestProgress, listenBreakevenAvailable, listenBreakevenAvailableOnce, listenDoneBacktest, listenDoneBacktestOnce, listenDoneLive, listenDoneLiveOnce, listenDoneWalker, listenDoneWalkerOnce, listenError, listenExit, listenPartialLossAvailable, listenPartialLossAvailableOnce, listenPartialProfitAvailable, listenPartialProfitAvailableOnce, listenPerformance, listenRisk, listenRiskOnce, listenSchedulePing, listenSchedulePingOnce, listenSignal, listenSignalBacktest, listenSignalBacktestOnce, listenSignalLive, listenSignalLiveOnce, listenSignalOnce, listenValidation, listenWalker, listenWalkerComplete, listenWalkerOnce, listenWalkerProgress, overrideActionSchema, overrideExchangeSchema, overrideFrameSchema, overrideRiskSchema, overrideSizingSchema, overrideStrategySchema, overrideWalkerSchema, parseArgs, roundTicks, set, setColumns, setConfig, setLogger, stopStrategy, validate };
19088
+ export { ActionBase, type ActivePingContract, Backtest, type BacktestDoneNotification, type BacktestStatisticsModel, Breakeven, type BreakevenContract, type BreakevenData, Cache, type CandleData, type CandleInterval, type ColumnConfig, type ColumnModel, Constant, type CriticalErrorNotification, type DoneContract, type EntityId, Exchange, ExecutionContextService, type FrameInterval, type GlobalConfig, Heat, type HeatmapStatisticsModel, type IBidData, type ICandleData, type IExchangeSchema, type IFrameSchema, type IHeatmapRow, type IMarkdownDumpOptions, type IOrderBookData, type IPersistBase, type IPositionSizeATRParams, type IPositionSizeFixedPercentageParams, type IPositionSizeKellyParams, type IPublicSignalRow, type IReportDumpOptions, type IRiskActivePosition, type IRiskCheckArgs, type IRiskSchema, type IRiskValidation, type IRiskValidationFn, type IRiskValidationPayload, type IScheduledSignalCancelRow, 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 IStrategyResult, type IStrategySchema, type IStrategyTickResult, type IStrategyTickResultActive, type IStrategyTickResultCancelled, type IStrategyTickResultClosed, type IStrategyTickResultIdle, type IStrategyTickResultOpened, type IStrategyTickResultScheduled, type IWalkerResults, type IWalkerSchema, type IWalkerStrategyResult, type InfoErrorNotification, Live, type LiveDoneNotification, type LiveStatisticsModel, Markdown, MarkdownFileBase, MarkdownFolderBase, type MarkdownName, MethodContextService, type MetricStats, Notification, type NotificationModel, Partial$1 as Partial, type PartialData, type PartialEvent, type PartialLossContract, type PartialLossNotification, type PartialProfitContract, type PartialProfitNotification, type PartialStatisticsModel, Performance, type PerformanceContract, type PerformanceMetricType, type PerformanceStatisticsModel, PersistBase, PersistBreakevenAdapter, PersistCandleAdapter, PersistPartialAdapter, PersistRiskAdapter, PersistScheduleAdapter, PersistSignalAdapter, PositionSize, type ProgressBacktestContract, type ProgressBacktestNotification, type ProgressWalkerContract, Report, ReportBase, type ReportName, Risk, type RiskContract, type RiskData, type RiskEvent, type RiskRejectionNotification, type RiskStatisticsModel, Schedule, type ScheduleData, type SchedulePingContract, type ScheduleStatisticsModel, type ScheduledEvent, type SignalCancelledNotification, type SignalClosedNotification, type SignalData, type SignalInterval, type SignalOpenedNotification, type SignalScheduledNotification, Strategy, type StrategyActionType, type StrategyCommitContract, type StrategyEvent, type StrategyStatisticsModel, type TMarkdownBase, type TPersistBase, type TPersistBaseCtor, type TReportBase, type TickEvent, type ValidationErrorNotification, Walker, type WalkerCompleteContract, type WalkerContract, type WalkerMetric, type SignalData$1 as WalkerSignalData, type WalkerStatisticsModel, addActionSchema, addExchangeSchema, addFrameSchema, addRiskSchema, addSizingSchema, addStrategySchema, addWalkerSchema, commitBreakeven, commitCancelScheduled, commitClosePending, commitPartialLoss, commitPartialProfit, commitTrailingStop, commitTrailingTake, emitters, formatPrice, formatQuantity, get, getActionSchema, getAveragePrice, getBacktestTimeframe, getCandles, getColumns, getConfig, getContext, getDate, getDefaultColumns, getDefaultConfig, getExchangeSchema, getFrameSchema, getMode, getOrderBook, getRawCandles, getRiskSchema, getSizingSchema, getStrategySchema, getSymbol, getWalkerSchema, hasTradeContext, backtest as lib, listExchangeSchema, listFrameSchema, listRiskSchema, listSizingSchema, listStrategySchema, listWalkerSchema, listenActivePing, listenActivePingOnce, listenBacktestProgress, listenBreakevenAvailable, listenBreakevenAvailableOnce, listenDoneBacktest, listenDoneBacktestOnce, listenDoneLive, listenDoneLiveOnce, listenDoneWalker, listenDoneWalkerOnce, listenError, listenExit, listenPartialLossAvailable, listenPartialLossAvailableOnce, listenPartialProfitAvailable, listenPartialProfitAvailableOnce, listenPerformance, listenRisk, listenRiskOnce, listenSchedulePing, listenSchedulePingOnce, listenSignal, listenSignalBacktest, listenSignalBacktestOnce, listenSignalLive, listenSignalLiveOnce, listenSignalOnce, listenStrategyCommit, listenStrategyCommitOnce, listenValidation, listenWalker, listenWalkerComplete, listenWalkerOnce, listenWalkerProgress, overrideActionSchema, overrideExchangeSchema, overrideFrameSchema, overrideRiskSchema, overrideSizingSchema, overrideStrategySchema, overrideWalkerSchema, parseArgs, roundTicks, set, setColumns, setConfig, setLogger, stopStrategy, validate };