backtest-kit 1.7.2 → 1.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. package/build/index.cjs +2673 -916
  2. package/build/index.mjs +2672 -918
  3. package/package.json +2 -1
  4. package/types.d.ts +1328 -417
package/types.d.ts CHANGED
@@ -155,6 +155,78 @@ declare function stop(symbol: string): Promise<void>;
155
155
  * ```
156
156
  */
157
157
  declare function cancel(symbol: string, cancelId?: string): Promise<void>;
158
+ /**
159
+ * Executes partial close at profit level (moving toward TP).
160
+ *
161
+ * Closes a percentage of the active pending position at profit.
162
+ * Price must be moving toward take profit (in profit direction).
163
+ *
164
+ * Automatically detects backtest/live mode from execution context.
165
+ *
166
+ * @param symbol - Trading pair symbol
167
+ * @param percentToClose - Percentage of position to close (0-100, absolute value)
168
+ * @returns Promise that resolves when state is updated
169
+ *
170
+ * @throws Error if currentPrice is not in profit direction:
171
+ * - LONG: currentPrice must be > priceOpen
172
+ * - SHORT: currentPrice must be < priceOpen
173
+ *
174
+ * @example
175
+ * ```typescript
176
+ * import { partialProfit } from "backtest-kit";
177
+ *
178
+ * // Close 30% of LONG position at profit
179
+ * await partialProfit("BTCUSDT", 30, 45000);
180
+ * ```
181
+ */
182
+ declare function partialProfit(symbol: string, percentToClose: number): Promise<void>;
183
+ /**
184
+ * Executes partial close at loss level (moving toward SL).
185
+ *
186
+ * Closes a percentage of the active pending position at loss.
187
+ * Price must be moving toward stop loss (in loss direction).
188
+ *
189
+ * Automatically detects backtest/live mode from execution context.
190
+ *
191
+ * @param symbol - Trading pair symbol
192
+ * @param percentToClose - Percentage of position to close (0-100, absolute value)
193
+ * @returns Promise that resolves when state is updated
194
+ *
195
+ * @throws Error if currentPrice is not in loss direction:
196
+ * - LONG: currentPrice must be < priceOpen
197
+ * - SHORT: currentPrice must be > priceOpen
198
+ *
199
+ * @example
200
+ * ```typescript
201
+ * import { partialLoss } from "backtest-kit";
202
+ *
203
+ * // Close 40% of LONG position at loss
204
+ * await partialLoss("BTCUSDT", 40, 38000);
205
+ * ```
206
+ */
207
+ declare function partialLoss(symbol: string, percentToClose: number): Promise<void>;
208
+ /**
209
+ * Adjusts the trailing stop-loss distance for an active pending signal.
210
+ *
211
+ * Updates the stop-loss distance by a percentage adjustment relative to the original SL distance.
212
+ * Positive percentShift tightens the SL (reduces distance), negative percentShift loosens it.
213
+ *
214
+ * Automatically detects backtest/live mode from execution context.
215
+ *
216
+ * @param symbol - Trading pair symbol
217
+ * @param percentShift - Percentage adjustment to SL distance (-100 to 100)
218
+ * @returns Promise that resolves when trailing SL is updated
219
+ *
220
+ * @example
221
+ * ```typescript
222
+ * import { trailingStop } from "backtest-kit";
223
+ *
224
+ * // LONG: entry=100, originalSL=90, distance=10
225
+ * // Tighten stop by 50%: newSL = 100 - 10*(1-0.5) = 95
226
+ * await trailingStop("BTCUSDT", -50);
227
+ * ```
228
+ */
229
+ declare function trailingStop(symbol: string, percentShift: number): Promise<void>;
158
230
 
159
231
  declare const GLOBAL_CONFIG: {
160
232
  /**
@@ -583,7 +655,7 @@ interface IExchangeParams extends IExchangeSchema {
583
655
  */
584
656
  interface IExchangeCallbacks {
585
657
  /** Called when candle data is fetched */
586
- onCandleData: (symbol: string, interval: CandleInterval, since: Date, limit: number, data: ICandleData[]) => void;
658
+ onCandleData: (symbol: string, interval: CandleInterval, since: Date, limit: number, data: ICandleData[]) => void | Promise<void>;
587
659
  }
588
660
  /**
589
661
  * Exchange schema registered via addExchange().
@@ -708,7 +780,7 @@ interface IFrameCallbacks {
708
780
  * @param endDate - End of the backtest period
709
781
  * @param interval - Interval used for generation
710
782
  */
711
- onTimeframe: (timeframe: Date[], startDate: Date, endDate: Date, interval: FrameInterval) => void;
783
+ onTimeframe: (timeframe: Date[], startDate: Date, endDate: Date, interval: FrameInterval) => void | Promise<void>;
712
784
  }
713
785
  /**
714
786
  * Frame schema registered via addFrame().
@@ -819,13 +891,13 @@ interface IRiskCheckArgs {
819
891
  /** Trading pair symbol (e.g., "BTCUSDT") */
820
892
  symbol: string;
821
893
  /** Pending signal to apply */
822
- pendingSignal: ISignalDto;
894
+ pendingSignal: ISignalDto | ISignalRow;
823
895
  /** Strategy name requesting to open a position */
824
896
  strategyName: StrategyName;
825
897
  /** Exchange name */
826
898
  exchangeName: ExchangeName;
827
899
  /** Frame name */
828
- frameName: string;
900
+ frameName: FrameName;
829
901
  /** Current VWAP price */
830
902
  currentPrice: number;
831
903
  /** Current timestamp */
@@ -836,9 +908,9 @@ interface IRiskCheckArgs {
836
908
  */
837
909
  interface IRiskActivePosition {
838
910
  /** Strategy name owning the position */
839
- strategyName: string;
911
+ strategyName: StrategyName;
840
912
  /** Exchange name */
841
- exchangeName: string;
913
+ exchangeName: ExchangeName;
842
914
  /** Timestamp when the position was opened */
843
915
  openTimestamp: number;
844
916
  }
@@ -847,17 +919,17 @@ interface IRiskActivePosition {
847
919
  */
848
920
  interface IRiskCallbacks {
849
921
  /** Called when a signal is rejected due to risk limits */
850
- onRejected: (symbol: string, params: IRiskCheckArgs) => void;
922
+ onRejected: (symbol: string, params: IRiskCheckArgs) => void | Promise<void>;
851
923
  /** Called when a signal passes risk checks */
852
- onAllowed: (symbol: string, params: IRiskCheckArgs) => void;
924
+ onAllowed: (symbol: string, params: IRiskCheckArgs) => void | Promise<void>;
853
925
  }
854
926
  /**
855
927
  * Payload passed to risk validation functions.
856
928
  * Extends IRiskCheckArgs with portfolio state data.
857
929
  */
858
930
  interface IRiskValidationPayload extends IRiskCheckArgs {
859
- /** Pending signal to apply */
860
- pendingSignal: ISignalDto;
931
+ /** Pending signal to apply (IRiskSignalRow is calculated internally so priceOpen always exist) */
932
+ pendingSignal: IRiskSignalRow;
861
933
  /** Number of currently active positions across all strategies */
862
934
  activePositionCount: number;
863
935
  /** List of currently active positions across all strategies */
@@ -952,10 +1024,10 @@ interface IRisk {
952
1024
  * @param context - Context information (strategyName, riskName, exchangeName, frameName)
953
1025
  */
954
1026
  addSignal: (symbol: string, context: {
955
- strategyName: string;
956
- riskName: string;
957
- exchangeName: string;
958
- frameName: string;
1027
+ strategyName: StrategyName;
1028
+ riskName: RiskName;
1029
+ exchangeName: ExchangeName;
1030
+ frameName: FrameName;
959
1031
  }) => Promise<void>;
960
1032
  /**
961
1033
  * Remove a closed signal/position.
@@ -964,10 +1036,10 @@ interface IRisk {
964
1036
  * @param context - Context information (strategyName, riskName, exchangeName, frameName)
965
1037
  */
966
1038
  removeSignal: (symbol: string, context: {
967
- strategyName: string;
968
- riskName: string;
969
- exchangeName: string;
970
- frameName: string;
1039
+ strategyName: StrategyName;
1040
+ riskName: RiskName;
1041
+ exchangeName: ExchangeName;
1042
+ frameName: FrameName;
971
1043
  }) => Promise<void>;
972
1044
  }
973
1045
  /**
@@ -1072,7 +1144,7 @@ interface IPartial {
1072
1144
  * // Emits events for 20% level only (10% already emitted)
1073
1145
  * ```
1074
1146
  */
1075
- profit(symbol: string, data: ISignalRow, currentPrice: number, revenuePercent: number, backtest: boolean, when: Date): Promise<void>;
1147
+ profit(symbol: string, data: IPublicSignalRow, currentPrice: number, revenuePercent: number, backtest: boolean, when: Date): Promise<void>;
1076
1148
  /**
1077
1149
  * Processes loss state and emits events for new loss levels reached.
1078
1150
  *
@@ -1106,7 +1178,7 @@ interface IPartial {
1106
1178
  * // Emits events for 20% level only (10% already emitted)
1107
1179
  * ```
1108
1180
  */
1109
- loss(symbol: string, data: ISignalRow, currentPrice: number, lossPercent: number, backtest: boolean, when: Date): Promise<void>;
1181
+ loss(symbol: string, data: IPublicSignalRow, currentPrice: number, lossPercent: number, backtest: boolean, when: Date): Promise<void>;
1110
1182
  /**
1111
1183
  * Clears partial profit/loss state when signal closes.
1112
1184
  *
@@ -1128,7 +1200,7 @@ interface IPartial {
1128
1200
  * // Memoized instance cleared from getPartial cache
1129
1201
  * ```
1130
1202
  */
1131
- clear(symbol: string, data: ISignalRow, priceClose: number, backtest: boolean): Promise<void>;
1203
+ clear(symbol: string, data: IPublicSignalRow, priceClose: number, backtest: boolean): Promise<void>;
1132
1204
  }
1133
1205
 
1134
1206
  /**
@@ -1179,6 +1251,33 @@ interface ISignalRow extends ISignalDto {
1179
1251
  symbol: string;
1180
1252
  /** Internal runtime marker for scheduled signals */
1181
1253
  _isScheduled: boolean;
1254
+ /**
1255
+ * History of partial closes for PNL calculation.
1256
+ * Each entry contains type (profit/loss), percent closed, and price.
1257
+ * Used to calculate weighted PNL: Σ(percent_i × pnl_i) for each partial + (remaining% × final_pnl)
1258
+ *
1259
+ * Computed values (derived from this array):
1260
+ * - _tpClosed: Sum of all "profit" type partial close percentages
1261
+ * - _slClosed: Sum of all "loss" type partial close percentages
1262
+ * - _totalClosed: Sum of all partial close percentages (profit + loss)
1263
+ */
1264
+ _partial?: Array<{
1265
+ /** Type of partial close: profit (moving toward TP) or loss (moving toward SL) */
1266
+ type: "profit" | "loss";
1267
+ /** Percentage of position closed (0-100) */
1268
+ percent: number;
1269
+ /** Price at which this partial was executed */
1270
+ price: number;
1271
+ }>;
1272
+ /**
1273
+ * Trailing stop-loss price that overrides priceStopLoss when set.
1274
+ * Updated by trailing() method based on position type and percentage distance.
1275
+ * - For LONG: moves upward as price moves toward TP (never moves down)
1276
+ * - For SHORT: moves downward as price moves toward TP (never moves up)
1277
+ * When _trailingPriceStopLoss is set, it replaces priceStopLoss for TP/SL checks.
1278
+ * Original priceStopLoss is preserved in persistence but ignored during execution.
1279
+ */
1280
+ _trailingPriceStopLoss?: number;
1182
1281
  }
1183
1282
  /**
1184
1283
  * Scheduled signal row for delayed entry at specific price.
@@ -1190,6 +1289,38 @@ interface IScheduledSignalRow extends ISignalRow {
1190
1289
  /** Entry price for the position */
1191
1290
  priceOpen: number;
1192
1291
  }
1292
+ /**
1293
+ * Public signal row with original stop-loss price.
1294
+ * Extends ISignalRow to include originalPriceStopLoss for external visibility.
1295
+ * Used in public APIs to show user the original SL even if trailing SL is active.
1296
+ * This allows users to see both the current effective SL and the original SL set at signal creation.
1297
+ * The originalPriceStopLoss remains unchanged even if _trailingPriceStopLoss modifies the effective SL.
1298
+ * Useful for transparency in reporting and user interfaces.
1299
+ * Note: originalPriceStopLoss is identical to priceStopLoss at signal creation time.
1300
+ */
1301
+ interface IPublicSignalRow extends ISignalRow {
1302
+ /**
1303
+ * Original stop-loss price set at signal creation.
1304
+ * Remains unchanged even if trailing stop-loss modifies effective SL.
1305
+ * Used for user visibility of initial SL parameters.
1306
+ */
1307
+ originalPriceStopLoss: number;
1308
+ }
1309
+ /**
1310
+ * Risk signal row for internal risk management.
1311
+ * Extends ISignalDto to include priceOpen and originalPriceStopLoss.
1312
+ * Used in risk validation to access entry price and original SL.
1313
+ */
1314
+ interface IRiskSignalRow extends ISignalDto {
1315
+ /**
1316
+ * Entry price for the position.
1317
+ */
1318
+ priceOpen: number;
1319
+ /**
1320
+ * Original stop-loss price set at signal creation.
1321
+ */
1322
+ originalPriceStopLoss: number;
1323
+ }
1193
1324
  /**
1194
1325
  * Scheduled signal row with cancellation ID.
1195
1326
  * Extends IScheduledSignalRow to include optional cancelId for user-initiated cancellations.
@@ -1204,27 +1335,27 @@ interface IScheduledSignalCancelRow extends IScheduledSignalRow {
1204
1335
  */
1205
1336
  interface IStrategyCallbacks {
1206
1337
  /** Called on every tick with the result */
1207
- onTick: (symbol: string, result: IStrategyTickResult, backtest: boolean) => void;
1338
+ onTick: (symbol: string, result: IStrategyTickResult, backtest: boolean) => void | Promise<void>;
1208
1339
  /** Called when new signal is opened (after validation) */
1209
- onOpen: (symbol: string, data: ISignalRow, currentPrice: number, backtest: boolean) => void;
1340
+ onOpen: (symbol: string, data: IPublicSignalRow, currentPrice: number, backtest: boolean) => void | Promise<void>;
1210
1341
  /** Called when signal is being monitored (active state) */
1211
- onActive: (symbol: string, data: ISignalRow, currentPrice: number, backtest: boolean) => void;
1342
+ onActive: (symbol: string, data: IPublicSignalRow, currentPrice: number, backtest: boolean) => void | Promise<void>;
1212
1343
  /** Called when no active signal exists (idle state) */
1213
- onIdle: (symbol: string, currentPrice: number, backtest: boolean) => void;
1344
+ onIdle: (symbol: string, currentPrice: number, backtest: boolean) => void | Promise<void>;
1214
1345
  /** Called when signal is closed with final price */
1215
- onClose: (symbol: string, data: ISignalRow, priceClose: number, backtest: boolean) => void;
1346
+ onClose: (symbol: string, data: IPublicSignalRow, priceClose: number, backtest: boolean) => void | Promise<void>;
1216
1347
  /** Called when scheduled signal is created (delayed entry) */
1217
- onSchedule: (symbol: string, data: IScheduledSignalRow, currentPrice: number, backtest: boolean) => void;
1348
+ onSchedule: (symbol: string, data: IPublicSignalRow, currentPrice: number, backtest: boolean) => void | Promise<void>;
1218
1349
  /** Called when scheduled signal is cancelled without opening position */
1219
- onCancel: (symbol: string, data: IScheduledSignalRow, currentPrice: number, backtest: boolean) => void;
1350
+ onCancel: (symbol: string, data: IPublicSignalRow, currentPrice: number, backtest: boolean) => void | Promise<void>;
1220
1351
  /** Called when signal is written to persist storage (for testing) */
1221
- onWrite: (symbol: string, data: ISignalRow | null, backtest: boolean) => void;
1352
+ onWrite: (symbol: string, data: IPublicSignalRow | null, backtest: boolean) => void;
1222
1353
  /** Called when signal is in partial profit state (price moved favorably but not reached TP yet) */
1223
- onPartialProfit: (symbol: string, data: ISignalRow, currentPrice: number, revenuePercent: number, backtest: boolean) => void;
1354
+ onPartialProfit: (symbol: string, data: IPublicSignalRow, currentPrice: number, revenuePercent: number, backtest: boolean) => void | Promise<void>;
1224
1355
  /** Called when signal is in partial loss state (price moved against position but not hit SL yet) */
1225
- onPartialLoss: (symbol: string, data: ISignalRow, currentPrice: number, lossPercent: number, backtest: boolean) => void;
1356
+ onPartialLoss: (symbol: string, data: IPublicSignalRow, currentPrice: number, lossPercent: number, backtest: boolean) => void | Promise<void>;
1226
1357
  /** Called every minute regardless of strategy interval (for custom monitoring like checking if signal should be cancelled) */
1227
- onPing: (symbol: string, data: IScheduledSignalRow, when: Date, backtest: boolean) => void | Promise<void>;
1358
+ onPing: (symbol: string, data: IPublicSignalRow, when: Date, backtest: boolean) => void | Promise<void>;
1228
1359
  }
1229
1360
  /**
1230
1361
  * Strategy schema registered via addStrategy().
@@ -1301,7 +1432,7 @@ interface IStrategyTickResultScheduled {
1301
1432
  /** Discriminator for type-safe union */
1302
1433
  action: "scheduled";
1303
1434
  /** Scheduled signal waiting for activation */
1304
- signal: IScheduledSignalRow;
1435
+ signal: IPublicSignalRow;
1305
1436
  /** Strategy name for tracking */
1306
1437
  strategyName: StrategyName;
1307
1438
  /** Exchange name for tracking */
@@ -1323,7 +1454,7 @@ interface IStrategyTickResultOpened {
1323
1454
  /** Discriminator for type-safe union */
1324
1455
  action: "opened";
1325
1456
  /** Newly created and validated signal with generated ID */
1326
- signal: ISignalRow;
1457
+ signal: IPublicSignalRow;
1327
1458
  /** Strategy name for tracking */
1328
1459
  strategyName: StrategyName;
1329
1460
  /** Exchange name for tracking */
@@ -1345,7 +1476,7 @@ interface IStrategyTickResultActive {
1345
1476
  /** Discriminator for type-safe union */
1346
1477
  action: "active";
1347
1478
  /** Currently monitored signal */
1348
- signal: ISignalRow;
1479
+ signal: IPublicSignalRow;
1349
1480
  /** Current VWAP price for monitoring */
1350
1481
  currentPrice: number;
1351
1482
  /** Strategy name for tracking */
@@ -1371,7 +1502,7 @@ interface IStrategyTickResultClosed {
1371
1502
  /** Discriminator for type-safe union */
1372
1503
  action: "closed";
1373
1504
  /** Completed signal with original parameters */
1374
- signal: ISignalRow;
1505
+ signal: IPublicSignalRow;
1375
1506
  /** Final VWAP price at close */
1376
1507
  currentPrice: number;
1377
1508
  /** Why signal closed (time_expired | take_profit | stop_loss) */
@@ -1399,7 +1530,7 @@ interface IStrategyTickResultCancelled {
1399
1530
  /** Discriminator for type-safe union */
1400
1531
  action: "cancelled";
1401
1532
  /** Cancelled scheduled signal */
1402
- signal: IScheduledSignalRow;
1533
+ signal: IPublicSignalRow;
1403
1534
  /** Final VWAP price at cancellation */
1404
1535
  currentPrice: number;
1405
1536
  /** Unix timestamp in milliseconds when signal cancelled */
@@ -1428,6 +1559,219 @@ type IStrategyTickResult = IStrategyTickResultIdle | IStrategyTickResultSchedule
1428
1559
  * Backtest returns closed result (TP/SL or time_expired) or cancelled result (scheduled signal never activated).
1429
1560
  */
1430
1561
  type IStrategyBacktestResult = IStrategyTickResultClosed | IStrategyTickResultCancelled;
1562
+ /**
1563
+ * Strategy interface implemented by ClientStrategy.
1564
+ * Defines core strategy execution methods.
1565
+ */
1566
+ interface IStrategy {
1567
+ /**
1568
+ * Single tick of strategy execution with VWAP monitoring.
1569
+ * Checks for signal generation (throttled) and TP/SL conditions.
1570
+ *
1571
+ * @param symbol - Trading pair symbol (e.g., "BTCUSDT")
1572
+ * @param strategyName - Name of the strategy
1573
+ * @returns Promise resolving to tick result (idle | opened | active | closed)
1574
+ */
1575
+ tick: (symbol: string, strategyName: StrategyName) => Promise<IStrategyTickResult>;
1576
+ /**
1577
+ * Retrieves the currently active pending signal for the symbol.
1578
+ * If no active signal exists, returns null.
1579
+ * Used internally for monitoring TP/SL and time expiration.
1580
+ *
1581
+ * @param symbol - Trading pair symbol
1582
+ * @returns Promise resolving to pending signal or null
1583
+ */
1584
+ getPendingSignal: (symbol: string) => Promise<IPublicSignalRow | null>;
1585
+ /**
1586
+ * Retrieves the currently active scheduled signal for the symbol.
1587
+ * If no scheduled signal exists, returns null.
1588
+ * Used internally for monitoring scheduled signal activation.
1589
+ *
1590
+ * @param symbol - Trading pair symbol
1591
+ * @returns Promise resolving to scheduled signal or null
1592
+ */
1593
+ getScheduledSignal: (symbol: string) => Promise<IPublicSignalRow | null>;
1594
+ /**
1595
+ * Checks if the strategy has been stopped.
1596
+ *
1597
+ * Returns the stopped state indicating whether the strategy should
1598
+ * cease processing new ticks or signals.
1599
+ *
1600
+ * @param symbol - Trading pair symbol
1601
+ * @returns Promise resolving to true if strategy is stopped, false otherwise
1602
+ */
1603
+ getStopped: (symbol: string) => Promise<boolean>;
1604
+ /**
1605
+ * Fast backtest using historical candles.
1606
+ * Iterates through candles, calculates VWAP, checks TP/SL on each candle.
1607
+ *
1608
+ * For scheduled signals: first monitors activation/cancellation,
1609
+ * then if activated continues with TP/SL monitoring.
1610
+ *
1611
+ * @param symbol - Trading pair symbol
1612
+ * @param strategyName - Name of the strategy
1613
+ * @param candles - Array of historical candle data
1614
+ * @returns Promise resolving to closed result (always completes signal)
1615
+ */
1616
+ backtest: (symbol: string, strategyName: StrategyName, candles: ICandleData[]) => Promise<IStrategyBacktestResult>;
1617
+ /**
1618
+ * Stops the strategy from generating new signals.
1619
+ *
1620
+ * Sets internal flag to prevent getSignal from being called on subsequent ticks.
1621
+ * Does NOT force-close active pending signals - they continue monitoring until natural closure (TP/SL/time_expired).
1622
+ *
1623
+ * Use case: Graceful shutdown in live trading mode without abandoning open positions.
1624
+ *
1625
+ * @param symbol - Trading pair symbol (e.g., "BTCUSDT")
1626
+ * @returns Promise that resolves immediately when stop flag is set
1627
+ *
1628
+ * @example
1629
+ * ```typescript
1630
+ * // Graceful shutdown in Live.background() cancellation
1631
+ * const cancel = await Live.background("BTCUSDT", { ... });
1632
+ *
1633
+ * // Later: stop new signals, let existing ones close naturally
1634
+ * await cancel();
1635
+ * ```
1636
+ */
1637
+ stop: (symbol: string, backtest: boolean) => Promise<void>;
1638
+ /**
1639
+ * Cancels the scheduled signal without stopping the strategy.
1640
+ *
1641
+ * Clears the scheduled signal (waiting for priceOpen activation).
1642
+ * Does NOT affect active pending signals or strategy operation.
1643
+ * Does NOT set stop flag - strategy can continue generating new signals.
1644
+ *
1645
+ * Use case: Cancel a scheduled entry that is no longer desired without stopping the entire strategy.
1646
+ *
1647
+ * @param symbol - Trading pair symbol (e.g., "BTCUSDT")
1648
+ * @param cancelId - Optional cancellation ID
1649
+ * @returns Promise that resolves when scheduled signal is cleared
1650
+ *
1651
+ * @example
1652
+ * ```typescript
1653
+ * // Cancel scheduled signal without stopping strategy
1654
+ * await strategy.cancel("BTCUSDT");
1655
+ * // Strategy continues, can generate new signals
1656
+ * ```
1657
+ */
1658
+ cancel: (symbol: string, backtest: boolean, cancelId?: string) => Promise<void>;
1659
+ /**
1660
+ * Executes partial close at profit level (moving toward TP).
1661
+ *
1662
+ * Closes specified percentage of position at current price.
1663
+ * Updates _tpClosed, _totalClosed, and _partialHistory state.
1664
+ * Persists updated signal state for crash recovery.
1665
+ *
1666
+ * Validations:
1667
+ * - Throws if no pending signal exists
1668
+ * - Throws if called on scheduled signal (not yet activated)
1669
+ * - Throws if percentToClose <= 0 or > 100
1670
+ * - Does nothing if _totalClosed + percentToClose > 100 (prevents over-closing)
1671
+ *
1672
+ * Use case: User-controlled partial close triggered from onPartialProfit callback.
1673
+ *
1674
+ * @param symbol - Trading pair symbol (e.g., "BTCUSDT")
1675
+ * @param percentToClose - Absolute percentage of position to close (0-100)
1676
+ * @param currentPrice - Current market price for partial close
1677
+ * @param backtest - Whether running in backtest mode
1678
+ * @returns Promise that resolves when partial close is complete
1679
+ *
1680
+ * @example
1681
+ * ```typescript
1682
+ * callbacks: {
1683
+ * onPartialProfit: async (symbol, signal, currentPrice, percentTp, backtest) => {
1684
+ * if (percentTp >= 50) {
1685
+ * await strategy.partialProfit(symbol, 25, currentPrice, backtest);
1686
+ * }
1687
+ * }
1688
+ * }
1689
+ * ```
1690
+ */
1691
+ partialProfit: (symbol: string, percentToClose: number, currentPrice: number, backtest: boolean) => Promise<void>;
1692
+ /**
1693
+ * Executes partial close at loss level (moving toward SL).
1694
+ *
1695
+ * Closes specified percentage of position at current price.
1696
+ * Updates _slClosed, _totalClosed, and _partialHistory state.
1697
+ * Persists updated signal state for crash recovery.
1698
+ *
1699
+ * Validations:
1700
+ * - Throws if no pending signal exists
1701
+ * - Throws if called on scheduled signal (not yet activated)
1702
+ * - Throws if percentToClose <= 0 or > 100
1703
+ * - Does nothing if _totalClosed + percentToClose > 100 (prevents over-closing)
1704
+ *
1705
+ * Use case: User-controlled partial close triggered from onPartialLoss callback.
1706
+ *
1707
+ * @param symbol - Trading pair symbol (e.g., "BTCUSDT")
1708
+ * @param percentToClose - Absolute percentage of position to close (0-100)
1709
+ * @param currentPrice - Current market price for partial close
1710
+ * @param backtest - Whether running in backtest mode
1711
+ * @returns Promise that resolves when partial close is complete
1712
+ *
1713
+ * @example
1714
+ * ```typescript
1715
+ * callbacks: {
1716
+ * onPartialLoss: async (symbol, signal, currentPrice, percentSl, backtest) => {
1717
+ * if (percentSl >= 80) {
1718
+ * await strategy.partialLoss(symbol, 50, currentPrice, backtest);
1719
+ * }
1720
+ * }
1721
+ * }
1722
+ * ```
1723
+ */
1724
+ partialLoss: (symbol: string, percentToClose: number, currentPrice: number, backtest: boolean) => Promise<void>;
1725
+ /**
1726
+ * Adjusts trailing stop-loss by shifting distance between entry and original SL.
1727
+ *
1728
+ * Calculates new SL based on percentage shift of the distance (entry - originalSL):
1729
+ * - Negative %: tightens stop (moves SL closer to entry, reduces risk)
1730
+ * - Positive %: loosens stop (moves SL away from entry, allows more drawdown)
1731
+ *
1732
+ * For LONG position (entry=100, originalSL=90, distance=10):
1733
+ * - percentShift = -50: newSL = 100 - 10*(1-0.5) = 95 (tighter, closer to entry)
1734
+ * - percentShift = +20: newSL = 100 - 10*(1+0.2) = 88 (looser, away from entry)
1735
+ *
1736
+ * For SHORT position (entry=100, originalSL=110, distance=10):
1737
+ * - percentShift = -50: newSL = 100 + 10*(1-0.5) = 105 (tighter, closer to entry)
1738
+ * - percentShift = +20: newSL = 100 + 10*(1+0.2) = 112 (looser, away from entry)
1739
+ *
1740
+ * Trailing behavior:
1741
+ * - Only updates if new SL is BETTER (protects more profit)
1742
+ * - For LONG: only accepts higher SL (never moves down)
1743
+ * - For SHORT: only accepts lower SL (never moves up)
1744
+ * - Validates that SL never crosses entry price
1745
+ * - Stores in _trailingPriceStopLoss, original priceStopLoss preserved
1746
+ *
1747
+ * Validations:
1748
+ * - Throws if no pending signal exists
1749
+ * - Throws if percentShift< -100 or > 100
1750
+ * - Throws if percentShift=== 0
1751
+ * - Skips if new SL would cross entry price
1752
+ *
1753
+ * Use case: User-controlled trailing stop triggered from onPartialProfit callback.
1754
+ *
1755
+ * @param symbol - Trading pair symbol (e.g., "BTCUSDT")
1756
+ * @param percentShift- Percentage shift of SL distance [-100, 100], excluding 0
1757
+ * @param backtest - Whether running in backtest mode
1758
+ * @returns Promise that resolves when trailing SL is updated
1759
+ *
1760
+ * @example
1761
+ * ```typescript
1762
+ * callbacks: {
1763
+ * onPartialProfit: async (symbol, signal, currentPrice, percentTp, backtest) => {
1764
+ * if (percentTp >= 50) {
1765
+ * // LONG: entry=100, originalSL=90, distance=10
1766
+ * // Tighten stop by 50%: newSL = 100 - 10*(1-0.5) = 95
1767
+ * await strategy.trailingStop(symbol, -50, backtest);
1768
+ * }
1769
+ * }
1770
+ * }
1771
+ * ```
1772
+ */
1773
+ trailingStop: (symbol: string, percentShift: number, backtest: boolean) => Promise<void>;
1774
+ }
1431
1775
  /**
1432
1776
  * Unique strategy identifier.
1433
1777
  */
@@ -1551,13 +1895,13 @@ interface IWalkerSchema {
1551
1895
  */
1552
1896
  interface IWalkerCallbacks {
1553
1897
  /** Called when starting to test a specific strategy */
1554
- onStrategyStart: (strategyName: StrategyName, symbol: string) => void;
1898
+ onStrategyStart: (strategyName: StrategyName, symbol: string) => void | Promise<void>;
1555
1899
  /** Called when a strategy backtest completes */
1556
- onStrategyComplete: (strategyName: StrategyName, symbol: string, stats: BacktestStatisticsModel, metric: number | null) => void;
1900
+ onStrategyComplete: (strategyName: StrategyName, symbol: string, stats: BacktestStatisticsModel, metric: number | null) => void | Promise<void>;
1557
1901
  /** Called when a strategy backtest fails with an error */
1558
- onStrategyError: (strategyName: StrategyName, symbol: string, error: Error | unknown) => void;
1902
+ onStrategyError: (strategyName: StrategyName, symbol: string, error: Error | unknown) => void | Promise<void>;
1559
1903
  /** Called when all strategies have been tested */
1560
- onComplete: (results: IWalkerResults) => void;
1904
+ onComplete: (results: IWalkerResults) => void | Promise<void>;
1561
1905
  }
1562
1906
  /**
1563
1907
  * Result for a single strategy in the comparison.
@@ -1692,7 +2036,7 @@ interface ISizingCallbacks {
1692
2036
  * @param quantity - Calculated position size
1693
2037
  * @param params - Parameters used for calculation
1694
2038
  */
1695
- onCalculate: (quantity: number, params: ISizingCalculateParams) => void;
2039
+ onCalculate: (quantity: number, params: ISizingCalculateParams) => void | Promise<void>;
1696
2040
  }
1697
2041
  /**
1698
2042
  * Base sizing schema with common fields.
@@ -2043,7 +2387,7 @@ interface IOptimizerTemplate {
2043
2387
  * @param strategies - Array of strategy names to compare
2044
2388
  * @returns Generated addWalker() call
2045
2389
  */
2046
- getWalkerTemplate(walkerName: string, exchangeName: string, frameName: string, strategies: string[]): string | Promise<string>;
2390
+ getWalkerTemplate(walkerName: WalkerName, exchangeName: ExchangeName, frameName: FrameName, strategies: string[]): string | Promise<string>;
2047
2391
  /**
2048
2392
  * Generates Exchange configuration code.
2049
2393
  *
@@ -2051,7 +2395,7 @@ interface IOptimizerTemplate {
2051
2395
  * @param exchangeName - Unique exchange identifier
2052
2396
  * @returns Generated addExchange() call with CCXT integration
2053
2397
  */
2054
- getExchangeTemplate(symbol: string, exchangeName: string): string | Promise<string>;
2398
+ getExchangeTemplate(symbol: string, exchangeName: ExchangeName): string | Promise<string>;
2055
2399
  /**
2056
2400
  * Generates Frame (timeframe) configuration code.
2057
2401
  *
@@ -2062,7 +2406,7 @@ interface IOptimizerTemplate {
2062
2406
  * @param endDate - Frame end date
2063
2407
  * @returns Generated addFrame() call
2064
2408
  */
2065
- getFrameTemplate(symbol: string, frameName: string, interval: CandleInterval, startDate: Date, endDate: Date): string | Promise<string>;
2409
+ getFrameTemplate(symbol: string, frameName: FrameName, interval: CandleInterval, startDate: Date, endDate: Date): string | Promise<string>;
2066
2410
  /**
2067
2411
  * Generates Strategy configuration code with LLM integration.
2068
2412
  *
@@ -2071,7 +2415,7 @@ interface IOptimizerTemplate {
2071
2415
  * @param prompt - Strategy logic prompt from getPrompt()
2072
2416
  * @returns Generated addStrategy() call with getSignal() function
2073
2417
  */
2074
- getStrategyTemplate(strategyName: string, interval: string, prompt: string): string | Promise<string>;
2418
+ getStrategyTemplate(strategyName: StrategyName, interval: CandleInterval, prompt: string): string | Promise<string>;
2075
2419
  /**
2076
2420
  * Generates launcher code to run Walker and listen to events.
2077
2421
  *
@@ -2079,7 +2423,7 @@ interface IOptimizerTemplate {
2079
2423
  * @param walkerName - Walker name to launch
2080
2424
  * @returns Generated Walker.background() call with event listeners
2081
2425
  */
2082
- getLauncherTemplate(symbol: string, walkerName: string): string | Promise<string>;
2426
+ getLauncherTemplate(symbol: string, walkerName: WalkerName): string | Promise<string>;
2083
2427
  /**
2084
2428
  * Generates text() helper function for LLM text generation.
2085
2429
  *
@@ -2783,9 +3127,11 @@ declare function listOptimizers(): Promise<IOptimizerSchema[]>;
2783
3127
  */
2784
3128
  interface DoneContract {
2785
3129
  /** exchangeName - Name of the exchange used in execution */
2786
- exchangeName: string;
3130
+ exchangeName: ExchangeName;
2787
3131
  /** strategyName - Name of the strategy that completed */
2788
- strategyName: string;
3132
+ strategyName: StrategyName;
3133
+ /** frameName - Name of the frame (empty string for live mode) */
3134
+ frameName: FrameName;
2789
3135
  /** backtest - True if backtest mode, false if live mode */
2790
3136
  backtest: boolean;
2791
3137
  /** symbol - Trading symbol (e.g., "BTCUSDT") */
@@ -2810,9 +3156,9 @@ interface DoneContract {
2810
3156
  */
2811
3157
  interface ProgressBacktestContract {
2812
3158
  /** exchangeName - Name of the exchange used in execution */
2813
- exchangeName: string;
3159
+ exchangeName: ExchangeName;
2814
3160
  /** strategyName - Name of the strategy being executed */
2815
- strategyName: string;
3161
+ strategyName: StrategyName;
2816
3162
  /** symbol - Trading symbol (e.g., "BTCUSDT") */
2817
3163
  symbol: string;
2818
3164
  /** totalFrames - Total number of frames to process */
@@ -2841,11 +3187,11 @@ interface ProgressBacktestContract {
2841
3187
  */
2842
3188
  interface ProgressWalkerContract {
2843
3189
  /** walkerName - Name of the walker being executed */
2844
- walkerName: string;
3190
+ walkerName: WalkerName;
2845
3191
  /** exchangeName - Name of the exchange used in execution */
2846
- exchangeName: string;
3192
+ exchangeName: ExchangeName;
2847
3193
  /** frameName - Name of the frame being used */
2848
- frameName: string;
3194
+ frameName: FrameName;
2849
3195
  /** symbol - Trading symbol (e.g., "BTCUSDT") */
2850
3196
  symbol: string;
2851
3197
  /** totalStrategies - Total number of strategies to process */
@@ -2923,11 +3269,11 @@ interface PerformanceContract {
2923
3269
  /** Duration of the operation in milliseconds */
2924
3270
  duration: number;
2925
3271
  /** Strategy name associated with this metric */
2926
- strategyName: string;
3272
+ strategyName: StrategyName;
2927
3273
  /** Exchange name associated with this metric */
2928
- exchangeName: string;
3274
+ exchangeName: ExchangeName;
2929
3275
  /** Frame name associated with this metric (empty string for live mode) */
2930
- frameName: string;
3276
+ frameName: FrameName;
2931
3277
  /** Trading symbol associated with this metric */
2932
3278
  symbol: string;
2933
3279
  /** Whether this metric is from backtest mode (true) or live mode (false) */
@@ -2944,7 +3290,7 @@ interface WalkerContract {
2944
3290
  /** Exchange name */
2945
3291
  exchangeName: ExchangeName;
2946
3292
  /** Frame name */
2947
- frameName: string;
3293
+ frameName: FrameName;
2948
3294
  /** Symbol being tested */
2949
3295
  symbol: string;
2950
3296
  /** Strategy that just completed */
@@ -3006,17 +3352,17 @@ interface PartialProfitContract {
3006
3352
  * Strategy name that generated this signal.
3007
3353
  * Identifies which strategy execution this profit event belongs to.
3008
3354
  */
3009
- strategyName: string;
3355
+ strategyName: StrategyName;
3010
3356
  /**
3011
3357
  * Exchange name where this signal is being executed.
3012
3358
  * Identifies which exchange this profit event belongs to.
3013
3359
  */
3014
- exchangeName: string;
3360
+ exchangeName: ExchangeName;
3015
3361
  /**
3016
3362
  * Frame name where this signal is being executed.
3017
3363
  * Identifies which frame this profit event belongs to (empty string for live mode).
3018
3364
  */
3019
- frameName: string;
3365
+ frameName: FrameName;
3020
3366
  /**
3021
3367
  * Complete signal row data.
3022
3368
  * Contains all signal information: id, position, priceOpen, priceTakeProfit, priceStopLoss, etc.
@@ -3106,17 +3452,17 @@ interface PartialLossContract {
3106
3452
  * Strategy name that generated this signal.
3107
3453
  * Identifies which strategy execution this loss event belongs to.
3108
3454
  */
3109
- strategyName: string;
3455
+ strategyName: StrategyName;
3110
3456
  /**
3111
3457
  * Exchange name where this signal is being executed.
3112
3458
  * Identifies which exchange this loss event belongs to.
3113
3459
  */
3114
- exchangeName: string;
3460
+ exchangeName: ExchangeName;
3115
3461
  /**
3116
3462
  * Frame name where this signal is being executed.
3117
3463
  * Identifies which frame this loss event belongs to (empty string for live mode).
3118
3464
  */
3119
- frameName: string;
3465
+ frameName: FrameName;
3120
3466
  /**
3121
3467
  * Complete signal row data.
3122
3468
  * Contains all signal information: id, position, priceOpen, priceTakeProfit, priceStopLoss, etc.
@@ -3315,12 +3661,12 @@ interface PingContract {
3315
3661
  * Strategy name that is monitoring this scheduled signal.
3316
3662
  * Identifies which strategy execution this ping event belongs to.
3317
3663
  */
3318
- strategyName: string;
3664
+ strategyName: StrategyName;
3319
3665
  /**
3320
3666
  * Exchange name where this scheduled signal is being monitored.
3321
3667
  * Identifies which exchange this ping event belongs to.
3322
3668
  */
3323
- exchangeName: string;
3669
+ exchangeName: ExchangeName;
3324
3670
  /**
3325
3671
  * Complete scheduled signal row data.
3326
3672
  * Contains all signal information: id, position, priceOpen, priceTakeProfit, priceStopLoss, etc.
@@ -4917,7 +5263,7 @@ interface MetricStats {
4917
5263
  */
4918
5264
  interface PerformanceStatisticsModel {
4919
5265
  /** Strategy name */
4920
- strategyName: string;
5266
+ strategyName: StrategyName;
4921
5267
  /** Total number of performance events recorded */
4922
5268
  totalEvents: number;
4923
5269
  /** Total execution time across all metrics (ms) */
@@ -4985,7 +5331,7 @@ interface PartialEvent {
4985
5331
  /** Trading pair symbol */
4986
5332
  symbol: string;
4987
5333
  /** Strategy name */
4988
- strategyName: string;
5334
+ strategyName: StrategyName;
4989
5335
  /** Signal ID */
4990
5336
  signalId: string;
4991
5337
  /** Position type */
@@ -5034,11 +5380,11 @@ interface RiskEvent {
5034
5380
  /** Pending signal details */
5035
5381
  pendingSignal: ISignalDto;
5036
5382
  /** Strategy name */
5037
- strategyName: string;
5383
+ strategyName: StrategyName;
5038
5384
  /** Exchange name */
5039
- exchangeName: string;
5385
+ exchangeName: ExchangeName;
5040
5386
  /** Time frame name */
5041
- frameName: string;
5387
+ frameName: FrameName;
5042
5388
  /** Current market price */
5043
5389
  currentPrice: number;
5044
5390
  /** Number of active positions at rejection time */
@@ -5631,7 +5977,7 @@ declare class BacktestMarkdownService {
5631
5977
  * console.log(stats.sharpeRatio, stats.winRate);
5632
5978
  * ```
5633
5979
  */
5634
- getData: (symbol: string, strategyName: StrategyName, exchangeName: string, frameName: string, backtest: boolean) => Promise<BacktestStatisticsModel>;
5980
+ getData: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean) => Promise<BacktestStatisticsModel>;
5635
5981
  /**
5636
5982
  * Generates markdown report with all closed signals for a symbol-strategy pair.
5637
5983
  * Delegates to ReportStorage.generateReport().
@@ -5651,7 +5997,7 @@ declare class BacktestMarkdownService {
5651
5997
  * console.log(markdown);
5652
5998
  * ```
5653
5999
  */
5654
- getReport: (symbol: string, strategyName: StrategyName, exchangeName: string, frameName: string, backtest: boolean, columns?: Columns$6[]) => Promise<string>;
6000
+ getReport: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, columns?: Columns$6[]) => Promise<string>;
5655
6001
  /**
5656
6002
  * Saves symbol-strategy report to disk.
5657
6003
  * Creates directory if it doesn't exist.
@@ -5676,7 +6022,7 @@ declare class BacktestMarkdownService {
5676
6022
  * await service.dump("BTCUSDT", "my-strategy", "binance", "1h", true, "./custom/path");
5677
6023
  * ```
5678
6024
  */
5679
- dump: (symbol: string, strategyName: StrategyName, exchangeName: string, frameName: string, backtest: boolean, path?: string, columns?: Columns$6[]) => Promise<void>;
6025
+ dump: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, path?: string, columns?: Columns$6[]) => Promise<void>;
5680
6026
  /**
5681
6027
  * Clears accumulated signal data from storage.
5682
6028
  * If payload is provided, clears only that specific symbol-strategy-exchange-frame-backtest combination's data.
@@ -5698,8 +6044,8 @@ declare class BacktestMarkdownService {
5698
6044
  clear: (payload?: {
5699
6045
  symbol: string;
5700
6046
  strategyName: StrategyName;
5701
- exchangeName: string;
5702
- frameName: string;
6047
+ exchangeName: ExchangeName;
6048
+ frameName: FrameName;
5703
6049
  backtest: boolean;
5704
6050
  }) => Promise<void>;
5705
6051
  /**
@@ -5714,6 +6060,11 @@ declare class BacktestMarkdownService {
5714
6060
  * ```
5715
6061
  */
5716
6062
  protected init: (() => Promise<void>) & functools_kit.ISingleshotClearable;
6063
+ /**
6064
+ * Function to unsubscribe from backtest signal events.
6065
+ * Assigned during init().
6066
+ */
6067
+ unsubscribe: Function;
5717
6068
  }
5718
6069
 
5719
6070
  /**
@@ -5749,9 +6100,9 @@ declare class BacktestUtils {
5749
6100
  * @returns Async generator yielding closed signals with PNL
5750
6101
  */
5751
6102
  run: (symbol: string, context: {
5752
- strategyName: string;
5753
- exchangeName: string;
5754
- frameName: string;
6103
+ strategyName: StrategyName;
6104
+ exchangeName: ExchangeName;
6105
+ frameName: FrameName;
5755
6106
  }) => AsyncGenerator<IStrategyBacktestResult, void, unknown>;
5756
6107
  /**
5757
6108
  * Runs backtest in background without yielding results.
@@ -5775,9 +6126,9 @@ declare class BacktestUtils {
5775
6126
  * ```
5776
6127
  */
5777
6128
  background: (symbol: string, context: {
5778
- strategyName: string;
5779
- exchangeName: string;
5780
- frameName: string;
6129
+ strategyName: StrategyName;
6130
+ exchangeName: ExchangeName;
6131
+ frameName: FrameName;
5781
6132
  }) => () => void;
5782
6133
  /**
5783
6134
  * Retrieves the currently active pending signal for the strategy.
@@ -5796,9 +6147,9 @@ declare class BacktestUtils {
5796
6147
  * ```
5797
6148
  */
5798
6149
  getPendingSignal: (symbol: string, context: {
5799
- strategyName: string;
5800
- exchangeName: string;
5801
- frameName: string;
6150
+ strategyName: StrategyName;
6151
+ exchangeName: ExchangeName;
6152
+ frameName: FrameName;
5802
6153
  }) => Promise<ISignalRow>;
5803
6154
  /**
5804
6155
  * Retrieves the currently active scheduled signal for the strategy.
@@ -5817,9 +6168,9 @@ declare class BacktestUtils {
5817
6168
  * ```
5818
6169
  */
5819
6170
  getScheduledSignal: (symbol: string, context: {
5820
- strategyName: string;
5821
- exchangeName: string;
5822
- frameName: string;
6171
+ strategyName: StrategyName;
6172
+ exchangeName: ExchangeName;
6173
+ frameName: FrameName;
5823
6174
  }) => Promise<IScheduledSignalRow>;
5824
6175
  /**
5825
6176
  * Stops the strategy from generating new signals.
@@ -5844,9 +6195,9 @@ declare class BacktestUtils {
5844
6195
  * ```
5845
6196
  */
5846
6197
  stop: (symbol: string, context: {
5847
- strategyName: string;
5848
- exchangeName: string;
5849
- frameName: string;
6198
+ strategyName: StrategyName;
6199
+ exchangeName: ExchangeName;
6200
+ frameName: FrameName;
5850
6201
  }) => Promise<void>;
5851
6202
  /**
5852
6203
  * Cancels the scheduled signal without stopping the strategy.
@@ -5872,32 +6223,121 @@ declare class BacktestUtils {
5872
6223
  * ```
5873
6224
  */
5874
6225
  cancel: (symbol: string, context: {
5875
- strategyName: string;
5876
- exchangeName: string;
5877
- frameName: string;
6226
+ strategyName: StrategyName;
6227
+ exchangeName: ExchangeName;
6228
+ frameName: FrameName;
5878
6229
  }, cancelId?: string) => Promise<void>;
5879
6230
  /**
5880
- * Gets statistical data from all closed signals for a symbol-strategy pair.
6231
+ * Executes partial close at profit level (moving toward TP).
6232
+ *
6233
+ * Closes a percentage of the active pending position at profit.
6234
+ * Price must be moving toward take profit (in profit direction).
5881
6235
  *
5882
6236
  * @param symbol - Trading pair symbol
5883
- * @param strategyName - Strategy name to get data for
5884
- * @param context - Execution context with exchangeName and frameName
5885
- * @returns Promise resolving to statistical data object
6237
+ * @param percentToClose - Percentage of position to close (0-100, absolute value)
6238
+ * @param currentPrice - Current market price for this partial close
6239
+ * @param context - Execution context with strategyName, exchangeName, and frameName
6240
+ * @returns Promise that resolves when state is updated
6241
+ *
6242
+ * @throws Error if currentPrice is not in profit direction:
6243
+ * - LONG: currentPrice must be > priceOpen
6244
+ * - SHORT: currentPrice must be < priceOpen
5886
6245
  *
5887
6246
  * @example
5888
6247
  * ```typescript
5889
- * const stats = await Backtest.getData("BTCUSDT", "my-strategy", {
6248
+ * // Close 30% of LONG position at profit
6249
+ * await Backtest.partialProfit("BTCUSDT", 30, 45000, {
5890
6250
  * exchangeName: "binance",
5891
6251
  * frameName: "frame1",
5892
6252
  * strategyName: "my-strategy"
5893
6253
  * });
5894
- * console.log(stats.sharpeRatio, stats.winRate);
5895
6254
  * ```
5896
6255
  */
5897
- getData: (symbol: string, context: {
5898
- strategyName: string;
5899
- exchangeName: string;
5900
- frameName: string;
6256
+ partialProfit: (symbol: string, percentToClose: number, currentPrice: number, context: {
6257
+ strategyName: StrategyName;
6258
+ exchangeName: ExchangeName;
6259
+ frameName: FrameName;
6260
+ }) => Promise<void>;
6261
+ /**
6262
+ * Executes partial close at loss level (moving toward SL).
6263
+ *
6264
+ * Closes a percentage of the active pending position at loss.
6265
+ * Price must be moving toward stop loss (in loss direction).
6266
+ *
6267
+ * @param symbol - Trading pair symbol
6268
+ * @param percentToClose - Percentage of position to close (0-100, absolute value)
6269
+ * @param currentPrice - Current market price for this partial close
6270
+ * @param context - Execution context with strategyName, exchangeName, and frameName
6271
+ * @returns Promise that resolves when state is updated
6272
+ *
6273
+ * @throws Error if currentPrice is not in loss direction:
6274
+ * - LONG: currentPrice must be < priceOpen
6275
+ * - SHORT: currentPrice must be > priceOpen
6276
+ *
6277
+ * @example
6278
+ * ```typescript
6279
+ * // Close 40% of LONG position at loss
6280
+ * await Backtest.partialLoss("BTCUSDT", 40, 38000, {
6281
+ * exchangeName: "binance",
6282
+ * frameName: "frame1",
6283
+ * strategyName: "my-strategy"
6284
+ * });
6285
+ * ```
6286
+ */
6287
+ partialLoss: (symbol: string, percentToClose: number, currentPrice: number, context: {
6288
+ strategyName: StrategyName;
6289
+ exchangeName: ExchangeName;
6290
+ frameName: FrameName;
6291
+ }) => Promise<void>;
6292
+ /**
6293
+ * Adjusts the trailing stop-loss distance for an active pending signal.
6294
+ *
6295
+ * Updates the stop-loss distance by a percentage adjustment relative to the original SL distance.
6296
+ * Positive percentShift tightens the SL (reduces distance), negative percentShift loosens it.
6297
+ *
6298
+ * @param symbol - Trading pair symbol
6299
+ * @param percentShift - Percentage adjustment to SL distance (-100 to 100)
6300
+ * @param context - Execution context with strategyName, exchangeName, and frameName
6301
+ * @returns Promise that resolves when trailing SL is updated
6302
+ *
6303
+ * @example
6304
+ * ```typescript
6305
+ * // LONG: entry=100, originalSL=90, distance=10
6306
+ * // Tighten stop by 50%: newSL = 100 - 10*(1-0.5) = 95
6307
+ * await Backtest.trailingStop("BTCUSDT", -50, {
6308
+ * exchangeName: "binance",
6309
+ * frameName: "frame1",
6310
+ * strategyName: "my-strategy"
6311
+ * });
6312
+ * ```
6313
+ */
6314
+ trailingStop: (symbol: string, percentShift: number, context: {
6315
+ strategyName: StrategyName;
6316
+ exchangeName: ExchangeName;
6317
+ frameName: FrameName;
6318
+ }) => Promise<void>;
6319
+ /**
6320
+ * Gets statistical data from all closed signals for a symbol-strategy pair.
6321
+ *
6322
+ * @param symbol - Trading pair symbol
6323
+ * @param strategyName - Strategy name to get data for
6324
+ * @param context - Execution context with exchangeName and frameName
6325
+ * @returns Promise resolving to statistical data object
6326
+ *
6327
+ * @example
6328
+ * ```typescript
6329
+ * const stats = await Backtest.getData("BTCUSDT", "my-strategy", {
6330
+ * exchangeName: "binance",
6331
+ * frameName: "frame1",
6332
+ * strategyName: "my-strategy"
6333
+ * });
6334
+ * console.log(stats.sharpeRatio, stats.winRate);
6335
+ * ```
6336
+ */
6337
+ getData: (symbol: string, context: {
6338
+ strategyName: StrategyName;
6339
+ exchangeName: ExchangeName;
6340
+ frameName: FrameName;
5901
6341
  }) => Promise<BacktestStatisticsModel>;
5902
6342
  /**
5903
6343
  * Generates markdown report with all closed signals for a symbol-strategy pair.
@@ -5919,9 +6359,9 @@ declare class BacktestUtils {
5919
6359
  * ```
5920
6360
  */
5921
6361
  getReport: (symbol: string, context: {
5922
- strategyName: string;
5923
- exchangeName: string;
5924
- frameName: string;
6362
+ strategyName: StrategyName;
6363
+ exchangeName: ExchangeName;
6364
+ frameName: FrameName;
5925
6365
  }, columns?: Columns$6[]) => Promise<string>;
5926
6366
  /**
5927
6367
  * Saves strategy report to disk.
@@ -5950,9 +6390,9 @@ declare class BacktestUtils {
5950
6390
  * ```
5951
6391
  */
5952
6392
  dump: (symbol: string, context: {
5953
- strategyName: string;
5954
- exchangeName: string;
5955
- frameName: string;
6393
+ strategyName: StrategyName;
6394
+ exchangeName: ExchangeName;
6395
+ frameName: FrameName;
5956
6396
  }, path?: string, columns?: Columns$6[]) => Promise<void>;
5957
6397
  /**
5958
6398
  * Lists all active backtest instances with their current status.
@@ -6106,7 +6546,7 @@ declare class LiveMarkdownService {
6106
6546
  * console.log(stats.sharpeRatio, stats.winRate);
6107
6547
  * ```
6108
6548
  */
6109
- getData: (symbol: string, strategyName: StrategyName, exchangeName: string, frameName: string, backtest: boolean) => Promise<LiveStatisticsModel>;
6549
+ getData: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean) => Promise<LiveStatisticsModel>;
6110
6550
  /**
6111
6551
  * Generates markdown report with all events for a symbol-strategy pair.
6112
6552
  * Delegates to ReportStorage.getReport().
@@ -6126,7 +6566,7 @@ declare class LiveMarkdownService {
6126
6566
  * console.log(markdown);
6127
6567
  * ```
6128
6568
  */
6129
- getReport: (symbol: string, strategyName: StrategyName, exchangeName: string, frameName: string, backtest: boolean, columns?: Columns$5[]) => Promise<string>;
6569
+ getReport: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, columns?: Columns$5[]) => Promise<string>;
6130
6570
  /**
6131
6571
  * Saves symbol-strategy report to disk.
6132
6572
  * Creates directory if it doesn't exist.
@@ -6151,7 +6591,7 @@ declare class LiveMarkdownService {
6151
6591
  * await service.dump("BTCUSDT", "my-strategy", "binance", "1h", false, "./custom/path");
6152
6592
  * ```
6153
6593
  */
6154
- dump: (symbol: string, strategyName: StrategyName, exchangeName: string, frameName: string, backtest: boolean, path?: string, columns?: Columns$5[]) => Promise<void>;
6594
+ dump: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, path?: string, columns?: Columns$5[]) => Promise<void>;
6155
6595
  /**
6156
6596
  * Clears accumulated event data from storage.
6157
6597
  * If payload is provided, clears only that specific symbol-strategy-exchange-frame-backtest combination's data.
@@ -6173,8 +6613,8 @@ declare class LiveMarkdownService {
6173
6613
  clear: (payload?: {
6174
6614
  symbol: string;
6175
6615
  strategyName: StrategyName;
6176
- exchangeName: string;
6177
- frameName: string;
6616
+ exchangeName: ExchangeName;
6617
+ frameName: FrameName;
6178
6618
  backtest: boolean;
6179
6619
  }) => Promise<void>;
6180
6620
  /**
@@ -6189,6 +6629,11 @@ declare class LiveMarkdownService {
6189
6629
  * ```
6190
6630
  */
6191
6631
  protected init: (() => Promise<void>) & functools_kit.ISingleshotClearable;
6632
+ /**
6633
+ * Function to unsubscribe from backtest signal events.
6634
+ * Assigned during init().
6635
+ */
6636
+ unsubscribe: Function;
6192
6637
  }
6193
6638
 
6194
6639
  /**
@@ -6237,8 +6682,8 @@ declare class LiveUtils {
6237
6682
  * @returns Infinite async generator yielding opened and closed signals
6238
6683
  */
6239
6684
  run: (symbol: string, context: {
6240
- strategyName: string;
6241
- exchangeName: string;
6685
+ strategyName: StrategyName;
6686
+ exchangeName: ExchangeName;
6242
6687
  }) => AsyncGenerator<IStrategyTickResultOpened | IStrategyTickResultClosed, void, unknown>;
6243
6688
  /**
6244
6689
  * Runs live trading in background without yielding results.
@@ -6262,8 +6707,8 @@ declare class LiveUtils {
6262
6707
  * ```
6263
6708
  */
6264
6709
  background: (symbol: string, context: {
6265
- strategyName: string;
6266
- exchangeName: string;
6710
+ strategyName: StrategyName;
6711
+ exchangeName: ExchangeName;
6267
6712
  }) => () => void;
6268
6713
  /**
6269
6714
  * Retrieves the currently active pending signal for the strategy.
@@ -6282,8 +6727,8 @@ declare class LiveUtils {
6282
6727
  * ```
6283
6728
  */
6284
6729
  getPendingSignal: (symbol: string, context: {
6285
- strategyName: string;
6286
- exchangeName: string;
6730
+ strategyName: StrategyName;
6731
+ exchangeName: ExchangeName;
6287
6732
  }) => Promise<ISignalRow>;
6288
6733
  /**
6289
6734
  * Retrieves the currently active scheduled signal for the strategy.
@@ -6302,8 +6747,8 @@ declare class LiveUtils {
6302
6747
  * ```
6303
6748
  */
6304
6749
  getScheduledSignal: (symbol: string, context: {
6305
- strategyName: string;
6306
- exchangeName: string;
6750
+ strategyName: StrategyName;
6751
+ exchangeName: ExchangeName;
6307
6752
  }) => Promise<IScheduledSignalRow>;
6308
6753
  /**
6309
6754
  * Stops the strategy from generating new signals.
@@ -6323,8 +6768,8 @@ declare class LiveUtils {
6323
6768
  * ```
6324
6769
  */
6325
6770
  stop: (symbol: string, context: {
6326
- strategyName: string;
6327
- exchangeName: string;
6771
+ strategyName: StrategyName;
6772
+ exchangeName: ExchangeName;
6328
6773
  }) => Promise<void>;
6329
6774
  /**
6330
6775
  * Cancels the scheduled signal without stopping the strategy.
@@ -6350,9 +6795,92 @@ declare class LiveUtils {
6350
6795
  * ```
6351
6796
  */
6352
6797
  cancel: (symbol: string, context: {
6353
- strategyName: string;
6354
- exchangeName: string;
6798
+ strategyName: StrategyName;
6799
+ exchangeName: ExchangeName;
6355
6800
  }, cancelId?: string) => Promise<void>;
6801
+ /**
6802
+ * Executes partial close at profit level (moving toward TP).
6803
+ *
6804
+ * Closes a percentage of the active pending position at profit.
6805
+ * Price must be moving toward take profit (in profit direction).
6806
+ *
6807
+ * @param symbol - Trading pair symbol
6808
+ * @param percentToClose - Percentage of position to close (0-100, absolute value)
6809
+ * @param currentPrice - Current market price for this partial close
6810
+ * @param context - Execution context with strategyName and exchangeName
6811
+ * @returns Promise that resolves when state is updated
6812
+ *
6813
+ * @throws Error if currentPrice is not in profit direction:
6814
+ * - LONG: currentPrice must be > priceOpen
6815
+ * - SHORT: currentPrice must be < priceOpen
6816
+ *
6817
+ * @example
6818
+ * ```typescript
6819
+ * // Close 30% of LONG position at profit
6820
+ * await Live.partialProfit("BTCUSDT", 30, 45000, {
6821
+ * exchangeName: "binance",
6822
+ * strategyName: "my-strategy"
6823
+ * });
6824
+ * ```
6825
+ */
6826
+ partialProfit: (symbol: string, percentToClose: number, currentPrice: number, context: {
6827
+ strategyName: StrategyName;
6828
+ exchangeName: ExchangeName;
6829
+ }) => Promise<void>;
6830
+ /**
6831
+ * Executes partial close at loss level (moving toward SL).
6832
+ *
6833
+ * Closes a percentage of the active pending position at loss.
6834
+ * Price must be moving toward stop loss (in loss direction).
6835
+ *
6836
+ * @param symbol - Trading pair symbol
6837
+ * @param percentToClose - Percentage of position to close (0-100, absolute value)
6838
+ * @param currentPrice - Current market price for this partial close
6839
+ * @param context - Execution context with strategyName and exchangeName
6840
+ * @returns Promise that resolves when state is updated
6841
+ *
6842
+ * @throws Error if currentPrice is not in loss direction:
6843
+ * - LONG: currentPrice must be < priceOpen
6844
+ * - SHORT: currentPrice must be > priceOpen
6845
+ *
6846
+ * @example
6847
+ * ```typescript
6848
+ * // Close 40% of LONG position at loss
6849
+ * await Live.partialLoss("BTCUSDT", 40, 38000, {
6850
+ * exchangeName: "binance",
6851
+ * strategyName: "my-strategy"
6852
+ * });
6853
+ * ```
6854
+ */
6855
+ partialLoss: (symbol: string, percentToClose: number, currentPrice: number, context: {
6856
+ strategyName: StrategyName;
6857
+ exchangeName: ExchangeName;
6858
+ }) => Promise<void>;
6859
+ /**
6860
+ * Adjusts the trailing stop-loss distance for an active pending signal.
6861
+ *
6862
+ * Updates the stop-loss distance by a percentage adjustment relative to the original SL distance.
6863
+ * Positive percentShift tightens the SL (reduces distance), negative percentShift loosens it.
6864
+ *
6865
+ * @param symbol - Trading pair symbol
6866
+ * @param percentShift - Percentage adjustment to SL distance (-100 to 100)
6867
+ * @param context - Execution context with strategyName and exchangeName
6868
+ * @returns Promise that resolves when trailing SL is updated
6869
+ *
6870
+ * @example
6871
+ * ```typescript
6872
+ * // LONG: entry=100, originalSL=90, distance=10
6873
+ * // Tighten stop by 50%: newSL = 100 - 10*(1-0.5) = 95
6874
+ * await Live.trailingStop("BTCUSDT", -50, {
6875
+ * exchangeName: "binance",
6876
+ * strategyName: "my-strategy"
6877
+ * });
6878
+ * ```
6879
+ */
6880
+ trailingStop: (symbol: string, percentShift: number, context: {
6881
+ strategyName: StrategyName;
6882
+ exchangeName: ExchangeName;
6883
+ }) => Promise<void>;
6356
6884
  /**
6357
6885
  * Gets statistical data from all live trading events for a symbol-strategy pair.
6358
6886
  *
@@ -6372,8 +6900,8 @@ declare class LiveUtils {
6372
6900
  * ```
6373
6901
  */
6374
6902
  getData: (symbol: string, context: {
6375
- strategyName: string;
6376
- exchangeName: string;
6903
+ strategyName: StrategyName;
6904
+ exchangeName: ExchangeName;
6377
6905
  }) => Promise<LiveStatisticsModel>;
6378
6906
  /**
6379
6907
  * Generates markdown report with all events for a symbol-strategy pair.
@@ -6395,8 +6923,8 @@ declare class LiveUtils {
6395
6923
  * ```
6396
6924
  */
6397
6925
  getReport: (symbol: string, context: {
6398
- strategyName: string;
6399
- exchangeName: string;
6926
+ strategyName: StrategyName;
6927
+ exchangeName: ExchangeName;
6400
6928
  }, columns?: Columns$5[]) => Promise<string>;
6401
6929
  /**
6402
6930
  * Saves strategy report to disk.
@@ -6425,8 +6953,8 @@ declare class LiveUtils {
6425
6953
  * ```
6426
6954
  */
6427
6955
  dump: (symbol: string, context: {
6428
- strategyName: string;
6429
- exchangeName: string;
6956
+ strategyName: StrategyName;
6957
+ exchangeName: ExchangeName;
6430
6958
  }, path?: string, columns?: Columns$5[]) => Promise<void>;
6431
6959
  /**
6432
6960
  * Lists all active live trading instances with their current status.
@@ -6560,7 +7088,7 @@ declare class ScheduleMarkdownService {
6560
7088
  * console.log(stats.cancellationRate, stats.avgWaitTime);
6561
7089
  * ```
6562
7090
  */
6563
- getData: (symbol: string, strategyName: StrategyName, exchangeName: string, frameName: string, backtest: boolean) => Promise<ScheduleStatisticsModel>;
7091
+ getData: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean) => Promise<ScheduleStatisticsModel>;
6564
7092
  /**
6565
7093
  * Generates markdown report with all scheduled events for a symbol-strategy pair.
6566
7094
  * Delegates to ReportStorage.getReport().
@@ -6580,7 +7108,7 @@ declare class ScheduleMarkdownService {
6580
7108
  * console.log(markdown);
6581
7109
  * ```
6582
7110
  */
6583
- getReport: (symbol: string, strategyName: StrategyName, exchangeName: string, frameName: string, backtest: boolean, columns?: Columns$4[]) => Promise<string>;
7111
+ getReport: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, columns?: Columns$4[]) => Promise<string>;
6584
7112
  /**
6585
7113
  * Saves symbol-strategy report to disk.
6586
7114
  * Creates directory if it doesn't exist.
@@ -6605,7 +7133,7 @@ declare class ScheduleMarkdownService {
6605
7133
  * await service.dump("BTCUSDT", "my-strategy", "binance", "1h", false, "./custom/path");
6606
7134
  * ```
6607
7135
  */
6608
- dump: (symbol: string, strategyName: StrategyName, exchangeName: string, frameName: string, backtest: boolean, path?: string, columns?: Columns$4[]) => Promise<void>;
7136
+ dump: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, path?: string, columns?: Columns$4[]) => Promise<void>;
6609
7137
  /**
6610
7138
  * Clears accumulated event data from storage.
6611
7139
  * If payload is provided, clears only that specific symbol-strategy-exchange-frame-backtest combination's data.
@@ -6627,8 +7155,8 @@ declare class ScheduleMarkdownService {
6627
7155
  clear: (payload?: {
6628
7156
  symbol: string;
6629
7157
  strategyName: StrategyName;
6630
- exchangeName: string;
6631
- frameName: string;
7158
+ exchangeName: ExchangeName;
7159
+ frameName: FrameName;
6632
7160
  backtest: boolean;
6633
7161
  }) => Promise<void>;
6634
7162
  /**
@@ -6643,6 +7171,11 @@ declare class ScheduleMarkdownService {
6643
7171
  * ```
6644
7172
  */
6645
7173
  protected init: (() => Promise<void>) & functools_kit.ISingleshotClearable;
7174
+ /**
7175
+ * Function to unsubscribe from partial profit/loss events.
7176
+ * Assigned during init().
7177
+ */
7178
+ unsubscribe: Function;
6646
7179
  }
6647
7180
 
6648
7181
  /**
@@ -6685,9 +7218,9 @@ declare class ScheduleUtils {
6685
7218
  * ```
6686
7219
  */
6687
7220
  getData: (symbol: string, context: {
6688
- strategyName: string;
6689
- exchangeName: string;
6690
- frameName: string;
7221
+ strategyName: StrategyName;
7222
+ exchangeName: ExchangeName;
7223
+ frameName: FrameName;
6691
7224
  }, backtest?: boolean) => Promise<ScheduleStatisticsModel>;
6692
7225
  /**
6693
7226
  * Generates markdown report with all scheduled events for a symbol-strategy pair.
@@ -6704,9 +7237,9 @@ declare class ScheduleUtils {
6704
7237
  * ```
6705
7238
  */
6706
7239
  getReport: (symbol: string, context: {
6707
- strategyName: string;
6708
- exchangeName: string;
6709
- frameName: string;
7240
+ strategyName: StrategyName;
7241
+ exchangeName: ExchangeName;
7242
+ frameName: FrameName;
6710
7243
  }, backtest?: boolean, columns?: Columns$4[]) => Promise<string>;
6711
7244
  /**
6712
7245
  * Saves strategy report to disk.
@@ -6726,9 +7259,9 @@ declare class ScheduleUtils {
6726
7259
  * ```
6727
7260
  */
6728
7261
  dump: (symbol: string, context: {
6729
- strategyName: string;
6730
- exchangeName: string;
6731
- frameName: string;
7262
+ strategyName: StrategyName;
7263
+ exchangeName: ExchangeName;
7264
+ frameName: FrameName;
6732
7265
  }, backtest?: boolean, path?: string, columns?: Columns$4[]) => Promise<void>;
6733
7266
  }
6734
7267
  /**
@@ -6836,7 +7369,7 @@ declare class PerformanceMarkdownService {
6836
7369
  * .sort((a, b) => b.avgDuration - a.avgDuration)[0]);
6837
7370
  * ```
6838
7371
  */
6839
- getData: (symbol: string, strategyName: string, exchangeName: string, frameName: string, backtest: boolean) => Promise<PerformanceStatisticsModel>;
7372
+ getData: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean) => Promise<PerformanceStatisticsModel>;
6840
7373
  /**
6841
7374
  * Generates markdown report with performance analysis.
6842
7375
  *
@@ -6854,7 +7387,7 @@ declare class PerformanceMarkdownService {
6854
7387
  * console.log(markdown);
6855
7388
  * ```
6856
7389
  */
6857
- getReport: (symbol: string, strategyName: string, exchangeName: string, frameName: string, backtest: boolean, columns?: Columns$3[]) => Promise<string>;
7390
+ getReport: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, columns?: Columns$3[]) => Promise<string>;
6858
7391
  /**
6859
7392
  * Saves performance report to disk.
6860
7393
  *
@@ -6875,7 +7408,7 @@ declare class PerformanceMarkdownService {
6875
7408
  * await performanceService.dump("BTCUSDT", "my-strategy", "binance", "1h", false, "./custom/path");
6876
7409
  * ```
6877
7410
  */
6878
- dump: (symbol: string, strategyName: string, exchangeName: string, frameName: string, backtest: boolean, path?: string, columns?: Columns$3[]) => Promise<void>;
7411
+ dump: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, path?: string, columns?: Columns$3[]) => Promise<void>;
6879
7412
  /**
6880
7413
  * Clears accumulated performance data from storage.
6881
7414
  *
@@ -6883,9 +7416,9 @@ declare class PerformanceMarkdownService {
6883
7416
  */
6884
7417
  clear: (payload?: {
6885
7418
  symbol: string;
6886
- strategyName: string;
6887
- exchangeName: string;
6888
- frameName: string;
7419
+ strategyName: StrategyName;
7420
+ exchangeName: ExchangeName;
7421
+ frameName: FrameName;
6889
7422
  backtest: boolean;
6890
7423
  }) => Promise<void>;
6891
7424
  /**
@@ -6893,6 +7426,11 @@ declare class PerformanceMarkdownService {
6893
7426
  * Uses singleshot to ensure initialization happens only once.
6894
7427
  */
6895
7428
  protected init: (() => Promise<void>) & functools_kit.ISingleshotClearable;
7429
+ /**
7430
+ * Function to unsubscribe from partial profit/loss events.
7431
+ * Assigned during init().
7432
+ */
7433
+ unsubscribe: Function;
6896
7434
  }
6897
7435
 
6898
7436
  /**
@@ -6957,9 +7495,9 @@ declare class Performance {
6957
7495
  * ```
6958
7496
  */
6959
7497
  static getData(symbol: string, context: {
6960
- strategyName: string;
6961
- exchangeName: string;
6962
- frameName: string;
7498
+ strategyName: StrategyName;
7499
+ exchangeName: ExchangeName;
7500
+ frameName: FrameName;
6963
7501
  }, backtest?: boolean): Promise<PerformanceStatisticsModel>;
6964
7502
  /**
6965
7503
  * Generates markdown report with performance analysis.
@@ -6985,9 +7523,9 @@ declare class Performance {
6985
7523
  * ```
6986
7524
  */
6987
7525
  static getReport(symbol: string, context: {
6988
- strategyName: string;
6989
- exchangeName: string;
6990
- frameName: string;
7526
+ strategyName: StrategyName;
7527
+ exchangeName: ExchangeName;
7528
+ frameName: FrameName;
6991
7529
  }, backtest?: boolean, columns?: Columns$3[]): Promise<string>;
6992
7530
  /**
6993
7531
  * Saves performance report to disk.
@@ -7010,9 +7548,9 @@ declare class Performance {
7010
7548
  * ```
7011
7549
  */
7012
7550
  static dump(symbol: string, context: {
7013
- strategyName: string;
7014
- exchangeName: string;
7015
- frameName: string;
7551
+ strategyName: StrategyName;
7552
+ exchangeName: ExchangeName;
7553
+ frameName: FrameName;
7016
7554
  }, backtest?: boolean, path?: string, columns?: Columns$3[]): Promise<void>;
7017
7555
  }
7018
7556
 
@@ -7135,8 +7673,8 @@ declare class WalkerMarkdownService {
7135
7673
  * ```
7136
7674
  */
7137
7675
  getData: (walkerName: WalkerName, symbol: string, metric: WalkerMetric, context: {
7138
- exchangeName: string;
7139
- frameName: string;
7676
+ exchangeName: ExchangeName;
7677
+ frameName: FrameName;
7140
7678
  }) => Promise<WalkerCompleteContract>;
7141
7679
  /**
7142
7680
  * Generates markdown report with all strategy results for a walker.
@@ -7158,8 +7696,8 @@ declare class WalkerMarkdownService {
7158
7696
  * ```
7159
7697
  */
7160
7698
  getReport: (walkerName: WalkerName, symbol: string, metric: WalkerMetric, context: {
7161
- exchangeName: string;
7162
- frameName: string;
7699
+ exchangeName: ExchangeName;
7700
+ frameName: FrameName;
7163
7701
  }, strategyColumns?: StrategyColumn[], pnlColumns?: PnlColumn[]) => Promise<string>;
7164
7702
  /**
7165
7703
  * Saves walker report to disk.
@@ -7186,8 +7724,8 @@ declare class WalkerMarkdownService {
7186
7724
  * ```
7187
7725
  */
7188
7726
  dump: (walkerName: WalkerName, symbol: string, metric: WalkerMetric, context: {
7189
- exchangeName: string;
7190
- frameName: string;
7727
+ exchangeName: ExchangeName;
7728
+ frameName: FrameName;
7191
7729
  }, path?: string, strategyColumns?: StrategyColumn[], pnlColumns?: PnlColumn[]) => Promise<void>;
7192
7730
  /**
7193
7731
  * Clears accumulated result data from storage.
@@ -7220,6 +7758,11 @@ declare class WalkerMarkdownService {
7220
7758
  * ```
7221
7759
  */
7222
7760
  protected init: (() => Promise<void>) & functools_kit.ISingleshotClearable;
7761
+ /**
7762
+ * Function to unsubscribe from partial profit/loss events.
7763
+ * Assigned during init().
7764
+ */
7765
+ unsubscribe: Function;
7223
7766
  }
7224
7767
 
7225
7768
  /**
@@ -7255,7 +7798,7 @@ declare class WalkerUtils {
7255
7798
  * @returns Async generator yielding progress updates after each strategy
7256
7799
  */
7257
7800
  run: (symbol: string, context: {
7258
- walkerName: string;
7801
+ walkerName: WalkerName;
7259
7802
  }) => AsyncGenerator<WalkerContract, any, any>;
7260
7803
  /**
7261
7804
  * Runs walker comparison in background without yielding results.
@@ -7277,7 +7820,7 @@ declare class WalkerUtils {
7277
7820
  * ```
7278
7821
  */
7279
7822
  background: (symbol: string, context: {
7280
- walkerName: string;
7823
+ walkerName: WalkerName;
7281
7824
  }) => () => void;
7282
7825
  /**
7283
7826
  * Stops all strategies in the walker from generating new signals.
@@ -7293,51 +7836,57 @@ declare class WalkerUtils {
7293
7836
  * Stop signal is filtered by walkerName to prevent interference.
7294
7837
  *
7295
7838
  * @param symbol - Trading pair symbol
7296
- * @param walkerName - Walker name to stop
7839
+ * @param context - Execution context with walker name
7297
7840
  * @returns Promise that resolves when all stop flags are set
7298
7841
  *
7299
7842
  * @example
7300
7843
  * ```typescript
7301
7844
  * // Stop walker and all its strategies
7302
- * await Walker.stop("BTCUSDT", "my-walker");
7845
+ * await Walker.stop("BTCUSDT", { walkerName: "my-walker" });
7303
7846
  * ```
7304
7847
  */
7305
- stop: (symbol: string, walkerName: WalkerName) => Promise<void>;
7848
+ stop: (symbol: string, context: {
7849
+ walkerName: WalkerName;
7850
+ }) => Promise<void>;
7306
7851
  /**
7307
7852
  * Gets walker results data from all strategy comparisons.
7308
7853
  *
7309
7854
  * @param symbol - Trading symbol
7310
- * @param walkerName - Walker name to get data for
7855
+ * @param context - Execution context with walker name
7311
7856
  * @returns Promise resolving to walker results data object
7312
7857
  *
7313
7858
  * @example
7314
7859
  * ```typescript
7315
- * const results = await Walker.getData("BTCUSDT", "my-walker");
7860
+ * const results = await Walker.getData("BTCUSDT", { walkerName: "my-walker" });
7316
7861
  * console.log(results.bestStrategy, results.bestMetric);
7317
7862
  * ```
7318
7863
  */
7319
- getData: (symbol: string, walkerName: WalkerName) => Promise<WalkerCompleteContract>;
7864
+ getData: (symbol: string, context: {
7865
+ walkerName: WalkerName;
7866
+ }) => Promise<WalkerCompleteContract>;
7320
7867
  /**
7321
7868
  * Generates markdown report with all strategy comparisons for a walker.
7322
7869
  *
7323
7870
  * @param symbol - Trading symbol
7324
- * @param walkerName - Walker name to generate report for
7871
+ * @param context - Execution context with walker name
7325
7872
  * @param strategyColumns - Optional strategy columns configuration
7326
7873
  * @param pnlColumns - Optional PNL columns configuration
7327
7874
  * @returns Promise resolving to markdown formatted report string
7328
7875
  *
7329
7876
  * @example
7330
7877
  * ```typescript
7331
- * const markdown = await Walker.getReport("BTCUSDT", "my-walker");
7878
+ * const markdown = await Walker.getReport("BTCUSDT", { walkerName: "my-walker" });
7332
7879
  * console.log(markdown);
7333
7880
  * ```
7334
7881
  */
7335
- getReport: (symbol: string, walkerName: WalkerName, strategyColumns?: StrategyColumn[], pnlColumns?: PnlColumn[]) => Promise<string>;
7882
+ getReport: (symbol: string, context: {
7883
+ walkerName: WalkerName;
7884
+ }, strategyColumns?: StrategyColumn[], pnlColumns?: PnlColumn[]) => Promise<string>;
7336
7885
  /**
7337
7886
  * Saves walker report to disk.
7338
7887
  *
7339
7888
  * @param symbol - Trading symbol
7340
- * @param walkerName - Walker name to save report for
7889
+ * @param context - Execution context with walker name
7341
7890
  * @param path - Optional directory path to save report (default: "./dump/walker")
7342
7891
  * @param strategyColumns - Optional strategy columns configuration
7343
7892
  * @param pnlColumns - Optional PNL columns configuration
@@ -7345,13 +7894,15 @@ declare class WalkerUtils {
7345
7894
  * @example
7346
7895
  * ```typescript
7347
7896
  * // Save to default path: ./dump/walker/my-walker.md
7348
- * await Walker.dump("BTCUSDT", "my-walker");
7897
+ * await Walker.dump("BTCUSDT", { walkerName: "my-walker" });
7349
7898
  *
7350
7899
  * // Save to custom path: ./custom/path/my-walker.md
7351
- * await Walker.dump("BTCUSDT", "my-walker", "./custom/path");
7900
+ * await Walker.dump("BTCUSDT", { walkerName: "my-walker" }, "./custom/path");
7352
7901
  * ```
7353
7902
  */
7354
- dump: (symbol: string, walkerName: WalkerName, path?: string, strategyColumns?: StrategyColumn[], pnlColumns?: PnlColumn[]) => Promise<void>;
7903
+ dump: (symbol: string, context: {
7904
+ walkerName: WalkerName;
7905
+ }, path?: string, strategyColumns?: StrategyColumn[], pnlColumns?: PnlColumn[]) => Promise<void>;
7355
7906
  /**
7356
7907
  * Lists all active walker instances with their current status.
7357
7908
  *
@@ -7485,7 +8036,7 @@ declare class HeatMarkdownService {
7485
8036
  * });
7486
8037
  * ```
7487
8038
  */
7488
- getData: (exchangeName: string, frameName: string, backtest: boolean) => Promise<HeatmapStatisticsModel>;
8039
+ getData: (exchangeName: ExchangeName, frameName: FrameName, backtest: boolean) => Promise<HeatmapStatisticsModel>;
7489
8040
  /**
7490
8041
  * Generates markdown report with portfolio heatmap table.
7491
8042
  *
@@ -7513,7 +8064,7 @@ declare class HeatMarkdownService {
7513
8064
  * // ...
7514
8065
  * ```
7515
8066
  */
7516
- getReport: (strategyName: StrategyName, exchangeName: string, frameName: string, backtest: boolean, columns?: Columns$2[]) => Promise<string>;
8067
+ getReport: (strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, columns?: Columns$2[]) => Promise<string>;
7517
8068
  /**
7518
8069
  * Saves heatmap report to disk.
7519
8070
  *
@@ -7538,7 +8089,7 @@ declare class HeatMarkdownService {
7538
8089
  * await service.dump("my-strategy", "binance", "frame1", true, "./reports");
7539
8090
  * ```
7540
8091
  */
7541
- dump: (strategyName: StrategyName, exchangeName: string, frameName: string, backtest: boolean, path?: string, columns?: Columns$2[]) => Promise<void>;
8092
+ dump: (strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, path?: string, columns?: Columns$2[]) => Promise<void>;
7542
8093
  /**
7543
8094
  * Clears accumulated heatmap data from storage.
7544
8095
  * If payload is provided, clears only that exchangeName+frameName+backtest combination's data.
@@ -7558,8 +8109,8 @@ declare class HeatMarkdownService {
7558
8109
  * ```
7559
8110
  */
7560
8111
  clear: (payload?: {
7561
- exchangeName: string;
7562
- frameName: string;
8112
+ exchangeName: ExchangeName;
8113
+ frameName: FrameName;
7563
8114
  backtest: boolean;
7564
8115
  }) => Promise<void>;
7565
8116
  /**
@@ -7574,6 +8125,11 @@ declare class HeatMarkdownService {
7574
8125
  * ```
7575
8126
  */
7576
8127
  protected init: (() => Promise<void>) & functools_kit.ISingleshotClearable;
8128
+ /**
8129
+ * Function to unsubscribe from backtest signal events.
8130
+ * Assigned during init().
8131
+ */
8132
+ unsubscribe: Function;
7577
8133
  }
7578
8134
 
7579
8135
  /**
@@ -7641,9 +8197,9 @@ declare class HeatUtils {
7641
8197
  * ```
7642
8198
  */
7643
8199
  getData: (context: {
7644
- strategyName: string;
7645
- exchangeName: string;
7646
- frameName: string;
8200
+ strategyName: StrategyName;
8201
+ exchangeName: ExchangeName;
8202
+ frameName: FrameName;
7647
8203
  }, backtest?: boolean) => Promise<HeatmapStatisticsModel>;
7648
8204
  /**
7649
8205
  * Generates markdown report with portfolio heatmap table for a strategy.
@@ -7677,9 +8233,9 @@ declare class HeatUtils {
7677
8233
  * ```
7678
8234
  */
7679
8235
  getReport: (context: {
7680
- strategyName: string;
7681
- exchangeName: string;
7682
- frameName: string;
8236
+ strategyName: StrategyName;
8237
+ exchangeName: ExchangeName;
8238
+ frameName: FrameName;
7683
8239
  }, backtest?: boolean, columns?: Columns$2[]) => Promise<string>;
7684
8240
  /**
7685
8241
  * Saves heatmap report to disk for a strategy.
@@ -7710,9 +8266,9 @@ declare class HeatUtils {
7710
8266
  * ```
7711
8267
  */
7712
8268
  dump: (context: {
7713
- strategyName: string;
7714
- exchangeName: string;
7715
- frameName: string;
8269
+ strategyName: StrategyName;
8270
+ exchangeName: ExchangeName;
8271
+ frameName: FrameName;
7716
8272
  }, backtest?: boolean, path?: string, columns?: Columns$2[]) => Promise<void>;
7717
8273
  }
7718
8274
  /**
@@ -8018,7 +8574,7 @@ declare class PartialMarkdownService {
8018
8574
  * console.log(stats.totalProfit, stats.totalLoss);
8019
8575
  * ```
8020
8576
  */
8021
- getData: (symbol: string, strategyName: string, exchangeName: string, frameName: string, backtest: boolean) => Promise<PartialStatisticsModel>;
8577
+ getData: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean) => Promise<PartialStatisticsModel>;
8022
8578
  /**
8023
8579
  * Generates markdown report with all partial events for a symbol-strategy pair.
8024
8580
  * Delegates to ReportStorage.getReport().
@@ -8038,7 +8594,7 @@ declare class PartialMarkdownService {
8038
8594
  * console.log(markdown);
8039
8595
  * ```
8040
8596
  */
8041
- getReport: (symbol: string, strategyName: string, exchangeName: string, frameName: string, backtest: boolean, columns?: Columns$1[]) => Promise<string>;
8597
+ getReport: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, columns?: Columns$1[]) => Promise<string>;
8042
8598
  /**
8043
8599
  * Saves symbol-strategy report to disk.
8044
8600
  * Creates directory if it doesn't exist.
@@ -8063,7 +8619,7 @@ declare class PartialMarkdownService {
8063
8619
  * await service.dump("BTCUSDT", "my-strategy", "binance", "1h", false, "./custom/path");
8064
8620
  * ```
8065
8621
  */
8066
- dump: (symbol: string, strategyName: string, exchangeName: string, frameName: string, backtest: boolean, path?: string, columns?: Columns$1[]) => Promise<void>;
8622
+ dump: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, path?: string, columns?: Columns$1[]) => Promise<void>;
8067
8623
  /**
8068
8624
  * Clears accumulated event data from storage.
8069
8625
  * If payload is provided, clears only that specific symbol-strategy-exchange-frame-backtest combination's data.
@@ -8084,9 +8640,9 @@ declare class PartialMarkdownService {
8084
8640
  */
8085
8641
  clear: (payload?: {
8086
8642
  symbol: string;
8087
- strategyName: string;
8088
- exchangeName: string;
8089
- frameName: string;
8643
+ strategyName: StrategyName;
8644
+ exchangeName: ExchangeName;
8645
+ frameName: FrameName;
8090
8646
  backtest: boolean;
8091
8647
  }) => Promise<void>;
8092
8648
  /**
@@ -8101,6 +8657,11 @@ declare class PartialMarkdownService {
8101
8657
  * ```
8102
8658
  */
8103
8659
  protected init: (() => Promise<void>) & functools_kit.ISingleshotClearable;
8660
+ /**
8661
+ * Function to unsubscribe from partial profit/loss events.
8662
+ * Assigned during init().
8663
+ */
8664
+ unsubscribe: Function;
8104
8665
  }
8105
8666
 
8106
8667
  /**
@@ -8164,9 +8725,9 @@ declare class PartialUtils {
8164
8725
  * ```
8165
8726
  */
8166
8727
  getData: (symbol: string, context: {
8167
- strategyName: string;
8168
- exchangeName: string;
8169
- frameName: string;
8728
+ strategyName: StrategyName;
8729
+ exchangeName: ExchangeName;
8730
+ frameName: FrameName;
8170
8731
  }, backtest?: boolean) => Promise<PartialStatisticsModel>;
8171
8732
  /**
8172
8733
  * Generates markdown report with all partial profit/loss events for a symbol-strategy pair.
@@ -8208,9 +8769,9 @@ declare class PartialUtils {
8208
8769
  * ```
8209
8770
  */
8210
8771
  getReport: (symbol: string, context: {
8211
- strategyName: string;
8212
- exchangeName: string;
8213
- frameName: string;
8772
+ strategyName: StrategyName;
8773
+ exchangeName: ExchangeName;
8774
+ frameName: FrameName;
8214
8775
  }, backtest?: boolean, columns?: Columns$1[]) => Promise<string>;
8215
8776
  /**
8216
8777
  * Generates and saves markdown report to file.
@@ -8245,9 +8806,9 @@ declare class PartialUtils {
8245
8806
  * ```
8246
8807
  */
8247
8808
  dump: (symbol: string, context: {
8248
- strategyName: string;
8249
- exchangeName: string;
8250
- frameName: string;
8809
+ strategyName: StrategyName;
8810
+ exchangeName: ExchangeName;
8811
+ frameName: FrameName;
8251
8812
  }, backtest?: boolean, path?: string, columns?: Columns$1[]) => Promise<void>;
8252
8813
  }
8253
8814
  /**
@@ -8437,7 +8998,7 @@ declare class RiskMarkdownService {
8437
8998
  * console.log(stats.totalRejections, stats.bySymbol);
8438
8999
  * ```
8439
9000
  */
8440
- getData: (symbol: string, strategyName: string, exchangeName: string, frameName: string, backtest: boolean) => Promise<RiskStatisticsModel>;
9001
+ getData: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean) => Promise<RiskStatisticsModel>;
8441
9002
  /**
8442
9003
  * Generates markdown report with all risk rejection events for a symbol-strategy pair.
8443
9004
  * Delegates to ReportStorage.getReport().
@@ -8457,7 +9018,7 @@ declare class RiskMarkdownService {
8457
9018
  * console.log(markdown);
8458
9019
  * ```
8459
9020
  */
8460
- getReport: (symbol: string, strategyName: string, exchangeName: string, frameName: string, backtest: boolean, columns?: Columns[]) => Promise<string>;
9021
+ getReport: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, columns?: Columns[]) => Promise<string>;
8461
9022
  /**
8462
9023
  * Saves symbol-strategy report to disk.
8463
9024
  * Creates directory if it doesn't exist.
@@ -8482,7 +9043,7 @@ declare class RiskMarkdownService {
8482
9043
  * await service.dump("BTCUSDT", "my-strategy", "binance", "1h", false, "./custom/path");
8483
9044
  * ```
8484
9045
  */
8485
- dump: (symbol: string, strategyName: string, exchangeName: string, frameName: string, backtest: boolean, path?: string, columns?: Columns[]) => Promise<void>;
9046
+ dump: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, path?: string, columns?: Columns[]) => Promise<void>;
8486
9047
  /**
8487
9048
  * Clears accumulated event data from storage.
8488
9049
  * If payload is provided, clears only that specific symbol-strategy-exchange-frame-backtest combination's data.
@@ -8503,9 +9064,9 @@ declare class RiskMarkdownService {
8503
9064
  */
8504
9065
  clear: (payload?: {
8505
9066
  symbol: string;
8506
- strategyName: string;
8507
- exchangeName: string;
8508
- frameName: string;
9067
+ strategyName: StrategyName;
9068
+ exchangeName: ExchangeName;
9069
+ frameName: FrameName;
8509
9070
  backtest: boolean;
8510
9071
  }) => Promise<void>;
8511
9072
  /**
@@ -8520,6 +9081,11 @@ declare class RiskMarkdownService {
8520
9081
  * ```
8521
9082
  */
8522
9083
  protected init: (() => Promise<void>) & functools_kit.ISingleshotClearable;
9084
+ /**
9085
+ * Function to unsubscribe from partial profit/loss events.
9086
+ * Assigned during init().
9087
+ */
9088
+ unsubscribe: Function;
8523
9089
  }
8524
9090
 
8525
9091
  /**
@@ -8583,9 +9149,9 @@ declare class RiskUtils {
8583
9149
  * ```
8584
9150
  */
8585
9151
  getData: (symbol: string, context: {
8586
- strategyName: string;
8587
- exchangeName: string;
8588
- frameName: string;
9152
+ strategyName: StrategyName;
9153
+ exchangeName: ExchangeName;
9154
+ frameName: FrameName;
8589
9155
  }, backtest?: boolean) => Promise<RiskStatisticsModel>;
8590
9156
  /**
8591
9157
  * Generates markdown report with all risk rejection events for a symbol-strategy pair.
@@ -8629,9 +9195,9 @@ declare class RiskUtils {
8629
9195
  * ```
8630
9196
  */
8631
9197
  getReport: (symbol: string, context: {
8632
- strategyName: string;
8633
- exchangeName: string;
8634
- frameName: string;
9198
+ strategyName: StrategyName;
9199
+ exchangeName: ExchangeName;
9200
+ frameName: FrameName;
8635
9201
  }, backtest?: boolean, columns?: Columns[]) => Promise<string>;
8636
9202
  /**
8637
9203
  * Generates and saves markdown report to file.
@@ -8666,9 +9232,9 @@ declare class RiskUtils {
8666
9232
  * ```
8667
9233
  */
8668
9234
  dump: (symbol: string, context: {
8669
- strategyName: string;
8670
- exchangeName: string;
8671
- frameName: string;
9235
+ strategyName: StrategyName;
9236
+ exchangeName: ExchangeName;
9237
+ frameName: FrameName;
8672
9238
  }, backtest?: boolean, path?: string, columns?: Columns[]) => Promise<void>;
8673
9239
  }
8674
9240
  /**
@@ -8795,7 +9361,7 @@ declare const Exchange: ExchangeUtils;
8795
9361
  * Generic function type that accepts any arguments and returns any value.
8796
9362
  * Used as a constraint for cached functions.
8797
9363
  */
8798
- type Function = (...args: any[]) => any;
9364
+ type Function$1 = (...args: any[]) => any;
8799
9365
  /**
8800
9366
  * Utility class for function caching with timeframe-based invalidation.
8801
9367
  *
@@ -8840,7 +9406,7 @@ declare class CacheUtils {
8840
9406
  * const result2 = cachedCalculate("BTCUSDT", 14); // Cached (same 15m interval)
8841
9407
  * ```
8842
9408
  */
8843
- fn: <T extends Function>(run: T, context: {
9409
+ fn: <T extends Function$1>(run: T, context: {
8844
9410
  interval: CandleInterval;
8845
9411
  }) => T;
8846
9412
  /**
@@ -8872,7 +9438,7 @@ declare class CacheUtils {
8872
9438
  * Cache.flush();
8873
9439
  * ```
8874
9440
  */
8875
- flush: <T extends Function>(run?: T) => void;
9441
+ flush: <T extends Function$1>(run?: T) => void;
8876
9442
  /**
8877
9443
  * Clear cached value for current execution context of a specific function.
8878
9444
  *
@@ -8902,7 +9468,7 @@ declare class CacheUtils {
8902
9468
  * // Other contexts (different strategies/exchanges) remain cached
8903
9469
  * ```
8904
9470
  */
8905
- clear: <T extends Function>(run: T) => void;
9471
+ clear: <T extends Function$1>(run: T) => void;
8906
9472
  }
8907
9473
  /**
8908
9474
  * Singleton instance of CacheUtils for convenient function caching.
@@ -9499,18 +10065,18 @@ declare class ClientRisk implements IRisk {
9499
10065
  * Called by StrategyConnectionService after signal is opened.
9500
10066
  */
9501
10067
  addSignal(symbol: string, context: {
9502
- strategyName: string;
9503
- riskName: string;
9504
- exchangeName: string;
10068
+ strategyName: StrategyName;
10069
+ riskName: RiskName;
10070
+ exchangeName: ExchangeName;
9505
10071
  }): Promise<void>;
9506
10072
  /**
9507
10073
  * Removes a closed signal.
9508
10074
  * Called by StrategyConnectionService when signal is closed.
9509
10075
  */
9510
10076
  removeSignal(symbol: string, context: {
9511
- strategyName: string;
9512
- riskName: string;
9513
- exchangeName: string;
10077
+ strategyName: StrategyName;
10078
+ riskName: RiskName;
10079
+ exchangeName: ExchangeName;
9514
10080
  }): Promise<void>;
9515
10081
  /**
9516
10082
  * Checks if a signal should be allowed based on risk limits.
@@ -9528,6 +10094,14 @@ declare class ClientRisk implements IRisk {
9528
10094
  checkSignal: (params: IRiskCheckArgs) => Promise<boolean>;
9529
10095
  }
9530
10096
 
10097
+ /**
10098
+ * Type definition for risk methods.
10099
+ * Maps all keys of IRisk to any type.
10100
+ * Used for dynamic method routing in RiskConnectionService.
10101
+ */
10102
+ type TRisk$1 = {
10103
+ [key in keyof IRisk]: any;
10104
+ };
9531
10105
  /**
9532
10106
  * Connection service routing risk operations to correct ClientRisk instance.
9533
10107
  *
@@ -9560,7 +10134,7 @@ declare class ClientRisk implements IRisk {
9560
10134
  * );
9561
10135
  * ```
9562
10136
  */
9563
- declare class RiskConnectionService {
10137
+ declare class RiskConnectionService implements TRisk$1 {
9564
10138
  private readonly loggerService;
9565
10139
  private readonly riskSchemaService;
9566
10140
  /**
@@ -9575,7 +10149,7 @@ declare class RiskConnectionService {
9575
10149
  * @param backtest - True if backtest mode, false if live mode
9576
10150
  * @returns Configured ClientRisk instance
9577
10151
  */
9578
- getRisk: ((riskName: RiskName, exchangeName: string, frameName: string, backtest: boolean) => ClientRisk) & functools_kit.IClearableMemoize<string> & functools_kit.IControlMemoize<string, ClientRisk>;
10152
+ getRisk: ((riskName: RiskName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean) => ClientRisk) & functools_kit.IClearableMemoize<string> & functools_kit.IControlMemoize<string, ClientRisk>;
9579
10153
  /**
9580
10154
  * Checks if a signal should be allowed based on risk limits.
9581
10155
  *
@@ -9589,8 +10163,8 @@ declare class RiskConnectionService {
9589
10163
  */
9590
10164
  checkSignal: (params: IRiskCheckArgs, payload: {
9591
10165
  riskName: RiskName;
9592
- exchangeName: string;
9593
- frameName: string;
10166
+ exchangeName: ExchangeName;
10167
+ frameName: FrameName;
9594
10168
  backtest: boolean;
9595
10169
  }) => Promise<boolean>;
9596
10170
  /**
@@ -9601,10 +10175,10 @@ declare class RiskConnectionService {
9601
10175
  * @param payload - Payload information (strategyName, riskName, exchangeName, frameName, backtest)
9602
10176
  */
9603
10177
  addSignal: (symbol: string, payload: {
9604
- strategyName: string;
10178
+ strategyName: StrategyName;
9605
10179
  riskName: RiskName;
9606
- exchangeName: string;
9607
- frameName: string;
10180
+ exchangeName: ExchangeName;
10181
+ frameName: FrameName;
9608
10182
  backtest: boolean;
9609
10183
  }) => Promise<void>;
9610
10184
  /**
@@ -9615,10 +10189,10 @@ declare class RiskConnectionService {
9615
10189
  * @param payload - Payload information (strategyName, riskName, exchangeName, frameName, backtest)
9616
10190
  */
9617
10191
  removeSignal: (symbol: string, payload: {
9618
- strategyName: string;
10192
+ strategyName: StrategyName;
9619
10193
  riskName: RiskName;
9620
- exchangeName: string;
9621
- frameName: string;
10194
+ exchangeName: ExchangeName;
10195
+ frameName: FrameName;
9622
10196
  backtest: boolean;
9623
10197
  }) => Promise<void>;
9624
10198
  /**
@@ -9628,8 +10202,8 @@ declare class RiskConnectionService {
9628
10202
  */
9629
10203
  clear: (payload?: {
9630
10204
  riskName: RiskName;
9631
- exchangeName: string;
9632
- frameName: string;
10205
+ exchangeName: ExchangeName;
10206
+ frameName: FrameName;
9633
10207
  backtest: boolean;
9634
10208
  }) => Promise<void>;
9635
10209
  }
@@ -9695,7 +10269,7 @@ declare class PartialConnectionService implements IPartial {
9695
10269
  * @param when - Event timestamp (current time for live, candle time for backtest)
9696
10270
  * @returns Promise that resolves when profit processing is complete
9697
10271
  */
9698
- profit: (symbol: string, data: ISignalRow, currentPrice: number, revenuePercent: number, backtest: boolean, when: Date) => Promise<void>;
10272
+ profit: (symbol: string, data: IPublicSignalRow, currentPrice: number, revenuePercent: number, backtest: boolean, when: Date) => Promise<void>;
9699
10273
  /**
9700
10274
  * Processes loss state and emits events for newly reached loss levels.
9701
10275
  *
@@ -9710,7 +10284,7 @@ declare class PartialConnectionService implements IPartial {
9710
10284
  * @param when - Event timestamp (current time for live, candle time for backtest)
9711
10285
  * @returns Promise that resolves when loss processing is complete
9712
10286
  */
9713
- loss: (symbol: string, data: ISignalRow, currentPrice: number, lossPercent: number, backtest: boolean, when: Date) => Promise<void>;
10287
+ loss: (symbol: string, data: IPublicSignalRow, currentPrice: number, lossPercent: number, backtest: boolean, when: Date) => Promise<void>;
9714
10288
  /**
9715
10289
  * Clears partial profit/loss state when signal closes.
9716
10290
  *
@@ -9731,6 +10305,14 @@ declare class PartialConnectionService implements IPartial {
9731
10305
  clear: (symbol: string, data: ISignalRow, priceClose: number, backtest: boolean) => Promise<void>;
9732
10306
  }
9733
10307
 
10308
+ /**
10309
+ * Type definition for strategy methods.
10310
+ * Maps all keys of IStrategy to any type.
10311
+ * Used for dynamic method routing in StrategyConnectionService.
10312
+ */
10313
+ type TStrategy$1 = {
10314
+ [key in keyof IStrategy]: any;
10315
+ };
9734
10316
  /**
9735
10317
  * Connection service routing strategy operations to correct ClientStrategy instance.
9736
10318
  *
@@ -9751,11 +10333,14 @@ declare class PartialConnectionService implements IPartial {
9751
10333
  * // Routes to correct strategy instance for symbol-strategy pair
9752
10334
  * ```
9753
10335
  */
9754
- declare class StrategyConnectionService {
10336
+ declare class StrategyConnectionService implements TStrategy$1 {
9755
10337
  readonly loggerService: LoggerService;
9756
10338
  readonly executionContextService: {
9757
10339
  readonly context: IExecutionContext;
9758
10340
  };
10341
+ readonly methodContextService: {
10342
+ readonly context: IMethodContext;
10343
+ };
9759
10344
  readonly strategySchemaService: StrategySchemaService;
9760
10345
  readonly riskConnectionService: RiskConnectionService;
9761
10346
  readonly exchangeConnectionService: ExchangeConnectionService;
@@ -9787,8 +10372,8 @@ declare class StrategyConnectionService {
9787
10372
  */
9788
10373
  getPendingSignal: (backtest: boolean, symbol: string, context: {
9789
10374
  strategyName: StrategyName;
9790
- exchangeName: string;
9791
- frameName: string;
10375
+ exchangeName: ExchangeName;
10376
+ frameName: FrameName;
9792
10377
  }) => Promise<ISignalRow | null>;
9793
10378
  /**
9794
10379
  * Retrieves the currently active scheduled signal for the strategy.
@@ -9803,8 +10388,8 @@ declare class StrategyConnectionService {
9803
10388
  */
9804
10389
  getScheduledSignal: (backtest: boolean, symbol: string, context: {
9805
10390
  strategyName: StrategyName;
9806
- exchangeName: string;
9807
- frameName: string;
10391
+ exchangeName: ExchangeName;
10392
+ frameName: FrameName;
9808
10393
  }) => Promise<IScheduledSignalRow | null>;
9809
10394
  /**
9810
10395
  * Retrieves the stopped state of the strategy.
@@ -9819,8 +10404,8 @@ declare class StrategyConnectionService {
9819
10404
  */
9820
10405
  getStopped: (backtest: boolean, symbol: string, context: {
9821
10406
  strategyName: StrategyName;
9822
- exchangeName: string;
9823
- frameName: string;
10407
+ exchangeName: ExchangeName;
10408
+ frameName: FrameName;
9824
10409
  }) => Promise<boolean>;
9825
10410
  /**
9826
10411
  * Executes live trading tick for current strategy.
@@ -9834,8 +10419,8 @@ declare class StrategyConnectionService {
9834
10419
  */
9835
10420
  tick: (symbol: string, context: {
9836
10421
  strategyName: StrategyName;
9837
- exchangeName: string;
9838
- frameName: string;
10422
+ exchangeName: ExchangeName;
10423
+ frameName: FrameName;
9839
10424
  }) => Promise<IStrategyTickResult>;
9840
10425
  /**
9841
10426
  * Executes backtest for current strategy with provided candles.
@@ -9850,8 +10435,8 @@ declare class StrategyConnectionService {
9850
10435
  */
9851
10436
  backtest: (symbol: string, context: {
9852
10437
  strategyName: StrategyName;
9853
- exchangeName: string;
9854
- frameName: string;
10438
+ exchangeName: ExchangeName;
10439
+ frameName: FrameName;
9855
10440
  }, candles: ICandleData[]) => Promise<IStrategyBacktestResult>;
9856
10441
  /**
9857
10442
  * Stops the specified strategy from generating new signals.
@@ -9866,8 +10451,8 @@ declare class StrategyConnectionService {
9866
10451
  */
9867
10452
  stop: (backtest: boolean, symbol: string, context: {
9868
10453
  strategyName: StrategyName;
9869
- exchangeName: string;
9870
- frameName: string;
10454
+ exchangeName: ExchangeName;
10455
+ frameName: FrameName;
9871
10456
  }) => Promise<void>;
9872
10457
  /**
9873
10458
  * Clears the memoized ClientStrategy instance from cache.
@@ -9880,8 +10465,8 @@ declare class StrategyConnectionService {
9880
10465
  clear: (payload?: {
9881
10466
  symbol: string;
9882
10467
  strategyName: StrategyName;
9883
- exchangeName: string;
9884
- frameName: string;
10468
+ exchangeName: ExchangeName;
10469
+ frameName: FrameName;
9885
10470
  backtest: boolean;
9886
10471
  }) => Promise<void>;
9887
10472
  /**
@@ -9901,9 +10486,104 @@ declare class StrategyConnectionService {
9901
10486
  */
9902
10487
  cancel: (backtest: boolean, symbol: string, context: {
9903
10488
  strategyName: StrategyName;
9904
- exchangeName: string;
9905
- frameName: string;
10489
+ exchangeName: ExchangeName;
10490
+ frameName: FrameName;
9906
10491
  }, cancelId?: string) => Promise<void>;
10492
+ /**
10493
+ * Executes partial close at profit level (moving toward TP).
10494
+ *
10495
+ * Closes a percentage of the pending position at the current price, recording it as a "profit" type partial.
10496
+ * The partial close is tracked in `_partial` array for weighted PNL calculation when position fully closes.
10497
+ *
10498
+ * Delegates to ClientStrategy.partialProfit() with current execution context.
10499
+ *
10500
+ * @param backtest - Whether running in backtest mode
10501
+ * @param symbol - Trading pair symbol
10502
+ * @param context - Execution context with strategyName, exchangeName, frameName
10503
+ * @param percentToClose - Percentage of position to close (0-100, absolute value)
10504
+ * @param currentPrice - Current market price for this partial close
10505
+ * @returns Promise that resolves when state is updated and persisted
10506
+ *
10507
+ * @example
10508
+ * ```typescript
10509
+ * // Close 30% of position at profit
10510
+ * await strategyConnectionService.partialProfit(
10511
+ * false,
10512
+ * "BTCUSDT",
10513
+ * { strategyName: "my-strategy", exchangeName: "binance", frameName: "" },
10514
+ * 30,
10515
+ * 45000
10516
+ * );
10517
+ * ```
10518
+ */
10519
+ partialProfit: (backtest: boolean, symbol: string, percentToClose: number, currentPrice: number, context: {
10520
+ strategyName: StrategyName;
10521
+ exchangeName: ExchangeName;
10522
+ frameName: FrameName;
10523
+ }) => Promise<void>;
10524
+ /**
10525
+ * Executes partial close at loss level (moving toward SL).
10526
+ *
10527
+ * Closes a percentage of the pending position at the current price, recording it as a "loss" type partial.
10528
+ * The partial close is tracked in `_partial` array for weighted PNL calculation when position fully closes.
10529
+ *
10530
+ * Delegates to ClientStrategy.partialLoss() with current execution context.
10531
+ *
10532
+ * @param backtest - Whether running in backtest mode
10533
+ * @param symbol - Trading pair symbol
10534
+ * @param context - Execution context with strategyName, exchangeName, frameName
10535
+ * @param percentToClose - Percentage of position to close (0-100, absolute value)
10536
+ * @param currentPrice - Current market price for this partial close
10537
+ * @returns Promise that resolves when state is updated and persisted
10538
+ *
10539
+ * @example
10540
+ * ```typescript
10541
+ * // Close 40% of position at loss
10542
+ * await strategyConnectionService.partialLoss(
10543
+ * false,
10544
+ * "BTCUSDT",
10545
+ * { strategyName: "my-strategy", exchangeName: "binance", frameName: "" },
10546
+ * 40,
10547
+ * 38000
10548
+ * );
10549
+ * ```
10550
+ */
10551
+ partialLoss: (backtest: boolean, symbol: string, percentToClose: number, currentPrice: number, context: {
10552
+ strategyName: StrategyName;
10553
+ exchangeName: ExchangeName;
10554
+ frameName: FrameName;
10555
+ }) => Promise<void>;
10556
+ /**
10557
+ * Adjusts the trailing stop-loss distance for an active pending signal.
10558
+ *
10559
+ * Updates the stop-loss distance by a percentage adjustment relative to the original SL distance.
10560
+ * Positive percentShift tightens the SL (reduces distance), negative percentShift loosens it.
10561
+ *
10562
+ * Delegates to ClientStrategy.trailingStop() with current execution context.
10563
+ *
10564
+ * @param backtest - Whether running in backtest mode
10565
+ * @param symbol - Trading pair symbol
10566
+ * @param percentShift - Percentage adjustment to SL distance (-100 to 100)
10567
+ * @param context - Execution context with strategyName, exchangeName, frameName
10568
+ * @returns Promise that resolves when trailing SL is updated
10569
+ *
10570
+ * @example
10571
+ * ```typescript
10572
+ * // LONG: entry=100, originalSL=90, distance=10
10573
+ * // Tighten stop by 50%: newSL = 100 - 10*(1-0.5) = 95
10574
+ * await strategyConnectionService.trailingStop(
10575
+ * false,
10576
+ * "BTCUSDT",
10577
+ * -50,
10578
+ * { strategyName: "my-strategy", exchangeName: "binance", frameName: "" }
10579
+ * );
10580
+ * ```
10581
+ */
10582
+ trailingStop: (backtest: boolean, symbol: string, percentShift: number, context: {
10583
+ strategyName: StrategyName;
10584
+ exchangeName: ExchangeName;
10585
+ frameName: FrameName;
10586
+ }) => Promise<void>;
9907
10587
  }
9908
10588
 
9909
10589
  /**
@@ -9976,7 +10656,7 @@ declare class FrameConnectionService implements IFrame {
9976
10656
  * @param symbol - Trading pair symbol (e.g., "BTCUSDT")
9977
10657
  * @returns Promise resolving to { startDate: Date, endDate: Date }
9978
10658
  */
9979
- getTimeframe: (symbol: string, frameName: string) => Promise<Date[]>;
10659
+ getTimeframe: (symbol: string, frameName: FrameName) => Promise<Date[]>;
9980
10660
  }
9981
10661
 
9982
10662
  /**
@@ -10003,6 +10683,14 @@ declare class ClientSizing implements ISizing {
10003
10683
  calculate(params: ISizingCalculateParams): Promise<number>;
10004
10684
  }
10005
10685
 
10686
+ /**
10687
+ * Type definition for sizing methods.
10688
+ * Maps all keys of ISizing to any type.
10689
+ * Used for dynamic method routing in SizingConnectionService.
10690
+ */
10691
+ type TSizing$1 = {
10692
+ [key in keyof ISizing]: any;
10693
+ };
10006
10694
  /**
10007
10695
  * Connection service routing sizing operations to correct ClientSizing instance.
10008
10696
  *
@@ -10032,7 +10720,7 @@ declare class ClientSizing implements ISizing {
10032
10720
  * );
10033
10721
  * ```
10034
10722
  */
10035
- declare class SizingConnectionService {
10723
+ declare class SizingConnectionService implements TSizing$1 {
10036
10724
  private readonly loggerService;
10037
10725
  private readonly sizingSchemaService;
10038
10726
  /**
@@ -10060,6 +10748,14 @@ declare class SizingConnectionService {
10060
10748
  }) => Promise<number>;
10061
10749
  }
10062
10750
 
10751
+ /**
10752
+ * Type definition for exchange methods.
10753
+ * Maps all keys of IExchange to any type.
10754
+ * Used for dynamic method routing in ExchangeCoreService.
10755
+ */
10756
+ type TExchange = {
10757
+ [key in keyof IExchange]: any;
10758
+ };
10063
10759
  /**
10064
10760
  * Global service for exchange operations with execution context injection.
10065
10761
  *
@@ -10068,7 +10764,7 @@ declare class SizingConnectionService {
10068
10764
  *
10069
10765
  * Used internally by BacktestLogicPrivateService and LiveLogicPrivateService.
10070
10766
  */
10071
- declare class ExchangeCoreService {
10767
+ declare class ExchangeCoreService implements TExchange {
10072
10768
  private readonly loggerService;
10073
10769
  private readonly exchangeConnectionService;
10074
10770
  private readonly methodContextService;
@@ -10134,6 +10830,14 @@ declare class ExchangeCoreService {
10134
10830
  formatQuantity: (symbol: string, quantity: number, when: Date, backtest: boolean) => Promise<string>;
10135
10831
  }
10136
10832
 
10833
+ /**
10834
+ * Type definition for strategy methods.
10835
+ * Maps all keys of IStrategy to any type.
10836
+ * Used for dynamic method routing in StrategyCoreService.
10837
+ */
10838
+ type TStrategy = {
10839
+ [key in keyof IStrategy]: any;
10840
+ };
10137
10841
  /**
10138
10842
  * Global service for strategy operations with execution context injection.
10139
10843
  *
@@ -10142,7 +10846,7 @@ declare class ExchangeCoreService {
10142
10846
  *
10143
10847
  * Used internally by BacktestLogicPrivateService and LiveLogicPrivateService.
10144
10848
  */
10145
- declare class StrategyCoreService {
10849
+ declare class StrategyCoreService implements TStrategy {
10146
10850
  private readonly loggerService;
10147
10851
  private readonly strategyConnectionService;
10148
10852
  private readonly strategySchemaService;
@@ -10170,8 +10874,8 @@ declare class StrategyCoreService {
10170
10874
  */
10171
10875
  getPendingSignal: (backtest: boolean, symbol: string, context: {
10172
10876
  strategyName: StrategyName;
10173
- exchangeName: string;
10174
- frameName: string;
10877
+ exchangeName: ExchangeName;
10878
+ frameName: FrameName;
10175
10879
  }) => Promise<ISignalRow | null>;
10176
10880
  /**
10177
10881
  * Retrieves the currently active scheduled signal for the symbol.
@@ -10185,8 +10889,8 @@ declare class StrategyCoreService {
10185
10889
  */
10186
10890
  getScheduledSignal: (backtest: boolean, symbol: string, context: {
10187
10891
  strategyName: StrategyName;
10188
- exchangeName: string;
10189
- frameName: string;
10892
+ exchangeName: ExchangeName;
10893
+ frameName: FrameName;
10190
10894
  }) => Promise<IScheduledSignalRow | null>;
10191
10895
  /**
10192
10896
  * Checks if the strategy has been stopped.
@@ -10201,8 +10905,8 @@ declare class StrategyCoreService {
10201
10905
  */
10202
10906
  getStopped: (backtest: boolean, symbol: string, context: {
10203
10907
  strategyName: StrategyName;
10204
- exchangeName: string;
10205
- frameName: string;
10908
+ exchangeName: ExchangeName;
10909
+ frameName: FrameName;
10206
10910
  }) => Promise<boolean>;
10207
10911
  /**
10208
10912
  * Checks signal status at a specific timestamp.
@@ -10218,8 +10922,8 @@ declare class StrategyCoreService {
10218
10922
  */
10219
10923
  tick: (symbol: string, when: Date, backtest: boolean, context: {
10220
10924
  strategyName: StrategyName;
10221
- exchangeName: string;
10222
- frameName: string;
10925
+ exchangeName: ExchangeName;
10926
+ frameName: FrameName;
10223
10927
  }) => Promise<IStrategyTickResult>;
10224
10928
  /**
10225
10929
  * Runs fast backtest against candle array.
@@ -10236,8 +10940,8 @@ declare class StrategyCoreService {
10236
10940
  */
10237
10941
  backtest: (symbol: string, candles: ICandleData[], when: Date, backtest: boolean, context: {
10238
10942
  strategyName: StrategyName;
10239
- exchangeName: string;
10240
- frameName: string;
10943
+ exchangeName: ExchangeName;
10944
+ frameName: FrameName;
10241
10945
  }) => Promise<IStrategyBacktestResult>;
10242
10946
  /**
10243
10947
  * Stops the strategy from generating new signals.
@@ -10252,8 +10956,8 @@ declare class StrategyCoreService {
10252
10956
  */
10253
10957
  stop: (backtest: boolean, symbol: string, context: {
10254
10958
  strategyName: StrategyName;
10255
- exchangeName: string;
10256
- frameName: string;
10959
+ exchangeName: ExchangeName;
10960
+ frameName: FrameName;
10257
10961
  }) => Promise<void>;
10258
10962
  /**
10259
10963
  * Cancels the scheduled signal without stopping the strategy.
@@ -10270,8 +10974,8 @@ declare class StrategyCoreService {
10270
10974
  */
10271
10975
  cancel: (backtest: boolean, symbol: string, context: {
10272
10976
  strategyName: StrategyName;
10273
- exchangeName: string;
10274
- frameName: string;
10977
+ exchangeName: ExchangeName;
10978
+ frameName: FrameName;
10275
10979
  }, cancelId?: string) => Promise<void>;
10276
10980
  /**
10277
10981
  * Clears the memoized ClientStrategy instance from cache.
@@ -10284,19 +10988,122 @@ declare class StrategyCoreService {
10284
10988
  clear: (payload?: {
10285
10989
  symbol: string;
10286
10990
  strategyName: StrategyName;
10287
- exchangeName: string;
10288
- frameName: string;
10991
+ exchangeName: ExchangeName;
10992
+ frameName: FrameName;
10289
10993
  backtest: boolean;
10290
10994
  }) => Promise<void>;
10995
+ /**
10996
+ * Executes partial close at profit level (moving toward TP).
10997
+ *
10998
+ * Validates strategy existence and delegates to connection service
10999
+ * to close a percentage of the pending position at profit.
11000
+ *
11001
+ * Does not require execution context as this is a direct state mutation.
11002
+ *
11003
+ * @param backtest - Whether running in backtest mode
11004
+ * @param symbol - Trading pair symbol
11005
+ * @param percentToClose - Percentage of position to close (0-100, absolute value)
11006
+ * @param currentPrice - Current market price for this partial close (must be in profit direction)
11007
+ * @param context - Execution context with strategyName, exchangeName, frameName
11008
+ * @returns Promise that resolves when state is updated and persisted
11009
+ *
11010
+ * @example
11011
+ * ```typescript
11012
+ * // Close 30% of position at profit
11013
+ * await strategyCoreService.partialProfit(
11014
+ * false,
11015
+ * "BTCUSDT",
11016
+ * 30,
11017
+ * 45000,
11018
+ * { strategyName: "my-strategy", exchangeName: "binance", frameName: "" }
11019
+ * );
11020
+ * ```
11021
+ */
11022
+ partialProfit: (backtest: boolean, symbol: string, percentToClose: number, currentPrice: number, context: {
11023
+ strategyName: StrategyName;
11024
+ exchangeName: ExchangeName;
11025
+ frameName: FrameName;
11026
+ }) => Promise<void>;
11027
+ /**
11028
+ * Executes partial close at loss level (moving toward SL).
11029
+ *
11030
+ * Validates strategy existence and delegates to connection service
11031
+ * to close a percentage of the pending position at loss.
11032
+ *
11033
+ * Does not require execution context as this is a direct state mutation.
11034
+ *
11035
+ * @param backtest - Whether running in backtest mode
11036
+ * @param symbol - Trading pair symbol
11037
+ * @param percentToClose - Percentage of position to close (0-100, absolute value)
11038
+ * @param currentPrice - Current market price for this partial close (must be in loss direction)
11039
+ * @param context - Execution context with strategyName, exchangeName, frameName
11040
+ * @returns Promise that resolves when state is updated and persisted
11041
+ *
11042
+ * @example
11043
+ * ```typescript
11044
+ * // Close 40% of position at loss
11045
+ * await strategyCoreService.partialLoss(
11046
+ * false,
11047
+ * "BTCUSDT",
11048
+ * 40,
11049
+ * 38000,
11050
+ * { strategyName: "my-strategy", exchangeName: "binance", frameName: "" }
11051
+ * );
11052
+ * ```
11053
+ */
11054
+ partialLoss: (backtest: boolean, symbol: string, percentToClose: number, currentPrice: number, context: {
11055
+ strategyName: StrategyName;
11056
+ exchangeName: ExchangeName;
11057
+ frameName: FrameName;
11058
+ }) => Promise<void>;
11059
+ /**
11060
+ * Adjusts the trailing stop-loss distance for an active pending signal.
11061
+ *
11062
+ * Validates strategy existence and delegates to connection service
11063
+ * to update the stop-loss distance by a percentage adjustment.
11064
+ *
11065
+ * Does not require execution context as this is a direct state mutation.
11066
+ *
11067
+ * @param backtest - Whether running in backtest mode
11068
+ * @param symbol - Trading pair symbol
11069
+ * @param percentShift - Percentage adjustment to SL distance (-100 to 100)
11070
+ * @param context - Execution context with strategyName, exchangeName, frameName
11071
+ * @returns Promise that resolves when trailing SL is updated
11072
+ *
11073
+ * @example
11074
+ * ```typescript
11075
+ * // LONG: entry=100, originalSL=90, distance=10
11076
+ * // Tighten stop by 50%: newSL = 100 - 10*(1-0.5) = 95
11077
+ * await strategyCoreService.trailingStop(
11078
+ * false,
11079
+ * "BTCUSDT",
11080
+ * -50,
11081
+ * { strategyName: "my-strategy", exchangeName: "binance", frameName: "" }
11082
+ * );
11083
+ * ```
11084
+ */
11085
+ trailingStop: (backtest: boolean, symbol: string, percentShift: number, context: {
11086
+ strategyName: StrategyName;
11087
+ exchangeName: ExchangeName;
11088
+ frameName: FrameName;
11089
+ }) => Promise<void>;
10291
11090
  }
10292
11091
 
11092
+ /**
11093
+ * Type definition for frame methods.
11094
+ * Maps all keys of IFrame to any type.
11095
+ * Used for dynamic method routing in FrameCoreService.
11096
+ */
11097
+ type TFrame = {
11098
+ [key in keyof IFrame]: any;
11099
+ };
10293
11100
  /**
10294
11101
  * Global service for frame operations.
10295
11102
  *
10296
11103
  * Wraps FrameConnectionService for timeframe generation.
10297
11104
  * Used internally by BacktestLogicPrivateService.
10298
11105
  */
10299
- declare class FrameCoreService {
11106
+ declare class FrameCoreService implements TFrame {
10300
11107
  private readonly loggerService;
10301
11108
  private readonly frameConnectionService;
10302
11109
  private readonly frameValidationService;
@@ -10306,16 +11113,24 @@ declare class FrameCoreService {
10306
11113
  * @param frameName - Target frame name (e.g., "1m", "1h")
10307
11114
  * @returns Promise resolving to array of Date objects
10308
11115
  */
10309
- getTimeframe: (symbol: string, frameName: string) => Promise<Date[]>;
11116
+ getTimeframe: (symbol: string, frameName: FrameName) => Promise<Date[]>;
10310
11117
  }
10311
11118
 
11119
+ /**
11120
+ * Type definition for sizing methods.
11121
+ * Maps all keys of ISizing to any type.
11122
+ * Used for dynamic method routing in SizingGlobalService.
11123
+ */
11124
+ type TSizing = {
11125
+ [key in keyof ISizing]: any;
11126
+ };
10312
11127
  /**
10313
11128
  * Global service for sizing operations.
10314
11129
  *
10315
11130
  * Wraps SizingConnectionService for position size calculation.
10316
11131
  * Used internally by strategy execution and public API.
10317
11132
  */
10318
- declare class SizingGlobalService {
11133
+ declare class SizingGlobalService implements TSizing {
10319
11134
  private readonly loggerService;
10320
11135
  private readonly sizingConnectionService;
10321
11136
  private readonly sizingValidationService;
@@ -10331,13 +11146,21 @@ declare class SizingGlobalService {
10331
11146
  }) => Promise<number>;
10332
11147
  }
10333
11148
 
11149
+ /**
11150
+ * Type definition for risk methods.
11151
+ * Maps all keys of IRisk to any type.
11152
+ * Used for dynamic method routing in RiskGlobalService.
11153
+ */
11154
+ type TRisk = {
11155
+ [key in keyof IRisk]: any;
11156
+ };
10334
11157
  /**
10335
11158
  * Global service for risk operations.
10336
11159
  *
10337
11160
  * Wraps RiskConnectionService for risk limit validation.
10338
11161
  * Used internally by strategy execution and public API.
10339
11162
  */
10340
- declare class RiskGlobalService {
11163
+ declare class RiskGlobalService implements TRisk {
10341
11164
  private readonly loggerService;
10342
11165
  private readonly riskConnectionService;
10343
11166
  private readonly riskValidationService;
@@ -10358,8 +11181,8 @@ declare class RiskGlobalService {
10358
11181
  */
10359
11182
  checkSignal: (params: IRiskCheckArgs, payload: {
10360
11183
  riskName: RiskName;
10361
- exchangeName: string;
10362
- frameName: string;
11184
+ exchangeName: ExchangeName;
11185
+ frameName: FrameName;
10363
11186
  backtest: boolean;
10364
11187
  }) => Promise<boolean>;
10365
11188
  /**
@@ -10369,10 +11192,10 @@ declare class RiskGlobalService {
10369
11192
  * @param payload - Payload information (strategyName, riskName, exchangeName, frameName, backtest)
10370
11193
  */
10371
11194
  addSignal: (symbol: string, payload: {
10372
- strategyName: string;
11195
+ strategyName: StrategyName;
10373
11196
  riskName: RiskName;
10374
- exchangeName: string;
10375
- frameName: string;
11197
+ exchangeName: ExchangeName;
11198
+ frameName: FrameName;
10376
11199
  backtest: boolean;
10377
11200
  }) => Promise<void>;
10378
11201
  /**
@@ -10382,10 +11205,10 @@ declare class RiskGlobalService {
10382
11205
  * @param payload - Payload information (strategyName, riskName, exchangeName, frameName, backtest)
10383
11206
  */
10384
11207
  removeSignal: (symbol: string, payload: {
10385
- strategyName: string;
11208
+ strategyName: StrategyName;
10386
11209
  riskName: RiskName;
10387
- exchangeName: string;
10388
- frameName: string;
11210
+ exchangeName: ExchangeName;
11211
+ frameName: FrameName;
10389
11212
  backtest: boolean;
10390
11213
  }) => Promise<void>;
10391
11214
  /**
@@ -10396,19 +11219,133 @@ declare class RiskGlobalService {
10396
11219
  */
10397
11220
  clear: (payload?: {
10398
11221
  riskName: RiskName;
10399
- exchangeName: string;
10400
- frameName: string;
11222
+ exchangeName: ExchangeName;
11223
+ frameName: FrameName;
10401
11224
  backtest: boolean;
10402
11225
  }) => Promise<void>;
10403
11226
  }
10404
11227
 
11228
+ /**
11229
+ * Private service for walker orchestration (strategy comparison).
11230
+ *
11231
+ * Flow:
11232
+ * 1. Yields progress updates as each strategy completes
11233
+ * 2. Tracks best metric in real-time
11234
+ * 3. Returns final results with all strategies ranked
11235
+ *
11236
+ * Uses BacktestLogicPublicService internally for each strategy.
11237
+ */
11238
+ declare class WalkerLogicPrivateService {
11239
+ private readonly loggerService;
11240
+ private readonly backtestLogicPublicService;
11241
+ private readonly backtestMarkdownService;
11242
+ private readonly walkerSchemaService;
11243
+ /**
11244
+ * Runs walker comparison for a symbol.
11245
+ *
11246
+ * Executes backtest for each strategy sequentially.
11247
+ * Yields WalkerContract after each strategy completes.
11248
+ *
11249
+ * @param symbol - Trading pair symbol (e.g., "BTCUSDT")
11250
+ * @param strategies - List of strategy names to compare
11251
+ * @param metric - Metric to use for comparison
11252
+ * @param context - Walker context with exchangeName, frameName, walkerName
11253
+ * @yields WalkerContract with progress after each strategy
11254
+ *
11255
+ * @example
11256
+ * ```typescript
11257
+ * for await (const progress of walkerLogic.run(
11258
+ * "BTCUSDT",
11259
+ * ["strategy-v1", "strategy-v2"],
11260
+ * "sharpeRatio",
11261
+ * {
11262
+ * exchangeName: "binance",
11263
+ * frameName: "1d-backtest",
11264
+ * walkerName: "my-optimizer"
11265
+ * }
11266
+ * )) {
11267
+ * console.log("Progress:", progress.strategiesTested, "/", progress.totalStrategies);
11268
+ * }
11269
+ * ```
11270
+ */
11271
+ run(symbol: string, strategies: StrategyName[], metric: WalkerMetric, context: {
11272
+ exchangeName: ExchangeName;
11273
+ frameName: FrameName;
11274
+ walkerName: WalkerName;
11275
+ }): AsyncGenerator<WalkerContract>;
11276
+ }
11277
+
11278
+ /**
11279
+ * Type definition for public WalkerLogic service.
11280
+ * Omits private dependencies from WalkerLogicPrivateService.
11281
+ */
11282
+ type IWalkerLogicPrivateService = Omit<WalkerLogicPrivateService, keyof {
11283
+ loggerService: never;
11284
+ walkerSchemaService: never;
11285
+ backtestMarkdownService: never;
11286
+ backtestLogicPublicService: never;
11287
+ }>;
11288
+ /**
11289
+ * Type definition for WalkerLogicPublicService.
11290
+ * Maps all keys of IWalkerLogicPrivateService to any type.
11291
+ */
11292
+ type TWalkerLogicPrivateService = {
11293
+ [key in keyof IWalkerLogicPrivateService]: any;
11294
+ };
11295
+ /**
11296
+ * Public service for walker orchestration with context management.
11297
+ *
11298
+ * Wraps WalkerLogicPrivateService with MethodContextService to provide
11299
+ * implicit context propagation for strategyName, exchangeName, frameName, and walkerName.
11300
+ *
11301
+ * @example
11302
+ * ```typescript
11303
+ * const walkerLogicPublicService = inject(TYPES.walkerLogicPublicService);
11304
+ *
11305
+ * const results = await walkerLogicPublicService.run("BTCUSDT", {
11306
+ * walkerName: "my-optimizer",
11307
+ * exchangeName: "binance",
11308
+ * frameName: "1d-backtest",
11309
+ * strategies: ["strategy-v1", "strategy-v2"],
11310
+ * metric: "sharpeRatio",
11311
+ * });
11312
+ *
11313
+ * console.log("Best strategy:", results.bestStrategy);
11314
+ * ```
11315
+ */
11316
+ declare class WalkerLogicPublicService implements TWalkerLogicPrivateService {
11317
+ private readonly loggerService;
11318
+ private readonly walkerLogicPrivateService;
11319
+ private readonly walkerSchemaService;
11320
+ /**
11321
+ * Runs walker comparison for a symbol with context propagation.
11322
+ *
11323
+ * Executes backtests for all strategies.
11324
+ *
11325
+ * @param symbol - Trading pair symbol (e.g., "BTCUSDT")
11326
+ * @param context - Walker context with strategies and metric
11327
+ */
11328
+ run: (symbol: string, context: {
11329
+ walkerName: WalkerName;
11330
+ exchangeName: ExchangeName;
11331
+ frameName: FrameName;
11332
+ }) => AsyncGenerator<WalkerContract, any, any>;
11333
+ }
11334
+
11335
+ /**
11336
+ * Type definition for WalkerLogicPublicService.
11337
+ * Maps all keys of WalkerLogicPublicService to any type.
11338
+ */
11339
+ type TWalkerLogicPublicService = {
11340
+ [key in keyof WalkerLogicPublicService]: any;
11341
+ };
10405
11342
  /**
10406
11343
  * Global service providing access to walker functionality.
10407
11344
  *
10408
11345
  * Simple wrapper around WalkerLogicPublicService for dependency injection.
10409
11346
  * Used by public API exports.
10410
11347
  */
10411
- declare class WalkerCommandService {
11348
+ declare class WalkerCommandService implements TWalkerLogicPublicService {
10412
11349
  private readonly loggerService;
10413
11350
  private readonly walkerLogicPublicService;
10414
11351
  private readonly walkerSchemaService;
@@ -10425,9 +11362,9 @@ declare class WalkerCommandService {
10425
11362
  * @param context - Walker context with strategies and metric
10426
11363
  */
10427
11364
  run: (symbol: string, context: {
10428
- walkerName: string;
10429
- exchangeName: string;
10430
- frameName: string;
11365
+ walkerName: WalkerName;
11366
+ exchangeName: ExchangeName;
11367
+ frameName: FrameName;
10431
11368
  }) => AsyncGenerator<WalkerContract, any, any>;
10432
11369
  }
10433
11370
 
@@ -10753,55 +11690,23 @@ declare class LiveLogicPrivateService {
10753
11690
  }
10754
11691
 
10755
11692
  /**
10756
- * Private service for walker orchestration (strategy comparison).
10757
- *
10758
- * Flow:
10759
- * 1. Yields progress updates as each strategy completes
10760
- * 2. Tracks best metric in real-time
10761
- * 3. Returns final results with all strategies ranked
10762
- *
10763
- * Uses BacktestLogicPublicService internally for each strategy.
11693
+ * Type definition for public BacktestLogic service.
11694
+ * Omits private dependencies from BacktestLogicPrivateService.
10764
11695
  */
10765
- declare class WalkerLogicPrivateService {
10766
- private readonly loggerService;
10767
- private readonly backtestLogicPublicService;
10768
- private readonly backtestMarkdownService;
10769
- private readonly walkerSchemaService;
10770
- /**
10771
- * Runs walker comparison for a symbol.
10772
- *
10773
- * Executes backtest for each strategy sequentially.
10774
- * Yields WalkerContract after each strategy completes.
10775
- *
10776
- * @param symbol - Trading pair symbol (e.g., "BTCUSDT")
10777
- * @param strategies - List of strategy names to compare
10778
- * @param metric - Metric to use for comparison
10779
- * @param context - Walker context with exchangeName, frameName, walkerName
10780
- * @yields WalkerContract with progress after each strategy
10781
- *
10782
- * @example
10783
- * ```typescript
10784
- * for await (const progress of walkerLogic.run(
10785
- * "BTCUSDT",
10786
- * ["strategy-v1", "strategy-v2"],
10787
- * "sharpeRatio",
10788
- * {
10789
- * exchangeName: "binance",
10790
- * frameName: "1d-backtest",
10791
- * walkerName: "my-optimizer"
10792
- * }
10793
- * )) {
10794
- * console.log("Progress:", progress.strategiesTested, "/", progress.totalStrategies);
10795
- * }
10796
- * ```
10797
- */
10798
- run(symbol: string, strategies: StrategyName[], metric: WalkerMetric, context: {
10799
- exchangeName: string;
10800
- frameName: string;
10801
- walkerName: string;
10802
- }): AsyncGenerator<WalkerContract>;
10803
- }
10804
-
11696
+ type IBacktestLogicPrivateService = Omit<BacktestLogicPrivateService, keyof {
11697
+ loggerService: never;
11698
+ strategyCoreService: never;
11699
+ exchangeCoreService: never;
11700
+ frameCoreService: never;
11701
+ methodContextService: never;
11702
+ }>;
11703
+ /**
11704
+ * Type definition for BacktestLogicPublicService.
11705
+ * Maps all keys of IBacktestLogicPrivateService to any type.
11706
+ */
11707
+ type TBacktestLogicPrivateService = {
11708
+ [key in keyof IBacktestLogicPrivateService]: any;
11709
+ };
10805
11710
  /**
10806
11711
  * Public service for backtest orchestration with context management.
10807
11712
  *
@@ -10826,7 +11731,7 @@ declare class WalkerLogicPrivateService {
10826
11731
  * }
10827
11732
  * ```
10828
11733
  */
10829
- declare class BacktestLogicPublicService {
11734
+ declare class BacktestLogicPublicService implements TBacktestLogicPrivateService {
10830
11735
  private readonly loggerService;
10831
11736
  private readonly backtestLogicPrivateService;
10832
11737
  /**
@@ -10840,12 +11745,28 @@ declare class BacktestLogicPublicService {
10840
11745
  * @returns Async generator yielding closed signals with PNL
10841
11746
  */
10842
11747
  run: (symbol: string, context: {
10843
- strategyName: string;
10844
- exchangeName: string;
10845
- frameName: string;
11748
+ strategyName: StrategyName;
11749
+ exchangeName: ExchangeName;
11750
+ frameName: FrameName;
10846
11751
  }) => AsyncGenerator<IStrategyBacktestResult, void, unknown>;
10847
11752
  }
10848
11753
 
11754
+ /**
11755
+ * Type definition for public LiveLogic service.
11756
+ * Omits private dependencies from LiveLogicPrivateService.
11757
+ */
11758
+ type ILiveLogicPrivateService = Omit<LiveLogicPrivateService, keyof {
11759
+ loggerService: never;
11760
+ strategyCoreService: never;
11761
+ methodContextService: never;
11762
+ }>;
11763
+ /**
11764
+ * Type definition for LiveLogicPublicService.
11765
+ * Maps all keys of ILiveLogicPrivateService to any type.
11766
+ */
11767
+ type TLiveLogicPrivateService = {
11768
+ [key in keyof ILiveLogicPrivateService]: any;
11769
+ };
10849
11770
  /**
10850
11771
  * Public service for live trading orchestration with context management.
10851
11772
  *
@@ -10877,7 +11798,7 @@ declare class BacktestLogicPublicService {
10877
11798
  * }
10878
11799
  * ```
10879
11800
  */
10880
- declare class LiveLogicPublicService {
11801
+ declare class LiveLogicPublicService implements TLiveLogicPrivateService {
10881
11802
  private readonly loggerService;
10882
11803
  private readonly liveLogicPrivateService;
10883
11804
  /**
@@ -10892,58 +11813,25 @@ declare class LiveLogicPublicService {
10892
11813
  * @returns Infinite async generator yielding opened and closed signals
10893
11814
  */
10894
11815
  run: (symbol: string, context: {
10895
- strategyName: string;
10896
- exchangeName: string;
11816
+ strategyName: StrategyName;
11817
+ exchangeName: ExchangeName;
10897
11818
  }) => AsyncGenerator<IStrategyTickResultOpened | IStrategyTickResultClosed, void, unknown>;
10898
11819
  }
10899
11820
 
10900
11821
  /**
10901
- * Public service for walker orchestration with context management.
10902
- *
10903
- * Wraps WalkerLogicPrivateService with MethodContextService to provide
10904
- * implicit context propagation for strategyName, exchangeName, frameName, and walkerName.
10905
- *
10906
- * @example
10907
- * ```typescript
10908
- * const walkerLogicPublicService = inject(TYPES.walkerLogicPublicService);
10909
- *
10910
- * const results = await walkerLogicPublicService.run("BTCUSDT", {
10911
- * walkerName: "my-optimizer",
10912
- * exchangeName: "binance",
10913
- * frameName: "1d-backtest",
10914
- * strategies: ["strategy-v1", "strategy-v2"],
10915
- * metric: "sharpeRatio",
10916
- * });
10917
- *
10918
- * console.log("Best strategy:", results.bestStrategy);
10919
- * ```
11822
+ * Type definition for LiveLogicPublicService.
11823
+ * Maps all keys of LiveLogicPublicService to any type.
10920
11824
  */
10921
- declare class WalkerLogicPublicService {
10922
- private readonly loggerService;
10923
- private readonly walkerLogicPrivateService;
10924
- private readonly walkerSchemaService;
10925
- /**
10926
- * Runs walker comparison for a symbol with context propagation.
10927
- *
10928
- * Executes backtests for all strategies.
10929
- *
10930
- * @param symbol - Trading pair symbol (e.g., "BTCUSDT")
10931
- * @param context - Walker context with strategies and metric
10932
- */
10933
- run: (symbol: string, context: {
10934
- walkerName: string;
10935
- exchangeName: string;
10936
- frameName: string;
10937
- }) => AsyncGenerator<WalkerContract, any, any>;
10938
- }
10939
-
11825
+ type TLiveLogicPublicService = {
11826
+ [key in keyof LiveLogicPublicService]: any;
11827
+ };
10940
11828
  /**
10941
11829
  * Global service providing access to live trading functionality.
10942
11830
  *
10943
11831
  * Simple wrapper around LiveLogicPublicService for dependency injection.
10944
11832
  * Used by public API exports.
10945
11833
  */
10946
- declare class LiveCommandService {
11834
+ declare class LiveCommandService implements TLiveLogicPublicService {
10947
11835
  private readonly loggerService;
10948
11836
  private readonly liveLogicPublicService;
10949
11837
  private readonly strategyValidationService;
@@ -10960,18 +11848,25 @@ declare class LiveCommandService {
10960
11848
  * @returns Infinite async generator yielding opened and closed signals
10961
11849
  */
10962
11850
  run: (symbol: string, context: {
10963
- strategyName: string;
10964
- exchangeName: string;
11851
+ strategyName: StrategyName;
11852
+ exchangeName: ExchangeName;
10965
11853
  }) => AsyncGenerator<IStrategyTickResultOpened | IStrategyTickResultClosed, void, unknown>;
10966
11854
  }
10967
11855
 
11856
+ /**
11857
+ * Type definition for BacktestLogicPublicService.
11858
+ * Maps all keys of BacktestLogicPublicService to any type.
11859
+ */
11860
+ type TBacktestLogicPublicService = {
11861
+ [key in keyof BacktestLogicPublicService]: any;
11862
+ };
10968
11863
  /**
10969
11864
  * Global service providing access to backtest functionality.
10970
11865
  *
10971
11866
  * Simple wrapper around BacktestLogicPublicService for dependency injection.
10972
11867
  * Used by public API exports.
10973
11868
  */
10974
- declare class BacktestCommandService {
11869
+ declare class BacktestCommandService implements TBacktestLogicPublicService {
10975
11870
  private readonly loggerService;
10976
11871
  private readonly strategySchemaService;
10977
11872
  private readonly riskValidationService;
@@ -10987,9 +11882,9 @@ declare class BacktestCommandService {
10987
11882
  * @returns Async generator yielding closed signals with PNL
10988
11883
  */
10989
11884
  run: (symbol: string, context: {
10990
- strategyName: string;
10991
- exchangeName: string;
10992
- frameName: string;
11885
+ strategyName: StrategyName;
11886
+ exchangeName: ExchangeName;
11887
+ frameName: FrameName;
10993
11888
  }) => AsyncGenerator<IStrategyBacktestResult, void, unknown>;
10994
11889
  }
10995
11890
 
@@ -11393,7 +12288,7 @@ declare class OptimizerTemplateService implements IOptimizerTemplate {
11393
12288
  * @param strategies - Array of strategy names to compare
11394
12289
  * @returns Generated addWalker() call
11395
12290
  */
11396
- getWalkerTemplate: (walkerName: string, exchangeName: string, frameName: string, strategies: string[]) => Promise<string>;
12291
+ getWalkerTemplate: (walkerName: WalkerName, exchangeName: ExchangeName, frameName: FrameName, strategies: string[]) => Promise<string>;
11397
12292
  /**
11398
12293
  * Generates Strategy configuration with LLM integration.
11399
12294
  * Includes multi-timeframe analysis and signal generation.
@@ -11403,7 +12298,7 @@ declare class OptimizerTemplateService implements IOptimizerTemplate {
11403
12298
  * @param prompt - Strategy logic from getPrompt()
11404
12299
  * @returns Generated addStrategy() call with getSignal() function
11405
12300
  */
11406
- getStrategyTemplate: (strategyName: string, interval: string, prompt: string) => Promise<string>;
12301
+ getStrategyTemplate: (strategyName: StrategyName, interval: CandleInterval, prompt: string) => Promise<string>;
11407
12302
  /**
11408
12303
  * Generates Exchange configuration code.
11409
12304
  * Uses CCXT Binance with standard formatters.
@@ -11423,7 +12318,7 @@ declare class OptimizerTemplateService implements IOptimizerTemplate {
11423
12318
  * @param endDate - Frame end date
11424
12319
  * @returns Generated addFrame() call
11425
12320
  */
11426
- getFrameTemplate: (symbol: string, frameName: string, interval: CandleInterval, startDate: Date, endDate: Date) => Promise<string>;
12321
+ getFrameTemplate: (symbol: string, frameName: FrameName, interval: CandleInterval, startDate: Date, endDate: Date) => Promise<string>;
11427
12322
  /**
11428
12323
  * Generates launcher code to run Walker with event listeners.
11429
12324
  * Includes progress tracking and completion handlers.
@@ -11432,7 +12327,7 @@ declare class OptimizerTemplateService implements IOptimizerTemplate {
11432
12327
  * @param walkerName - Walker name to launch
11433
12328
  * @returns Generated Walker.background() call with listeners
11434
12329
  */
11435
- getLauncherTemplate: (symbol: string, walkerName: string) => Promise<string>;
12330
+ getLauncherTemplate: (symbol: string, walkerName: WalkerName) => Promise<string>;
11436
12331
  /**
11437
12332
  * Generates dumpJson() helper function for debug output.
11438
12333
  * Saves LLM conversations and results to ./dump/strategy/{resultId}/
@@ -11593,7 +12488,7 @@ declare class ClientOptimizer implements IOptimizer {
11593
12488
  * Type helper for optimizer method signatures.
11594
12489
  * Maps IOptimizer interface methods to any return type.
11595
12490
  */
11596
- type TOptimizer = {
12491
+ type TOptimizer$1 = {
11597
12492
  [key in keyof IOptimizer]: any;
11598
12493
  };
11599
12494
  /**
@@ -11606,7 +12501,7 @@ type TOptimizer = {
11606
12501
  * - Logger injection
11607
12502
  * - Delegates to ClientOptimizer for actual operations
11608
12503
  */
11609
- declare class OptimizerConnectionService implements TOptimizer {
12504
+ declare class OptimizerConnectionService implements TOptimizer$1 {
11610
12505
  private readonly loggerService;
11611
12506
  private readonly optimizerSchemaService;
11612
12507
  private readonly optimizerTemplateService;
@@ -11646,6 +12541,14 @@ declare class OptimizerConnectionService implements TOptimizer {
11646
12541
  dump: (symbol: string, optimizerName: string, path?: string) => Promise<void>;
11647
12542
  }
11648
12543
 
12544
+ /**
12545
+ * Type definition for optimizer methods.
12546
+ * Maps all keys of IOptimizer to any type.
12547
+ * Used for dynamic method routing in OptimizerGlobalService.
12548
+ */
12549
+ type TOptimizer = {
12550
+ [key in keyof IOptimizer]: any;
12551
+ };
11649
12552
  /**
11650
12553
  * Global service for optimizer operations with validation.
11651
12554
  * Entry point for public API, performs validation before delegating to ConnectionService.
@@ -11655,7 +12558,7 @@ declare class OptimizerConnectionService implements TOptimizer {
11655
12558
  * 2. Validate optimizer exists
11656
12559
  * 3. Delegate to OptimizerConnectionService
11657
12560
  */
11658
- declare class OptimizerGlobalService {
12561
+ declare class OptimizerGlobalService implements TOptimizer {
11659
12562
  private readonly loggerService;
11660
12563
  private readonly optimizerConnectionService;
11661
12564
  private readonly optimizerValidationService;
@@ -11691,6 +12594,14 @@ declare class OptimizerGlobalService {
11691
12594
  dump: (symbol: string, optimizerName: string, path?: string) => Promise<void>;
11692
12595
  }
11693
12596
 
12597
+ /**
12598
+ * Type definition for partial methods.
12599
+ * Maps all keys of IPartial to any type.
12600
+ * Used for dynamic method routing in PartialGlobalService.
12601
+ */
12602
+ type TPartial = {
12603
+ [key in keyof IPartial]: any;
12604
+ };
11694
12605
  /**
11695
12606
  * Global service for partial profit/loss tracking.
11696
12607
  *
@@ -11720,7 +12631,7 @@ declare class OptimizerGlobalService {
11720
12631
  * // Logs at global level → delegates to PartialConnectionService
11721
12632
  * ```
11722
12633
  */
11723
- declare class PartialGlobalService {
12634
+ declare class PartialGlobalService implements TPartial {
11724
12635
  /**
11725
12636
  * Logger service injected from DI container.
11726
12637
  * Used for logging operations at global service level.
@@ -11764,7 +12675,7 @@ declare class PartialGlobalService {
11764
12675
  * @param when - Event timestamp (current time for live, candle time for backtest)
11765
12676
  * @returns Promise that resolves when profit processing is complete
11766
12677
  */
11767
- profit: (symbol: string, data: ISignalRow, currentPrice: number, revenuePercent: number, backtest: boolean, when: Date) => Promise<void>;
12678
+ profit: (symbol: string, data: IPublicSignalRow, currentPrice: number, revenuePercent: number, backtest: boolean, when: Date) => Promise<void>;
11768
12679
  /**
11769
12680
  * Processes loss state and emits events for newly reached loss levels.
11770
12681
  *
@@ -11778,7 +12689,7 @@ declare class PartialGlobalService {
11778
12689
  * @param when - Event timestamp (current time for live, candle time for backtest)
11779
12690
  * @returns Promise that resolves when loss processing is complete
11780
12691
  */
11781
- loss: (symbol: string, data: ISignalRow, currentPrice: number, lossPercent: number, backtest: boolean, when: Date) => Promise<void>;
12692
+ loss: (symbol: string, data: IPublicSignalRow, currentPrice: number, lossPercent: number, backtest: boolean, when: Date) => Promise<void>;
11782
12693
  /**
11783
12694
  * Clears partial profit/loss state when signal closes.
11784
12695
  *
@@ -11997,4 +12908,4 @@ declare const backtest: {
11997
12908
  loggerService: LoggerService;
11998
12909
  };
11999
12910
 
12000
- export { Backtest, type BacktestDoneNotification, type BacktestStatisticsModel, type BootstrapNotification, Cache, type CandleInterval, type ColumnConfig, type ColumnModel, Constant, type CriticalErrorNotification, type DoneContract, type EntityId, Exchange, ExecutionContextService, type FrameInterval, type GlobalConfig, Heat, type HeatmapStatisticsModel, type ICandleData, type IExchangeSchema, type IFrameSchema, type IHeatmapRow, type IOptimizerCallbacks, type IOptimizerData, type IOptimizerFetchArgs, type IOptimizerFilterArgs, type IOptimizerRange, type IOptimizerSchema, type IOptimizerSource, type IOptimizerStrategy, type IOptimizerTemplate, type IPersistBase, type IPositionSizeATRParams, type IPositionSizeFixedPercentageParams, type IPositionSizeKellyParams, 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, type MessageModel, type MessageRole, MethodContextService, type MetricStats, Notification, type NotificationModel, Optimizer, 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, PersistPartialAdapter, PersistRiskAdapter, PersistScheduleAdapter, PersistSignalAdapter, type PingContract, PositionSize, type ProgressBacktestContract, type ProgressBacktestNotification, type ProgressOptimizerContract, type ProgressWalkerContract, Risk, type RiskContract, type RiskData, type RiskEvent, type RiskRejectionNotification, type RiskStatisticsModel, Schedule, type ScheduleData, type ScheduleStatisticsModel, type ScheduledEvent, type SignalCancelledNotification, type SignalClosedNotification, type SignalData, type SignalInterval, type SignalOpenedNotification, type SignalScheduledNotification, type TPersistBase, type TPersistBaseCtor, type TickEvent, type ValidationErrorNotification, Walker, type WalkerCompleteContract, type WalkerContract, type WalkerMetric, type SignalData$1 as WalkerSignalData, type WalkerStatisticsModel, addExchange, addFrame, addOptimizer, addRisk, addSizing, addStrategy, addWalker, cancel, dumpSignal, emitters, formatPrice, formatQuantity, getAveragePrice, getCandles, getColumns, getConfig, getDate, getDefaultColumns, getDefaultConfig, getMode, hasTradeContext, backtest as lib, listExchanges, listFrames, listOptimizers, listRisks, listSizings, listStrategies, listWalkers, listenBacktestProgress, listenDoneBacktest, listenDoneBacktestOnce, listenDoneLive, listenDoneLiveOnce, listenDoneWalker, listenDoneWalkerOnce, listenError, listenExit, listenOptimizerProgress, listenPartialLoss, listenPartialLossOnce, listenPartialProfit, listenPartialProfitOnce, listenPerformance, listenPing, listenPingOnce, listenRisk, listenRiskOnce, listenSignal, listenSignalBacktest, listenSignalBacktestOnce, listenSignalLive, listenSignalLiveOnce, listenSignalOnce, listenValidation, listenWalker, listenWalkerComplete, listenWalkerOnce, listenWalkerProgress, setColumns, setConfig, setLogger, stop, validate };
12911
+ export { Backtest, type BacktestDoneNotification, type BacktestStatisticsModel, type BootstrapNotification, Cache, type CandleInterval, type ColumnConfig, type ColumnModel, Constant, type CriticalErrorNotification, type DoneContract, type EntityId, Exchange, ExecutionContextService, type FrameInterval, type GlobalConfig, Heat, type HeatmapStatisticsModel, type ICandleData, type IExchangeSchema, type IFrameSchema, type IHeatmapRow, type IOptimizerCallbacks, type IOptimizerData, type IOptimizerFetchArgs, type IOptimizerFilterArgs, type IOptimizerRange, type IOptimizerSchema, type IOptimizerSource, type IOptimizerStrategy, type IOptimizerTemplate, type IPersistBase, type IPositionSizeATRParams, type IPositionSizeFixedPercentageParams, type IPositionSizeKellyParams, type IPublicSignalRow, 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, type MessageModel, type MessageRole, MethodContextService, type MetricStats, Notification, type NotificationModel, Optimizer, 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, PersistPartialAdapter, PersistRiskAdapter, PersistScheduleAdapter, PersistSignalAdapter, type PingContract, PositionSize, type ProgressBacktestContract, type ProgressBacktestNotification, type ProgressOptimizerContract, type ProgressWalkerContract, Risk, type RiskContract, type RiskData, type RiskEvent, type RiskRejectionNotification, type RiskStatisticsModel, Schedule, type ScheduleData, type ScheduleStatisticsModel, type ScheduledEvent, type SignalCancelledNotification, type SignalClosedNotification, type SignalData, type SignalInterval, type SignalOpenedNotification, type SignalScheduledNotification, type TPersistBase, type TPersistBaseCtor, type TickEvent, type ValidationErrorNotification, Walker, type WalkerCompleteContract, type WalkerContract, type WalkerMetric, type SignalData$1 as WalkerSignalData, type WalkerStatisticsModel, addExchange, addFrame, addOptimizer, addRisk, addSizing, addStrategy, addWalker, cancel, dumpSignal, emitters, formatPrice, formatQuantity, getAveragePrice, getCandles, getColumns, getConfig, getDate, getDefaultColumns, getDefaultConfig, getMode, hasTradeContext, backtest as lib, listExchanges, listFrames, listOptimizers, listRisks, listSizings, listStrategies, listWalkers, listenBacktestProgress, listenDoneBacktest, listenDoneBacktestOnce, listenDoneLive, listenDoneLiveOnce, listenDoneWalker, listenDoneWalkerOnce, listenError, listenExit, listenOptimizerProgress, listenPartialLoss, listenPartialLossOnce, listenPartialProfit, listenPartialProfitOnce, listenPerformance, listenPing, listenPingOnce, listenRisk, listenRiskOnce, listenSignal, listenSignalBacktest, listenSignalBacktestOnce, listenSignalLive, listenSignalLiveOnce, listenSignalOnce, listenValidation, listenWalker, listenWalkerComplete, listenWalkerOnce, listenWalkerProgress, partialLoss, partialProfit, setColumns, setConfig, setLogger, stop, trailingStop, validate };