backtest-kit 3.8.1 → 4.0.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.
package/types.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import * as di_scoped from 'di-scoped';
2
- import SignalSyncContract$1 from 'src/contract/SignalSync.contract';
3
2
  import * as functools_kit from 'functools-kit';
4
3
  import { Subject } from 'functools-kit';
5
4
  import { WriteStream } from 'fs';
@@ -2986,6 +2985,25 @@ interface IStrategy {
2986
2985
  * ```
2987
2986
  */
2988
2987
  partialProfit: (symbol: string, percentToClose: number, currentPrice: number, backtest: boolean) => Promise<boolean>;
2988
+ /**
2989
+ * Checks whether `partialProfit` would succeed without executing it.
2990
+ *
2991
+ * Returns `true` if all preconditions for a profitable partial close are met:
2992
+ * - Active pending signal exists
2993
+ * - `percentToClose` is a finite number in range (0, 100]
2994
+ * - `currentPrice` is a positive finite number
2995
+ * - Price is moving toward TP (not toward SL) relative to effective entry
2996
+ * - Price has not already crossed the TP level
2997
+ * - Closing the given percentage would not exceed 100% total closed
2998
+ *
2999
+ * Never throws. Safe to call at any time as a pre-flight check.
3000
+ *
3001
+ * @param symbol - Trading pair symbol (e.g., "BTCUSDT")
3002
+ * @param percentToClose - Percentage of position to check (0-100]
3003
+ * @param currentPrice - Current market price to validate against
3004
+ * @returns `true` if `partialProfit` would execute, `false` otherwise
3005
+ */
3006
+ validatePartialProfit: (symbol: string, percentToClose: number, currentPrice: number) => Promise<boolean>;
2989
3007
  /**
2990
3008
  * Executes partial close at loss level (moving toward SL).
2991
3009
  *
@@ -3022,6 +3040,25 @@ interface IStrategy {
3022
3040
  * ```
3023
3041
  */
3024
3042
  partialLoss: (symbol: string, percentToClose: number, currentPrice: number, backtest: boolean) => Promise<boolean>;
3043
+ /**
3044
+ * Checks whether `partialLoss` would succeed without executing it.
3045
+ *
3046
+ * Returns `true` if all preconditions for a loss-side partial close are met:
3047
+ * - Active pending signal exists
3048
+ * - `percentToClose` is a finite number in range (0, 100]
3049
+ * - `currentPrice` is a positive finite number
3050
+ * - Price is moving toward SL (not toward TP) relative to effective entry
3051
+ * - Price has not already crossed the SL level
3052
+ * - Closing the given percentage would not exceed 100% total closed
3053
+ *
3054
+ * Never throws. Safe to call at any time as a pre-flight check.
3055
+ *
3056
+ * @param symbol - Trading pair symbol (e.g., "BTCUSDT")
3057
+ * @param percentToClose - Percentage of position to check (0-100]
3058
+ * @param currentPrice - Current market price to validate against
3059
+ * @returns `true` if `partialLoss` would execute, `false` otherwise
3060
+ */
3061
+ validatePartialLoss: (symbol: string, percentToClose: number, currentPrice: number) => Promise<boolean>;
3025
3062
  /**
3026
3063
  * Adjusts trailing stop-loss by shifting distance between entry and original SL.
3027
3064
  *
@@ -3087,6 +3124,25 @@ interface IStrategy {
3087
3124
  * ```
3088
3125
  */
3089
3126
  trailingStop: (symbol: string, percentShift: number, currentPrice: number, backtest: boolean) => Promise<boolean>;
3127
+ /**
3128
+ * Checks whether `trailingStop` would succeed without executing it.
3129
+ *
3130
+ * Returns `true` if all preconditions for a trailing SL update are met:
3131
+ * - Active pending signal exists
3132
+ * - `percentShift` is a finite number in [-100, 100], non-zero
3133
+ * - `currentPrice` is a positive finite number
3134
+ * - Computed new SL does not intrude current price (price hasn't crossed it)
3135
+ * - New SL does not conflict with effective TP (SL must remain on the safe side)
3136
+ * - If a trailing SL already exists, new SL offers better protection (absorption rule)
3137
+ *
3138
+ * Never throws. Safe to call at any time as a pre-flight check.
3139
+ *
3140
+ * @param symbol - Trading pair symbol (e.g., "BTCUSDT")
3141
+ * @param percentShift - Percentage shift of ORIGINAL SL distance [-100, 100], excluding 0
3142
+ * @param currentPrice - Current market price to validate against
3143
+ * @returns `true` if `trailingStop` would execute, `false` otherwise
3144
+ */
3145
+ validateTrailingStop: (symbol: string, percentShift: number, currentPrice: number) => Promise<boolean>;
3090
3146
  /**
3091
3147
  * Adjusts the trailing take-profit distance for an active pending signal.
3092
3148
  *
@@ -3136,6 +3192,26 @@ interface IStrategy {
3136
3192
  * ```
3137
3193
  */
3138
3194
  trailingTake: (symbol: string, percentShift: number, currentPrice: number, backtest: boolean) => Promise<boolean>;
3195
+ /**
3196
+ * Checks whether `trailingTake` would succeed without executing it.
3197
+ *
3198
+ * Returns `true` if all preconditions for a trailing TP update are met:
3199
+ * - Active pending signal exists
3200
+ * - `percentShift` is a finite number in [-100, 100], non-zero
3201
+ * - `currentPrice` is a positive finite number
3202
+ * - Computed new TP does not intrude current price (price hasn't crossed it)
3203
+ * - New TP does not conflict with effective SL (TP must remain on the profit side)
3204
+ * - If a trailing TP already exists, new TP is more conservative (absorption rule:
3205
+ * LONG accepts only lower TP, SHORT accepts only higher TP)
3206
+ *
3207
+ * Never throws. Safe to call at any time as a pre-flight check.
3208
+ *
3209
+ * @param symbol - Trading pair symbol (e.g., "BTCUSDT")
3210
+ * @param percentShift - Percentage adjustment to ORIGINAL TP distance [-100, 100], excluding 0
3211
+ * @param currentPrice - Current market price to validate against
3212
+ * @returns `true` if `trailingTake` would execute, `false` otherwise
3213
+ */
3214
+ validateTrailingTake: (symbol: string, percentShift: number, currentPrice: number) => Promise<boolean>;
3139
3215
  /**
3140
3216
  * Moves stop-loss to breakeven (entry price) when price reaches threshold.
3141
3217
  *
@@ -3186,6 +3262,24 @@ interface IStrategy {
3186
3262
  * ```
3187
3263
  */
3188
3264
  breakeven: (symbol: string, currentPrice: number, backtest: boolean) => Promise<boolean>;
3265
+ /**
3266
+ * Checks whether `breakeven` would succeed without executing it.
3267
+ *
3268
+ * Returns `true` if all preconditions for moving SL to breakeven are met:
3269
+ * - Active pending signal exists
3270
+ * - `currentPrice` is a positive finite number
3271
+ * - Price has moved far enough in profit direction to cover costs
3272
+ * (threshold: `(CC_PERCENT_SLIPPAGE + CC_PERCENT_FEE) * 2`)
3273
+ * - Breakeven SL would not conflict with effective TP
3274
+ * - Breakeven has not already been set (idempotent — returns `false` on repeat)
3275
+ *
3276
+ * Never throws. Safe to call at any time as a pre-flight check.
3277
+ *
3278
+ * @param symbol - Trading pair symbol (e.g., "BTCUSDT")
3279
+ * @param currentPrice - Current market price to validate against
3280
+ * @returns `true` if `breakeven` would execute, `false` otherwise
3281
+ */
3282
+ validateBreakeven: (symbol: string, currentPrice: number) => Promise<boolean>;
3189
3283
  /**
3190
3284
  * Adds a new averaging entry to an open position (DCA — Dollar Cost Averaging).
3191
3285
  *
@@ -3207,6 +3301,24 @@ interface IStrategy {
3207
3301
  * @returns Promise<boolean> - true if entry added, false if rejected by direction check
3208
3302
  */
3209
3303
  averageBuy: (symbol: string, currentPrice: number, backtest: boolean) => Promise<boolean>;
3304
+ /**
3305
+ * Checks whether `averageBuy` would succeed without executing it.
3306
+ *
3307
+ * Returns `true` if all preconditions for a DCA entry are met:
3308
+ * - Active pending signal exists
3309
+ * - `currentPrice` is a positive finite number
3310
+ * - LONG: `currentPrice` is below the all-time lowest entry price
3311
+ * (or `CC_ENABLE_DCA_EVERYWHERE` is set)
3312
+ * - SHORT: `currentPrice` is above the all-time highest entry price
3313
+ * (or `CC_ENABLE_DCA_EVERYWHERE` is set)
3314
+ *
3315
+ * Never throws. Safe to call at any time as a pre-flight check.
3316
+ *
3317
+ * @param symbol - Trading pair symbol (e.g., "BTCUSDT")
3318
+ * @param currentPrice - New entry price to validate
3319
+ * @returns `true` if `averageBuy` would execute, `false` otherwise
3320
+ */
3321
+ validateAverageBuy: (symbol: string, currentPrice: number) => Promise<boolean>;
3210
3322
  /**
3211
3323
  * Checks if there is an active pending signal for the symbol.
3212
3324
  *
@@ -4430,6 +4542,34 @@ declare function commitTrailingStop(symbol: string, percentShift: number, curren
4430
4542
  * ```
4431
4543
  */
4432
4544
  declare function commitTrailingTake(symbol: string, percentShift: number, currentPrice: number): Promise<boolean>;
4545
+ /**
4546
+ * Adjusts the trailing stop-loss to an absolute price level.
4547
+ *
4548
+ * Convenience wrapper around commitTrailingStop that converts an absolute
4549
+ * stop-loss price to a percentShift relative to the ORIGINAL SL distance.
4550
+ *
4551
+ * Automatically detects backtest/live mode from execution context.
4552
+ * Automatically fetches current price via getAveragePrice.
4553
+ *
4554
+ * @param symbol - Trading pair symbol
4555
+ * @param newStopLossPrice - Desired absolute stop-loss price
4556
+ * @returns Promise<boolean> - true if trailing SL was set/updated, false if rejected
4557
+ */
4558
+ declare function commitTrailingStopCost(symbol: string, newStopLossPrice: number): Promise<boolean>;
4559
+ /**
4560
+ * Adjusts the trailing take-profit to an absolute price level.
4561
+ *
4562
+ * Convenience wrapper around commitTrailingTake that converts an absolute
4563
+ * take-profit price to a percentShift relative to the ORIGINAL TP distance.
4564
+ *
4565
+ * Automatically detects backtest/live mode from execution context.
4566
+ * Automatically fetches current price via getAveragePrice.
4567
+ *
4568
+ * @param symbol - Trading pair symbol
4569
+ * @param newTakeProfitPrice - Desired absolute take-profit price
4570
+ * @returns Promise<boolean> - true if trailing TP was set/updated, false if rejected
4571
+ */
4572
+ declare function commitTrailingTakeCost(symbol: string, newTakeProfitPrice: number): Promise<boolean>;
4433
4573
  /**
4434
4574
  * Moves stop-loss to breakeven when price reaches threshold.
4435
4575
  *
@@ -4690,6 +4830,34 @@ declare function getPositionPnlCost(symbol: string): Promise<number | null>;
4690
4830
  * ```
4691
4831
  */
4692
4832
  declare function getPositionLevels(symbol: string): Promise<number[] | null>;
4833
+ /**
4834
+ * Returns the list of partial close events for the current pending signal.
4835
+ *
4836
+ * Each element represents a partial profit or loss close executed via
4837
+ * commitPartialProfit / commitPartialLoss (or their Cost variants).
4838
+ *
4839
+ * Returns null if no pending signal exists.
4840
+ * Returns an empty array if no partials were executed yet.
4841
+ *
4842
+ * Each entry contains:
4843
+ * - `type` — "profit" or "loss"
4844
+ * - `percent` — percentage of position closed at this partial
4845
+ * - `currentPrice` — execution price of the partial close
4846
+ * - `costBasisAtClose` — accounting cost basis at the moment of this partial
4847
+ * - `entryCountAtClose` — number of DCA entries accumulated at this partial
4848
+ *
4849
+ * @param symbol - Trading pair symbol
4850
+ * @returns Promise resolving to array of partial close records or null
4851
+ *
4852
+ * @example
4853
+ * ```typescript
4854
+ * import { getPositionPartials } from "backtest-kit";
4855
+ *
4856
+ * const partials = await getPositionPartials("BTCUSDT");
4857
+ * // No partials yet: []
4858
+ * // After one partial profit: [{ type: "profit", percent: 50, currentPrice: 45000, ... }]
4859
+ * ```
4860
+ */
4693
4861
  declare function getPositionPartials(symbol: string): Promise<{
4694
4862
  type: "profit" | "loss";
4695
4863
  percent: number;
@@ -7277,7 +7445,7 @@ declare function listenStrategyCommitOnce(filterFn: (event: StrategyCommitContra
7277
7445
  * @param fn - Callback function to handle sync events. If the function returns a promise, signal processing will wait until it resolves.
7278
7446
  * @returns Unsubscribe function to stop listening
7279
7447
  */
7280
- declare function listenSync(fn: (event: SignalSyncContract$1) => void): () => void;
7448
+ declare function listenSync(fn: (event: SignalSyncContract) => void): () => void;
7281
7449
  /**
7282
7450
  * Subscribes to filtered signal synchronization events with one-time execution.
7283
7451
  * If throws position is not being opened/closed until the async function completes. Useful for synchronizing with external systems.
@@ -7286,7 +7454,7 @@ declare function listenSync(fn: (event: SignalSyncContract$1) => void): () => vo
7286
7454
  * @param fn - Callback function to handle the filtered event (called only once). If the function returns a promise, signal processing will wait until it resolves.
7287
7455
  * @returns Unsubscribe function to cancel the listener before it fires
7288
7456
  */
7289
- declare function listenSyncOnce(filterFn: (event: SignalSyncContract$1) => boolean, fn: (event: SignalSyncContract$1) => void): () => void;
7457
+ declare function listenSyncOnce(filterFn: (event: SignalSyncContract) => boolean, fn: (event: SignalSyncContract) => void): () => void;
7290
7458
 
7291
7459
  /**
7292
7460
  * Checks if trade context is active (execution and method contexts).
@@ -11340,36 +11508,117 @@ declare class BacktestUtils {
11340
11508
  exchangeName: ExchangeName;
11341
11509
  frameName: FrameName;
11342
11510
  }) => Promise<boolean>;
11511
+ /**
11512
+ * Returns the effective (weighted average) entry price for the current pending signal.
11513
+ *
11514
+ * Accounts for all DCA entries via commitAverageBuy.
11515
+ * Returns null if no pending signal exists.
11516
+ *
11517
+ * @param symbol - Trading pair symbol
11518
+ * @param context - Execution context with strategyName, exchangeName, and frameName
11519
+ * @returns Effective entry price, or null if no active position
11520
+ */
11343
11521
  getPositionAveragePrice: (symbol: string, context: {
11344
11522
  strategyName: StrategyName;
11345
11523
  exchangeName: ExchangeName;
11346
11524
  frameName: FrameName;
11347
11525
  }) => Promise<number | null>;
11526
+ /**
11527
+ * Returns the total number of base-asset units currently held in the position.
11528
+ *
11529
+ * Includes units from all DCA entries. Returns null if no pending signal exists.
11530
+ *
11531
+ * @param symbol - Trading pair symbol
11532
+ * @param context - Execution context with strategyName, exchangeName, and frameName
11533
+ * @returns Total units held, or null if no active position
11534
+ */
11348
11535
  getPositionInvestedCount: (symbol: string, context: {
11349
11536
  strategyName: StrategyName;
11350
11537
  exchangeName: ExchangeName;
11351
11538
  frameName: FrameName;
11352
11539
  }) => Promise<number | null>;
11540
+ /**
11541
+ * Returns the total dollar cost invested in the current position.
11542
+ *
11543
+ * Sum of all entry costs across DCA entries. Returns null if no pending signal exists.
11544
+ *
11545
+ * @param symbol - Trading pair symbol
11546
+ * @param context - Execution context with strategyName, exchangeName, and frameName
11547
+ * @returns Total invested cost in quote currency, or null if no active position
11548
+ */
11353
11549
  getPositionInvestedCost: (symbol: string, context: {
11354
11550
  strategyName: StrategyName;
11355
11551
  exchangeName: ExchangeName;
11356
11552
  frameName: FrameName;
11357
11553
  }) => Promise<number | null>;
11554
+ /**
11555
+ * Returns the current unrealized PnL as a percentage of the invested cost.
11556
+ *
11557
+ * Calculated relative to the effective (weighted average) entry price.
11558
+ * Positive for profit, negative for loss. Returns null if no pending signal exists.
11559
+ *
11560
+ * @param symbol - Trading pair symbol
11561
+ * @param currentPrice - Current market price
11562
+ * @param context - Execution context with strategyName, exchangeName, and frameName
11563
+ * @returns PnL percentage, or null if no active position
11564
+ */
11358
11565
  getPositionPnlPercent: (symbol: string, currentPrice: number, context: {
11359
11566
  strategyName: StrategyName;
11360
11567
  exchangeName: ExchangeName;
11361
11568
  frameName: FrameName;
11362
11569
  }) => Promise<number | null>;
11570
+ /**
11571
+ * Returns the current unrealized PnL in quote currency (dollar amount).
11572
+ *
11573
+ * Calculated as (currentPrice - effectiveEntry) * units for LONG,
11574
+ * reversed for SHORT. Returns null if no pending signal exists.
11575
+ *
11576
+ * @param symbol - Trading pair symbol
11577
+ * @param currentPrice - Current market price
11578
+ * @param context - Execution context with strategyName, exchangeName, and frameName
11579
+ * @returns PnL in quote currency, or null if no active position
11580
+ */
11363
11581
  getPositionPnlCost: (symbol: string, currentPrice: number, context: {
11364
11582
  strategyName: StrategyName;
11365
11583
  exchangeName: ExchangeName;
11366
11584
  frameName: FrameName;
11367
11585
  }) => Promise<number | null>;
11586
+ /**
11587
+ * Returns the list of DCA entry prices for the current pending signal.
11588
+ *
11589
+ * The first element is always the original priceOpen (initial entry).
11590
+ * Each subsequent element is a price added by commitAverageBuy().
11591
+ * Returns null if no pending signal exists.
11592
+ * Returns a single-element array [priceOpen] if no DCA entries were made.
11593
+ *
11594
+ * @param symbol - Trading pair symbol
11595
+ * @param context - Execution context with strategyName, exchangeName, and frameName
11596
+ * @returns Array of entry prices, or null if no active position
11597
+ */
11368
11598
  getPositionLevels: (symbol: string, context: {
11369
11599
  strategyName: StrategyName;
11370
11600
  exchangeName: ExchangeName;
11371
11601
  frameName: FrameName;
11372
11602
  }) => Promise<number[] | null>;
11603
+ /**
11604
+ * Returns the list of partial close events for the current pending signal.
11605
+ *
11606
+ * Each element represents a partial profit or loss close executed via
11607
+ * commitPartialProfit / commitPartialLoss (or their Cost variants).
11608
+ * Returns null if no pending signal exists.
11609
+ * Returns an empty array if no partials were executed yet.
11610
+ *
11611
+ * Each entry contains:
11612
+ * - `type` — "profit" or "loss"
11613
+ * - `percent` — percentage of position closed at this partial
11614
+ * - `currentPrice` — execution price of the partial close
11615
+ * - `costBasisAtClose` — accounting cost basis at the moment of this partial
11616
+ * - `entryCountAtClose` — number of DCA entries accumulated at this partial
11617
+ *
11618
+ * @param symbol - Trading pair symbol
11619
+ * @param context - Execution context with strategyName, exchangeName, and frameName
11620
+ * @returns Array of partial close records, or null if no active position
11621
+ */
11373
11622
  getPositionPartials: (symbol: string, context: {
11374
11623
  strategyName: StrategyName;
11375
11624
  exchangeName: ExchangeName;
@@ -11700,6 +11949,40 @@ declare class BacktestUtils {
11700
11949
  exchangeName: ExchangeName;
11701
11950
  frameName: FrameName;
11702
11951
  }) => Promise<boolean>;
11952
+ /**
11953
+ * Adjusts the trailing stop-loss to an absolute price level.
11954
+ *
11955
+ * Convenience wrapper around commitTrailingStop that converts an absolute
11956
+ * stop-loss price to a percentShift relative to the ORIGINAL SL distance.
11957
+ *
11958
+ * @param symbol - Trading pair symbol
11959
+ * @param newStopLossPrice - Desired absolute stop-loss price
11960
+ * @param currentPrice - Current market price to check for intrusion
11961
+ * @param context - Execution context with strategyName, exchangeName, and frameName
11962
+ * @returns Promise<boolean> - true if trailing SL was set/updated, false if rejected
11963
+ */
11964
+ commitTrailingStopCost: (symbol: string, newStopLossPrice: number, currentPrice: number, context: {
11965
+ strategyName: StrategyName;
11966
+ exchangeName: ExchangeName;
11967
+ frameName: FrameName;
11968
+ }) => Promise<boolean>;
11969
+ /**
11970
+ * Adjusts the trailing take-profit to an absolute price level.
11971
+ *
11972
+ * Convenience wrapper around commitTrailingTake that converts an absolute
11973
+ * take-profit price to a percentShift relative to the ORIGINAL TP distance.
11974
+ *
11975
+ * @param symbol - Trading pair symbol
11976
+ * @param newTakeProfitPrice - Desired absolute take-profit price
11977
+ * @param currentPrice - Current market price to check for intrusion
11978
+ * @param context - Execution context with strategyName, exchangeName, and frameName
11979
+ * @returns Promise<boolean> - true if trailing TP was set/updated, false if rejected
11980
+ */
11981
+ commitTrailingTakeCost: (symbol: string, newTakeProfitPrice: number, currentPrice: number, context: {
11982
+ strategyName: StrategyName;
11983
+ exchangeName: ExchangeName;
11984
+ frameName: FrameName;
11985
+ }) => Promise<boolean>;
11703
11986
  /**
11704
11987
  * Moves stop-loss to breakeven when price reaches threshold.
11705
11988
  *
@@ -12290,30 +12573,111 @@ declare class LiveUtils {
12290
12573
  strategyName: StrategyName;
12291
12574
  exchangeName: ExchangeName;
12292
12575
  }) => Promise<boolean>;
12576
+ /**
12577
+ * Returns the effective (weighted average) entry price for the current pending signal.
12578
+ *
12579
+ * Accounts for all DCA entries via commitAverageBuy.
12580
+ * Returns null if no pending signal exists.
12581
+ *
12582
+ * @param symbol - Trading pair symbol
12583
+ * @param context - Execution context with strategyName and exchangeName
12584
+ * @returns Effective entry price, or null if no active position
12585
+ */
12293
12586
  getPositionAveragePrice: (symbol: string, context: {
12294
12587
  strategyName: StrategyName;
12295
12588
  exchangeName: ExchangeName;
12296
12589
  }) => Promise<number | null>;
12590
+ /**
12591
+ * Returns the total number of base-asset units currently held in the position.
12592
+ *
12593
+ * Includes units from all DCA entries. Returns null if no pending signal exists.
12594
+ *
12595
+ * @param symbol - Trading pair symbol
12596
+ * @param context - Execution context with strategyName and exchangeName
12597
+ * @returns Total units held, or null if no active position
12598
+ */
12297
12599
  getPositionInvestedCount: (symbol: string, context: {
12298
12600
  strategyName: StrategyName;
12299
12601
  exchangeName: ExchangeName;
12300
12602
  }) => Promise<number | null>;
12603
+ /**
12604
+ * Returns the total dollar cost invested in the current position.
12605
+ *
12606
+ * Sum of all entry costs across DCA entries. Returns null if no pending signal exists.
12607
+ *
12608
+ * @param symbol - Trading pair symbol
12609
+ * @param context - Execution context with strategyName and exchangeName
12610
+ * @returns Total invested cost in quote currency, or null if no active position
12611
+ */
12301
12612
  getPositionInvestedCost: (symbol: string, context: {
12302
12613
  strategyName: StrategyName;
12303
12614
  exchangeName: ExchangeName;
12304
12615
  }) => Promise<number | null>;
12616
+ /**
12617
+ * Returns the current unrealized PnL as a percentage of the invested cost.
12618
+ *
12619
+ * Calculated relative to the effective (weighted average) entry price.
12620
+ * Positive for profit, negative for loss. Returns null if no pending signal exists.
12621
+ *
12622
+ * @param symbol - Trading pair symbol
12623
+ * @param currentPrice - Current market price
12624
+ * @param context - Execution context with strategyName and exchangeName
12625
+ * @returns PnL percentage, or null if no active position
12626
+ */
12305
12627
  getPositionPnlPercent: (symbol: string, currentPrice: number, context: {
12306
12628
  strategyName: StrategyName;
12307
12629
  exchangeName: ExchangeName;
12308
12630
  }) => Promise<number | null>;
12631
+ /**
12632
+ * Returns the current unrealized PnL in quote currency (dollar amount).
12633
+ *
12634
+ * Calculated as (currentPrice - effectiveEntry) * units for LONG,
12635
+ * reversed for SHORT. Returns null if no pending signal exists.
12636
+ *
12637
+ * @param symbol - Trading pair symbol
12638
+ * @param currentPrice - Current market price
12639
+ * @param context - Execution context with strategyName and exchangeName
12640
+ * @returns PnL in quote currency, or null if no active position
12641
+ */
12309
12642
  getPositionPnlCost: (symbol: string, currentPrice: number, context: {
12310
12643
  strategyName: StrategyName;
12311
12644
  exchangeName: ExchangeName;
12312
12645
  }) => Promise<number | null>;
12646
+ /**
12647
+ * Returns the list of DCA entry prices for the current pending signal.
12648
+ *
12649
+ * The first element is always the original priceOpen (initial entry).
12650
+ * Each subsequent element is a price added by commitAverageBuy().
12651
+ * Returns null if no pending signal exists.
12652
+ * Returns a single-element array [priceOpen] if no DCA entries were made.
12653
+ *
12654
+ * @param symbol - Trading pair symbol
12655
+ * @param context - Execution context with strategyName and exchangeName
12656
+ * @returns Array of entry prices, or null if no active position
12657
+ */
12313
12658
  getPositionLevels: (symbol: string, context: {
12314
12659
  strategyName: StrategyName;
12315
12660
  exchangeName: ExchangeName;
12316
12661
  }) => Promise<number[] | null>;
12662
+ /**
12663
+ * Returns the list of partial close events for the current pending signal.
12664
+ *
12665
+ * Each element represents a partial profit or loss close executed via
12666
+ * commitPartialProfit / commitPartialLoss (or their Cost variants).
12667
+ * Returns null if no pending signal exists.
12668
+ * Returns an empty array if no partials were executed yet.
12669
+ *
12670
+ * Each entry contains:
12671
+ * - `type` — "profit" or "loss"
12672
+ * - `percent` — percentage of position closed at this partial
12673
+ * - `currentPrice` — execution price of the partial close
12674
+ * - `costBasisAtClose` — accounting cost basis at the moment of this partial
12675
+ * - `entryCountAtClose` — number of DCA entries accumulated at this partial
12676
+ *
12677
+ * @param symbol - Trading pair symbol
12678
+ * @param context - Execution context with strategyName and exchangeName
12679
+ * @returns Array of partial close records, or null if no active position
12680
+ */
12317
12681
  getPositionPartials: (symbol: string, context: {
12318
12682
  strategyName: StrategyName;
12319
12683
  exchangeName: ExchangeName;
@@ -12622,6 +12986,38 @@ declare class LiveUtils {
12622
12986
  strategyName: StrategyName;
12623
12987
  exchangeName: ExchangeName;
12624
12988
  }) => Promise<boolean>;
12989
+ /**
12990
+ * Adjusts the trailing stop-loss to an absolute price level.
12991
+ *
12992
+ * Convenience wrapper around commitTrailingStop that converts an absolute
12993
+ * stop-loss price to a percentShift relative to the ORIGINAL SL distance.
12994
+ *
12995
+ * @param symbol - Trading pair symbol
12996
+ * @param newStopLossPrice - Desired absolute stop-loss price
12997
+ * @param currentPrice - Current market price to check for intrusion
12998
+ * @param context - Execution context with strategyName and exchangeName
12999
+ * @returns Promise<boolean> - true if trailing SL was set/updated, false if rejected
13000
+ */
13001
+ commitTrailingStopCost: (symbol: string, newStopLossPrice: number, currentPrice: number, context: {
13002
+ strategyName: StrategyName;
13003
+ exchangeName: ExchangeName;
13004
+ }) => Promise<boolean>;
13005
+ /**
13006
+ * Adjusts the trailing take-profit to an absolute price level.
13007
+ *
13008
+ * Convenience wrapper around commitTrailingTake that converts an absolute
13009
+ * take-profit price to a percentShift relative to the ORIGINAL TP distance.
13010
+ *
13011
+ * @param symbol - Trading pair symbol
13012
+ * @param newTakeProfitPrice - Desired absolute take-profit price
13013
+ * @param currentPrice - Current market price to check for intrusion
13014
+ * @param context - Execution context with strategyName and exchangeName
13015
+ * @returns Promise<boolean> - true if trailing TP was set/updated, false if rejected
13016
+ */
13017
+ commitTrailingTakeCost: (symbol: string, newTakeProfitPrice: number, currentPrice: number, context: {
13018
+ strategyName: StrategyName;
13019
+ exchangeName: ExchangeName;
13020
+ }) => Promise<boolean>;
12625
13021
  /**
12626
13022
  * Moves stop-loss to breakeven when price reaches threshold.
12627
13023
  *
@@ -17816,47 +18212,983 @@ declare class ActionBase implements IPublicAction {
17816
18212
  }
17817
18213
 
17818
18214
  /**
17819
- * Contract for walker stop signal events.
17820
- *
17821
- * Emitted when Walker.stop() is called to interrupt a running walker.
17822
- * Contains metadata about which walker and strategy should be stopped.
18215
+ * Payload for the signal-open broker event.
17823
18216
  *
17824
- * Supports multiple walkers running on the same symbol simultaneously
17825
- * by including walkerName for filtering.
18217
+ * Emitted automatically via syncSubject when a new pending signal is activated.
18218
+ * Forwarded to the registered IBroker adapter via `onSignalOpenCommit`.
17826
18219
  *
17827
18220
  * @example
17828
18221
  * ```typescript
17829
- * import { walkerStopSubject } from "backtest-kit";
17830
- *
17831
- * walkerStopSubject
17832
- * .filter((event) => event.symbol === "BTCUSDT")
17833
- * .connect((event) => {
17834
- * console.log("Walker stopped:", event.walkerName);
17835
- * console.log("Strategy:", event.strategyName);
17836
- * });
18222
+ * const payload: BrokerSignalOpenPayload = {
18223
+ * symbol: "BTCUSDT",
18224
+ * cost: 100,
18225
+ * position: "long",
18226
+ * priceOpen: 50000,
18227
+ * priceTakeProfit: 55000,
18228
+ * priceStopLoss: 48000,
18229
+ * context: { strategyName: "my-strategy", exchangeName: "binance", frameName: "1h" },
18230
+ * backtest: false,
18231
+ * };
17837
18232
  * ```
17838
18233
  */
17839
- interface WalkerStopContract {
17840
- /** symbol - Trading symbol (e.g., "BTCUSDT") */
18234
+ type BrokerSignalOpenPayload = {
18235
+ /** Trading pair symbol, e.g. "BTCUSDT" */
17841
18236
  symbol: string;
17842
- /** strategyName - Name of the strategy to stop */
17843
- strategyName: StrategyName;
17844
- /** walkerName - Name of the walker to stop (for filtering) */
17845
- walkerName: WalkerName;
17846
- }
17847
-
18237
+ /** Dollar cost of the position entry (CC_POSITION_ENTRY_COST) */
18238
+ cost: number;
18239
+ /** Position direction */
18240
+ position: "long" | "short";
18241
+ /** Activation price — the price at which the signal became active */
18242
+ priceOpen: number;
18243
+ /** Original take-profit price from the signal */
18244
+ priceTakeProfit: number;
18245
+ /** Original stop-loss price from the signal */
18246
+ priceStopLoss: number;
18247
+ /** Strategy/exchange/frame routing context */
18248
+ context: {
18249
+ strategyName: StrategyName;
18250
+ exchangeName: ExchangeName;
18251
+ frameName?: FrameName;
18252
+ };
18253
+ /** true when called during a backtest run — adapter should skip exchange calls */
18254
+ backtest: boolean;
18255
+ };
17848
18256
  /**
17849
- * Exchange signal synchronization emitter.
17850
- * If listenner throws, it means the signal was not properly synchronized to the exchange (e.g. limit order failed to fill).
18257
+ * Payload for the signal-close broker event.
17851
18258
  *
17852
- * The framework will skip position open/close and will try again on the next tick until successful synchronization.
17853
- * This ensures that the framework's internal state remains consistent with the exchange's state.
17854
- * Consumers should implement retry logic in their listeners to handle transient synchronization failures.
18259
+ * Emitted automatically via syncSubject when a pending signal is closed (SL/TP hit or manual close).
18260
+ * Forwarded to the registered IBroker adapter via `onSignalCloseCommit`.
18261
+ *
18262
+ * @example
18263
+ * ```typescript
18264
+ * const payload: BrokerSignalClosePayload = {
18265
+ * symbol: "BTCUSDT",
18266
+ * cost: 100,
18267
+ * position: "long",
18268
+ * currentPrice: 54000,
18269
+ * priceTakeProfit: 55000,
18270
+ * priceStopLoss: 48000,
18271
+ * totalEntries: 2,
18272
+ * totalPartials: 1,
18273
+ * pnl: { profit: 80, loss: 0, volume: 100 },
18274
+ * context: { strategyName: "my-strategy", exchangeName: "binance", frameName: "1h" },
18275
+ * backtest: false,
18276
+ * };
18277
+ * ```
17855
18278
  */
17856
- declare const syncSubject: Subject<SignalSyncContract$1>;
17857
- /**
17858
- * Global signal emitter for all trading events (live + backtest).
17859
- * Emits all signal events regardless of execution mode.
18279
+ type BrokerSignalClosePayload = {
18280
+ /** Trading pair symbol, e.g. "BTCUSDT" */
18281
+ symbol: string;
18282
+ /** Total dollar cost basis of the position at close */
18283
+ cost: number;
18284
+ /** Position direction */
18285
+ position: "long" | "short";
18286
+ /** Market price at the moment of close */
18287
+ currentPrice: number;
18288
+ /** Original take-profit price from the signal */
18289
+ priceTakeProfit: number;
18290
+ /** Original stop-loss price from the signal */
18291
+ priceStopLoss: number;
18292
+ /** Total number of DCA entries (including initial open) */
18293
+ totalEntries: number;
18294
+ /** Total number of partial closes executed before final close */
18295
+ totalPartials: number;
18296
+ /** Realized PnL breakdown for the closed position */
18297
+ pnl: IStrategyPnL;
18298
+ /** Strategy/exchange/frame routing context */
18299
+ context: {
18300
+ strategyName: StrategyName;
18301
+ exchangeName: ExchangeName;
18302
+ frameName?: FrameName;
18303
+ };
18304
+ /** true when called during a backtest run — adapter should skip exchange calls */
18305
+ backtest: boolean;
18306
+ };
18307
+ /**
18308
+ * Payload for a partial-profit close broker event.
18309
+ *
18310
+ * Forwarded to the registered IBroker adapter via `onPartialProfitCommit`.
18311
+ * Called explicitly after all validations pass, before `strategyCoreService.partialProfit()`.
18312
+ *
18313
+ * @example
18314
+ * ```typescript
18315
+ * const payload: BrokerPartialProfitPayload = {
18316
+ * symbol: "BTCUSDT",
18317
+ * percentToClose: 30,
18318
+ * cost: 30,
18319
+ * currentPrice: 52000,
18320
+ * context: { strategyName: "my-strategy", exchangeName: "binance", frameName: "1h" },
18321
+ * backtest: false,
18322
+ * };
18323
+ * ```
18324
+ */
18325
+ type BrokerPartialProfitPayload = {
18326
+ /** Trading pair symbol, e.g. "BTCUSDT" */
18327
+ symbol: string;
18328
+ /** Percentage of the position to close (0–100) */
18329
+ percentToClose: number;
18330
+ /** Dollar value of the portion being closed */
18331
+ cost: number;
18332
+ /** Current market price at which the partial close executes */
18333
+ currentPrice: number;
18334
+ /** Position direction */
18335
+ position: "long" | "short";
18336
+ /** Active take profit price at the time of the partial close */
18337
+ priceTakeProfit: number;
18338
+ /** Active stop loss price at the time of the partial close */
18339
+ priceStopLoss: number;
18340
+ /** Strategy/exchange/frame routing context */
18341
+ context: {
18342
+ strategyName: StrategyName;
18343
+ exchangeName: ExchangeName;
18344
+ frameName?: FrameName;
18345
+ };
18346
+ /** true when called during a backtest run — adapter should skip exchange calls */
18347
+ backtest: boolean;
18348
+ };
18349
+ /**
18350
+ * Payload for a partial-loss close broker event.
18351
+ *
18352
+ * Forwarded to the registered IBroker adapter via `onPartialLossCommit`.
18353
+ * Called explicitly after all validations pass, before `strategyCoreService.partialLoss()`.
18354
+ *
18355
+ * @example
18356
+ * ```typescript
18357
+ * const payload: BrokerPartialLossPayload = {
18358
+ * symbol: "BTCUSDT",
18359
+ * percentToClose: 40,
18360
+ * cost: 40,
18361
+ * currentPrice: 48500,
18362
+ * context: { strategyName: "my-strategy", exchangeName: "binance", frameName: "1h" },
18363
+ * backtest: false,
18364
+ * };
18365
+ * ```
18366
+ */
18367
+ type BrokerPartialLossPayload = {
18368
+ /** Trading pair symbol, e.g. "BTCUSDT" */
18369
+ symbol: string;
18370
+ /** Percentage of the position to close (0–100) */
18371
+ percentToClose: number;
18372
+ /** Dollar value of the portion being closed */
18373
+ cost: number;
18374
+ /** Current market price at which the partial close executes */
18375
+ currentPrice: number;
18376
+ /** Position direction */
18377
+ position: "long" | "short";
18378
+ /** Active take profit price at the time of the partial close */
18379
+ priceTakeProfit: number;
18380
+ /** Active stop loss price at the time of the partial close */
18381
+ priceStopLoss: number;
18382
+ /** Strategy/exchange/frame routing context */
18383
+ context: {
18384
+ strategyName: StrategyName;
18385
+ exchangeName: ExchangeName;
18386
+ frameName?: FrameName;
18387
+ };
18388
+ /** true when called during a backtest run — adapter should skip exchange calls */
18389
+ backtest: boolean;
18390
+ };
18391
+ /**
18392
+ * Payload for a trailing stop-loss update broker event.
18393
+ *
18394
+ * Forwarded to the registered IBroker adapter via `onTrailingStopCommit`.
18395
+ * Called explicitly after all validations pass, before `strategyCoreService.trailingStop()`.
18396
+ * `newStopLossPrice` is the absolute SL price computed from percentShift + original SL + effectivePriceOpen.
18397
+ *
18398
+ * @example
18399
+ * ```typescript
18400
+ * // LONG: entry=100, originalSL=90, percentShift=-5 → newSL=95
18401
+ * const payload: BrokerTrailingStopPayload = {
18402
+ * symbol: "BTCUSDT",
18403
+ * percentShift: -5,
18404
+ * currentPrice: 102,
18405
+ * newStopLossPrice: 95,
18406
+ * context: { strategyName: "my-strategy", exchangeName: "binance", frameName: "1h" },
18407
+ * backtest: false,
18408
+ * };
18409
+ * ```
18410
+ */
18411
+ type BrokerTrailingStopPayload = {
18412
+ /** Trading pair symbol, e.g. "BTCUSDT" */
18413
+ symbol: string;
18414
+ /** Percentage shift applied to the ORIGINAL SL distance (-100 to 100) */
18415
+ percentShift: number;
18416
+ /** Current market price used for intrusion validation */
18417
+ currentPrice: number;
18418
+ /** Absolute stop-loss price after applying percentShift */
18419
+ newStopLossPrice: number;
18420
+ /** Position direction */
18421
+ position: "long" | "short";
18422
+ /** Strategy/exchange/frame routing context */
18423
+ context: {
18424
+ strategyName: StrategyName;
18425
+ exchangeName: ExchangeName;
18426
+ frameName?: FrameName;
18427
+ };
18428
+ /** true when called during a backtest run — adapter should skip exchange calls */
18429
+ backtest: boolean;
18430
+ };
18431
+ /**
18432
+ * Payload for a trailing take-profit update broker event.
18433
+ *
18434
+ * Forwarded to the registered IBroker adapter via `onTrailingTakeCommit`.
18435
+ * Called explicitly after all validations pass, before `strategyCoreService.trailingTake()`.
18436
+ * `newTakeProfitPrice` is the absolute TP price computed from percentShift + original TP + effectivePriceOpen.
18437
+ *
18438
+ * @example
18439
+ * ```typescript
18440
+ * // LONG: entry=100, originalTP=110, percentShift=-3 → newTP=107
18441
+ * const payload: BrokerTrailingTakePayload = {
18442
+ * symbol: "BTCUSDT",
18443
+ * percentShift: -3,
18444
+ * currentPrice: 102,
18445
+ * newTakeProfitPrice: 107,
18446
+ * context: { strategyName: "my-strategy", exchangeName: "binance", frameName: "1h" },
18447
+ * backtest: false,
18448
+ * };
18449
+ * ```
18450
+ */
18451
+ type BrokerTrailingTakePayload = {
18452
+ /** Trading pair symbol, e.g. "BTCUSDT" */
18453
+ symbol: string;
18454
+ /** Percentage shift applied to the ORIGINAL TP distance (-100 to 100) */
18455
+ percentShift: number;
18456
+ /** Current market price used for intrusion validation */
18457
+ currentPrice: number;
18458
+ /** Absolute take-profit price after applying percentShift */
18459
+ newTakeProfitPrice: number;
18460
+ /** Position direction */
18461
+ position: "long" | "short";
18462
+ /** Strategy/exchange/frame routing context */
18463
+ context: {
18464
+ strategyName: StrategyName;
18465
+ exchangeName: ExchangeName;
18466
+ frameName?: FrameName;
18467
+ };
18468
+ /** true when called during a backtest run — adapter should skip exchange calls */
18469
+ backtest: boolean;
18470
+ };
18471
+ /**
18472
+ * Payload for a breakeven operation broker event.
18473
+ *
18474
+ * Forwarded to the registered IBroker adapter via `onBreakevenCommit`.
18475
+ * Called explicitly after all validations pass, before `strategyCoreService.breakeven()`.
18476
+ * `newStopLossPrice` equals `effectivePriceOpen` (entry price).
18477
+ * `newTakeProfitPrice` equals `_trailingPriceTakeProfit ?? priceTakeProfit` (TP is unchanged).
18478
+ *
18479
+ * @example
18480
+ * ```typescript
18481
+ * // LONG: entry=100, currentPrice=100.5, newSL=100 (entry), newTP=110 (unchanged)
18482
+ * const payload: BrokerBreakevenPayload = {
18483
+ * symbol: "BTCUSDT",
18484
+ * currentPrice: 100.5,
18485
+ * newStopLossPrice: 100,
18486
+ * newTakeProfitPrice: 110,
18487
+ * context: { strategyName: "my-strategy", exchangeName: "binance", frameName: "1h" },
18488
+ * backtest: false,
18489
+ * };
18490
+ * ```
18491
+ */
18492
+ type BrokerBreakevenPayload = {
18493
+ /** Trading pair symbol, e.g. "BTCUSDT" */
18494
+ symbol: string;
18495
+ /** Current market price at the moment breakeven is triggered */
18496
+ currentPrice: number;
18497
+ /** New stop-loss price = effectivePriceOpen (the position's effective entry price) */
18498
+ newStopLossPrice: number;
18499
+ /** Effective take-profit price = _trailingPriceTakeProfit ?? priceTakeProfit (unchanged by breakeven) */
18500
+ newTakeProfitPrice: number;
18501
+ /** Position direction */
18502
+ position: "long" | "short";
18503
+ /** Strategy/exchange/frame routing context */
18504
+ context: {
18505
+ strategyName: StrategyName;
18506
+ exchangeName: ExchangeName;
18507
+ frameName?: FrameName;
18508
+ };
18509
+ /** true when called during a backtest run — adapter should skip exchange calls */
18510
+ backtest: boolean;
18511
+ };
18512
+ /**
18513
+ * Payload for a DCA average-buy entry broker event.
18514
+ *
18515
+ * Forwarded to the registered IBroker adapter via `onAverageBuyCommit`.
18516
+ * Called explicitly after all validations pass, before `strategyCoreService.averageBuy()`.
18517
+ * `currentPrice` is the market price at which the new DCA entry is added.
18518
+ *
18519
+ * @example
18520
+ * ```typescript
18521
+ * const payload: BrokerAverageBuyPayload = {
18522
+ * symbol: "BTCUSDT",
18523
+ * currentPrice: 42000,
18524
+ * cost: 100,
18525
+ * context: { strategyName: "my-strategy", exchangeName: "binance", frameName: "1h" },
18526
+ * backtest: false,
18527
+ * };
18528
+ * ```
18529
+ */
18530
+ type BrokerAverageBuyPayload = {
18531
+ /** Trading pair symbol, e.g. "BTCUSDT" */
18532
+ symbol: string;
18533
+ /** Market price at which the DCA entry is placed */
18534
+ currentPrice: number;
18535
+ /** Dollar amount of the new DCA entry (default: CC_POSITION_ENTRY_COST) */
18536
+ cost: number;
18537
+ /** Position direction */
18538
+ position: "long" | "short";
18539
+ /** Active take profit price at the time of the DCA entry */
18540
+ priceTakeProfit: number;
18541
+ /** Active stop loss price at the time of the DCA entry */
18542
+ priceStopLoss: number;
18543
+ /** Strategy/exchange/frame routing context */
18544
+ context: {
18545
+ strategyName: StrategyName;
18546
+ exchangeName: ExchangeName;
18547
+ frameName?: FrameName;
18548
+ };
18549
+ /** true when called during a backtest run — adapter should skip exchange calls */
18550
+ backtest: boolean;
18551
+ };
18552
+ interface IBroker {
18553
+ waitForInit(): Promise<void>;
18554
+ onSignalCloseCommit(payload: BrokerSignalClosePayload): Promise<void>;
18555
+ onSignalOpenCommit(payload: BrokerSignalOpenPayload): Promise<void>;
18556
+ onPartialProfitCommit(payload: BrokerPartialProfitPayload): Promise<void>;
18557
+ onPartialLossCommit(payload: BrokerPartialLossPayload): Promise<void>;
18558
+ onTrailingStopCommit(payload: BrokerTrailingStopPayload): Promise<void>;
18559
+ onTrailingTakeCommit(payload: BrokerTrailingTakePayload): Promise<void>;
18560
+ onBreakevenCommit(payload: BrokerBreakevenPayload): Promise<void>;
18561
+ onAverageBuyCommit(payload: BrokerAverageBuyPayload): Promise<void>;
18562
+ }
18563
+ type TBrokerCtor = new () => Partial<IBroker>;
18564
+ /**
18565
+ * Facade for broker integration — intercepts all commit* operations before DI-core mutations.
18566
+ *
18567
+ * Acts as a transaction control point: if any commit* method throws, the DI-core mutation
18568
+ * is never reached and the state remains unchanged.
18569
+ *
18570
+ * In backtest mode all commit* calls are silently skipped (payload.backtest === true).
18571
+ * In live mode the call is forwarded to the registered IBroker adapter via BrokerProxy.
18572
+ *
18573
+ * signal-open and signal-close events are routed automatically via syncSubject subscription
18574
+ * (activated on `enable()`). All other commit* methods are called explicitly from
18575
+ * Live.ts / Backtest.ts / strategy.ts before the corresponding strategyCoreService call.
18576
+ *
18577
+ * @example
18578
+ * ```typescript
18579
+ * import { Broker } from "backtest-kit";
18580
+ *
18581
+ * // Register a custom broker adapter
18582
+ * Broker.useBrokerAdapter(MyBrokerAdapter);
18583
+ *
18584
+ * // Activate syncSubject subscription (signal-open / signal-close routing)
18585
+ * const dispose = Broker.enable();
18586
+ *
18587
+ * // ... run strategy ...
18588
+ *
18589
+ * // Deactivate when done
18590
+ * Broker.disable();
18591
+ * ```
18592
+ */
18593
+ declare class BrokerAdapter {
18594
+ private _brokerInstance;
18595
+ /**
18596
+ * Forwards a signal-open event to the registered broker adapter.
18597
+ *
18598
+ * Called automatically via syncSubject when `enable()` is active.
18599
+ * Skipped silently in backtest mode or when no adapter is registered.
18600
+ *
18601
+ * @param payload - Signal open details: symbol, cost, position, prices, context, backtest flag
18602
+ *
18603
+ * @example
18604
+ * ```typescript
18605
+ * await Broker.commitSignalOpen({
18606
+ * symbol: "BTCUSDT",
18607
+ * cost: 100,
18608
+ * position: "long",
18609
+ * priceOpen: 50000,
18610
+ * priceTakeProfit: 55000,
18611
+ * priceStopLoss: 48000,
18612
+ * context: { strategyName: "my-strategy", exchangeName: "binance", frameName: "1h" },
18613
+ * backtest: false,
18614
+ * });
18615
+ * ```
18616
+ */
18617
+ commitSignalOpen: (payload: BrokerSignalOpenPayload) => Promise<void>;
18618
+ /**
18619
+ * Forwards a signal-close event to the registered broker adapter.
18620
+ *
18621
+ * Called automatically via syncSubject when `enable()` is active.
18622
+ * Skipped silently in backtest mode or when no adapter is registered.
18623
+ *
18624
+ * @param payload - Signal close details: symbol, cost, position, currentPrice, pnl, context, backtest flag
18625
+ *
18626
+ * @example
18627
+ * ```typescript
18628
+ * await Broker.commitSignalClose({
18629
+ * symbol: "BTCUSDT",
18630
+ * cost: 100,
18631
+ * position: "long",
18632
+ * currentPrice: 54000,
18633
+ * priceTakeProfit: 55000,
18634
+ * priceStopLoss: 48000,
18635
+ * totalEntries: 2,
18636
+ * totalPartials: 1,
18637
+ * pnl: { profit: 80, loss: 0, volume: 100 },
18638
+ * context: { strategyName: "my-strategy", exchangeName: "binance", frameName: "1h" },
18639
+ * backtest: false,
18640
+ * });
18641
+ * ```
18642
+ */
18643
+ commitSignalClose: (payload: BrokerSignalClosePayload) => Promise<void>;
18644
+ /**
18645
+ * Intercepts a partial-profit close before DI-core mutation.
18646
+ *
18647
+ * Called explicitly from Live.ts / Backtest.ts / strategy.ts after all validations pass,
18648
+ * but before `strategyCoreService.partialProfit()`. If this method throws, the DI mutation
18649
+ * is skipped and state remains unchanged.
18650
+ *
18651
+ * Skipped silently in backtest mode or when no adapter is registered.
18652
+ *
18653
+ * @param payload - Partial profit details: symbol, percentToClose, cost (dollar value), currentPrice, context, backtest flag
18654
+ *
18655
+ * @example
18656
+ * ```typescript
18657
+ * await Broker.commitPartialProfit({
18658
+ * symbol: "BTCUSDT",
18659
+ * percentToClose: 30,
18660
+ * cost: 30,
18661
+ * currentPrice: 52000,
18662
+ * context: { strategyName: "my-strategy", exchangeName: "binance", frameName: "1h" },
18663
+ * backtest: false,
18664
+ * });
18665
+ * ```
18666
+ */
18667
+ commitPartialProfit: (payload: BrokerPartialProfitPayload) => Promise<void>;
18668
+ /**
18669
+ * Intercepts a partial-loss close before DI-core mutation.
18670
+ *
18671
+ * Called explicitly from Live.ts / Backtest.ts / strategy.ts after all validations pass,
18672
+ * but before `strategyCoreService.partialLoss()`. If this method throws, the DI mutation
18673
+ * is skipped and state remains unchanged.
18674
+ *
18675
+ * Skipped silently in backtest mode or when no adapter is registered.
18676
+ *
18677
+ * @param payload - Partial loss details: symbol, percentToClose, cost (dollar value), currentPrice, context, backtest flag
18678
+ *
18679
+ * @example
18680
+ * ```typescript
18681
+ * await Broker.commitPartialLoss({
18682
+ * symbol: "BTCUSDT",
18683
+ * percentToClose: 40,
18684
+ * cost: 40,
18685
+ * currentPrice: 48500,
18686
+ * context: { strategyName: "my-strategy", exchangeName: "binance", frameName: "1h" },
18687
+ * backtest: false,
18688
+ * });
18689
+ * ```
18690
+ */
18691
+ commitPartialLoss: (payload: BrokerPartialLossPayload) => Promise<void>;
18692
+ /**
18693
+ * Intercepts a trailing stop-loss update before DI-core mutation.
18694
+ *
18695
+ * Called explicitly after all validations pass, but before `strategyCoreService.trailingStop()`.
18696
+ * `newStopLossPrice` is the absolute price computed from percentShift + original SL + effectivePriceOpen.
18697
+ *
18698
+ * Skipped silently in backtest mode or when no adapter is registered.
18699
+ *
18700
+ * @param payload - Trailing stop details: symbol, percentShift, currentPrice, newStopLossPrice, context, backtest flag
18701
+ *
18702
+ * @example
18703
+ * ```typescript
18704
+ * // LONG: entry=100, originalSL=90, percentShift=-5 → newSL=95
18705
+ * await Broker.commitTrailingStop({
18706
+ * symbol: "BTCUSDT",
18707
+ * percentShift: -5,
18708
+ * currentPrice: 102,
18709
+ * newStopLossPrice: 95,
18710
+ * context: { strategyName: "my-strategy", exchangeName: "binance", frameName: "1h" },
18711
+ * backtest: false,
18712
+ * });
18713
+ * ```
18714
+ */
18715
+ commitTrailingStop: (payload: BrokerTrailingStopPayload) => Promise<void>;
18716
+ /**
18717
+ * Intercepts a trailing take-profit update before DI-core mutation.
18718
+ *
18719
+ * Called explicitly after all validations pass, but before `strategyCoreService.trailingTake()`.
18720
+ * `newTakeProfitPrice` is the absolute price computed from percentShift + original TP + effectivePriceOpen.
18721
+ *
18722
+ * Skipped silently in backtest mode or when no adapter is registered.
18723
+ *
18724
+ * @param payload - Trailing take details: symbol, percentShift, currentPrice, newTakeProfitPrice, context, backtest flag
18725
+ *
18726
+ * @example
18727
+ * ```typescript
18728
+ * // LONG: entry=100, originalTP=110, percentShift=-3 → newTP=107
18729
+ * await Broker.commitTrailingTake({
18730
+ * symbol: "BTCUSDT",
18731
+ * percentShift: -3,
18732
+ * currentPrice: 102,
18733
+ * newTakeProfitPrice: 107,
18734
+ * context: { strategyName: "my-strategy", exchangeName: "binance", frameName: "1h" },
18735
+ * backtest: false,
18736
+ * });
18737
+ * ```
18738
+ */
18739
+ commitTrailingTake: (payload: BrokerTrailingTakePayload) => Promise<void>;
18740
+ /**
18741
+ * Intercepts a breakeven operation before DI-core mutation.
18742
+ *
18743
+ * Called explicitly after all validations pass, but before `strategyCoreService.breakeven()`.
18744
+ * `newStopLossPrice` equals effectivePriceOpen (entry price).
18745
+ * `newTakeProfitPrice` equals `_trailingPriceTakeProfit ?? priceTakeProfit` (TP is unchanged by breakeven).
18746
+ *
18747
+ * Skipped silently in backtest mode or when no adapter is registered.
18748
+ *
18749
+ * @param payload - Breakeven details: symbol, currentPrice, newStopLossPrice, newTakeProfitPrice, context, backtest flag
18750
+ *
18751
+ * @example
18752
+ * ```typescript
18753
+ * // LONG: entry=100, currentPrice=100.5, newSL=100 (entry), newTP=110 (unchanged)
18754
+ * await Broker.commitBreakeven({
18755
+ * symbol: "BTCUSDT",
18756
+ * currentPrice: 100.5,
18757
+ * newStopLossPrice: 100,
18758
+ * newTakeProfitPrice: 110,
18759
+ * context: { strategyName: "my-strategy", exchangeName: "binance", frameName: "1h" },
18760
+ * backtest: false,
18761
+ * });
18762
+ * ```
18763
+ */
18764
+ commitBreakeven: (payload: BrokerBreakevenPayload) => Promise<void>;
18765
+ /**
18766
+ * Intercepts a DCA average-buy entry before DI-core mutation.
18767
+ *
18768
+ * Called explicitly after all validations pass, but before `strategyCoreService.averageBuy()`.
18769
+ * `currentPrice` is the market price at which the new DCA entry is added.
18770
+ * `cost` is the dollar amount of the new entry (default: CC_POSITION_ENTRY_COST).
18771
+ *
18772
+ * Skipped silently in backtest mode or when no adapter is registered.
18773
+ *
18774
+ * @param payload - Average buy details: symbol, currentPrice, cost, context, backtest flag
18775
+ *
18776
+ * @example
18777
+ * ```typescript
18778
+ * // Add DCA entry at current market price
18779
+ * await Broker.commitAverageBuy({
18780
+ * symbol: "BTCUSDT",
18781
+ * currentPrice: 42000,
18782
+ * cost: 100,
18783
+ * context: { strategyName: "my-strategy", exchangeName: "binance", frameName: "1h" },
18784
+ * backtest: false,
18785
+ * });
18786
+ * ```
18787
+ */
18788
+ commitAverageBuy: (payload: BrokerAverageBuyPayload) => Promise<void>;
18789
+ /**
18790
+ * Registers a broker adapter instance or constructor to receive commit* callbacks.
18791
+ *
18792
+ * Must be called before `enable()`. Accepts either a class constructor (called with `new`)
18793
+ * or an already-instantiated object implementing `Partial<IBroker>`.
18794
+ *
18795
+ * @param broker - IBroker constructor or instance
18796
+ *
18797
+ * @example
18798
+ * ```typescript
18799
+ * import { Broker } from "backtest-kit";
18800
+ *
18801
+ * // Register via constructor
18802
+ * Broker.useBrokerAdapter(MyBrokerAdapter);
18803
+ *
18804
+ * // Register via instance
18805
+ * Broker.useBrokerAdapter(new MyBrokerAdapter());
18806
+ * ```
18807
+ */
18808
+ useBrokerAdapter: (broker: TBrokerCtor | Partial<IBroker>) => void;
18809
+ /**
18810
+ * Activates the broker: subscribes to syncSubject for signal-open / signal-close routing.
18811
+ *
18812
+ * Must be called after `useBrokerAdapter()`. Returns a dispose function that unsubscribes
18813
+ * from syncSubject (equivalent to calling `disable()`).
18814
+ *
18815
+ * Calling `enable()` without a registered adapter throws immediately.
18816
+ * Calling `enable()` more than once is idempotent (singleshot guard).
18817
+ *
18818
+ * @returns Dispose function — call it to deactivate the broker subscription
18819
+ *
18820
+ * @example
18821
+ * ```typescript
18822
+ * import { Broker } from "backtest-kit";
18823
+ *
18824
+ * Broker.useBrokerAdapter(MyBrokerAdapter);
18825
+ * const dispose = Broker.enable();
18826
+ *
18827
+ * // ... run backtest or live session ...
18828
+ *
18829
+ * dispose(); // or Broker.disable()
18830
+ * ```
18831
+ */
18832
+ enable: (() => () => void) & functools_kit.ISingleshotClearable;
18833
+ /**
18834
+ * Deactivates the broker: unsubscribes from syncSubject and resets the singleshot guard.
18835
+ *
18836
+ * Idempotent — safe to call even if `enable()` was never called.
18837
+ * After `disable()`, `enable()` can be called again to reactivate.
18838
+ *
18839
+ * @example
18840
+ * ```typescript
18841
+ * import { Broker } from "backtest-kit";
18842
+ *
18843
+ * Broker.useBrokerAdapter(MyBrokerAdapter);
18844
+ * Broker.enable();
18845
+ *
18846
+ * // Stop receiving events
18847
+ * Broker.disable();
18848
+ * ```
18849
+ */
18850
+ disable: () => void;
18851
+ }
18852
+ /**
18853
+ * Base class for custom broker adapter implementations.
18854
+ *
18855
+ * Provides default no-op implementations for all IBroker methods that log events.
18856
+ * Extend this class to implement a real exchange adapter for:
18857
+ * - Placing and canceling limit/market orders
18858
+ * - Updating stop-loss and take-profit levels on exchange
18859
+ * - Tracking position state in an external system
18860
+ * - Sending trade notifications (Telegram, Discord, Email)
18861
+ * - Recording trades to a database or analytics service
18862
+ *
18863
+ * Key features:
18864
+ * - All methods have default implementations (no need to override unused methods)
18865
+ * - Automatic logging of all events via bt.loggerService
18866
+ * - Implements the full IBroker interface
18867
+ * - `makeExtendable` applied for correct subclass instantiation
18868
+ *
18869
+ * Lifecycle:
18870
+ * 1. Constructor called (no arguments)
18871
+ * 2. `waitForInit()` called once for async initialization (e.g. exchange login)
18872
+ * 3. Event methods called as strategy executes
18873
+ * 4. No explicit dispose — clean up in `waitForInit` teardown or externally
18874
+ *
18875
+ * Event flow (called only in live mode, skipped in backtest):
18876
+ * - `onSignalOpenCommit` — new position opened
18877
+ * - `onSignalCloseCommit` — position closed (SL/TP hit or manual close)
18878
+ * - `onPartialProfitCommit` — partial close at profit executed
18879
+ * - `onPartialLossCommit` — partial close at loss executed
18880
+ * - `onTrailingStopCommit` — trailing stop-loss updated
18881
+ * - `onTrailingTakeCommit` — trailing take-profit updated
18882
+ * - `onBreakevenCommit` — stop-loss moved to entry price
18883
+ * - `onAverageBuyCommit` — new DCA entry added to position
18884
+ *
18885
+ * @example
18886
+ * ```typescript
18887
+ * import { BrokerBase, Broker } from "backtest-kit";
18888
+ *
18889
+ * // Extend BrokerBase and override only needed methods
18890
+ * class BinanceBroker extends BrokerBase {
18891
+ * private client: BinanceClient | null = null;
18892
+ *
18893
+ * async waitForInit() {
18894
+ * super.waitForInit(); // Call parent for logging
18895
+ * this.client = new BinanceClient(process.env.API_KEY, process.env.SECRET);
18896
+ * await this.client.connect();
18897
+ * }
18898
+ *
18899
+ * async onSignalOpenCommit(payload: BrokerSignalOpenPayload) {
18900
+ * super.onSignalOpenCommit(payload); // Call parent for logging
18901
+ * await this.client!.placeOrder({
18902
+ * symbol: payload.symbol,
18903
+ * side: payload.position === "long" ? "BUY" : "SELL",
18904
+ * quantity: payload.cost / payload.priceOpen,
18905
+ * });
18906
+ * }
18907
+ *
18908
+ * async onSignalCloseCommit(payload: BrokerSignalClosePayload) {
18909
+ * super.onSignalCloseCommit(payload); // Call parent for logging
18910
+ * await this.client!.closePosition(payload.symbol);
18911
+ * }
18912
+ * }
18913
+ *
18914
+ * // Register the adapter
18915
+ * Broker.useBrokerAdapter(BinanceBroker);
18916
+ * Broker.enable();
18917
+ * ```
18918
+ *
18919
+ * @example
18920
+ * ```typescript
18921
+ * // Minimal implementation — only handle opens and closes
18922
+ * class NotifyBroker extends BrokerBase {
18923
+ * async onSignalOpenCommit(payload: BrokerSignalOpenPayload) {
18924
+ * await sendTelegram(`Opened ${payload.position} on ${payload.symbol}`);
18925
+ * }
18926
+ *
18927
+ * async onSignalCloseCommit(payload: BrokerSignalClosePayload) {
18928
+ * const pnl = payload.pnl.profit - payload.pnl.loss;
18929
+ * await sendTelegram(`Closed ${payload.symbol}: PnL $${pnl.toFixed(2)}`);
18930
+ * }
18931
+ * }
18932
+ * ```
18933
+ */
18934
+ declare class BrokerBase implements IBroker {
18935
+ /**
18936
+ * Performs async initialization before the broker starts receiving events.
18937
+ *
18938
+ * Called once by BrokerProxy via `waitForInit()` (singleshot) before the first event.
18939
+ * Override to establish exchange connections, authenticate API clients, load configuration.
18940
+ *
18941
+ * Default implementation: Logs initialization event.
18942
+ *
18943
+ * @example
18944
+ * ```typescript
18945
+ * async waitForInit() {
18946
+ * super.waitForInit(); // Keep parent logging
18947
+ * this.exchange = new ExchangeClient(process.env.API_KEY);
18948
+ * await this.exchange.authenticate();
18949
+ * }
18950
+ * ```
18951
+ */
18952
+ waitForInit(): Promise<void>;
18953
+ /**
18954
+ * Called when a new position is opened (signal activated).
18955
+ *
18956
+ * Triggered automatically via syncSubject when a scheduled signal's priceOpen is hit.
18957
+ * Use to place the actual entry order on the exchange.
18958
+ *
18959
+ * Default implementation: Logs signal-open event.
18960
+ *
18961
+ * @param payload - Signal open details: symbol, cost, position, priceOpen, priceTakeProfit, priceStopLoss, context, backtest
18962
+ *
18963
+ * @example
18964
+ * ```typescript
18965
+ * async onSignalOpenCommit(payload: BrokerSignalOpenPayload) {
18966
+ * super.onSignalOpenCommit(payload); // Keep parent logging
18967
+ * await this.exchange.placeMarketOrder({
18968
+ * symbol: payload.symbol,
18969
+ * side: payload.position === "long" ? "BUY" : "SELL",
18970
+ * quantity: payload.cost / payload.priceOpen,
18971
+ * });
18972
+ * }
18973
+ * ```
18974
+ */
18975
+ onSignalOpenCommit(payload: BrokerSignalOpenPayload): Promise<void>;
18976
+ /**
18977
+ * Called when a position is fully closed (SL/TP hit or manual close).
18978
+ *
18979
+ * Triggered automatically via syncSubject when a pending signal is closed.
18980
+ * Use to place the exit order and record final PnL.
18981
+ *
18982
+ * Default implementation: Logs signal-close event.
18983
+ *
18984
+ * @param payload - Signal close details: symbol, cost, position, currentPrice, pnl, totalEntries, totalPartials, context, backtest
18985
+ *
18986
+ * @example
18987
+ * ```typescript
18988
+ * async onSignalCloseCommit(payload: BrokerSignalClosePayload) {
18989
+ * super.onSignalCloseCommit(payload); // Keep parent logging
18990
+ * await this.exchange.closePosition(payload.symbol);
18991
+ * await this.db.recordTrade({ symbol: payload.symbol, pnl: payload.pnl });
18992
+ * }
18993
+ * ```
18994
+ */
18995
+ onSignalCloseCommit(payload: BrokerSignalClosePayload): Promise<void>;
18996
+ /**
18997
+ * Called when a partial close at profit is executed.
18998
+ *
18999
+ * Triggered explicitly from strategy.ts / Live.ts / Backtest.ts after all validations pass,
19000
+ * before `strategyCoreService.partialProfit()`. If this method throws, the DI mutation is skipped.
19001
+ * Use to partially close the position on the exchange at the profit level.
19002
+ *
19003
+ * Default implementation: Logs partial profit event.
19004
+ *
19005
+ * @param payload - Partial profit details: symbol, percentToClose, cost (dollar value), currentPrice, context, backtest
19006
+ *
19007
+ * @example
19008
+ * ```typescript
19009
+ * async onPartialProfitCommit(payload: BrokerPartialProfitPayload) {
19010
+ * super.onPartialProfitCommit(payload); // Keep parent logging
19011
+ * await this.exchange.reducePosition({
19012
+ * symbol: payload.symbol,
19013
+ * dollarAmount: payload.cost,
19014
+ * price: payload.currentPrice,
19015
+ * });
19016
+ * }
19017
+ * ```
19018
+ */
19019
+ onPartialProfitCommit(payload: BrokerPartialProfitPayload): Promise<void>;
19020
+ /**
19021
+ * Called when a partial close at loss is executed.
19022
+ *
19023
+ * Triggered explicitly from strategy.ts / Live.ts / Backtest.ts after all validations pass,
19024
+ * before `strategyCoreService.partialLoss()`. If this method throws, the DI mutation is skipped.
19025
+ * Use to partially close the position on the exchange at the loss level.
19026
+ *
19027
+ * Default implementation: Logs partial loss event.
19028
+ *
19029
+ * @param payload - Partial loss details: symbol, percentToClose, cost (dollar value), currentPrice, context, backtest
19030
+ *
19031
+ * @example
19032
+ * ```typescript
19033
+ * async onPartialLossCommit(payload: BrokerPartialLossPayload) {
19034
+ * super.onPartialLossCommit(payload); // Keep parent logging
19035
+ * await this.exchange.reducePosition({
19036
+ * symbol: payload.symbol,
19037
+ * dollarAmount: payload.cost,
19038
+ * price: payload.currentPrice,
19039
+ * });
19040
+ * }
19041
+ * ```
19042
+ */
19043
+ onPartialLossCommit(payload: BrokerPartialLossPayload): Promise<void>;
19044
+ /**
19045
+ * Called when the trailing stop-loss level is updated.
19046
+ *
19047
+ * Triggered explicitly after all validations pass, before `strategyCoreService.trailingStop()`.
19048
+ * `newStopLossPrice` is the absolute SL price — use it to update the exchange order directly.
19049
+ *
19050
+ * Default implementation: Logs trailing stop event.
19051
+ *
19052
+ * @param payload - Trailing stop details: symbol, percentShift, currentPrice, newStopLossPrice, context, backtest
19053
+ *
19054
+ * @example
19055
+ * ```typescript
19056
+ * async onTrailingStopCommit(payload: BrokerTrailingStopPayload) {
19057
+ * super.onTrailingStopCommit(payload); // Keep parent logging
19058
+ * await this.exchange.updateStopLoss({
19059
+ * symbol: payload.symbol,
19060
+ * price: payload.newStopLossPrice,
19061
+ * });
19062
+ * }
19063
+ * ```
19064
+ */
19065
+ onTrailingStopCommit(payload: BrokerTrailingStopPayload): Promise<void>;
19066
+ /**
19067
+ * Called when the trailing take-profit level is updated.
19068
+ *
19069
+ * Triggered explicitly after all validations pass, before `strategyCoreService.trailingTake()`.
19070
+ * `newTakeProfitPrice` is the absolute TP price — use it to update the exchange order directly.
19071
+ *
19072
+ * Default implementation: Logs trailing take event.
19073
+ *
19074
+ * @param payload - Trailing take details: symbol, percentShift, currentPrice, newTakeProfitPrice, context, backtest
19075
+ *
19076
+ * @example
19077
+ * ```typescript
19078
+ * async onTrailingTakeCommit(payload: BrokerTrailingTakePayload) {
19079
+ * super.onTrailingTakeCommit(payload); // Keep parent logging
19080
+ * await this.exchange.updateTakeProfit({
19081
+ * symbol: payload.symbol,
19082
+ * price: payload.newTakeProfitPrice,
19083
+ * });
19084
+ * }
19085
+ * ```
19086
+ */
19087
+ onTrailingTakeCommit(payload: BrokerTrailingTakePayload): Promise<void>;
19088
+ /**
19089
+ * Called when the stop-loss is moved to breakeven (entry price).
19090
+ *
19091
+ * Triggered explicitly after all validations pass, before `strategyCoreService.breakeven()`.
19092
+ * `newStopLossPrice` equals `effectivePriceOpen` — the position's effective entry price.
19093
+ * `newTakeProfitPrice` is unchanged by breakeven.
19094
+ *
19095
+ * Default implementation: Logs breakeven event.
19096
+ *
19097
+ * @param payload - Breakeven details: symbol, currentPrice, newStopLossPrice, newTakeProfitPrice, context, backtest
19098
+ *
19099
+ * @example
19100
+ * ```typescript
19101
+ * async onBreakevenCommit(payload: BrokerBreakevenPayload) {
19102
+ * super.onBreakevenCommit(payload); // Keep parent logging
19103
+ * await this.exchange.updateStopLoss({
19104
+ * symbol: payload.symbol,
19105
+ * price: payload.newStopLossPrice, // = entry price
19106
+ * });
19107
+ * }
19108
+ * ```
19109
+ */
19110
+ onBreakevenCommit(payload: BrokerBreakevenPayload): Promise<void>;
19111
+ /**
19112
+ * Called when a new DCA entry is added to the active position.
19113
+ *
19114
+ * Triggered explicitly after all validations pass, before `strategyCoreService.averageBuy()`.
19115
+ * `currentPrice` is the market price at which the new averaging entry is placed.
19116
+ * `cost` is the dollar amount of the new DCA entry.
19117
+ *
19118
+ * Default implementation: Logs average buy event.
19119
+ *
19120
+ * @param payload - Average buy details: symbol, currentPrice, cost, context, backtest
19121
+ *
19122
+ * @example
19123
+ * ```typescript
19124
+ * async onAverageBuyCommit(payload: BrokerAverageBuyPayload) {
19125
+ * super.onAverageBuyCommit(payload); // Keep parent logging
19126
+ * await this.exchange.placeMarketOrder({
19127
+ * symbol: payload.symbol,
19128
+ * side: "BUY",
19129
+ * quantity: payload.cost / payload.currentPrice,
19130
+ * });
19131
+ * }
19132
+ * ```
19133
+ */
19134
+ onAverageBuyCommit(payload: BrokerAverageBuyPayload): Promise<void>;
19135
+ }
19136
+ /**
19137
+ * Global singleton instance of BrokerAdapter.
19138
+ * Provides static-like access to all broker commit methods and lifecycle controls.
19139
+ *
19140
+ * @example
19141
+ * ```typescript
19142
+ * import { Broker } from "backtest-kit";
19143
+ *
19144
+ * Broker.useBrokerAdapter(MyBrokerAdapter);
19145
+ * const dispose = Broker.enable();
19146
+ * ```
19147
+ */
19148
+ declare const Broker: BrokerAdapter;
19149
+
19150
+ /**
19151
+ * Contract for walker stop signal events.
19152
+ *
19153
+ * Emitted when Walker.stop() is called to interrupt a running walker.
19154
+ * Contains metadata about which walker and strategy should be stopped.
19155
+ *
19156
+ * Supports multiple walkers running on the same symbol simultaneously
19157
+ * by including walkerName for filtering.
19158
+ *
19159
+ * @example
19160
+ * ```typescript
19161
+ * import { walkerStopSubject } from "backtest-kit";
19162
+ *
19163
+ * walkerStopSubject
19164
+ * .filter((event) => event.symbol === "BTCUSDT")
19165
+ * .connect((event) => {
19166
+ * console.log("Walker stopped:", event.walkerName);
19167
+ * console.log("Strategy:", event.strategyName);
19168
+ * });
19169
+ * ```
19170
+ */
19171
+ interface WalkerStopContract {
19172
+ /** symbol - Trading symbol (e.g., "BTCUSDT") */
19173
+ symbol: string;
19174
+ /** strategyName - Name of the strategy to stop */
19175
+ strategyName: StrategyName;
19176
+ /** walkerName - Name of the walker to stop (for filtering) */
19177
+ walkerName: WalkerName;
19178
+ }
19179
+
19180
+ /**
19181
+ * Exchange signal synchronization emitter.
19182
+ * If listenner throws, it means the signal was not properly synchronized to the exchange (e.g. limit order failed to fill).
19183
+ *
19184
+ * The framework will skip position open/close and will try again on the next tick until successful synchronization.
19185
+ * This ensures that the framework's internal state remains consistent with the exchange's state.
19186
+ * Consumers should implement retry logic in their listeners to handle transient synchronization failures.
19187
+ */
19188
+ declare const syncSubject: Subject<SignalSyncContract>;
19189
+ /**
19190
+ * Global signal emitter for all trading events (live + backtest).
19191
+ * Emits all signal events regardless of execution mode.
17860
19192
  */
17861
19193
  declare const signalEmitter: Subject<IStrategyTickResult>;
17862
19194
  /**
@@ -18176,6 +19508,99 @@ declare const percentValue: (yesterdayValue: number, todayValue: number) => numb
18176
19508
  */
18177
19509
  declare const investedCostToPercent: (dollarAmount: number, investedCost: number) => number;
18178
19510
 
19511
+ /**
19512
+ * Convert an absolute stop-loss price to a percentShift for `commitTrailingStop`.
19513
+ *
19514
+ * percentShift = newSlDistancePercent - originalSlDistancePercent
19515
+ * where distance = Math.abs((effectivePriceOpen - slPrice) / effectivePriceOpen * 100)
19516
+ *
19517
+ * @param newStopLossPrice - Desired absolute stop-loss price
19518
+ * @param originalStopLossPrice - Original stop-loss price from the pending signal
19519
+ * @param effectivePriceOpen - Effective entry price (from `getPositionAveragePrice`)
19520
+ * @returns percentShift to pass to `commitTrailingStop`
19521
+ *
19522
+ * @example
19523
+ * // LONG: entry=100, originalSL=90, desired newSL=95
19524
+ * const shift = slPriceToPercentShift(95, 90, 100); // -5
19525
+ * await commitTrailingStop("BTCUSDT", shift, currentPrice);
19526
+ */
19527
+ declare const slPriceToPercentShift: (newStopLossPrice: number, originalStopLossPrice: number, effectivePriceOpen: number) => number;
19528
+
19529
+ /**
19530
+ * Convert an absolute take-profit price to a percentShift for `commitTrailingTake`.
19531
+ *
19532
+ * percentShift = newTpDistancePercent - originalTpDistancePercent
19533
+ * where distance = Math.abs((tpPrice - effectivePriceOpen) / effectivePriceOpen * 100)
19534
+ *
19535
+ * @param newTakeProfitPrice - Desired absolute take-profit price
19536
+ * @param originalTakeProfitPrice - Original take-profit price from the pending signal
19537
+ * @param effectivePriceOpen - Effective entry price (from `getPositionAveragePrice`)
19538
+ * @returns percentShift to pass to `commitTrailingTake`
19539
+ *
19540
+ * @example
19541
+ * // LONG: entry=100, originalTP=110, desired newTP=107
19542
+ * const shift = tpPriceToPercentShift(107, 110, 100); // -3
19543
+ * await commitTrailingTake("BTCUSDT", shift, currentPrice);
19544
+ */
19545
+ declare const tpPriceToPercentShift: (newTakeProfitPrice: number, originalTakeProfitPrice: number, effectivePriceOpen: number) => number;
19546
+
19547
+ /**
19548
+ * Convert a percentShift for `commitTrailingStop` back to an absolute stop-loss price.
19549
+ *
19550
+ * Inverse of `slPriceToPercentShift`.
19551
+ *
19552
+ * newSlDistancePercent = originalSlDistancePercent + percentShift
19553
+ * LONG: newStopLossPrice = effectivePriceOpen * (1 - newSlDistancePercent / 100)
19554
+ * SHORT: newStopLossPrice = effectivePriceOpen * (1 + newSlDistancePercent / 100)
19555
+ *
19556
+ * @param percentShift - Value returned by `slPriceToPercentShift` (or passed to `commitTrailingStop`)
19557
+ * @param originalStopLossPrice - Original stop-loss price from the pending signal
19558
+ * @param effectivePriceOpen - Effective entry price (from `getPositionAveragePrice`)
19559
+ * @param position - Position direction: "long" or "short"
19560
+ * @returns Absolute stop-loss price corresponding to the given percentShift
19561
+ *
19562
+ * @example
19563
+ * // LONG: entry=100, originalSL=90, percentShift=-5
19564
+ * const price = slPercentShiftToPrice(-5, 90, 100, "long"); // 95
19565
+ */
19566
+ declare const slPercentShiftToPrice: (percentShift: number, originalStopLossPrice: number, effectivePriceOpen: number, position: "long" | "short") => number;
19567
+
19568
+ /**
19569
+ * Convert a percentShift for `commitTrailingTake` back to an absolute take-profit price.
19570
+ *
19571
+ * Inverse of `tpPriceToPercentShift`.
19572
+ *
19573
+ * newTpDistancePercent = originalTpDistancePercent + percentShift
19574
+ * LONG: newTakeProfitPrice = effectivePriceOpen * (1 + newTpDistancePercent / 100)
19575
+ * SHORT: newTakeProfitPrice = effectivePriceOpen * (1 - newTpDistancePercent / 100)
19576
+ *
19577
+ * @param percentShift - Value returned by `tpPriceToPercentShift` (or passed to `commitTrailingTake`)
19578
+ * @param originalTakeProfitPrice - Original take-profit price from the pending signal
19579
+ * @param effectivePriceOpen - Effective entry price (from `getPositionAveragePrice`)
19580
+ * @param position - Position direction: "long" or "short"
19581
+ * @returns Absolute take-profit price corresponding to the given percentShift
19582
+ *
19583
+ * @example
19584
+ * // LONG: entry=100, originalTP=110, percentShift=-3
19585
+ * const price = tpPercentShiftToPrice(-3, 110, 100, "long"); // 107
19586
+ */
19587
+ declare const tpPercentShiftToPrice: (percentShift: number, originalTakeProfitPrice: number, effectivePriceOpen: number, position: "long" | "short") => number;
19588
+
19589
+ /**
19590
+ * Compute the dollar cost of a partial close from percentToClose and current invested cost basis.
19591
+ *
19592
+ * cost = (percentToClose / 100) * investedCost
19593
+ *
19594
+ * @param percentToClose - Percentage of position to close (0–100)
19595
+ * @param investedCost - Current invested cost basis (from `getPositionInvestedCost`)
19596
+ * @returns Dollar amount that will be closed
19597
+ *
19598
+ * @example
19599
+ * // Position investedCost=$1000, closing 25%
19600
+ * const cost = percentToCloseCost(25, 1000); // 250
19601
+ */
19602
+ declare const percentToCloseCost: (percentToClose: number, investedCost: number) => number;
19603
+
18179
19604
  /**
18180
19605
  * Client implementation for exchange data access.
18181
19606
  *
@@ -19497,6 +20922,22 @@ declare class StrategyConnectionService implements TStrategy$1 {
19497
20922
  exchangeName: ExchangeName;
19498
20923
  frameName: FrameName;
19499
20924
  }, closeId?: string) => Promise<void>;
20925
+ /**
20926
+ * Checks whether `partialProfit` would succeed without executing it.
20927
+ * Delegates to `ClientStrategy.validatePartialProfit()` — no throws, pure boolean result.
20928
+ *
20929
+ * @param backtest - Whether running in backtest mode
20930
+ * @param symbol - Trading pair symbol
20931
+ * @param percentToClose - Percentage of position to check (0-100]
20932
+ * @param currentPrice - Current market price to validate against
20933
+ * @param context - Execution context with strategyName, exchangeName, frameName
20934
+ * @returns Promise<boolean> - true if `partialProfit` would execute, false otherwise
20935
+ */
20936
+ validatePartialProfit: (backtest: boolean, symbol: string, percentToClose: number, currentPrice: number, context: {
20937
+ strategyName: StrategyName;
20938
+ exchangeName: ExchangeName;
20939
+ frameName: FrameName;
20940
+ }) => Promise<boolean>;
19500
20941
  /**
19501
20942
  * Executes partial close at profit level (moving toward TP).
19502
20943
  *
@@ -19532,6 +20973,22 @@ declare class StrategyConnectionService implements TStrategy$1 {
19532
20973
  exchangeName: ExchangeName;
19533
20974
  frameName: FrameName;
19534
20975
  }) => Promise<boolean>;
20976
+ /**
20977
+ * Checks whether `partialLoss` would succeed without executing it.
20978
+ * Delegates to `ClientStrategy.validatePartialLoss()` — no throws, pure boolean result.
20979
+ *
20980
+ * @param backtest - Whether running in backtest mode
20981
+ * @param symbol - Trading pair symbol
20982
+ * @param percentToClose - Percentage of position to check (0-100]
20983
+ * @param currentPrice - Current market price to validate against
20984
+ * @param context - Execution context with strategyName, exchangeName, frameName
20985
+ * @returns Promise<boolean> - true if `partialLoss` would execute, false otherwise
20986
+ */
20987
+ validatePartialLoss: (backtest: boolean, symbol: string, percentToClose: number, currentPrice: number, context: {
20988
+ strategyName: StrategyName;
20989
+ exchangeName: ExchangeName;
20990
+ frameName: FrameName;
20991
+ }) => Promise<boolean>;
19535
20992
  /**
19536
20993
  * Executes partial close at loss level (moving toward SL).
19537
20994
  *
@@ -19567,6 +21024,22 @@ declare class StrategyConnectionService implements TStrategy$1 {
19567
21024
  exchangeName: ExchangeName;
19568
21025
  frameName: FrameName;
19569
21026
  }) => Promise<boolean>;
21027
+ /**
21028
+ * Checks whether `trailingStop` would succeed without executing it.
21029
+ * Delegates to `ClientStrategy.validateTrailingStop()` — no throws, pure boolean result.
21030
+ *
21031
+ * @param backtest - Whether running in backtest mode
21032
+ * @param symbol - Trading pair symbol
21033
+ * @param percentShift - Percentage shift of ORIGINAL SL distance [-100, 100], excluding 0
21034
+ * @param currentPrice - Current market price to validate against
21035
+ * @param context - Execution context with strategyName, exchangeName, frameName
21036
+ * @returns Promise<boolean> - true if `trailingStop` would execute, false otherwise
21037
+ */
21038
+ validateTrailingStop: (backtest: boolean, symbol: string, percentShift: number, currentPrice: number, context: {
21039
+ strategyName: StrategyName;
21040
+ exchangeName: ExchangeName;
21041
+ frameName: FrameName;
21042
+ }) => Promise<boolean>;
19570
21043
  /**
19571
21044
  * Adjusts the trailing stop-loss distance for an active pending signal.
19572
21045
  *
@@ -19600,6 +21073,22 @@ declare class StrategyConnectionService implements TStrategy$1 {
19600
21073
  exchangeName: ExchangeName;
19601
21074
  frameName: FrameName;
19602
21075
  }) => Promise<boolean>;
21076
+ /**
21077
+ * Checks whether `trailingTake` would succeed without executing it.
21078
+ * Delegates to `ClientStrategy.validateTrailingTake()` — no throws, pure boolean result.
21079
+ *
21080
+ * @param backtest - Whether running in backtest mode
21081
+ * @param symbol - Trading pair symbol
21082
+ * @param percentShift - Percentage adjustment to ORIGINAL TP distance [-100, 100], excluding 0
21083
+ * @param currentPrice - Current market price to validate against
21084
+ * @param context - Execution context with strategyName, exchangeName, frameName
21085
+ * @returns Promise<boolean> - true if `trailingTake` would execute, false otherwise
21086
+ */
21087
+ validateTrailingTake: (backtest: boolean, symbol: string, percentShift: number, currentPrice: number, context: {
21088
+ strategyName: StrategyName;
21089
+ exchangeName: ExchangeName;
21090
+ frameName: FrameName;
21091
+ }) => Promise<boolean>;
19603
21092
  /**
19604
21093
  * Adjusts the trailing take-profit distance for an active pending signal.
19605
21094
  *
@@ -19633,6 +21122,21 @@ declare class StrategyConnectionService implements TStrategy$1 {
19633
21122
  exchangeName: ExchangeName;
19634
21123
  frameName: FrameName;
19635
21124
  }) => Promise<boolean>;
21125
+ /**
21126
+ * Checks whether `breakeven` would succeed without executing it.
21127
+ * Delegates to `ClientStrategy.validateBreakeven()` — no throws, pure boolean result.
21128
+ *
21129
+ * @param backtest - Whether running in backtest mode
21130
+ * @param symbol - Trading pair symbol
21131
+ * @param currentPrice - Current market price to validate against
21132
+ * @param context - Execution context with strategyName, exchangeName, frameName
21133
+ * @returns Promise<boolean> - true if `breakeven` would execute, false otherwise
21134
+ */
21135
+ validateBreakeven: (backtest: boolean, symbol: string, currentPrice: number, context: {
21136
+ strategyName: StrategyName;
21137
+ exchangeName: ExchangeName;
21138
+ frameName: FrameName;
21139
+ }) => Promise<boolean>;
19636
21140
  /**
19637
21141
  * Delegates to ClientStrategy.breakeven() with current execution context.
19638
21142
  *
@@ -19688,6 +21192,21 @@ declare class StrategyConnectionService implements TStrategy$1 {
19688
21192
  exchangeName: ExchangeName;
19689
21193
  frameName: FrameName;
19690
21194
  }, activateId?: string) => Promise<void>;
21195
+ /**
21196
+ * Checks whether `averageBuy` would succeed without executing it.
21197
+ * Delegates to `ClientStrategy.validateAverageBuy()` — no throws, pure boolean result.
21198
+ *
21199
+ * @param backtest - Whether running in backtest mode
21200
+ * @param symbol - Trading pair symbol
21201
+ * @param currentPrice - New entry price to validate
21202
+ * @param context - Execution context with strategyName, exchangeName, frameName
21203
+ * @returns Promise<boolean> - true if `averageBuy` would execute, false otherwise
21204
+ */
21205
+ validateAverageBuy: (backtest: boolean, symbol: string, currentPrice: number, context: {
21206
+ strategyName: StrategyName;
21207
+ exchangeName: ExchangeName;
21208
+ frameName: FrameName;
21209
+ }) => Promise<boolean>;
19691
21210
  /**
19692
21211
  * Adds a new DCA entry to the active pending signal.
19693
21212
  *
@@ -20637,6 +22156,22 @@ declare class StrategyCoreService implements TStrategy {
20637
22156
  frameName: FrameName;
20638
22157
  backtest: boolean;
20639
22158
  }) => Promise<void>;
22159
+ /**
22160
+ * Checks whether `partialProfit` would succeed without executing it.
22161
+ * Validates context, then delegates to StrategyConnectionService.validatePartialProfit().
22162
+ *
22163
+ * @param backtest - Whether running in backtest mode
22164
+ * @param symbol - Trading pair symbol
22165
+ * @param percentToClose - Percentage of position to check (0-100]
22166
+ * @param currentPrice - Current market price to validate against
22167
+ * @param context - Execution context with strategyName, exchangeName, frameName
22168
+ * @returns Promise<boolean> - true if `partialProfit` would execute, false otherwise
22169
+ */
22170
+ validatePartialProfit: (backtest: boolean, symbol: string, percentToClose: number, currentPrice: number, context: {
22171
+ strategyName: StrategyName;
22172
+ exchangeName: ExchangeName;
22173
+ frameName: FrameName;
22174
+ }) => Promise<boolean>;
20640
22175
  /**
20641
22176
  * Executes partial close at profit level (moving toward TP).
20642
22177
  *
@@ -20672,6 +22207,22 @@ declare class StrategyCoreService implements TStrategy {
20672
22207
  exchangeName: ExchangeName;
20673
22208
  frameName: FrameName;
20674
22209
  }) => Promise<boolean>;
22210
+ /**
22211
+ * Checks whether `partialLoss` would succeed without executing it.
22212
+ * Validates context, then delegates to StrategyConnectionService.validatePartialLoss().
22213
+ *
22214
+ * @param backtest - Whether running in backtest mode
22215
+ * @param symbol - Trading pair symbol
22216
+ * @param percentToClose - Percentage of position to check (0-100]
22217
+ * @param currentPrice - Current market price to validate against
22218
+ * @param context - Execution context with strategyName, exchangeName, frameName
22219
+ * @returns Promise<boolean> - true if `partialLoss` would execute, false otherwise
22220
+ */
22221
+ validatePartialLoss: (backtest: boolean, symbol: string, percentToClose: number, currentPrice: number, context: {
22222
+ strategyName: StrategyName;
22223
+ exchangeName: ExchangeName;
22224
+ frameName: FrameName;
22225
+ }) => Promise<boolean>;
20675
22226
  /**
20676
22227
  * Executes partial close at loss level (moving toward SL).
20677
22228
  *
@@ -20735,6 +22286,22 @@ declare class StrategyCoreService implements TStrategy {
20735
22286
  * );
20736
22287
  * ```
20737
22288
  */
22289
+ validateTrailingStop: (backtest: boolean, symbol: string, percentShift: number, currentPrice: number, context: {
22290
+ strategyName: StrategyName;
22291
+ exchangeName: ExchangeName;
22292
+ frameName: FrameName;
22293
+ }) => Promise<boolean>;
22294
+ /**
22295
+ * Checks whether `trailingStop` would succeed without executing it.
22296
+ * Validates context, then delegates to StrategyConnectionService.validateTrailingStop().
22297
+ *
22298
+ * @param backtest - Whether running in backtest mode
22299
+ * @param symbol - Trading pair symbol
22300
+ * @param percentShift - Percentage shift of ORIGINAL SL distance [-100, 100], excluding 0
22301
+ * @param currentPrice - Current market price to validate against
22302
+ * @param context - Execution context with strategyName, exchangeName, frameName
22303
+ * @returns Promise<boolean> - true if `trailingStop` would execute, false otherwise
22304
+ */
20738
22305
  trailingStop: (backtest: boolean, symbol: string, percentShift: number, currentPrice: number, context: {
20739
22306
  strategyName: StrategyName;
20740
22307
  exchangeName: ExchangeName;
@@ -20764,6 +22331,22 @@ declare class StrategyCoreService implements TStrategy {
20764
22331
  * );
20765
22332
  * ```
20766
22333
  */
22334
+ validateTrailingTake: (backtest: boolean, symbol: string, percentShift: number, currentPrice: number, context: {
22335
+ strategyName: StrategyName;
22336
+ exchangeName: ExchangeName;
22337
+ frameName: FrameName;
22338
+ }) => Promise<boolean>;
22339
+ /**
22340
+ * Checks whether `trailingTake` would succeed without executing it.
22341
+ * Validates context, then delegates to StrategyConnectionService.validateTrailingTake().
22342
+ *
22343
+ * @param backtest - Whether running in backtest mode
22344
+ * @param symbol - Trading pair symbol
22345
+ * @param percentShift - Percentage adjustment to ORIGINAL TP distance [-100, 100], excluding 0
22346
+ * @param currentPrice - Current market price to validate against
22347
+ * @param context - Execution context with strategyName, exchangeName, frameName
22348
+ * @returns Promise<boolean> - true if `trailingTake` would execute, false otherwise
22349
+ */
20767
22350
  trailingTake: (backtest: boolean, symbol: string, percentShift: number, currentPrice: number, context: {
20768
22351
  strategyName: StrategyName;
20769
22352
  exchangeName: ExchangeName;
@@ -20789,6 +22372,21 @@ declare class StrategyCoreService implements TStrategy {
20789
22372
  * );
20790
22373
  * ```
20791
22374
  */
22375
+ validateBreakeven: (backtest: boolean, symbol: string, currentPrice: number, context: {
22376
+ strategyName: StrategyName;
22377
+ exchangeName: ExchangeName;
22378
+ frameName: FrameName;
22379
+ }) => Promise<boolean>;
22380
+ /**
22381
+ * Checks whether `breakeven` would succeed without executing it.
22382
+ * Validates context, then delegates to StrategyConnectionService.validateBreakeven().
22383
+ *
22384
+ * @param backtest - Whether running in backtest mode
22385
+ * @param symbol - Trading pair symbol
22386
+ * @param currentPrice - Current market price to validate against
22387
+ * @param context - Execution context with strategyName, exchangeName, frameName
22388
+ * @returns Promise<boolean> - true if `breakeven` would execute, false otherwise
22389
+ */
20792
22390
  breakeven: (backtest: boolean, symbol: string, currentPrice: number, context: {
20793
22391
  strategyName: StrategyName;
20794
22392
  exchangeName: ExchangeName;
@@ -20834,6 +22432,21 @@ declare class StrategyCoreService implements TStrategy {
20834
22432
  * @param context - Execution context with strategyName, exchangeName, frameName
20835
22433
  * @returns Promise<boolean> - true if entry added, false if rejected
20836
22434
  */
22435
+ validateAverageBuy: (backtest: boolean, symbol: string, currentPrice: number, context: {
22436
+ strategyName: StrategyName;
22437
+ exchangeName: ExchangeName;
22438
+ frameName: FrameName;
22439
+ }) => Promise<boolean>;
22440
+ /**
22441
+ * Checks whether `averageBuy` would succeed without executing it.
22442
+ * Validates context, then delegates to StrategyConnectionService.validateAverageBuy().
22443
+ *
22444
+ * @param backtest - Whether running in backtest mode
22445
+ * @param symbol - Trading pair symbol
22446
+ * @param currentPrice - New entry price to validate
22447
+ * @param context - Execution context with strategyName, exchangeName, frameName
22448
+ * @returns Promise<boolean> - true if `averageBuy` would execute, false otherwise
22449
+ */
20837
22450
  averageBuy: (backtest: boolean, symbol: string, currentPrice: number, context: {
20838
22451
  strategyName: StrategyName;
20839
22452
  exchangeName: ExchangeName;
@@ -23477,4 +25090,4 @@ declare const getTotalClosed: (signal: Signal) => {
23477
25090
  remainingCostBasis: number;
23478
25091
  };
23479
25092
 
23480
- export { ActionBase, type ActivateScheduledCommit, type ActivateScheduledCommitNotification, type ActivePingContract, type AverageBuyCommit, type AverageBuyCommitNotification, Backtest, type BacktestStatisticsModel, Breakeven, type BreakevenAvailableNotification, type BreakevenCommit, type BreakevenCommitNotification, type BreakevenContract, type BreakevenData, Cache, type CancelScheduledCommit, type CandleData, type CandleInterval, type ClosePendingCommit, type ColumnConfig, type ColumnModel, Constant, type CriticalErrorNotification, type DoneContract, type EntityId, Exchange, ExecutionContextService, type FrameInterval, type GlobalConfig, Heat, type HeatmapStatisticsModel, type IActionSchema, type IActivateScheduledCommitRow, type IAggregatedTradeData, type IBidData, type IBreakevenCommitRow, type ICandleData, type ICommitRow, type IExchangeSchema, type IFrameSchema, type IHeatmapRow, type ILog, type ILogEntry, type ILogger, type IMarkdownDumpOptions, type INotificationUtils, type IOrderBookData, type IPartialLossCommitRow, type IPartialProfitCommitRow, type IPersistBase, type IPositionSizeATRParams, type IPositionSizeFixedPercentageParams, type IPositionSizeKellyParams, type IPublicAction, type IPublicCandleData, type IPublicSignalRow, type IReportDumpOptions, type IRiskActivePosition, type IRiskCheckArgs, type IRiskSchema, type IRiskSignalRow, type IRiskValidation, type IRiskValidationFn, type IRiskValidationPayload, type IScheduledSignalCancelRow, type IScheduledSignalRow, type ISignalDto, type ISignalRow, type ISizingCalculateParams, type ISizingCalculateParamsATR, type ISizingCalculateParamsFixedPercentage, type ISizingCalculateParamsKelly, type ISizingParams, type ISizingParamsATR, type ISizingParamsFixedPercentage, type ISizingParamsKelly, type ISizingSchema, type ISizingSchemaATR, type ISizingSchemaFixedPercentage, type ISizingSchemaKelly, type IStorageSignalRow, type IStorageUtils, type IStrategyPnL, type IStrategyResult, type IStrategySchema, type IStrategyTickResult, type IStrategyTickResultActive, type IStrategyTickResultCancelled, type IStrategyTickResultClosed, type IStrategyTickResultIdle, type IStrategyTickResultOpened, type IStrategyTickResultScheduled, type IStrategyTickResultWaiting, type ITrailingStopCommitRow, type ITrailingTakeCommitRow, type IWalkerResults, type IWalkerSchema, type IWalkerStrategyResult, type InfoErrorNotification, Live, type LiveStatisticsModel, Log, type LogData, Markdown, MarkdownFileBase, MarkdownFolderBase, type MarkdownName, type MeasureData, MethodContextService, type MetricStats, Notification, NotificationBacktest, type NotificationData, NotificationLive, type NotificationModel, Partial$1 as Partial, type PartialData, type PartialEvent, type PartialLossAvailableNotification, type PartialLossCommit, type PartialLossCommitNotification, type PartialLossContract, type PartialProfitAvailableNotification, type PartialProfitCommit, type PartialProfitCommitNotification, type PartialProfitContract, type PartialStatisticsModel, Performance, type PerformanceContract, type PerformanceMetricType, type PerformanceStatisticsModel, PersistBase, PersistBreakevenAdapter, PersistCandleAdapter, PersistLogAdapter, PersistMeasureAdapter, PersistNotificationAdapter, PersistPartialAdapter, PersistRiskAdapter, PersistScheduleAdapter, PersistSignalAdapter, PersistStorageAdapter, PositionSize, type ProgressBacktestContract, type ProgressWalkerContract, Report, ReportBase, type ReportName, Risk, type RiskContract, type RiskData, type RiskEvent, type RiskRejectionNotification, type RiskStatisticsModel, Schedule, type ScheduleData, type SchedulePingContract, type ScheduleStatisticsModel, type ScheduledEvent, type SignalCancelledNotification, type SignalCloseContract, type SignalClosedNotification, type SignalData, type SignalInterval, type SignalOpenContract, type SignalOpenedNotification, type SignalScheduledNotification, type SignalSyncCloseNotification, type SignalSyncContract, type SignalSyncOpenNotification, Storage, StorageBacktest, type StorageData, StorageLive, Strategy, type StrategyActionType, type StrategyCancelReason, type StrategyCloseReason, type StrategyCommitContract, type StrategyEvent, type StrategyStatisticsModel, Sync, type SyncEvent, type SyncStatisticsModel, type TLogCtor, type TMarkdownBase, type TNotificationUtilsCtor, type TPersistBase, type TPersistBaseCtor, type TReportBase, type TStorageUtilsCtor, type TickEvent, type TrailingStopCommit, type TrailingStopCommitNotification, type TrailingTakeCommit, type TrailingTakeCommitNotification, type ValidationErrorNotification, Walker, type WalkerCompleteContract, type WalkerContract, type WalkerMetric, type SignalData$1 as WalkerSignalData, type WalkerStatisticsModel, addActionSchema, addExchangeSchema, addFrameSchema, addRiskSchema, addSizingSchema, addStrategySchema, addWalkerSchema, alignToInterval, checkCandles, commitActivateScheduled, commitAverageBuy, commitBreakeven, commitCancelScheduled, commitClosePending, commitPartialLoss, commitPartialLossCost, commitPartialProfit, commitPartialProfitCost, commitTrailingStop, commitTrailingTake, dumpMessages, emitters, formatPrice, formatQuantity, get, getActionSchema, getAggregatedTrades, getAveragePrice, getBacktestTimeframe, getBreakeven, getCandles, getColumns, getConfig, getContext, getDate, getDefaultColumns, getDefaultConfig, getEffectivePriceOpen, getExchangeSchema, getFrameSchema, getMode, getNextCandles, getOrderBook, getPendingSignal, getPositionAveragePrice, getPositionInvestedCost, getPositionInvestedCount, getPositionLevels, getPositionPartials, getPositionPnlCost, getPositionPnlPercent, getRawCandles, getRiskSchema, getScheduledSignal, getSizingSchema, getStrategySchema, getSymbol, getTimestamp, getTotalClosed, getTotalCostClosed, getTotalPercentClosed, getWalkerSchema, hasTradeContext, investedCostToPercent, backtest as lib, listExchangeSchema, listFrameSchema, listRiskSchema, listSizingSchema, listStrategySchema, listWalkerSchema, listenActivePing, listenActivePingOnce, listenBacktestProgress, listenBreakevenAvailable, listenBreakevenAvailableOnce, listenDoneBacktest, listenDoneBacktestOnce, listenDoneLive, listenDoneLiveOnce, listenDoneWalker, listenDoneWalkerOnce, listenError, listenExit, listenPartialLossAvailable, listenPartialLossAvailableOnce, listenPartialProfitAvailable, listenPartialProfitAvailableOnce, listenPerformance, listenRisk, listenRiskOnce, listenSchedulePing, listenSchedulePingOnce, listenSignal, listenSignalBacktest, listenSignalBacktestOnce, listenSignalLive, listenSignalLiveOnce, listenSignalOnce, listenStrategyCommit, listenStrategyCommitOnce, listenSync, listenSyncOnce, listenValidation, listenWalker, listenWalkerComplete, listenWalkerOnce, listenWalkerProgress, overrideActionSchema, overrideExchangeSchema, overrideFrameSchema, overrideRiskSchema, overrideSizingSchema, overrideStrategySchema, overrideWalkerSchema, parseArgs, percentDiff, percentValue, roundTicks, set, setColumns, setConfig, setLogger, shutdown, stopStrategy, toProfitLossDto, validate, waitForCandle, warmCandles };
25093
+ export { ActionBase, type ActivateScheduledCommit, type ActivateScheduledCommitNotification, type ActivePingContract, type AverageBuyCommit, type AverageBuyCommitNotification, Backtest, type BacktestStatisticsModel, Breakeven, type BreakevenAvailableNotification, type BreakevenCommit, type BreakevenCommitNotification, type BreakevenContract, type BreakevenData, Broker, type BrokerAverageBuyPayload, BrokerBase, type BrokerBreakevenPayload, type BrokerPartialLossPayload, type BrokerPartialProfitPayload, type BrokerSignalClosePayload, type BrokerSignalOpenPayload, type BrokerTrailingStopPayload, type BrokerTrailingTakePayload, Cache, type CancelScheduledCommit, type CandleData, type CandleInterval, type ClosePendingCommit, type ColumnConfig, type ColumnModel, Constant, type CriticalErrorNotification, type DoneContract, type EntityId, Exchange, ExecutionContextService, type FrameInterval, type GlobalConfig, Heat, type HeatmapStatisticsModel, type IActionSchema, type IActivateScheduledCommitRow, type IAggregatedTradeData, type IBidData, type IBreakevenCommitRow, type IBroker, type ICandleData, type ICommitRow, type IExchangeSchema, type IFrameSchema, type IHeatmapRow, type ILog, type ILogEntry, type ILogger, type IMarkdownDumpOptions, type INotificationUtils, type IOrderBookData, type IPartialLossCommitRow, type IPartialProfitCommitRow, type IPersistBase, type IPositionSizeATRParams, type IPositionSizeFixedPercentageParams, type IPositionSizeKellyParams, type IPublicAction, type IPublicCandleData, type IPublicSignalRow, type IReportDumpOptions, type IRiskActivePosition, type IRiskCheckArgs, type IRiskSchema, type IRiskSignalRow, type IRiskValidation, type IRiskValidationFn, type IRiskValidationPayload, type IScheduledSignalCancelRow, type IScheduledSignalRow, type ISignalDto, type ISignalRow, type ISizingCalculateParams, type ISizingCalculateParamsATR, type ISizingCalculateParamsFixedPercentage, type ISizingCalculateParamsKelly, type ISizingParams, type ISizingParamsATR, type ISizingParamsFixedPercentage, type ISizingParamsKelly, type ISizingSchema, type ISizingSchemaATR, type ISizingSchemaFixedPercentage, type ISizingSchemaKelly, type IStorageSignalRow, type IStorageUtils, type IStrategyPnL, type IStrategyResult, type IStrategySchema, type IStrategyTickResult, type IStrategyTickResultActive, type IStrategyTickResultCancelled, type IStrategyTickResultClosed, type IStrategyTickResultIdle, type IStrategyTickResultOpened, type IStrategyTickResultScheduled, type IStrategyTickResultWaiting, type ITrailingStopCommitRow, type ITrailingTakeCommitRow, type IWalkerResults, type IWalkerSchema, type IWalkerStrategyResult, type InfoErrorNotification, Live, type LiveStatisticsModel, Log, type LogData, Markdown, MarkdownFileBase, MarkdownFolderBase, type MarkdownName, type MeasureData, MethodContextService, type MetricStats, Notification, NotificationBacktest, type NotificationData, NotificationLive, type NotificationModel, Partial$1 as Partial, type PartialData, type PartialEvent, type PartialLossAvailableNotification, type PartialLossCommit, type PartialLossCommitNotification, type PartialLossContract, type PartialProfitAvailableNotification, type PartialProfitCommit, type PartialProfitCommitNotification, type PartialProfitContract, type PartialStatisticsModel, Performance, type PerformanceContract, type PerformanceMetricType, type PerformanceStatisticsModel, PersistBase, PersistBreakevenAdapter, PersistCandleAdapter, PersistLogAdapter, PersistMeasureAdapter, PersistNotificationAdapter, PersistPartialAdapter, PersistRiskAdapter, PersistScheduleAdapter, PersistSignalAdapter, PersistStorageAdapter, PositionSize, type ProgressBacktestContract, type ProgressWalkerContract, Report, ReportBase, type ReportName, Risk, type RiskContract, type RiskData, type RiskEvent, type RiskRejectionNotification, type RiskStatisticsModel, Schedule, type ScheduleData, type SchedulePingContract, type ScheduleStatisticsModel, type ScheduledEvent, type SignalCancelledNotification, type SignalCloseContract, type SignalClosedNotification, type SignalData, type SignalInterval, type SignalOpenContract, type SignalOpenedNotification, type SignalScheduledNotification, type SignalSyncCloseNotification, type SignalSyncContract, type SignalSyncOpenNotification, Storage, StorageBacktest, type StorageData, StorageLive, Strategy, type StrategyActionType, type StrategyCancelReason, type StrategyCloseReason, type StrategyCommitContract, type StrategyEvent, type StrategyStatisticsModel, Sync, type SyncEvent, type SyncStatisticsModel, type TBrokerCtor, type TLogCtor, type TMarkdownBase, type TNotificationUtilsCtor, type TPersistBase, type TPersistBaseCtor, type TReportBase, type TStorageUtilsCtor, type TickEvent, type TrailingStopCommit, type TrailingStopCommitNotification, type TrailingTakeCommit, type TrailingTakeCommitNotification, type ValidationErrorNotification, Walker, type WalkerCompleteContract, type WalkerContract, type WalkerMetric, type SignalData$1 as WalkerSignalData, type WalkerStatisticsModel, addActionSchema, addExchangeSchema, addFrameSchema, addRiskSchema, addSizingSchema, addStrategySchema, addWalkerSchema, alignToInterval, checkCandles, commitActivateScheduled, commitAverageBuy, commitBreakeven, commitCancelScheduled, commitClosePending, commitPartialLoss, commitPartialLossCost, commitPartialProfit, commitPartialProfitCost, commitTrailingStop, commitTrailingStopCost, commitTrailingTake, commitTrailingTakeCost, dumpMessages, emitters, formatPrice, formatQuantity, get, getActionSchema, getAggregatedTrades, getAveragePrice, getBacktestTimeframe, getBreakeven, getCandles, getColumns, getConfig, getContext, getDate, getDefaultColumns, getDefaultConfig, getEffectivePriceOpen, getExchangeSchema, getFrameSchema, getMode, getNextCandles, getOrderBook, getPendingSignal, getPositionAveragePrice, getPositionInvestedCost, getPositionInvestedCount, getPositionLevels, getPositionPartials, getPositionPnlCost, getPositionPnlPercent, getRawCandles, getRiskSchema, getScheduledSignal, getSizingSchema, getStrategySchema, getSymbol, getTimestamp, getTotalClosed, getTotalCostClosed, getTotalPercentClosed, getWalkerSchema, hasTradeContext, investedCostToPercent, backtest as lib, listExchangeSchema, listFrameSchema, listRiskSchema, listSizingSchema, listStrategySchema, listWalkerSchema, listenActivePing, listenActivePingOnce, listenBacktestProgress, listenBreakevenAvailable, listenBreakevenAvailableOnce, listenDoneBacktest, listenDoneBacktestOnce, listenDoneLive, listenDoneLiveOnce, listenDoneWalker, listenDoneWalkerOnce, listenError, listenExit, listenPartialLossAvailable, listenPartialLossAvailableOnce, listenPartialProfitAvailable, listenPartialProfitAvailableOnce, listenPerformance, listenRisk, listenRiskOnce, listenSchedulePing, listenSchedulePingOnce, listenSignal, listenSignalBacktest, listenSignalBacktestOnce, listenSignalLive, listenSignalLiveOnce, listenSignalOnce, listenStrategyCommit, listenStrategyCommitOnce, listenSync, listenSyncOnce, listenValidation, listenWalker, listenWalkerComplete, listenWalkerOnce, listenWalkerProgress, overrideActionSchema, overrideExchangeSchema, overrideFrameSchema, overrideRiskSchema, overrideSizingSchema, overrideStrategySchema, overrideWalkerSchema, parseArgs, percentDiff, percentToCloseCost, percentValue, roundTicks, set, setColumns, setConfig, setLogger, shutdown, slPercentShiftToPrice, slPriceToPercentShift, stopStrategy, toProfitLossDto, tpPercentShiftToPrice, tpPriceToPercentShift, validate, waitForCandle, warmCandles };