backtest-kit 9.0.2 → 9.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/index.cjs +140 -108
- package/build/index.mjs +140 -108
- package/package.json +1 -1
- package/types.d.ts +128 -112
package/package.json
CHANGED
package/types.d.ts
CHANGED
|
@@ -142,6 +142,95 @@ interface IFrame {
|
|
|
142
142
|
*/
|
|
143
143
|
type FrameName = string;
|
|
144
144
|
|
|
145
|
+
/**
|
|
146
|
+
* Service for tracking the latest candle timestamp per symbol-strategy-exchange-frame combination.
|
|
147
|
+
*
|
|
148
|
+
* Maintains a memoized BehaviorSubject per unique key that is updated on every strategy tick
|
|
149
|
+
* by StrategyConnectionService. Consumers can synchronously read the last known timestamp or
|
|
150
|
+
* await the first value if none has arrived yet.
|
|
151
|
+
*
|
|
152
|
+
* Primary use case: providing the current candle time outside of a tick execution context,
|
|
153
|
+
* e.g., when a command is triggered between ticks.
|
|
154
|
+
*
|
|
155
|
+
* Features:
|
|
156
|
+
* - One BehaviorSubject per (symbol, strategyName, exchangeName, frameName, backtest) key
|
|
157
|
+
* - Falls back to ExecutionContextService.context.when when called inside an execution context
|
|
158
|
+
* - Waits up to LISTEN_TIMEOUT ms for the first timestamp if none is cached yet
|
|
159
|
+
* - clear() disposes the BehaviorSubject for a single key or all keys
|
|
160
|
+
*
|
|
161
|
+
* Architecture:
|
|
162
|
+
* - Registered as singleton in DI container
|
|
163
|
+
* - Updated by StrategyConnectionService after each tick
|
|
164
|
+
* - Cleared by Backtest/Live/Walker at strategy start to prevent stale data
|
|
165
|
+
*
|
|
166
|
+
* @example
|
|
167
|
+
* ```typescript
|
|
168
|
+
* const ts = await backtest.timeMetaService.getTimestamp("BTCUSDT", context, false);
|
|
169
|
+
* ```
|
|
170
|
+
*/
|
|
171
|
+
declare class TimeMetaService {
|
|
172
|
+
private readonly loggerService;
|
|
173
|
+
private readonly executionContextService;
|
|
174
|
+
/**
|
|
175
|
+
* Memoized factory for BehaviorSubject streams keyed by (symbol, strategyName, exchangeName, frameName, backtest).
|
|
176
|
+
*
|
|
177
|
+
* Each subject holds the latest createdAt timestamp emitted by the strategy iterator for that key.
|
|
178
|
+
* Instances are cached until clear() is called.
|
|
179
|
+
*/
|
|
180
|
+
private getSource;
|
|
181
|
+
/**
|
|
182
|
+
* Returns the current candle timestamp (in milliseconds) for the given symbol and context.
|
|
183
|
+
*
|
|
184
|
+
* When called inside an execution context (i.e., during a signal handler or action),
|
|
185
|
+
* reads the timestamp directly from ExecutionContextService.context.when.
|
|
186
|
+
* Otherwise, reads the last value from the cached BehaviorSubject. If no value has
|
|
187
|
+
* been emitted yet, waits up to LISTEN_TIMEOUT ms for the first tick before throwing.
|
|
188
|
+
*
|
|
189
|
+
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
190
|
+
* @param context - Strategy, exchange, and frame identifiers
|
|
191
|
+
* @param backtest - True if backtest mode, false if live mode
|
|
192
|
+
* @returns Unix timestamp in milliseconds of the latest processed candle
|
|
193
|
+
* @throws When no timestamp arrives within LISTEN_TIMEOUT ms
|
|
194
|
+
*/
|
|
195
|
+
getTimestamp: (symbol: string, context: {
|
|
196
|
+
strategyName: string;
|
|
197
|
+
exchangeName: string;
|
|
198
|
+
frameName: string;
|
|
199
|
+
}, backtest: boolean) => Promise<number>;
|
|
200
|
+
/**
|
|
201
|
+
* Pushes a new timestamp value into the BehaviorSubject for the given key.
|
|
202
|
+
*
|
|
203
|
+
* Called by StrategyConnectionService after each strategy tick to keep
|
|
204
|
+
* the cached timestamp up to date.
|
|
205
|
+
*
|
|
206
|
+
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
207
|
+
* @param timestamp - The createdAt timestamp from the tick (milliseconds)
|
|
208
|
+
* @param context - Strategy, exchange, and frame identifiers
|
|
209
|
+
* @param backtest - True if backtest mode, false if live mode
|
|
210
|
+
*/
|
|
211
|
+
next: (symbol: string, timestamp: number, context: {
|
|
212
|
+
strategyName: string;
|
|
213
|
+
exchangeName: string;
|
|
214
|
+
frameName: string;
|
|
215
|
+
}, backtest: boolean) => Promise<void>;
|
|
216
|
+
/**
|
|
217
|
+
* Disposes cached BehaviorSubject(s) to free memory and prevent stale data.
|
|
218
|
+
*
|
|
219
|
+
* When called without arguments, clears all memoized timestamp streams.
|
|
220
|
+
* When called with a payload, clears only the stream for the specified key.
|
|
221
|
+
* Should be called at strategy start (Backtest/Live/Walker) to reset state.
|
|
222
|
+
*
|
|
223
|
+
* @param payload - Optional key to clear a single stream; omit to clear all
|
|
224
|
+
*/
|
|
225
|
+
clear: (payload?: {
|
|
226
|
+
symbol: string;
|
|
227
|
+
strategyName: string;
|
|
228
|
+
exchangeName: string;
|
|
229
|
+
frameName: string;
|
|
230
|
+
backtest: boolean;
|
|
231
|
+
}) => void;
|
|
232
|
+
}
|
|
233
|
+
|
|
145
234
|
/**
|
|
146
235
|
* Risk rejection result type.
|
|
147
236
|
* Can be void, null, or an IRiskRejectionResult object.
|
|
@@ -281,8 +370,8 @@ interface IRiskParams extends IRiskSchema {
|
|
|
281
370
|
exchangeName: ExchangeName;
|
|
282
371
|
/** Logger service for debug output */
|
|
283
372
|
logger: ILogger;
|
|
284
|
-
/**
|
|
285
|
-
|
|
373
|
+
/** Time context service (when date in backtest/live to prevent look ahead bias) */
|
|
374
|
+
time: TimeMetaService;
|
|
286
375
|
/** True if backtest mode, false if live mode */
|
|
287
376
|
backtest: boolean;
|
|
288
377
|
/**
|
|
@@ -13161,16 +13250,18 @@ interface IPersistRiskInstance {
|
|
|
13161
13250
|
/**
|
|
13162
13251
|
* Read persisted active positions for this context.
|
|
13163
13252
|
*
|
|
13253
|
+
* @param when - Logical timestamp at which the read is happening (reserved for API consistency)
|
|
13164
13254
|
* @returns Promise resolving to position entries (empty array if none persisted)
|
|
13165
13255
|
*/
|
|
13166
|
-
readPositionData(): Promise<RiskData>;
|
|
13256
|
+
readPositionData(when: Date): Promise<RiskData>;
|
|
13167
13257
|
/**
|
|
13168
13258
|
* Write active positions for this context.
|
|
13169
13259
|
*
|
|
13170
13260
|
* @param riskRow - Position entries to persist
|
|
13261
|
+
* @param when - Logical timestamp this write belongs to (reserved for API consistency)
|
|
13171
13262
|
* @returns Promise that resolves when write is complete
|
|
13172
13263
|
*/
|
|
13173
|
-
writePositionData(riskRow: RiskData): Promise<void>;
|
|
13264
|
+
writePositionData(riskRow: RiskData, when: Date): Promise<void>;
|
|
13174
13265
|
}
|
|
13175
13266
|
/**
|
|
13176
13267
|
* Default file-based implementation of IPersistRiskInstance.
|
|
@@ -13214,14 +13305,15 @@ declare class PersistRiskInstance implements IPersistRiskInstance {
|
|
|
13214
13305
|
*
|
|
13215
13306
|
* @returns Promise resolving to positions (empty array if none persisted)
|
|
13216
13307
|
*/
|
|
13217
|
-
readPositionData(): Promise<RiskData>;
|
|
13308
|
+
readPositionData(_when: Date): Promise<RiskData>;
|
|
13218
13309
|
/**
|
|
13219
13310
|
* Writes the positions array using the fixed STORAGE_KEY.
|
|
13220
13311
|
*
|
|
13221
13312
|
* @param riskRow - Position entries to persist
|
|
13313
|
+
* @param when - Logical timestamp (reserved for API consistency; not used)
|
|
13222
13314
|
* @returns Promise that resolves when write is complete
|
|
13223
13315
|
*/
|
|
13224
|
-
writePositionData(riskRow: RiskData): Promise<void>;
|
|
13316
|
+
writePositionData(riskRow: RiskData, _when: Date): Promise<void>;
|
|
13225
13317
|
}
|
|
13226
13318
|
/**
|
|
13227
13319
|
* Constructor type for IPersistRiskInstance.
|
|
@@ -13262,9 +13354,10 @@ declare class PersistRiskUtils {
|
|
|
13262
13354
|
*
|
|
13263
13355
|
* @param riskName - Risk profile identifier
|
|
13264
13356
|
* @param exchangeName - Exchange identifier
|
|
13357
|
+
* @param when - Logical timestamp at which the read is happening (reserved for API consistency)
|
|
13265
13358
|
* @returns Promise resolving to position entries (empty array if none)
|
|
13266
13359
|
*/
|
|
13267
|
-
readPositionData: (riskName: RiskName, exchangeName: ExchangeName) => Promise<RiskData>;
|
|
13360
|
+
readPositionData: (riskName: RiskName, exchangeName: ExchangeName, when: Date) => Promise<RiskData>;
|
|
13268
13361
|
/**
|
|
13269
13362
|
* Writes active positions for the given risk context.
|
|
13270
13363
|
* Lazily initializes the instance on first access.
|
|
@@ -13272,9 +13365,10 @@ declare class PersistRiskUtils {
|
|
|
13272
13365
|
* @param riskRow - Position entries to persist
|
|
13273
13366
|
* @param riskName - Risk profile identifier
|
|
13274
13367
|
* @param exchangeName - Exchange identifier
|
|
13368
|
+
* @param when - Logical timestamp this write belongs to (reserved for API consistency)
|
|
13275
13369
|
* @returns Promise that resolves when write is complete
|
|
13276
13370
|
*/
|
|
13277
|
-
writePositionData: (riskRow: RiskData, riskName: RiskName, exchangeName: ExchangeName) => Promise<void>;
|
|
13371
|
+
writePositionData: (riskRow: RiskData, riskName: RiskName, exchangeName: ExchangeName, when: Date) => Promise<void>;
|
|
13278
13372
|
/**
|
|
13279
13373
|
* Clears the memoized instance cache.
|
|
13280
13374
|
* Call when process.cwd() changes between strategy iterations.
|
|
@@ -13503,17 +13597,19 @@ interface IPersistPartialInstance {
|
|
|
13503
13597
|
* Read persisted partial data for a specific signal.
|
|
13504
13598
|
*
|
|
13505
13599
|
* @param signalId - Signal identifier
|
|
13600
|
+
* @param when - Logical timestamp at which the read is happening (reserved for API consistency)
|
|
13506
13601
|
* @returns Promise resolving to partial data record (empty object if none persisted)
|
|
13507
13602
|
*/
|
|
13508
|
-
readPartialData(signalId: string): Promise<PartialData>;
|
|
13603
|
+
readPartialData(signalId: string, when: Date): Promise<PartialData>;
|
|
13509
13604
|
/**
|
|
13510
13605
|
* Write partial data for a specific signal.
|
|
13511
13606
|
*
|
|
13512
13607
|
* @param data - Partial data record to persist
|
|
13513
13608
|
* @param signalId - Signal identifier
|
|
13609
|
+
* @param when - Logical timestamp this write belongs to (reserved for API consistency)
|
|
13514
13610
|
* @returns Promise that resolves when write is complete
|
|
13515
13611
|
*/
|
|
13516
|
-
writePartialData(data: PartialData, signalId: string): Promise<void>;
|
|
13612
|
+
writePartialData(data: PartialData, signalId: string, when: Date): Promise<void>;
|
|
13517
13613
|
}
|
|
13518
13614
|
/**
|
|
13519
13615
|
* Default file-based implementation of IPersistPartialInstance.
|
|
@@ -13558,15 +13654,16 @@ declare class PersistPartialInstance implements IPersistPartialInstance {
|
|
|
13558
13654
|
* @param signalId - Signal identifier
|
|
13559
13655
|
* @returns Promise resolving to partial data record (empty object if not found)
|
|
13560
13656
|
*/
|
|
13561
|
-
readPartialData(signalId: string): Promise<PartialData>;
|
|
13657
|
+
readPartialData(signalId: string, _when: Date): Promise<PartialData>;
|
|
13562
13658
|
/**
|
|
13563
13659
|
* Writes the partial data for the given signal using `signalId` as the entity key.
|
|
13564
13660
|
*
|
|
13565
13661
|
* @param data - Partial data record to persist
|
|
13566
13662
|
* @param signalId - Signal identifier
|
|
13663
|
+
* @param when - Logical timestamp (reserved for API consistency; not used)
|
|
13567
13664
|
* @returns Promise that resolves when write is complete
|
|
13568
13665
|
*/
|
|
13569
|
-
writePartialData(data: PartialData, signalId: string): Promise<void>;
|
|
13666
|
+
writePartialData(data: PartialData, signalId: string, _when: Date): Promise<void>;
|
|
13570
13667
|
}
|
|
13571
13668
|
/**
|
|
13572
13669
|
* Constructor type for IPersistPartialInstance.
|
|
@@ -13610,9 +13707,10 @@ declare class PersistPartialUtils {
|
|
|
13610
13707
|
* @param strategyName - Strategy identifier
|
|
13611
13708
|
* @param signalId - Signal identifier
|
|
13612
13709
|
* @param exchangeName - Exchange identifier
|
|
13710
|
+
* @param when - Logical timestamp at which the read is happening (reserved for API consistency)
|
|
13613
13711
|
* @returns Promise resolving to partial data record (empty object if none)
|
|
13614
13712
|
*/
|
|
13615
|
-
readPartialData: (symbol: string, strategyName: StrategyName, signalId: string, exchangeName: ExchangeName) => Promise<PartialData>;
|
|
13713
|
+
readPartialData: (symbol: string, strategyName: StrategyName, signalId: string, exchangeName: ExchangeName, when: Date) => Promise<PartialData>;
|
|
13616
13714
|
/**
|
|
13617
13715
|
* Writes partial data for the given context and signalId.
|
|
13618
13716
|
* Lazily initializes the instance on first access.
|
|
@@ -13622,9 +13720,10 @@ declare class PersistPartialUtils {
|
|
|
13622
13720
|
* @param strategyName - Strategy identifier
|
|
13623
13721
|
* @param signalId - Signal identifier
|
|
13624
13722
|
* @param exchangeName - Exchange identifier
|
|
13723
|
+
* @param when - Logical timestamp this write belongs to (reserved for API consistency)
|
|
13625
13724
|
* @returns Promise that resolves when write is complete
|
|
13626
13725
|
*/
|
|
13627
|
-
writePartialData: (partialData: PartialData, symbol: string, strategyName: StrategyName, signalId: string, exchangeName: ExchangeName) => Promise<void>;
|
|
13726
|
+
writePartialData: (partialData: PartialData, symbol: string, strategyName: StrategyName, signalId: string, exchangeName: ExchangeName, when: Date) => Promise<void>;
|
|
13628
13727
|
/**
|
|
13629
13728
|
* Clears the memoized instance cache.
|
|
13630
13729
|
* Call when process.cwd() changes between strategy iterations.
|
|
@@ -13683,17 +13782,19 @@ interface IPersistBreakevenInstance {
|
|
|
13683
13782
|
* Read persisted breakeven data for a specific signal.
|
|
13684
13783
|
*
|
|
13685
13784
|
* @param signalId - Signal identifier
|
|
13785
|
+
* @param when - Logical timestamp at which the read is happening (reserved for API consistency)
|
|
13686
13786
|
* @returns Promise resolving to breakeven data record (empty object if none persisted)
|
|
13687
13787
|
*/
|
|
13688
|
-
readBreakevenData(signalId: string): Promise<BreakevenData>;
|
|
13788
|
+
readBreakevenData(signalId: string, when: Date): Promise<BreakevenData>;
|
|
13689
13789
|
/**
|
|
13690
13790
|
* Write breakeven data for a specific signal.
|
|
13691
13791
|
*
|
|
13692
13792
|
* @param data - Breakeven data record to persist
|
|
13693
13793
|
* @param signalId - Signal identifier
|
|
13794
|
+
* @param when - Logical timestamp this write belongs to (reserved for API consistency)
|
|
13694
13795
|
* @returns Promise that resolves when write is complete
|
|
13695
13796
|
*/
|
|
13696
|
-
writeBreakevenData(data: BreakevenData, signalId: string): Promise<void>;
|
|
13797
|
+
writeBreakevenData(data: BreakevenData, signalId: string, when: Date): Promise<void>;
|
|
13697
13798
|
}
|
|
13698
13799
|
/**
|
|
13699
13800
|
* Default file-based implementation of IPersistBreakevenInstance.
|
|
@@ -13738,15 +13839,16 @@ declare class PersistBreakevenInstance implements IPersistBreakevenInstance {
|
|
|
13738
13839
|
* @param signalId - Signal identifier
|
|
13739
13840
|
* @returns Promise resolving to breakeven data record (empty object if not found)
|
|
13740
13841
|
*/
|
|
13741
|
-
readBreakevenData(signalId: string): Promise<BreakevenData>;
|
|
13842
|
+
readBreakevenData(signalId: string, _when: Date): Promise<BreakevenData>;
|
|
13742
13843
|
/**
|
|
13743
13844
|
* Writes the breakeven data for the given signal using `signalId` as the entity key.
|
|
13744
13845
|
*
|
|
13745
13846
|
* @param data - Breakeven data record to persist
|
|
13746
13847
|
* @param signalId - Signal identifier
|
|
13848
|
+
* @param when - Logical timestamp (reserved for API consistency; not used)
|
|
13747
13849
|
* @returns Promise that resolves when write is complete
|
|
13748
13850
|
*/
|
|
13749
|
-
writeBreakevenData(data: BreakevenData, signalId: string): Promise<void>;
|
|
13851
|
+
writeBreakevenData(data: BreakevenData, signalId: string, _when: Date): Promise<void>;
|
|
13750
13852
|
}
|
|
13751
13853
|
/**
|
|
13752
13854
|
* Constructor type for IPersistBreakevenInstance.
|
|
@@ -13810,9 +13912,10 @@ declare class PersistBreakevenUtils {
|
|
|
13810
13912
|
* @param strategyName - Strategy identifier
|
|
13811
13913
|
* @param signalId - Signal identifier
|
|
13812
13914
|
* @param exchangeName - Exchange identifier
|
|
13915
|
+
* @param when - Logical timestamp at which the read is happening (reserved for API consistency)
|
|
13813
13916
|
* @returns Promise resolving to breakeven data record (empty object if none)
|
|
13814
13917
|
*/
|
|
13815
|
-
readBreakevenData: (symbol: string, strategyName: StrategyName, signalId: string, exchangeName: ExchangeName) => Promise<BreakevenData>;
|
|
13918
|
+
readBreakevenData: (symbol: string, strategyName: StrategyName, signalId: string, exchangeName: ExchangeName, when: Date) => Promise<BreakevenData>;
|
|
13816
13919
|
/**
|
|
13817
13920
|
* Writes breakeven data for the given context and signalId.
|
|
13818
13921
|
* Lazily initializes the instance on first access.
|
|
@@ -13822,9 +13925,10 @@ declare class PersistBreakevenUtils {
|
|
|
13822
13925
|
* @param strategyName - Strategy identifier
|
|
13823
13926
|
* @param signalId - Signal identifier
|
|
13824
13927
|
* @param exchangeName - Exchange identifier
|
|
13928
|
+
* @param when - Logical timestamp this write belongs to (reserved for API consistency)
|
|
13825
13929
|
* @returns Promise that resolves when write is complete
|
|
13826
13930
|
*/
|
|
13827
|
-
writeBreakevenData: (breakevenData: BreakevenData, symbol: string, strategyName: StrategyName, signalId: string, exchangeName: ExchangeName) => Promise<void>;
|
|
13931
|
+
writeBreakevenData: (breakevenData: BreakevenData, symbol: string, strategyName: StrategyName, signalId: string, exchangeName: ExchangeName, when: Date) => Promise<void>;
|
|
13828
13932
|
/**
|
|
13829
13933
|
* Clears the memoized instance cache.
|
|
13830
13934
|
* Call when process.cwd() changes between strategy iterations.
|
|
@@ -28907,6 +29011,7 @@ declare class ClientRisk implements IRisk {
|
|
|
28907
29011
|
strategyName: StrategyName;
|
|
28908
29012
|
riskName: RiskName;
|
|
28909
29013
|
exchangeName: ExchangeName;
|
|
29014
|
+
frameName: string;
|
|
28910
29015
|
}): Promise<void>;
|
|
28911
29016
|
/**
|
|
28912
29017
|
* Checks if a signal should be allowed based on risk limits.
|
|
@@ -29330,9 +29435,7 @@ declare class RiskConnectionService implements TRisk$1 {
|
|
|
29330
29435
|
setLogger: (logger: ILogger) => void;
|
|
29331
29436
|
};
|
|
29332
29437
|
readonly riskSchemaService: RiskSchemaService;
|
|
29333
|
-
readonly
|
|
29334
|
-
readonly context: IExecutionContext;
|
|
29335
|
-
};
|
|
29438
|
+
readonly timeMetaService: TimeMetaService;
|
|
29336
29439
|
/**
|
|
29337
29440
|
* Action core service injected from DI container.
|
|
29338
29441
|
*/
|
|
@@ -29492,6 +29595,7 @@ declare class PartialConnectionService implements IPartial {
|
|
|
29492
29595
|
* Action core service injected from DI container.
|
|
29493
29596
|
*/
|
|
29494
29597
|
readonly actionCoreService: ActionCoreService;
|
|
29598
|
+
readonly timeMetaService: TimeMetaService;
|
|
29495
29599
|
/**
|
|
29496
29600
|
* Memoized factory function for ClientPartial instances.
|
|
29497
29601
|
*
|
|
@@ -29608,6 +29712,7 @@ declare class BreakevenConnectionService implements IBreakeven {
|
|
|
29608
29712
|
* Action core service injected from DI container.
|
|
29609
29713
|
*/
|
|
29610
29714
|
readonly actionCoreService: ActionCoreService;
|
|
29715
|
+
readonly timeMetaService: TimeMetaService;
|
|
29611
29716
|
/**
|
|
29612
29717
|
* Memoized factory function for ClientBreakeven instances.
|
|
29613
29718
|
*
|
|
@@ -29653,95 +29758,6 @@ declare class BreakevenConnectionService implements IBreakeven {
|
|
|
29653
29758
|
clear: (symbol: string, data: IPublicSignalRow, priceClose: number, backtest: boolean) => Promise<void>;
|
|
29654
29759
|
}
|
|
29655
29760
|
|
|
29656
|
-
/**
|
|
29657
|
-
* Service for tracking the latest candle timestamp per symbol-strategy-exchange-frame combination.
|
|
29658
|
-
*
|
|
29659
|
-
* Maintains a memoized BehaviorSubject per unique key that is updated on every strategy tick
|
|
29660
|
-
* by StrategyConnectionService. Consumers can synchronously read the last known timestamp or
|
|
29661
|
-
* await the first value if none has arrived yet.
|
|
29662
|
-
*
|
|
29663
|
-
* Primary use case: providing the current candle time outside of a tick execution context,
|
|
29664
|
-
* e.g., when a command is triggered between ticks.
|
|
29665
|
-
*
|
|
29666
|
-
* Features:
|
|
29667
|
-
* - One BehaviorSubject per (symbol, strategyName, exchangeName, frameName, backtest) key
|
|
29668
|
-
* - Falls back to ExecutionContextService.context.when when called inside an execution context
|
|
29669
|
-
* - Waits up to LISTEN_TIMEOUT ms for the first timestamp if none is cached yet
|
|
29670
|
-
* - clear() disposes the BehaviorSubject for a single key or all keys
|
|
29671
|
-
*
|
|
29672
|
-
* Architecture:
|
|
29673
|
-
* - Registered as singleton in DI container
|
|
29674
|
-
* - Updated by StrategyConnectionService after each tick
|
|
29675
|
-
* - Cleared by Backtest/Live/Walker at strategy start to prevent stale data
|
|
29676
|
-
*
|
|
29677
|
-
* @example
|
|
29678
|
-
* ```typescript
|
|
29679
|
-
* const ts = await backtest.timeMetaService.getTimestamp("BTCUSDT", context, false);
|
|
29680
|
-
* ```
|
|
29681
|
-
*/
|
|
29682
|
-
declare class TimeMetaService {
|
|
29683
|
-
private readonly loggerService;
|
|
29684
|
-
private readonly executionContextService;
|
|
29685
|
-
/**
|
|
29686
|
-
* Memoized factory for BehaviorSubject streams keyed by (symbol, strategyName, exchangeName, frameName, backtest).
|
|
29687
|
-
*
|
|
29688
|
-
* Each subject holds the latest createdAt timestamp emitted by the strategy iterator for that key.
|
|
29689
|
-
* Instances are cached until clear() is called.
|
|
29690
|
-
*/
|
|
29691
|
-
private getSource;
|
|
29692
|
-
/**
|
|
29693
|
-
* Returns the current candle timestamp (in milliseconds) for the given symbol and context.
|
|
29694
|
-
*
|
|
29695
|
-
* When called inside an execution context (i.e., during a signal handler or action),
|
|
29696
|
-
* reads the timestamp directly from ExecutionContextService.context.when.
|
|
29697
|
-
* Otherwise, reads the last value from the cached BehaviorSubject. If no value has
|
|
29698
|
-
* been emitted yet, waits up to LISTEN_TIMEOUT ms for the first tick before throwing.
|
|
29699
|
-
*
|
|
29700
|
-
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
29701
|
-
* @param context - Strategy, exchange, and frame identifiers
|
|
29702
|
-
* @param backtest - True if backtest mode, false if live mode
|
|
29703
|
-
* @returns Unix timestamp in milliseconds of the latest processed candle
|
|
29704
|
-
* @throws When no timestamp arrives within LISTEN_TIMEOUT ms
|
|
29705
|
-
*/
|
|
29706
|
-
getTimestamp: (symbol: string, context: {
|
|
29707
|
-
strategyName: string;
|
|
29708
|
-
exchangeName: string;
|
|
29709
|
-
frameName: string;
|
|
29710
|
-
}, backtest: boolean) => Promise<number>;
|
|
29711
|
-
/**
|
|
29712
|
-
* Pushes a new timestamp value into the BehaviorSubject for the given key.
|
|
29713
|
-
*
|
|
29714
|
-
* Called by StrategyConnectionService after each strategy tick to keep
|
|
29715
|
-
* the cached timestamp up to date.
|
|
29716
|
-
*
|
|
29717
|
-
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
29718
|
-
* @param timestamp - The createdAt timestamp from the tick (milliseconds)
|
|
29719
|
-
* @param context - Strategy, exchange, and frame identifiers
|
|
29720
|
-
* @param backtest - True if backtest mode, false if live mode
|
|
29721
|
-
*/
|
|
29722
|
-
next: (symbol: string, timestamp: number, context: {
|
|
29723
|
-
strategyName: string;
|
|
29724
|
-
exchangeName: string;
|
|
29725
|
-
frameName: string;
|
|
29726
|
-
}, backtest: boolean) => Promise<void>;
|
|
29727
|
-
/**
|
|
29728
|
-
* Disposes cached BehaviorSubject(s) to free memory and prevent stale data.
|
|
29729
|
-
*
|
|
29730
|
-
* When called without arguments, clears all memoized timestamp streams.
|
|
29731
|
-
* When called with a payload, clears only the stream for the specified key.
|
|
29732
|
-
* Should be called at strategy start (Backtest/Live/Walker) to reset state.
|
|
29733
|
-
*
|
|
29734
|
-
* @param payload - Optional key to clear a single stream; omit to clear all
|
|
29735
|
-
*/
|
|
29736
|
-
clear: (payload?: {
|
|
29737
|
-
symbol: string;
|
|
29738
|
-
strategyName: string;
|
|
29739
|
-
exchangeName: string;
|
|
29740
|
-
frameName: string;
|
|
29741
|
-
backtest: boolean;
|
|
29742
|
-
}) => void;
|
|
29743
|
-
}
|
|
29744
|
-
|
|
29745
29761
|
/**
|
|
29746
29762
|
* Service for tracking the latest market price per symbol-strategy-exchange-frame combination.
|
|
29747
29763
|
*
|