backtest-kit 5.0.0 → 5.1.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": "5.0.0",
3
+ "version": "5.1.0",
4
4
  "description": "A TypeScript library for trading system backtest",
5
5
  "author": {
6
6
  "name": "Petr Tripolsky",
package/types.d.ts CHANGED
@@ -2164,8 +2164,8 @@ interface ISignalRow extends ISignalDto {
2164
2164
  * Used to slice _entry to only entries that existed at this partial.
2165
2165
  */
2166
2166
  entryCountAtClose: number;
2167
- /** Debug only timestamp in milliseconds */
2168
- debugTimestamp?: number;
2167
+ /** Unix timestamp in milliseconds when this partial close was executed */
2168
+ timestamp: number;
2169
2169
  }>;
2170
2170
  /**
2171
2171
  * Trailing stop-loss price that overrides priceStopLoss when set.
@@ -2188,8 +2188,8 @@ interface ISignalRow extends ISignalDto {
2188
2188
  price: number;
2189
2189
  /** Cost of this entry in USD (e.g. 100 for $100 position) */
2190
2190
  cost: number;
2191
- /** Debug only timestamp in milliseconds */
2192
- debugTimestamp?: number;
2191
+ /** Unix timestamp in milliseconds when this entry was executed */
2192
+ timestamp: number;
2193
2193
  }>;
2194
2194
  /**
2195
2195
  * Trailing take-profit price that overrides priceTakeProfit when set.
@@ -2866,9 +2866,29 @@ interface IStrategy {
2866
2866
  * @param symbol - Trading pair symbol
2867
2867
  * @returns Promise resolving to array of entry records or null
2868
2868
  */
2869
- getPositionEntries: (symbol: string) => Promise<Array<{
2869
+ getPositionEntries: (symbol: string, timestamp: number) => Promise<Array<{
2870
2870
  price: number;
2871
2871
  cost: number;
2872
+ timestamp: number;
2873
+ }> | null>;
2874
+ /**
2875
+ * Returns the history of partial closes for the current pending signal.
2876
+ *
2877
+ * Each record includes the type (profit or loss), percentage closed, price, cost basis at close, and timestamp.
2878
+ * Used for tracking how the position was partially closed over time.
2879
+ *
2880
+ * Returns null if no pending signal exists or no partial closes were executed.
2881
+ *
2882
+ * @param symbol - Trading pair symbol
2883
+ * @returns Promise resolving to array of partial close records or null
2884
+ */
2885
+ getPositionPartials: (symbol: string) => Promise<Array<{
2886
+ type: "profit" | "loss";
2887
+ percent: number;
2888
+ currentPrice: number;
2889
+ costBasisAtClose: number;
2890
+ entryCountAtClose: number;
2891
+ timestamp: number;
2872
2892
  }> | null>;
2873
2893
  /**
2874
2894
  * Fast backtest using historical candles.
@@ -2988,14 +3008,15 @@ interface IStrategy {
2988
3008
  * @param percentToClose - Absolute percentage of position to close (0-100)
2989
3009
  * @param currentPrice - Current market price for partial close
2990
3010
  * @param backtest - Whether running in backtest mode
3011
+ * @param timestamp - Unix timestamp (ms) of the candle that triggered this partial close
2991
3012
  * @returns Promise<boolean> - true if partial close executed, false if skipped
2992
3013
  *
2993
3014
  * @example
2994
3015
  * ```typescript
2995
3016
  * callbacks: {
2996
- * onPartialProfit: async (symbol, signal, currentPrice, percentTp, backtest) => {
3017
+ * onPartialProfit: async (symbol, signal, currentPrice, percentTp, backtest, timestamp) => {
2997
3018
  * if (percentTp >= 50) {
2998
- * const success = await strategy.partialProfit(symbol, 25, currentPrice, backtest);
3019
+ * const success = await strategy.partialProfit(symbol, 25, currentPrice, backtest, timestamp);
2999
3020
  * if (success) {
3000
3021
  * console.log('Partial profit executed');
3001
3022
  * }
@@ -3004,7 +3025,7 @@ interface IStrategy {
3004
3025
  * }
3005
3026
  * ```
3006
3027
  */
3007
- partialProfit: (symbol: string, percentToClose: number, currentPrice: number, backtest: boolean) => Promise<boolean>;
3028
+ partialProfit: (symbol: string, percentToClose: number, currentPrice: number, backtest: boolean, timestamp: number) => Promise<boolean>;
3008
3029
  /**
3009
3030
  * Checks whether `partialProfit` would succeed without executing it.
3010
3031
  *
@@ -3043,14 +3064,15 @@ interface IStrategy {
3043
3064
  * @param percentToClose - Absolute percentage of position to close (0-100)
3044
3065
  * @param currentPrice - Current market price for partial close
3045
3066
  * @param backtest - Whether running in backtest mode
3067
+ * @param timestamp - Unix timestamp (ms) of the candle that triggered this partial close
3046
3068
  * @returns Promise<boolean> - true if partial close executed, false if skipped
3047
3069
  *
3048
3070
  * @example
3049
3071
  * ```typescript
3050
3072
  * callbacks: {
3051
- * onPartialLoss: async (symbol, signal, currentPrice, percentSl, backtest) => {
3073
+ * onPartialLoss: async (symbol, signal, currentPrice, percentSl, backtest, timestamp) => {
3052
3074
  * if (percentSl >= 80) {
3053
- * const success = await strategy.partialLoss(symbol, 50, currentPrice, backtest);
3075
+ * const success = await strategy.partialLoss(symbol, 50, currentPrice, backtest, timestamp);
3054
3076
  * if (success) {
3055
3077
  * console.log('Partial loss executed');
3056
3078
  * }
@@ -3059,7 +3081,7 @@ interface IStrategy {
3059
3081
  * }
3060
3082
  * ```
3061
3083
  */
3062
- partialLoss: (symbol: string, percentToClose: number, currentPrice: number, backtest: boolean) => Promise<boolean>;
3084
+ partialLoss: (symbol: string, percentToClose: number, currentPrice: number, backtest: boolean, timestamp: number) => Promise<boolean>;
3063
3085
  /**
3064
3086
  * Checks whether `partialLoss` would succeed without executing it.
3065
3087
  *
@@ -3318,9 +3340,11 @@ interface IStrategy {
3318
3340
  * @param symbol - Trading pair symbol (e.g., "BTCUSDT")
3319
3341
  * @param currentPrice - New entry price to add to the averaging history
3320
3342
  * @param backtest - Whether running in backtest mode
3343
+ * @param timestamp - Unix timestamp (ms) of the candle that triggered this DCA entry
3344
+ * @param cost - Optional cost of the new entry (defaults to $100 if not provided)
3321
3345
  * @returns Promise<boolean> - true if entry added, false if rejected by direction check
3322
3346
  */
3323
- averageBuy: (symbol: string, currentPrice: number, backtest: boolean) => Promise<boolean>;
3347
+ averageBuy: (symbol: string, currentPrice: number, backtest: boolean, timestamp: number, cost?: number) => Promise<boolean>;
3324
3348
  /**
3325
3349
  * Checks whether `averageBuy` would succeed without executing it.
3326
3350
  *
@@ -5010,7 +5034,7 @@ declare function getPositionPartials(symbol: string): Promise<{
5010
5034
  currentPrice: number;
5011
5035
  costBasisAtClose: number;
5012
5036
  entryCountAtClose: number;
5013
- debugTimestamp?: number;
5037
+ timestamp: number;
5014
5038
  }[]>;
5015
5039
  /**
5016
5040
  * Checks whether the current price falls within the tolerance zone of any existing DCA entry level.
@@ -11837,7 +11861,7 @@ declare class BacktestUtils {
11837
11861
  currentPrice: number;
11838
11862
  costBasisAtClose: number;
11839
11863
  entryCountAtClose: number;
11840
- debugTimestamp?: number;
11864
+ timestamp: number;
11841
11865
  }[]>;
11842
11866
  /**
11843
11867
  * Returns the list of DCA entry prices and costs for the current pending signal.
@@ -11863,6 +11887,7 @@ declare class BacktestUtils {
11863
11887
  }) => Promise<{
11864
11888
  price: number;
11865
11889
  cost: number;
11890
+ timestamp: number;
11866
11891
  }[]>;
11867
11892
  /**
11868
11893
  * Checks whether the current price falls within the tolerance zone of any existing DCA entry level.
@@ -12958,7 +12983,7 @@ declare class LiveUtils {
12958
12983
  currentPrice: number;
12959
12984
  costBasisAtClose: number;
12960
12985
  entryCountAtClose: number;
12961
- debugTimestamp?: number;
12986
+ timestamp: number;
12962
12987
  }[]>;
12963
12988
  /**
12964
12989
  * Returns the list of DCA entry prices and costs for the current pending signal.
@@ -12983,6 +13008,7 @@ declare class LiveUtils {
12983
13008
  }) => Promise<{
12984
13009
  price: number;
12985
13010
  cost: number;
13011
+ timestamp: number;
12986
13012
  }[]>;
12987
13013
  /**
12988
13014
  * Checks whether the current price falls within the tolerance zone of any existing DCA entry level.
@@ -16417,7 +16443,7 @@ declare class NotificationBacktestAdapter implements INotificationUtils {
16417
16443
  * Proxies call to the underlying notification adapter.
16418
16444
  * @param data - The signal sync contract data
16419
16445
  */
16420
- handleSync: (data: SignalSyncContract) => Promise<void>;
16446
+ handleSync: (data: SignalSyncContract) => any;
16421
16447
  /**
16422
16448
  * Handles risk rejection event.
16423
16449
  * Proxies call to the underlying notification adapter.
@@ -16523,7 +16549,7 @@ declare class NotificationLiveAdapter implements INotificationUtils {
16523
16549
  * Proxies call to the underlying notification adapter.
16524
16550
  * @param data - The signal sync contract data
16525
16551
  */
16526
- handleSync: (data: SignalSyncContract) => Promise<void>;
16552
+ handleSync: (data: SignalSyncContract) => any;
16527
16553
  /**
16528
16554
  * Handles risk rejection event.
16529
16555
  * Proxies call to the underlying notification adapter.
@@ -20907,6 +20933,184 @@ declare class BreakevenConnectionService implements IBreakeven {
20907
20933
  clear: (symbol: string, data: IPublicSignalRow, priceClose: number, backtest: boolean) => Promise<void>;
20908
20934
  }
20909
20935
 
20936
+ /**
20937
+ * Service for tracking the latest candle timestamp per symbol-strategy-exchange-frame combination.
20938
+ *
20939
+ * Maintains a memoized BehaviorSubject per unique key that is updated on every strategy tick
20940
+ * by StrategyConnectionService. Consumers can synchronously read the last known timestamp or
20941
+ * await the first value if none has arrived yet.
20942
+ *
20943
+ * Primary use case: providing the current candle time outside of a tick execution context,
20944
+ * e.g., when a command is triggered between ticks.
20945
+ *
20946
+ * Features:
20947
+ * - One BehaviorSubject per (symbol, strategyName, exchangeName, frameName, backtest) key
20948
+ * - Falls back to ExecutionContextService.context.when when called inside an execution context
20949
+ * - Waits up to LISTEN_TIMEOUT ms for the first timestamp if none is cached yet
20950
+ * - clear() disposes the BehaviorSubject for a single key or all keys
20951
+ *
20952
+ * Architecture:
20953
+ * - Registered as singleton in DI container
20954
+ * - Updated by StrategyConnectionService after each tick
20955
+ * - Cleared by Backtest/Live/Walker at strategy start to prevent stale data
20956
+ *
20957
+ * @example
20958
+ * ```typescript
20959
+ * const ts = await backtest.timeMetaService.getTimestamp("BTCUSDT", context, false);
20960
+ * ```
20961
+ */
20962
+ declare class TimeMetaService {
20963
+ private readonly loggerService;
20964
+ private readonly executionContextService;
20965
+ /**
20966
+ * Memoized factory for BehaviorSubject streams keyed by (symbol, strategyName, exchangeName, frameName, backtest).
20967
+ *
20968
+ * Each subject holds the latest createdAt timestamp emitted by the strategy iterator for that key.
20969
+ * Instances are cached until clear() is called.
20970
+ */
20971
+ private getSource;
20972
+ /**
20973
+ * Returns the current candle timestamp (in milliseconds) for the given symbol and context.
20974
+ *
20975
+ * When called inside an execution context (i.e., during a signal handler or action),
20976
+ * reads the timestamp directly from ExecutionContextService.context.when.
20977
+ * Otherwise, reads the last value from the cached BehaviorSubject. If no value has
20978
+ * been emitted yet, waits up to LISTEN_TIMEOUT ms for the first tick before throwing.
20979
+ *
20980
+ * @param symbol - Trading pair symbol (e.g., "BTCUSDT")
20981
+ * @param context - Strategy, exchange, and frame identifiers
20982
+ * @param backtest - True if backtest mode, false if live mode
20983
+ * @returns Unix timestamp in milliseconds of the latest processed candle
20984
+ * @throws When no timestamp arrives within LISTEN_TIMEOUT ms
20985
+ */
20986
+ getTimestamp: (symbol: string, context: {
20987
+ strategyName: string;
20988
+ exchangeName: string;
20989
+ frameName: string;
20990
+ }, backtest: boolean) => Promise<number>;
20991
+ /**
20992
+ * Pushes a new timestamp value into the BehaviorSubject for the given key.
20993
+ *
20994
+ * Called by StrategyConnectionService after each strategy tick to keep
20995
+ * the cached timestamp up to date.
20996
+ *
20997
+ * @param symbol - Trading pair symbol (e.g., "BTCUSDT")
20998
+ * @param timestamp - The createdAt timestamp from the tick (milliseconds)
20999
+ * @param context - Strategy, exchange, and frame identifiers
21000
+ * @param backtest - True if backtest mode, false if live mode
21001
+ */
21002
+ next: (symbol: string, timestamp: number, context: {
21003
+ strategyName: string;
21004
+ exchangeName: string;
21005
+ frameName: string;
21006
+ }, backtest: boolean) => Promise<void>;
21007
+ /**
21008
+ * Disposes cached BehaviorSubject(s) to free memory and prevent stale data.
21009
+ *
21010
+ * When called without arguments, clears all memoized timestamp streams.
21011
+ * When called with a payload, clears only the stream for the specified key.
21012
+ * Should be called at strategy start (Backtest/Live/Walker) to reset state.
21013
+ *
21014
+ * @param payload - Optional key to clear a single stream; omit to clear all
21015
+ */
21016
+ clear: (payload?: {
21017
+ symbol: string;
21018
+ strategyName: string;
21019
+ exchangeName: string;
21020
+ frameName: string;
21021
+ backtest: boolean;
21022
+ }) => void;
21023
+ }
21024
+
21025
+ /**
21026
+ * Service for tracking the latest market price per symbol-strategy-exchange-frame combination.
21027
+ *
21028
+ * Maintains a memoized BehaviorSubject per unique key that is updated on every strategy tick
21029
+ * by StrategyConnectionService. Consumers can synchronously read the last known price or
21030
+ * await the first value if none has arrived yet.
21031
+ *
21032
+ * Primary use case: providing the current price outside of a tick execution context,
21033
+ * e.g., when a command is triggered between ticks.
21034
+ *
21035
+ * Features:
21036
+ * - One BehaviorSubject per (symbol, strategyName, exchangeName, frameName, backtest) key
21037
+ * - Falls back to ExchangeConnectionService.getAveragePrice when called inside an execution context
21038
+ * - Waits up to LISTEN_TIMEOUT ms for the first price if none is cached yet
21039
+ * - clear() disposes the BehaviorSubject for a single key or all keys
21040
+ *
21041
+ * Architecture:
21042
+ * - Registered as singleton in DI container
21043
+ * - Updated by StrategyConnectionService after each tick
21044
+ * - Cleared by Backtest/Live/Walker at strategy start to prevent stale data
21045
+ *
21046
+ * @example
21047
+ * ```typescript
21048
+ * const price = await backtest.priceMetaService.getCurrentPrice("BTCUSDT", context, false);
21049
+ * ```
21050
+ */
21051
+ declare class PriceMetaService {
21052
+ private readonly loggerService;
21053
+ private readonly exchangeConnectionService;
21054
+ /**
21055
+ * Memoized factory for BehaviorSubject streams keyed by (symbol, strategyName, exchangeName, frameName, backtest).
21056
+ *
21057
+ * Each subject holds the latest currentPrice emitted by the strategy iterator for that key.
21058
+ * Instances are cached until clear() is called.
21059
+ */
21060
+ private getSource;
21061
+ /**
21062
+ * Returns the current market price for the given symbol and context.
21063
+ *
21064
+ * When called inside an execution context (i.e., during a signal handler or action),
21065
+ * delegates to ExchangeConnectionService.getAveragePrice for the live exchange price.
21066
+ * Otherwise, reads the last value from the cached BehaviorSubject. If no value has
21067
+ * been emitted yet, waits up to LISTEN_TIMEOUT ms for the first tick before throwing.
21068
+ *
21069
+ * @param symbol - Trading pair symbol (e.g., "BTCUSDT")
21070
+ * @param context - Strategy, exchange, and frame identifiers
21071
+ * @param backtest - True if backtest mode, false if live mode
21072
+ * @returns Current market price in quote currency
21073
+ * @throws When no price arrives within LISTEN_TIMEOUT ms
21074
+ */
21075
+ getCurrentPrice: (symbol: string, context: {
21076
+ strategyName: string;
21077
+ exchangeName: string;
21078
+ frameName: string;
21079
+ }, backtest: boolean) => Promise<number>;
21080
+ /**
21081
+ * Pushes a new price value into the BehaviorSubject for the given key.
21082
+ *
21083
+ * Called by StrategyConnectionService after each strategy tick to keep
21084
+ * the cached price up to date.
21085
+ *
21086
+ * @param symbol - Trading pair symbol (e.g., "BTCUSDT")
21087
+ * @param currentPrice - The latest price from the tick
21088
+ * @param context - Strategy, exchange, and frame identifiers
21089
+ * @param backtest - True if backtest mode, false if live mode
21090
+ */
21091
+ next: (symbol: string, currentPrice: number, context: {
21092
+ strategyName: string;
21093
+ exchangeName: string;
21094
+ frameName: string;
21095
+ }, backtest: boolean) => Promise<void>;
21096
+ /**
21097
+ * Disposes cached BehaviorSubject(s) to free memory and prevent stale data.
21098
+ *
21099
+ * When called without arguments, clears all memoized price streams.
21100
+ * When called with a payload, clears only the stream for the specified key.
21101
+ * Should be called at strategy start (Backtest/Live/Walker) to reset state.
21102
+ *
21103
+ * @param payload - Optional key to clear a single stream; omit to clear all
21104
+ */
21105
+ clear: (payload?: {
21106
+ symbol: string;
21107
+ strategyName: string;
21108
+ exchangeName: string;
21109
+ frameName: string;
21110
+ backtest: boolean;
21111
+ }) => void;
21112
+ }
21113
+
20910
21114
  /**
20911
21115
  * Type definition for strategy methods.
20912
21116
  * Maps all keys of IStrategy to any type.
@@ -20949,6 +21153,8 @@ declare class StrategyConnectionService implements TStrategy$1 {
20949
21153
  readonly partialConnectionService: PartialConnectionService;
20950
21154
  readonly breakevenConnectionService: BreakevenConnectionService;
20951
21155
  readonly actionCoreService: ActionCoreService;
21156
+ readonly timeMetaService: TimeMetaService;
21157
+ readonly priceMetaService: PriceMetaService;
20952
21158
  /**
20953
21159
  * Retrieves memoized ClientStrategy instance for given symbol-strategy pair with exchange and frame isolation.
20954
21160
  *
@@ -21008,36 +21214,139 @@ declare class StrategyConnectionService implements TStrategy$1 {
21008
21214
  exchangeName: ExchangeName;
21009
21215
  frameName: FrameName;
21010
21216
  }) => Promise<number | null>;
21217
+ /**
21218
+ * Returns the effective (DCA-averaged) entry price for the current pending signal.
21219
+ *
21220
+ * This is the harmonic mean of all _entry prices, which is the correct
21221
+ * cost-basis price used in all PNL calculations.
21222
+ * With no DCA entries, equals the original priceOpen.
21223
+ *
21224
+ * Returns null if no pending signal exists.
21225
+ *
21226
+ * @param backtest - Whether running in backtest mode
21227
+ * @param symbol - Trading pair symbol
21228
+ * @param context - Execution context with strategyName, exchangeName, frameName
21229
+ * @returns Promise resolving to effective entry price or null
21230
+ */
21011
21231
  getPositionAveragePrice: (backtest: boolean, symbol: string, context: {
21012
21232
  strategyName: StrategyName;
21013
21233
  exchangeName: ExchangeName;
21014
21234
  frameName: FrameName;
21015
21235
  }) => Promise<number | null>;
21236
+ /**
21237
+ * Returns the number of DCA entries made for the current pending signal.
21238
+ *
21239
+ * 1 = original entry only (no DCA).
21240
+ * Increases by 1 with each successful commitAverageBuy().
21241
+ *
21242
+ * Returns null if no pending signal exists.
21243
+ *
21244
+ * @param backtest - Whether running in backtest mode
21245
+ * @param symbol - Trading pair symbol
21246
+ * @param context - Execution context with strategyName, exchangeName, frameName
21247
+ * @returns Promise resolving to entry count or null
21248
+ */
21016
21249
  getPositionInvestedCount: (backtest: boolean, symbol: string, context: {
21017
21250
  strategyName: StrategyName;
21018
21251
  exchangeName: ExchangeName;
21019
21252
  frameName: FrameName;
21020
21253
  }) => Promise<number | null>;
21254
+ /**
21255
+ * Returns the total invested cost basis in dollars for the current pending signal.
21256
+ *
21257
+ * Equal to entryCount × $100 (COST_BASIS_PER_ENTRY).
21258
+ * 1 entry = $100, 2 entries = $200, etc.
21259
+ *
21260
+ * Returns null if no pending signal exists.
21261
+ *
21262
+ * @param backtest - Whether running in backtest mode
21263
+ * @param symbol - Trading pair symbol
21264
+ * @param context - Execution context with strategyName, exchangeName, frameName
21265
+ * @returns Promise resolving to total invested cost in dollars or null
21266
+ */
21021
21267
  getPositionInvestedCost: (backtest: boolean, symbol: string, context: {
21022
21268
  strategyName: StrategyName;
21023
21269
  exchangeName: ExchangeName;
21024
21270
  frameName: FrameName;
21025
21271
  }) => Promise<number | null>;
21272
+ /**
21273
+ * Returns the unrealized PNL percentage for the current pending signal at currentPrice.
21274
+ *
21275
+ * Accounts for partial closes, DCA entries, slippage and fees
21276
+ * (delegates to toProfitLossDto).
21277
+ *
21278
+ * Returns null if no pending signal exists.
21279
+ *
21280
+ * @param backtest - Whether running in backtest mode
21281
+ * @param symbol - Trading pair symbol
21282
+ * @param currentPrice - Current market price
21283
+ * @param context - Execution context with strategyName, exchangeName, frameName
21284
+ * @returns Promise resolving to pnlPercentage or null
21285
+ */
21026
21286
  getPositionPnlPercent: (backtest: boolean, symbol: string, currentPrice: number, context: {
21027
21287
  strategyName: StrategyName;
21028
21288
  exchangeName: ExchangeName;
21029
21289
  frameName: FrameName;
21030
21290
  }) => Promise<number | null>;
21291
+ /**
21292
+ * Returns the unrealized PNL in dollars for the current pending signal at currentPrice.
21293
+ *
21294
+ * Calculated as: pnlPercentage / 100 × totalInvestedCost
21295
+ * Accounts for partial closes, DCA entries, slippage and fees.
21296
+ *
21297
+ * Returns null if no pending signal exists.
21298
+ *
21299
+ * @param backtest - Whether running in backtest mode
21300
+ * @param symbol - Trading pair symbol
21301
+ * @param currentPrice - Current market price
21302
+ * @param context - Execution context with strategyName, exchangeName, frameName
21303
+ * @returns Promise resolving to pnl in dollars or null
21304
+ */
21031
21305
  getPositionPnlCost: (backtest: boolean, symbol: string, currentPrice: number, context: {
21032
21306
  strategyName: StrategyName;
21033
21307
  exchangeName: ExchangeName;
21034
21308
  frameName: FrameName;
21035
21309
  }) => Promise<number | null>;
21310
+ /**
21311
+ * Returns the list of DCA entry prices for the current pending signal.
21312
+ *
21313
+ * The first element is always the original priceOpen (initial entry).
21314
+ * Each subsequent element is a price added by commitAverageBuy().
21315
+ *
21316
+ * Returns null if no pending signal exists.
21317
+ * Returns a single-element array [priceOpen] if no DCA entries were made.
21318
+ *
21319
+ * @param backtest - Whether running in backtest mode
21320
+ * @param symbol - Trading pair symbol
21321
+ * @param context - Execution context with strategyName, exchangeName, frameName
21322
+ * @returns Promise resolving to array of entry prices or null
21323
+ *
21324
+ * @example
21325
+ * ```typescript
21326
+ * // No DCA: [43000]
21327
+ * // One DCA: [43000, 42000]
21328
+ * // Two DCA: [43000, 42000, 41500]
21329
+ * ```
21330
+ */
21036
21331
  getPositionLevels: (backtest: boolean, symbol: string, context: {
21037
21332
  strategyName: StrategyName;
21038
21333
  exchangeName: ExchangeName;
21039
21334
  frameName: FrameName;
21040
21335
  }) => Promise<number[] | null>;
21336
+ /**
21337
+ * Returns the list of partial closes for the current pending signal.
21338
+ *
21339
+ * Each entry records a partial profit or loss close event with its type,
21340
+ * percent closed, price at close, cost basis snapshot, and entry count at close.
21341
+ *
21342
+ * Returns null if no pending signal exists.
21343
+ * Returns an empty array if no partial closes have been executed.
21344
+ *
21345
+ * @param backtest - Whether running in backtest mode
21346
+ * @param symbol - Trading pair symbol
21347
+ * @param context - Execution context with strategyName, exchangeName, frameName
21348
+ * @returns Promise resolving to array of partial close records or null
21349
+ */
21041
21350
  getPositionPartials: (backtest: boolean, symbol: string, context: {
21042
21351
  strategyName: StrategyName;
21043
21352
  exchangeName: ExchangeName;
@@ -21048,8 +21357,29 @@ declare class StrategyConnectionService implements TStrategy$1 {
21048
21357
  currentPrice: number;
21049
21358
  costBasisAtClose: number;
21050
21359
  entryCountAtClose: number;
21051
- debugTimestamp?: number;
21360
+ timestamp: number;
21052
21361
  }[]>;
21362
+ /**
21363
+ * Returns the list of DCA entry prices and costs for the current pending signal.
21364
+ *
21365
+ * Each entry records the price and cost of a single position entry.
21366
+ * The first element is always the original priceOpen (initial entry).
21367
+ * Each subsequent element is an entry added by averageBuy().
21368
+ *
21369
+ * Returns null if no pending signal exists.
21370
+ * Returns a single-element array [{ price: priceOpen, cost }] if no DCA entries were made.
21371
+ *
21372
+ * @param backtest - Whether running in backtest mode
21373
+ * @param symbol - Trading pair symbol
21374
+ * @param context - Execution context with strategyName, exchangeName, frameName
21375
+ * @returns Promise resolving to array of entry records or null
21376
+ *
21377
+ * @example
21378
+ * ```typescript
21379
+ * // No DCA: [{ price: 43000, cost: 100 }]
21380
+ * // One DCA: [{ price: 43000, cost: 100 }, { price: 42000, cost: 100 }]
21381
+ * ```
21382
+ */
21053
21383
  getPositionEntries: (backtest: boolean, symbol: string, context: {
21054
21384
  strategyName: StrategyName;
21055
21385
  exchangeName: ExchangeName;
@@ -21057,6 +21387,7 @@ declare class StrategyConnectionService implements TStrategy$1 {
21057
21387
  }) => Promise<{
21058
21388
  price: number;
21059
21389
  cost: number;
21390
+ timestamp: number;
21060
21391
  }[]>;
21061
21392
  /**
21062
21393
  * Retrieves the currently active scheduled signal for the strategy.
@@ -22301,7 +22632,7 @@ declare class StrategyCoreService implements TStrategy {
22301
22632
  currentPrice: number;
22302
22633
  costBasisAtClose: number;
22303
22634
  entryCountAtClose: number;
22304
- debugTimestamp?: number;
22635
+ timestamp: number;
22305
22636
  }[]>;
22306
22637
  getPositionEntries: (backtest: boolean, symbol: string, context: {
22307
22638
  strategyName: StrategyName;
@@ -22310,6 +22641,7 @@ declare class StrategyCoreService implements TStrategy {
22310
22641
  }) => Promise<{
22311
22642
  price: number;
22312
22643
  cost: number;
22644
+ timestamp: number;
22313
22645
  }[]>;
22314
22646
  /**
22315
22647
  * Retrieves the currently active scheduled signal for the symbol.
@@ -25328,6 +25660,8 @@ declare const backtest: {
25328
25660
  riskGlobalService: RiskGlobalService;
25329
25661
  partialGlobalService: PartialGlobalService;
25330
25662
  breakevenGlobalService: BreakevenGlobalService;
25663
+ timeMetaService: TimeMetaService;
25664
+ priceMetaService: PriceMetaService;
25331
25665
  exchangeCoreService: ExchangeCoreService;
25332
25666
  strategyCoreService: StrategyCoreService;
25333
25667
  actionCoreService: ActionCoreService;