backtest-kit 4.0.1 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "backtest-kit",
3
- "version": "4.0.1",
3
+ "version": "5.0.0",
4
4
  "description": "A TypeScript library for trading system backtest",
5
5
  "author": {
6
6
  "name": "Petr Tripolsky",
package/types.d.ts CHANGED
@@ -1792,6 +1792,9 @@ interface IAction {
1792
1792
  *
1793
1793
  * NOTE: Exceptions are NOT swallowed here — they propagate to CREATE_SYNC_FN.
1794
1794
  *
1795
+ * @deprecated This method is not recommended for use. Implement custom logic in signal(), signalLive(), or signalBacktest() instead.
1796
+ * If you need to implement custom logic on signal open/close, please use signal(), signalBacktest(), signalLive() instead.
1797
+ * If Action::signalSync throws the exchange will not execute the order!
1795
1798
  * @param event - Sync event with action "signal-open" or "signal-close"
1796
1799
  */
1797
1800
  signalSync(event: SignalSyncContract): void | Promise<void>;
@@ -2850,6 +2853,23 @@ interface IStrategy {
2850
2853
  * Returns null if no pending signal exists.
2851
2854
  */
2852
2855
  getPositionPnlCost: (symbol: string, currentPrice: number) => Promise<number | null>;
2856
+ /**
2857
+ * Returns the list of DCA entry prices and costs for the current pending signal.
2858
+ *
2859
+ * Each entry records the price and cost of a single position entry.
2860
+ * The first element is always the original priceOpen (initial entry).
2861
+ * Each subsequent element is an entry added by averageBuy().
2862
+ *
2863
+ * Returns null if no pending signal exists.
2864
+ * Returns a single-element array [{ price: priceOpen, cost }] if no DCA entries were made.
2865
+ *
2866
+ * @param symbol - Trading pair symbol
2867
+ * @returns Promise resolving to array of entry records or null
2868
+ */
2869
+ getPositionEntries: (symbol: string) => Promise<Array<{
2870
+ price: number;
2871
+ cost: number;
2872
+ }> | null>;
2853
2873
  /**
2854
2874
  * Fast backtest using historical candles.
2855
2875
  * Iterates through candles, calculates VWAP, checks TP/SL on each candle.
@@ -4353,6 +4373,17 @@ declare function getRiskSchema(riskName: RiskName): IRiskSchema;
4353
4373
  */
4354
4374
  declare function getActionSchema(actionName: ActionName): IActionSchema;
4355
4375
 
4376
+ /**
4377
+ * Tolerance zone configuration for DCA overlap detection.
4378
+ * Percentages are in 0–100 format (e.g. 5 means 5%).
4379
+ */
4380
+ interface IPositionOverlapLadder {
4381
+ /** Upper tolerance in percent (0–100): how far above each DCA level to flag as overlap */
4382
+ upperPercent: number;
4383
+ /** Lower tolerance in percent (0–100): how far below each DCA level to flag as overlap */
4384
+ lowerPercent: number;
4385
+ }
4386
+
4356
4387
  /**
4357
4388
  * Cancels the scheduled signal without stopping the strategy.
4358
4389
  *
@@ -4698,7 +4729,7 @@ declare function getTotalCostClosed(symbol: string): Promise<number>;
4698
4729
  * }
4699
4730
  * ```
4700
4731
  */
4701
- declare function getPendingSignal(symbol: string): Promise<ISignalRow>;
4732
+ declare function getPendingSignal(symbol: string): Promise<IPublicSignalRow>;
4702
4733
  /**
4703
4734
  * Returns the currently active scheduled signal for the strategy.
4704
4735
  * If no scheduled signal exists, returns null.
@@ -4743,9 +4774,101 @@ declare function getScheduledSignal(symbol: string): Promise<IScheduledSignalRow
4743
4774
  * ```
4744
4775
  */
4745
4776
  declare function getBreakeven(symbol: string, currentPrice: number): Promise<boolean>;
4777
+ /**
4778
+ * Returns the effective (DCA-weighted) entry price for the current pending signal.
4779
+ *
4780
+ * Uses cost-weighted harmonic mean: Σcost / Σ(cost/price).
4781
+ * When partial closes exist, the price is computed iteratively using
4782
+ * costBasisAtClose snapshots from each partial, then blended with any
4783
+ * DCA entries added after the last partial.
4784
+ * With no DCA entries, equals the original priceOpen.
4785
+ *
4786
+ * Returns null if no pending signal exists.
4787
+ *
4788
+ * Automatically detects backtest/live mode from execution context.
4789
+ *
4790
+ * @param symbol - Trading pair symbol
4791
+ * @returns Promise resolving to effective entry price or null
4792
+ *
4793
+ * @example
4794
+ * ```typescript
4795
+ * import { getPositionAveragePrice } from "backtest-kit";
4796
+ *
4797
+ * const avgPrice = await getPositionAveragePrice("BTCUSDT");
4798
+ * // No DCA: avgPrice === priceOpen
4799
+ * // After DCA at lower price: avgPrice < priceOpen
4800
+ * ```
4801
+ */
4746
4802
  declare function getPositionAveragePrice(symbol: string): Promise<number | null>;
4803
+ /**
4804
+ * Returns the number of DCA entries made for the current pending signal.
4805
+ *
4806
+ * 1 = original entry only (no DCA).
4807
+ * Increases by 1 with each successful commitAverageBuy().
4808
+ *
4809
+ * Returns null if no pending signal exists.
4810
+ *
4811
+ * Automatically detects backtest/live mode from execution context.
4812
+ *
4813
+ * @param symbol - Trading pair symbol
4814
+ * @returns Promise resolving to entry count or null
4815
+ *
4816
+ * @example
4817
+ * ```typescript
4818
+ * import { getPositionInvestedCount } from "backtest-kit";
4819
+ *
4820
+ * const count = await getPositionInvestedCount("BTCUSDT");
4821
+ * // No DCA: count === 1
4822
+ * // After one DCA: count === 2
4823
+ * ```
4824
+ */
4747
4825
  declare function getPositionInvestedCount(symbol: string): Promise<number | null>;
4826
+ /**
4827
+ * Returns the total invested cost basis in dollars for the current pending signal.
4828
+ *
4829
+ * Equal to the sum of all _entry costs (Σ entry.cost).
4830
+ * Each entry cost is set at the time of commitAverageBuy (defaults to CC_POSITION_ENTRY_COST).
4831
+ *
4832
+ * Returns null if no pending signal exists.
4833
+ *
4834
+ * Automatically detects backtest/live mode from execution context.
4835
+ *
4836
+ * @param symbol - Trading pair symbol
4837
+ * @returns Promise resolving to total invested cost in dollars or null
4838
+ *
4839
+ * @example
4840
+ * ```typescript
4841
+ * import { getPositionInvestedCost } from "backtest-kit";
4842
+ *
4843
+ * const cost = await getPositionInvestedCost("BTCUSDT");
4844
+ * // No DCA, default cost: cost === 100
4845
+ * // After one DCA with default cost: cost === 200
4846
+ * ```
4847
+ */
4748
4848
  declare function getPositionInvestedCost(symbol: string): Promise<number | null>;
4849
+ /**
4850
+ * Returns the unrealized PNL percentage for the current pending signal at current market price.
4851
+ *
4852
+ * Accounts for partial closes, DCA entries, slippage and fees
4853
+ * (delegates to toProfitLossDto).
4854
+ *
4855
+ * Returns null if no pending signal exists.
4856
+ *
4857
+ * Automatically detects backtest/live mode from execution context.
4858
+ * Automatically fetches current price via getAveragePrice.
4859
+ *
4860
+ * @param symbol - Trading pair symbol
4861
+ * @returns Promise resolving to PNL percentage or null
4862
+ *
4863
+ * @example
4864
+ * ```typescript
4865
+ * import { getPositionPnlPercent } from "backtest-kit";
4866
+ *
4867
+ * const pnlPct = await getPositionPnlPercent("BTCUSDT");
4868
+ * // LONG at 100, current=105: pnlPct ≈ 5
4869
+ * // LONG at 100, current=95: pnlPct ≈ -5
4870
+ * ```
4871
+ */
4749
4872
  declare function getPositionPnlPercent(symbol: string): Promise<number | null>;
4750
4873
  /**
4751
4874
  * Executes partial close at profit level by absolute dollar amount (moving toward TP).
@@ -4807,6 +4930,29 @@ declare function commitPartialProfitCost(symbol: string, dollarAmount: number):
4807
4930
  * ```
4808
4931
  */
4809
4932
  declare function commitPartialLossCost(symbol: string, dollarAmount: number): Promise<boolean>;
4933
+ /**
4934
+ * Returns the unrealized PNL in dollars for the current pending signal at current market price.
4935
+ *
4936
+ * Calculated as: pnlPercentage / 100 × totalInvestedCost.
4937
+ * Accounts for partial closes, DCA entries, slippage and fees.
4938
+ *
4939
+ * Returns null if no pending signal exists.
4940
+ *
4941
+ * Automatically detects backtest/live mode from execution context.
4942
+ * Automatically fetches current price via getAveragePrice.
4943
+ *
4944
+ * @param symbol - Trading pair symbol
4945
+ * @returns Promise resolving to PNL in dollars or null
4946
+ *
4947
+ * @example
4948
+ * ```typescript
4949
+ * import { getPositionPnlCost } from "backtest-kit";
4950
+ *
4951
+ * const pnlCost = await getPositionPnlCost("BTCUSDT");
4952
+ * // LONG at 100, invested $100, current=105: pnlCost ≈ 5
4953
+ * // LONG at 100, invested $200 (DCA), current=95: pnlCost ≈ -10
4954
+ * ```
4955
+ */
4810
4956
  declare function getPositionPnlCost(symbol: string): Promise<number | null>;
4811
4957
  /**
4812
4958
  * Returns the list of DCA entry prices for the current pending signal.
@@ -4866,6 +5012,58 @@ declare function getPositionPartials(symbol: string): Promise<{
4866
5012
  entryCountAtClose: number;
4867
5013
  debugTimestamp?: number;
4868
5014
  }[]>;
5015
+ /**
5016
+ * Checks whether the current price falls within the tolerance zone of any existing DCA entry level.
5017
+ * Use this to prevent duplicate DCA entries at the same price area.
5018
+ *
5019
+ * Returns true if currentPrice is within [level - lowerStep, level + upperStep] for any level,
5020
+ * where step = level * percent / 100.
5021
+ * Returns false if no pending signal exists.
5022
+ *
5023
+ * @param symbol - Trading pair symbol
5024
+ * @param currentPrice - Price to check against existing DCA levels
5025
+ * @param ladder - Tolerance zone config; percentages in 0–100 format (default: 1.5% up and down)
5026
+ * @returns Promise<boolean> - true if price overlaps an existing entry level (DCA not recommended)
5027
+ *
5028
+ * @example
5029
+ * ```typescript
5030
+ * import { getPositionEntryOverlap } from "backtest-kit";
5031
+ *
5032
+ * // LONG with levels [43000, 42000], check if 42100 is too close to 42000
5033
+ * const overlap = await getPositionEntryOverlap("BTCUSDT", 42100, { upperPercent: 5, lowerPercent: 5 });
5034
+ * // overlap = true (42100 is within 5% of 42000 = [39900, 44100])
5035
+ * if (!overlap) {
5036
+ * await commitAverageBuy("BTCUSDT");
5037
+ * }
5038
+ * ```
5039
+ */
5040
+ declare function getPositionEntryOverlap(symbol: string, currentPrice: number, ladder?: IPositionOverlapLadder): Promise<boolean>;
5041
+ /**
5042
+ * Checks whether the current price falls within the tolerance zone of any existing partial close price.
5043
+ * Use this to prevent duplicate partial closes at the same price area.
5044
+ *
5045
+ * Returns true if currentPrice is within [partial.currentPrice - lowerStep, partial.currentPrice + upperStep]
5046
+ * for any partial, where step = partial.currentPrice * percent / 100.
5047
+ * Returns false if no pending signal exists or no partials have been executed yet.
5048
+ *
5049
+ * @param symbol - Trading pair symbol
5050
+ * @param currentPrice - Price to check against existing partial close prices
5051
+ * @param ladder - Tolerance zone config; percentages in 0–100 format (default: 1.5% up and down)
5052
+ * @returns Promise<boolean> - true if price overlaps an existing partial price (partial not recommended)
5053
+ *
5054
+ * @example
5055
+ * ```typescript
5056
+ * import { getPositionPartialOverlap } from "backtest-kit";
5057
+ *
5058
+ * // Partials at [45000], check if 45100 is too close
5059
+ * const overlap = await getPositionPartialOverlap("BTCUSDT", 45100, { upperPercent: 1.5, lowerPercent: 1.5 });
5060
+ * // overlap = true (45100 is within 1.5% of 45000)
5061
+ * if (!overlap) {
5062
+ * await commitPartialProfit("BTCUSDT", 50);
5063
+ * }
5064
+ * ```
5065
+ */
5066
+ declare function getPositionPartialOverlap(symbol: string, currentPrice: number, ladder?: IPositionOverlapLadder): Promise<boolean>;
4869
5067
 
4870
5068
  /**
4871
5069
  * Stops the strategy from generating new signals.
@@ -5148,9 +5346,17 @@ declare const GLOBAL_CONFIG: {
5148
5346
  * Allows to commitAverageBuy if currentPrice is not the lowest price since entry, but still lower than priceOpen.
5149
5347
  * This can help improve average entry price in cases where price has rebounded after entry but is still below priceOpen, without waiting for a new lower price.
5150
5348
  *
5151
- * Default: true (DCA logic enabled everywhere, not just when antirecord is broken)
5349
+ * Default: false (DCA logic enabled only when antirecord is broken)
5152
5350
  */
5153
5351
  CC_ENABLE_DCA_EVERYWHERE: boolean;
5352
+ /**
5353
+ * Enables PPPL (Partial Profit, Partial Loss) logic even if this breaks a direction of exits
5354
+ * Allows to take partial profit or loss on a position even if it results in a mix of profit and loss exits
5355
+ * This can help lock in profits or cut losses on part of the position without waiting for a perfect exit scenario.
5356
+ *
5357
+ * Default: false (PPPL logic is only applied when it does not break the direction of exits, ensuring clearer profit/loss outcomes)
5358
+ */
5359
+ CC_ENABLE_PPPL_EVERYWHERE: boolean;
5154
5360
  /**
5155
5361
  * Cost of entering a position (in USD).
5156
5362
  * This is used as a default value for calculating position size and risk management when cost data is not provided by the strategy
@@ -5271,6 +5477,7 @@ declare function getConfig(): {
5271
5477
  CC_MAX_LOG_LINES: number;
5272
5478
  CC_ENABLE_CANDLE_FETCH_MUTEX: boolean;
5273
5479
  CC_ENABLE_DCA_EVERYWHERE: boolean;
5480
+ CC_ENABLE_PPPL_EVERYWHERE: boolean;
5274
5481
  CC_POSITION_ENTRY_COST: number;
5275
5482
  };
5276
5483
  /**
@@ -5312,6 +5519,7 @@ declare function getDefaultConfig(): Readonly<{
5312
5519
  CC_MAX_LOG_LINES: number;
5313
5520
  CC_ENABLE_CANDLE_FETCH_MUTEX: boolean;
5314
5521
  CC_ENABLE_DCA_EVERYWHERE: boolean;
5522
+ CC_ENABLE_PPPL_EVERYWHERE: boolean;
5315
5523
  CC_POSITION_ENTRY_COST: number;
5316
5524
  }>;
5317
5525
  /**
@@ -11418,7 +11626,7 @@ declare class BacktestUtils {
11418
11626
  strategyName: StrategyName;
11419
11627
  exchangeName: ExchangeName;
11420
11628
  frameName: FrameName;
11421
- }) => Promise<ISignalRow>;
11629
+ }) => Promise<IPublicSignalRow>;
11422
11630
  /**
11423
11631
  * Returns the percentage of the position currently held (not closed).
11424
11632
  * 100 = nothing has been closed (full position), 0 = fully closed.
@@ -11631,6 +11839,69 @@ declare class BacktestUtils {
11631
11839
  entryCountAtClose: number;
11632
11840
  debugTimestamp?: number;
11633
11841
  }[]>;
11842
+ /**
11843
+ * Returns the list of DCA entry prices and costs for the current pending signal.
11844
+ *
11845
+ * Each element represents a single position entry — the initial open or a subsequent
11846
+ * DCA entry added via commitAverageBuy.
11847
+ *
11848
+ * Returns null if no pending signal exists.
11849
+ * Returns a single-element array if no DCA entries were made.
11850
+ *
11851
+ * Each entry contains:
11852
+ * - `price` — execution price of this entry
11853
+ * - `cost` — dollar cost allocated to this entry (e.g. 100 for $100)
11854
+ *
11855
+ * @param symbol - Trading pair symbol
11856
+ * @param context - Execution context with strategyName, exchangeName, and frameName
11857
+ * @returns Array of entry records, or null if no active position
11858
+ */
11859
+ getPositionEntries: (symbol: string, context: {
11860
+ strategyName: StrategyName;
11861
+ exchangeName: ExchangeName;
11862
+ frameName: FrameName;
11863
+ }) => Promise<{
11864
+ price: number;
11865
+ cost: number;
11866
+ }[]>;
11867
+ /**
11868
+ * Checks whether the current price falls within the tolerance zone of any existing DCA entry level.
11869
+ * Use this to prevent duplicate DCA entries at the same price area.
11870
+ *
11871
+ * Returns true if currentPrice is within [level - lowerStep, level + upperStep] for any level,
11872
+ * where step = level * percent / 100.
11873
+ * Returns false if no pending signal exists.
11874
+ *
11875
+ * @param symbol - Trading pair symbol
11876
+ * @param currentPrice - Price to check against existing DCA levels
11877
+ * @param context - Execution context with strategyName, exchangeName, and frameName
11878
+ * @param ladder - Tolerance zone config; percentages in 0–100 format (default: 1.5% up and down)
11879
+ * @returns true if price overlaps an existing entry level (DCA not recommended)
11880
+ */
11881
+ getPositionEntryOverlap: (symbol: string, currentPrice: number, context: {
11882
+ strategyName: StrategyName;
11883
+ exchangeName: ExchangeName;
11884
+ frameName: FrameName;
11885
+ }, ladder?: IPositionOverlapLadder) => Promise<boolean>;
11886
+ /**
11887
+ * Checks whether the current price falls within the tolerance zone of any existing partial close price.
11888
+ * Use this to prevent duplicate partial closes at the same price area.
11889
+ *
11890
+ * Returns true if currentPrice is within [partial.currentPrice - lowerStep, partial.currentPrice + upperStep]
11891
+ * for any partial, where step = partial.currentPrice * percent / 100.
11892
+ * Returns false if no pending signal exists or no partials have been executed yet.
11893
+ *
11894
+ * @param symbol - Trading pair symbol
11895
+ * @param currentPrice - Price to check against existing partial close prices
11896
+ * @param context - Execution context with strategyName, exchangeName, and frameName
11897
+ * @param ladder - Tolerance zone config; percentages in 0–100 format (default: 1.5% up and down)
11898
+ * @returns true if price overlaps an existing partial price (partial not recommended)
11899
+ */
11900
+ getPositionPartialOverlap: (symbol: string, currentPrice: number, context: {
11901
+ strategyName: StrategyName;
11902
+ exchangeName: ExchangeName;
11903
+ frameName: FrameName;
11904
+ }, ladder?: IPositionOverlapLadder) => Promise<boolean>;
11634
11905
  /**
11635
11906
  * Stops the strategy from generating new signals.
11636
11907
  *
@@ -12488,7 +12759,7 @@ declare class LiveUtils {
12488
12759
  getPendingSignal: (symbol: string, currentPrice: number, context: {
12489
12760
  strategyName: StrategyName;
12490
12761
  exchangeName: ExchangeName;
12491
- }) => Promise<ISignalRow>;
12762
+ }) => Promise<IPublicSignalRow>;
12492
12763
  /**
12493
12764
  * Returns the percentage of the position currently held (not closed).
12494
12765
  * 100 = nothing has been closed (full position), 0 = fully closed.
@@ -12689,6 +12960,66 @@ declare class LiveUtils {
12689
12960
  entryCountAtClose: number;
12690
12961
  debugTimestamp?: number;
12691
12962
  }[]>;
12963
+ /**
12964
+ * Returns the list of DCA entry prices and costs for the current pending signal.
12965
+ *
12966
+ * Each element represents a single position entry — the initial open or a subsequent
12967
+ * DCA entry added via commitAverageBuy.
12968
+ *
12969
+ * Returns null if no pending signal exists.
12970
+ * Returns a single-element array if no DCA entries were made.
12971
+ *
12972
+ * Each entry contains:
12973
+ * - `price` — execution price of this entry
12974
+ * - `cost` — dollar cost allocated to this entry (e.g. 100 for $100)
12975
+ *
12976
+ * @param symbol - Trading pair symbol
12977
+ * @param context - Execution context with strategyName and exchangeName
12978
+ * @returns Array of entry records, or null if no active position
12979
+ */
12980
+ getPositionEntries: (symbol: string, context: {
12981
+ strategyName: StrategyName;
12982
+ exchangeName: ExchangeName;
12983
+ }) => Promise<{
12984
+ price: number;
12985
+ cost: number;
12986
+ }[]>;
12987
+ /**
12988
+ * Checks whether the current price falls within the tolerance zone of any existing DCA entry level.
12989
+ * Use this to prevent duplicate DCA entries at the same price area.
12990
+ *
12991
+ * Returns true if currentPrice is within [level - lowerStep, level + upperStep] for any level,
12992
+ * where step = level * percent / 100.
12993
+ * Returns false if no pending signal exists.
12994
+ *
12995
+ * @param symbol - Trading pair symbol
12996
+ * @param currentPrice - Price to check against existing DCA levels
12997
+ * @param context - Execution context with strategyName and exchangeName
12998
+ * @param ladder - Tolerance zone config; percentages in 0–100 format (default: 1.5% up and down)
12999
+ * @returns true if price overlaps an existing entry level (DCA not recommended)
13000
+ */
13001
+ getPositionEntryOverlap: (symbol: string, currentPrice: number, context: {
13002
+ strategyName: StrategyName;
13003
+ exchangeName: ExchangeName;
13004
+ }, ladder?: IPositionOverlapLadder) => Promise<boolean>;
13005
+ /**
13006
+ * Checks whether the current price falls within the tolerance zone of any existing partial close price.
13007
+ * Use this to prevent duplicate partial closes at the same price area.
13008
+ *
13009
+ * Returns true if currentPrice is within [partial.currentPrice - lowerStep, partial.currentPrice + upperStep]
13010
+ * for any partial, where step = partial.currentPrice * percent / 100.
13011
+ * Returns false if no pending signal exists or no partials have been executed yet.
13012
+ *
13013
+ * @param symbol - Trading pair symbol
13014
+ * @param currentPrice - Price to check against existing partial close prices
13015
+ * @param context - Execution context with strategyName and exchangeName
13016
+ * @param ladder - Tolerance zone config; percentages in 0–100 format (default: 1.5% up and down)
13017
+ * @returns true if price overlaps an existing partial price (partial not recommended)
13018
+ */
13019
+ getPositionPartialOverlap: (symbol: string, currentPrice: number, context: {
13020
+ strategyName: StrategyName;
13021
+ exchangeName: ExchangeName;
13022
+ }, ladder?: IPositionOverlapLadder) => Promise<boolean>;
12692
13023
  /**
12693
13024
  * Stops the strategy from generating new signals.
12694
13025
  *
@@ -18173,15 +18504,6 @@ declare class ActionBase implements IPublicAction {
18173
18504
  * ```
18174
18505
  */
18175
18506
  riskRejection(event: RiskContract, source?: string): void | Promise<void>;
18176
- /**
18177
- * Gate for position open/close via limit order. Default allows all.
18178
- * Throw to reject — framework retries next tick.
18179
- *
18180
- * NOTE: Exceptions are NOT swallowed — they propagate to CREATE_SYNC_FN.
18181
- *
18182
- * @param event - Sync event with action "signal-open" or "signal-close"
18183
- */
18184
- signalSync(_event: SignalSyncContract, source?: string): void | Promise<void>;
18185
18507
  /**
18186
18508
  * Cleans up resources and subscriptions when action handler is disposed.
18187
18509
  *
@@ -18417,6 +18739,8 @@ type BrokerTrailingStopPayload = {
18417
18739
  currentPrice: number;
18418
18740
  /** Absolute stop-loss price after applying percentShift */
18419
18741
  newStopLossPrice: number;
18742
+ /** Active take profit price at the time of the trailing update */
18743
+ takeProfitPrice: number;
18420
18744
  /** Position direction */
18421
18745
  position: "long" | "short";
18422
18746
  /** Strategy/exchange/frame routing context */
@@ -18457,6 +18781,8 @@ type BrokerTrailingTakePayload = {
18457
18781
  currentPrice: number;
18458
18782
  /** Absolute take-profit price after applying percentShift */
18459
18783
  newTakeProfitPrice: number;
18784
+ /** Active take profit price at the time of the trailing update */
18785
+ takeProfitPrice: number;
18460
18786
  /** Position direction */
18461
18787
  position: "long" | "short";
18462
18788
  /** Strategy/exchange/frame routing context */
@@ -20652,7 +20978,7 @@ declare class StrategyConnectionService implements TStrategy$1 {
20652
20978
  strategyName: StrategyName;
20653
20979
  exchangeName: ExchangeName;
20654
20980
  frameName: FrameName;
20655
- }) => Promise<ISignalRow | null>;
20981
+ }) => Promise<IPublicSignalRow | null>;
20656
20982
  /**
20657
20983
  * Returns the percentage of the position currently held (not closed).
20658
20984
  * 100 = nothing has been closed (full position), 0 = fully closed.
@@ -20724,6 +21050,14 @@ declare class StrategyConnectionService implements TStrategy$1 {
20724
21050
  entryCountAtClose: number;
20725
21051
  debugTimestamp?: number;
20726
21052
  }[]>;
21053
+ getPositionEntries: (backtest: boolean, symbol: string, context: {
21054
+ strategyName: StrategyName;
21055
+ exchangeName: ExchangeName;
21056
+ frameName: FrameName;
21057
+ }) => Promise<{
21058
+ price: number;
21059
+ cost: number;
21060
+ }[]>;
20727
21061
  /**
20728
21062
  * Retrieves the currently active scheduled signal for the strategy.
20729
21063
  * If no scheduled signal exists, returns null.
@@ -21897,7 +22231,7 @@ declare class StrategyCoreService implements TStrategy {
21897
22231
  strategyName: StrategyName;
21898
22232
  exchangeName: ExchangeName;
21899
22233
  frameName: FrameName;
21900
- }) => Promise<ISignalRow | null>;
22234
+ }) => Promise<IPublicSignalRow | null>;
21901
22235
  /**
21902
22236
  * Returns the percentage of the position currently held (not closed).
21903
22237
  * 100 = nothing has been closed (full position), 0 = fully closed.
@@ -21969,6 +22303,14 @@ declare class StrategyCoreService implements TStrategy {
21969
22303
  entryCountAtClose: number;
21970
22304
  debugTimestamp?: number;
21971
22305
  }[]>;
22306
+ getPositionEntries: (backtest: boolean, symbol: string, context: {
22307
+ strategyName: StrategyName;
22308
+ exchangeName: ExchangeName;
22309
+ frameName: FrameName;
22310
+ }) => Promise<{
22311
+ price: number;
22312
+ cost: number;
22313
+ }[]>;
21972
22314
  /**
21973
22315
  * Retrieves the currently active scheduled signal for the symbol.
21974
22316
  * If no scheduled signal exists, returns null.
@@ -25090,4 +25432,4 @@ declare const getTotalClosed: (signal: Signal) => {
25090
25432
  remainingCostBasis: number;
25091
25433
  };
25092
25434
 
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 };
25435
+ 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, getPositionEntryOverlap, getPositionInvestedCost, getPositionInvestedCount, getPositionLevels, getPositionPartialOverlap, 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 };