backtest-kit 3.4.0 → 3.4.2
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/README.md +22 -22
- package/build/index.cjs +755 -1
- package/build/index.mjs +753 -2
- package/package.json +2 -2
- package/types.d.ts +333 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "backtest-kit",
|
|
3
|
-
"version": "3.4.
|
|
3
|
+
"version": "3.4.2",
|
|
4
4
|
"description": "A TypeScript library for trading system backtest",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Petr Tripolsky",
|
|
@@ -77,7 +77,7 @@
|
|
|
77
77
|
"di-kit": "^1.1.1",
|
|
78
78
|
"di-scoped": "^1.0.21",
|
|
79
79
|
"functools-kit": "^1.0.95",
|
|
80
|
-
"get-moment-stamp": "^1.1.
|
|
80
|
+
"get-moment-stamp": "^1.1.2"
|
|
81
81
|
},
|
|
82
82
|
"publishConfig": {
|
|
83
83
|
"access": "public"
|
package/types.d.ts
CHANGED
|
@@ -57,6 +57,23 @@ declare const ExecutionContextService: (new () => {
|
|
|
57
57
|
*/
|
|
58
58
|
type TExecutionContextService = InstanceType<typeof ExecutionContextService>;
|
|
59
59
|
|
|
60
|
+
/**
|
|
61
|
+
* Single log entry stored in the log history.
|
|
62
|
+
*/
|
|
63
|
+
interface ILogEntry {
|
|
64
|
+
/** Unique entry identifier generated via randomString */
|
|
65
|
+
id: string;
|
|
66
|
+
/** Log level */
|
|
67
|
+
type: "log" | "debug" | "info" | "warn";
|
|
68
|
+
/** Unix timestamp in milliseconds when the entry was created */
|
|
69
|
+
timestamp: number;
|
|
70
|
+
/** Date taken from backtest context to improve user experience */
|
|
71
|
+
createdAt: string;
|
|
72
|
+
/** Log topic / method name */
|
|
73
|
+
topic: string;
|
|
74
|
+
/** Additional arguments passed to the log call */
|
|
75
|
+
args: unknown[];
|
|
76
|
+
}
|
|
60
77
|
/**
|
|
61
78
|
* Interface representing a logging mechanism for the swarm system.
|
|
62
79
|
* Provides methods to record messages at different severity levels, used across components like agents, sessions, states, storage, swarms, history, embeddings, completions, and policies.
|
|
@@ -89,6 +106,22 @@ interface ILogger {
|
|
|
89
106
|
* Candle time interval for fetching historical data.
|
|
90
107
|
*/
|
|
91
108
|
type CandleInterval = "1m" | "3m" | "5m" | "15m" | "30m" | "1h" | "2h" | "4h" | "6h" | "8h";
|
|
109
|
+
/** Numeric type that can be undefined (used for optional numeric values) */
|
|
110
|
+
type Num = number | undefined;
|
|
111
|
+
interface IPublicCandleData {
|
|
112
|
+
/** Unix timestamp in milliseconds when candle opened */
|
|
113
|
+
timestamp: Num;
|
|
114
|
+
/** Opening price at candle start */
|
|
115
|
+
open: Num;
|
|
116
|
+
/** Highest price during candle period */
|
|
117
|
+
high: Num;
|
|
118
|
+
/** Lowest price during candle period */
|
|
119
|
+
low: Num;
|
|
120
|
+
/** Closing price at candle end */
|
|
121
|
+
close: Num;
|
|
122
|
+
/** Trading volume during candle period */
|
|
123
|
+
volume: Num;
|
|
124
|
+
}
|
|
92
125
|
/**
|
|
93
126
|
* Single OHLCV candle data point.
|
|
94
127
|
* Used for VWAP calculation and backtesting.
|
|
@@ -127,6 +160,24 @@ interface IOrderBookData {
|
|
|
127
160
|
/** Array of ask orders (sell orders) */
|
|
128
161
|
asks: IBidData[];
|
|
129
162
|
}
|
|
163
|
+
/**
|
|
164
|
+
* Aggregated trade data point.
|
|
165
|
+
* Represents a single trade that has occurred, used for detailed analysis and backtesting.
|
|
166
|
+
* Includes price, quantity, timestamp, and whether the buyer is the market maker (which can indicate trade direction).
|
|
167
|
+
*
|
|
168
|
+
*/
|
|
169
|
+
interface IAggregatedTradeData {
|
|
170
|
+
/** Unique identifier for the aggregated trade */
|
|
171
|
+
id: string;
|
|
172
|
+
/** Price at which the trade occurred */
|
|
173
|
+
price: number;
|
|
174
|
+
/** Quantity traded */
|
|
175
|
+
qty: number;
|
|
176
|
+
/** Unix timestamp in milliseconds when the trade occurred */
|
|
177
|
+
timestamp: number;
|
|
178
|
+
/** Whether the buyer is the market maker (true if buyer is maker, false if seller is maker) */
|
|
179
|
+
isBuyerMaker: boolean;
|
|
180
|
+
}
|
|
130
181
|
/**
|
|
131
182
|
* Exchange parameters passed to ClientExchange constructor.
|
|
132
183
|
* Combines schema with runtime dependencies.
|
|
@@ -145,6 +196,8 @@ interface IExchangeParams extends IExchangeSchema {
|
|
|
145
196
|
formatPrice: (symbol: string, price: number, backtest: boolean) => Promise<string>;
|
|
146
197
|
/** Fetch order book for a trading pair (required, defaults applied) */
|
|
147
198
|
getOrderBook: (symbol: string, depth: number, from: Date, to: Date, backtest: boolean) => Promise<IOrderBookData>;
|
|
199
|
+
/** Fetch aggregated trades for a trading pair (required, defaults applied) */
|
|
200
|
+
getAggregatedTrades: (symbol: string, from: Date, to: Date, backtest: boolean) => Promise<IAggregatedTradeData[]>;
|
|
148
201
|
}
|
|
149
202
|
/**
|
|
150
203
|
* Optional callbacks for exchange data events.
|
|
@@ -172,7 +225,7 @@ interface IExchangeSchema {
|
|
|
172
225
|
* @param backtest - Whether running in backtest mode
|
|
173
226
|
* @returns Promise resolving to array of OHLCV candle data
|
|
174
227
|
*/
|
|
175
|
-
getCandles: (symbol: string, interval: CandleInterval, since: Date, limit: number, backtest: boolean) => Promise<
|
|
228
|
+
getCandles: (symbol: string, interval: CandleInterval, since: Date, limit: number, backtest: boolean) => Promise<IPublicCandleData[]>;
|
|
176
229
|
/**
|
|
177
230
|
* Format quantity according to exchange precision rules.
|
|
178
231
|
*
|
|
@@ -224,6 +277,31 @@ interface IExchangeSchema {
|
|
|
224
277
|
* ```
|
|
225
278
|
*/
|
|
226
279
|
getOrderBook?: (symbol: string, depth: number, from: Date, to: Date, backtest: boolean) => Promise<IOrderBookData>;
|
|
280
|
+
/**
|
|
281
|
+
* Fetch aggregated trades for a trading pair.
|
|
282
|
+
* Optional. If not provided, throws an error when called.
|
|
283
|
+
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
284
|
+
* @param from - Start of time range (used in backtest for historical data, can be ignored in live)
|
|
285
|
+
* @param to - End of time range (used in backtest for historical data, can be ignored in live)
|
|
286
|
+
* @param backtest - Whether running in backtest mode
|
|
287
|
+
* @return Promise resolving to array of aggregated trade data
|
|
288
|
+
* @example
|
|
289
|
+
* ```typescript
|
|
290
|
+
* // Backtest implementation: returns historical aggregated trades for the time range
|
|
291
|
+
* const backtestAggregatedTrades = async (symbol: string, from: Date, to: Date, backtest: boolean) => {
|
|
292
|
+
* if (backtest) {
|
|
293
|
+
* return await database.getAggregatedTrades(symbol, from, to);
|
|
294
|
+
* }
|
|
295
|
+
* return await exchange.fetchAggregatedTrades(symbol);
|
|
296
|
+
* };
|
|
297
|
+
*
|
|
298
|
+
* // Live implementation: ignores from/to when not in backtest mode
|
|
299
|
+
* const liveAggregatedTrades = async (symbol: string, _from: Date, _to: Date, backtest: boolean) => {
|
|
300
|
+
* return await exchange.fetchAggregatedTrades(symbol);
|
|
301
|
+
* };
|
|
302
|
+
* ```
|
|
303
|
+
*/
|
|
304
|
+
getAggregatedTrades?: (symbol: string, from: Date, to: Date, backtest: boolean) => Promise<IAggregatedTradeData[]>;
|
|
227
305
|
/** Optional lifecycle event callbacks (onCandleData) */
|
|
228
306
|
callbacks?: Partial<IExchangeCallbacks>;
|
|
229
307
|
}
|
|
@@ -284,6 +362,14 @@ interface IExchange {
|
|
|
284
362
|
* @returns Promise resolving to order book data
|
|
285
363
|
*/
|
|
286
364
|
getOrderBook: (symbol: string, depth?: number) => Promise<IOrderBookData>;
|
|
365
|
+
/**
|
|
366
|
+
* Fetch aggregated trades for a trading pair.
|
|
367
|
+
*
|
|
368
|
+
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
369
|
+
* @param limit - Optional maximum number of aggregated trades to fetch. If empty returns one hour of data.
|
|
370
|
+
* @returns Promise resolving to array of aggregated trade data
|
|
371
|
+
*/
|
|
372
|
+
getAggregatedTrades: (symbol: string, limit?: number) => Promise<IAggregatedTradeData[]>;
|
|
287
373
|
/**
|
|
288
374
|
* Fetch raw candles with flexible date/limit parameters.
|
|
289
375
|
*
|
|
@@ -4349,6 +4435,12 @@ declare const GLOBAL_CONFIG: {
|
|
|
4349
4435
|
* Default: 20 levels
|
|
4350
4436
|
*/
|
|
4351
4437
|
CC_ORDER_BOOK_MAX_DEPTH_LEVELS: number;
|
|
4438
|
+
/**
|
|
4439
|
+
* Maximum minutes of aggregated trades to fetch when no limit is provided.
|
|
4440
|
+
* If limit is not specified, the system will fetch aggregated trades for this many minutes starting from the current time minus the offset.
|
|
4441
|
+
* Binance requirement
|
|
4442
|
+
*/
|
|
4443
|
+
CC_AGGREGATED_TRADES_MAX_MINUTES: number;
|
|
4352
4444
|
/**
|
|
4353
4445
|
* Maximum number of notifications to keep in storage.
|
|
4354
4446
|
* Older notifications are removed when this limit is exceeded.
|
|
@@ -4363,6 +4455,14 @@ declare const GLOBAL_CONFIG: {
|
|
|
4363
4455
|
* Default: 50 signals
|
|
4364
4456
|
*/
|
|
4365
4457
|
CC_MAX_SIGNALS: number;
|
|
4458
|
+
/**
|
|
4459
|
+
* Maximum number of log lines to keep in storage.
|
|
4460
|
+
* Older log lines are removed when this limit is exceeded.
|
|
4461
|
+
* This helps prevent unbounded log growth which can consume memory and degrade performance over time.
|
|
4462
|
+
*
|
|
4463
|
+
* Default: 1000 log lines
|
|
4464
|
+
*/
|
|
4465
|
+
CC_MAX_LOG_LINES: number;
|
|
4366
4466
|
/**
|
|
4367
4467
|
* Enables mutex locking for candle fetching to prevent concurrent fetches of the same candles.
|
|
4368
4468
|
* This can help avoid redundant API calls and ensure data consistency when multiple processes/threads attempt to fetch candles simultaneously.
|
|
@@ -4476,8 +4576,10 @@ declare function getConfig(): {
|
|
|
4476
4576
|
CC_BREAKEVEN_THRESHOLD: number;
|
|
4477
4577
|
CC_ORDER_BOOK_TIME_OFFSET_MINUTES: number;
|
|
4478
4578
|
CC_ORDER_BOOK_MAX_DEPTH_LEVELS: number;
|
|
4579
|
+
CC_AGGREGATED_TRADES_MAX_MINUTES: number;
|
|
4479
4580
|
CC_MAX_NOTIFICATIONS: number;
|
|
4480
4581
|
CC_MAX_SIGNALS: number;
|
|
4582
|
+
CC_MAX_LOG_LINES: number;
|
|
4481
4583
|
CC_ENABLE_CANDLE_FETCH_MUTEX: boolean;
|
|
4482
4584
|
};
|
|
4483
4585
|
/**
|
|
@@ -4513,8 +4615,10 @@ declare function getDefaultConfig(): Readonly<{
|
|
|
4513
4615
|
CC_BREAKEVEN_THRESHOLD: number;
|
|
4514
4616
|
CC_ORDER_BOOK_TIME_OFFSET_MINUTES: number;
|
|
4515
4617
|
CC_ORDER_BOOK_MAX_DEPTH_LEVELS: number;
|
|
4618
|
+
CC_AGGREGATED_TRADES_MAX_MINUTES: number;
|
|
4516
4619
|
CC_MAX_NOTIFICATIONS: number;
|
|
4517
4620
|
CC_MAX_SIGNALS: number;
|
|
4621
|
+
CC_MAX_LOG_LINES: number;
|
|
4518
4622
|
CC_ENABLE_CANDLE_FETCH_MUTEX: boolean;
|
|
4519
4623
|
}>;
|
|
4520
4624
|
/**
|
|
@@ -6855,6 +6959,29 @@ declare function getRawCandles(symbol: string, interval: CandleInterval, limit?:
|
|
|
6855
6959
|
* @returns Promise resolving to array of candle data
|
|
6856
6960
|
*/
|
|
6857
6961
|
declare function getNextCandles(symbol: string, interval: CandleInterval, limit: number): Promise<ICandleData[]>;
|
|
6962
|
+
/**
|
|
6963
|
+
* Fetches aggregated trades for a trading pair from the registered exchange.
|
|
6964
|
+
*
|
|
6965
|
+
* Trades are fetched backwards from the current execution context time.
|
|
6966
|
+
* If limit is not specified, returns all trades within one CC_AGGREGATED_TRADES_MAX_MINUTES window.
|
|
6967
|
+
* If limit is specified, paginates backwards until at least limit trades are collected.
|
|
6968
|
+
*
|
|
6969
|
+
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
6970
|
+
* @param limit - Optional maximum number of trades to fetch
|
|
6971
|
+
* @returns Promise resolving to array of aggregated trade data
|
|
6972
|
+
* @throws Error if execution or method context is missing
|
|
6973
|
+
*
|
|
6974
|
+
* @example
|
|
6975
|
+
* ```typescript
|
|
6976
|
+
* // Fetch last hour of trades
|
|
6977
|
+
* const trades = await getAggregatedTrades("BTCUSDT");
|
|
6978
|
+
*
|
|
6979
|
+
* // Fetch last 500 trades
|
|
6980
|
+
* const lastTrades = await getAggregatedTrades("BTCUSDT", 500);
|
|
6981
|
+
* console.log(lastTrades[0]); // { id, price, qty, timestamp, isBuyerMaker }
|
|
6982
|
+
* ```
|
|
6983
|
+
*/
|
|
6984
|
+
declare function getAggregatedTrades(symbol: string, limit?: number): Promise<IAggregatedTradeData[]>;
|
|
6858
6985
|
|
|
6859
6986
|
/** Unique identifier for a dump result. Can be a string or numeric ID. */
|
|
6860
6987
|
type ResultId = string | number;
|
|
@@ -9112,6 +9239,71 @@ declare class PersistNotificationUtils {
|
|
|
9112
9239
|
*/
|
|
9113
9240
|
declare const PersistNotificationAdapter: PersistNotificationUtils;
|
|
9114
9241
|
|
|
9242
|
+
/**
|
|
9243
|
+
* Type for persisted log data.
|
|
9244
|
+
* Each log entry is stored as a separate file keyed by its id.
|
|
9245
|
+
*/
|
|
9246
|
+
type LogData = ILogEntry[];
|
|
9247
|
+
/**
|
|
9248
|
+
* Utility class for managing log entry persistence.
|
|
9249
|
+
*
|
|
9250
|
+
* Features:
|
|
9251
|
+
* - Memoized storage instance
|
|
9252
|
+
* - Custom adapter support
|
|
9253
|
+
* - Atomic read/write operations for LogData
|
|
9254
|
+
* - Each log entry stored as separate file keyed by id
|
|
9255
|
+
* - Crash-safe log state management
|
|
9256
|
+
*
|
|
9257
|
+
* Used by LogPersistUtils for log entry persistence.
|
|
9258
|
+
*/
|
|
9259
|
+
declare class PersistLogUtils {
|
|
9260
|
+
private PersistLogFactory;
|
|
9261
|
+
private _logStorage;
|
|
9262
|
+
private getLogStorage;
|
|
9263
|
+
/**
|
|
9264
|
+
* Registers a custom persistence adapter.
|
|
9265
|
+
*
|
|
9266
|
+
* @param Ctor - Custom PersistBase constructor
|
|
9267
|
+
*/
|
|
9268
|
+
usePersistLogAdapter(Ctor: TPersistBaseCtor<string, ILogEntry>): void;
|
|
9269
|
+
/**
|
|
9270
|
+
* Reads persisted log entries.
|
|
9271
|
+
*
|
|
9272
|
+
* Called by LogPersistUtils.waitForInit() to restore state.
|
|
9273
|
+
* Uses keys() from PersistBase to iterate over all stored entries.
|
|
9274
|
+
* Returns empty array if no entries exist.
|
|
9275
|
+
*
|
|
9276
|
+
* @returns Promise resolving to array of log entries
|
|
9277
|
+
*/
|
|
9278
|
+
readLogData: () => Promise<LogData>;
|
|
9279
|
+
/**
|
|
9280
|
+
* Writes log entries to disk with atomic file writes.
|
|
9281
|
+
*
|
|
9282
|
+
* Called by LogPersistUtils after each log call to persist state.
|
|
9283
|
+
* Uses entry.id as the storage key for individual file storage.
|
|
9284
|
+
* Uses atomic writes to prevent corruption on crashes.
|
|
9285
|
+
*
|
|
9286
|
+
* @param logData - Log entries to persist
|
|
9287
|
+
* @returns Promise that resolves when write is complete
|
|
9288
|
+
*/
|
|
9289
|
+
writeLogData: (logData: LogData) => Promise<void>;
|
|
9290
|
+
/**
|
|
9291
|
+
* Switches to the default JSON persist adapter.
|
|
9292
|
+
* All future persistence writes will use JSON storage.
|
|
9293
|
+
*/
|
|
9294
|
+
useJson(): void;
|
|
9295
|
+
/**
|
|
9296
|
+
* Switches to a dummy persist adapter that discards all writes.
|
|
9297
|
+
* All future persistence writes will be no-ops.
|
|
9298
|
+
*/
|
|
9299
|
+
useDummy(): void;
|
|
9300
|
+
}
|
|
9301
|
+
/**
|
|
9302
|
+
* Global singleton instance of PersistLogUtils.
|
|
9303
|
+
* Used by LogPersistUtils for log entry persistence.
|
|
9304
|
+
*/
|
|
9305
|
+
declare const PersistLogAdapter: PersistLogUtils;
|
|
9306
|
+
|
|
9115
9307
|
declare const WAIT_FOR_INIT_SYMBOL$1: unique symbol;
|
|
9116
9308
|
declare const WRITE_SAFE_SYMBOL$1: unique symbol;
|
|
9117
9309
|
/**
|
|
@@ -9721,6 +9913,95 @@ declare class MarkdownAdapter extends MarkdownUtils {
|
|
|
9721
9913
|
*/
|
|
9722
9914
|
declare const Markdown: MarkdownAdapter;
|
|
9723
9915
|
|
|
9916
|
+
/**
|
|
9917
|
+
* Extended logger interface with log history access.
|
|
9918
|
+
*/
|
|
9919
|
+
interface ILog extends ILogger {
|
|
9920
|
+
/**
|
|
9921
|
+
* Returns all stored log entries.
|
|
9922
|
+
* @returns Array of all log entries
|
|
9923
|
+
*/
|
|
9924
|
+
getList(): Promise<ILogEntry[]>;
|
|
9925
|
+
}
|
|
9926
|
+
/**
|
|
9927
|
+
* Constructor type for log adapters.
|
|
9928
|
+
* Used for custom log implementations.
|
|
9929
|
+
*/
|
|
9930
|
+
type TLogCtor = new () => Partial<ILog>;
|
|
9931
|
+
/**
|
|
9932
|
+
* Log adapter with pluggable storage backend.
|
|
9933
|
+
*
|
|
9934
|
+
* Features:
|
|
9935
|
+
* - Adapter pattern for swappable log implementations
|
|
9936
|
+
* - Default adapter: LogMemoryUtils (in-memory storage)
|
|
9937
|
+
* - Alternative adapters: LogPersistUtils, LogDummyUtils
|
|
9938
|
+
* - Convenience methods: usePersist(), useMemory(), useDummy()
|
|
9939
|
+
*/
|
|
9940
|
+
declare class LogAdapter implements ILog {
|
|
9941
|
+
/** Internal log utils instance */
|
|
9942
|
+
private _log;
|
|
9943
|
+
/**
|
|
9944
|
+
* Lists all stored log entries.
|
|
9945
|
+
* Proxies call to the underlying log adapter.
|
|
9946
|
+
* @returns Array of all log entries
|
|
9947
|
+
*/
|
|
9948
|
+
getList: () => Promise<ILogEntry[]>;
|
|
9949
|
+
/**
|
|
9950
|
+
* Logs a general-purpose message.
|
|
9951
|
+
* Proxies call to the underlying log adapter.
|
|
9952
|
+
* @param topic - The log topic / method name
|
|
9953
|
+
* @param args - Additional arguments
|
|
9954
|
+
*/
|
|
9955
|
+
log: (topic: string, ...args: any[]) => void;
|
|
9956
|
+
/**
|
|
9957
|
+
* Logs a debug-level message.
|
|
9958
|
+
* Proxies call to the underlying log adapter.
|
|
9959
|
+
* @param topic - The log topic / method name
|
|
9960
|
+
* @param args - Additional arguments
|
|
9961
|
+
*/
|
|
9962
|
+
debug: (topic: string, ...args: any[]) => void;
|
|
9963
|
+
/**
|
|
9964
|
+
* Logs an info-level message.
|
|
9965
|
+
* Proxies call to the underlying log adapter.
|
|
9966
|
+
* @param topic - The log topic / method name
|
|
9967
|
+
* @param args - Additional arguments
|
|
9968
|
+
*/
|
|
9969
|
+
info: (topic: string, ...args: any[]) => void;
|
|
9970
|
+
/**
|
|
9971
|
+
* Logs a warning-level message.
|
|
9972
|
+
* Proxies call to the underlying log adapter.
|
|
9973
|
+
* @param topic - The log topic / method name
|
|
9974
|
+
* @param args - Additional arguments
|
|
9975
|
+
*/
|
|
9976
|
+
warn: (topic: string, ...args: any[]) => void;
|
|
9977
|
+
/**
|
|
9978
|
+
* Sets the log adapter constructor.
|
|
9979
|
+
* All future log operations will use this adapter.
|
|
9980
|
+
* @param Ctor - Constructor for log adapter
|
|
9981
|
+
*/
|
|
9982
|
+
useLogger: (Ctor: TLogCtor) => void;
|
|
9983
|
+
/**
|
|
9984
|
+
* Switches to persistent log adapter.
|
|
9985
|
+
* Log entries will be persisted to disk.
|
|
9986
|
+
*/
|
|
9987
|
+
usePersist: () => void;
|
|
9988
|
+
/**
|
|
9989
|
+
* Switches to in-memory log adapter (default).
|
|
9990
|
+
* Log entries will be stored in memory only.
|
|
9991
|
+
*/
|
|
9992
|
+
useMemory: () => void;
|
|
9993
|
+
/**
|
|
9994
|
+
* Switches to dummy log adapter.
|
|
9995
|
+
* All future log writes will be no-ops.
|
|
9996
|
+
*/
|
|
9997
|
+
useDummy: () => void;
|
|
9998
|
+
}
|
|
9999
|
+
/**
|
|
10000
|
+
* Global singleton instance of LogAdapter.
|
|
10001
|
+
* Provides unified log management with pluggable backends.
|
|
10002
|
+
*/
|
|
10003
|
+
declare const Log: LogAdapter;
|
|
10004
|
+
|
|
9724
10005
|
/**
|
|
9725
10006
|
* Type alias for column configuration used in backtest markdown reports.
|
|
9726
10007
|
*
|
|
@@ -14196,6 +14477,17 @@ declare class ExchangeUtils {
|
|
|
14196
14477
|
getOrderBook: (symbol: string, context: {
|
|
14197
14478
|
exchangeName: ExchangeName;
|
|
14198
14479
|
}, depth?: number) => Promise<IOrderBookData>;
|
|
14480
|
+
/**
|
|
14481
|
+
* Fetch aggregated trades for a trading pair.
|
|
14482
|
+
*
|
|
14483
|
+
* @param symbol - Trading pair symbol
|
|
14484
|
+
* @param context - Execution context with exchange name
|
|
14485
|
+
* @param limit - Optional maximum number of trades to return
|
|
14486
|
+
* @returns Promise resolving to array of aggregated trade data
|
|
14487
|
+
*/
|
|
14488
|
+
getAggregatedTrades: (symbol: string, context: {
|
|
14489
|
+
exchangeName: ExchangeName;
|
|
14490
|
+
}, limit?: number) => Promise<IAggregatedTradeData[]>;
|
|
14199
14491
|
/**
|
|
14200
14492
|
* Fetches raw candles with flexible date/limit parameters.
|
|
14201
14493
|
*
|
|
@@ -16813,6 +17105,25 @@ declare class ClientExchange implements IExchange {
|
|
|
16813
17105
|
* @throws Error if getOrderBook is not implemented
|
|
16814
17106
|
*/
|
|
16815
17107
|
getOrderBook(symbol: string, depth?: number): Promise<IOrderBookData>;
|
|
17108
|
+
/**
|
|
17109
|
+
* Fetches aggregated trades backwards from execution context time.
|
|
17110
|
+
*
|
|
17111
|
+
* Algorithm:
|
|
17112
|
+
* 1. Align when down to the nearest minute boundary (1-minute granularity)
|
|
17113
|
+
* 2. If limit is not specified: fetch one window of CC_AGGREGATED_TRADES_MAX_MINUTES
|
|
17114
|
+
* 3. If limit is specified: paginate backwards in CC_AGGREGATED_TRADES_MAX_MINUTES
|
|
17115
|
+
* chunks until at least limit trades are collected, then slice to limit
|
|
17116
|
+
*
|
|
17117
|
+
* Look-ahead bias prevention:
|
|
17118
|
+
* - `to` is always aligned down to the minute (never exceeds current when)
|
|
17119
|
+
* - Each pagination window goes strictly backwards from alignedWhen
|
|
17120
|
+
*
|
|
17121
|
+
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
17122
|
+
* @param limit - Optional maximum number of trades to return. If not specified,
|
|
17123
|
+
* returns all trades within the last CC_AGGREGATED_TRADES_MAX_MINUTES window.
|
|
17124
|
+
* @returns Promise resolving to array of aggregated trade data
|
|
17125
|
+
*/
|
|
17126
|
+
getAggregatedTrades(symbol: string, limit?: number): Promise<IAggregatedTradeData[]>;
|
|
16816
17127
|
}
|
|
16817
17128
|
|
|
16818
17129
|
/**
|
|
@@ -16917,6 +17228,16 @@ declare class ExchangeConnectionService implements IExchange {
|
|
|
16917
17228
|
* @returns Promise resolving to order book data
|
|
16918
17229
|
*/
|
|
16919
17230
|
getOrderBook: (symbol: string, depth?: number) => Promise<IOrderBookData>;
|
|
17231
|
+
/**
|
|
17232
|
+
* Fetches aggregated trades for a trading pair using configured exchange.
|
|
17233
|
+
*
|
|
17234
|
+
* Routes to exchange determined by methodContextService.context.exchangeName.
|
|
17235
|
+
*
|
|
17236
|
+
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
17237
|
+
* @param limit - Optional maximum number of trades to fetch. If empty returns one window of data.
|
|
17238
|
+
* @returns Promise resolving to array of aggregated trade data
|
|
17239
|
+
*/
|
|
17240
|
+
getAggregatedTrades: (symbol: string, limit?: number) => Promise<IAggregatedTradeData[]>;
|
|
16920
17241
|
/**
|
|
16921
17242
|
* Fetches raw candles with flexible date/limit parameters.
|
|
16922
17243
|
*
|
|
@@ -18653,6 +18974,16 @@ declare class ExchangeCoreService implements TExchange {
|
|
|
18653
18974
|
* @returns Promise resolving to order book data
|
|
18654
18975
|
*/
|
|
18655
18976
|
getOrderBook: (symbol: string, when: Date, backtest: boolean, depth?: number) => Promise<IOrderBookData>;
|
|
18977
|
+
/**
|
|
18978
|
+
* Fetches aggregated trades with execution context.
|
|
18979
|
+
*
|
|
18980
|
+
* @param symbol - Trading pair symbol
|
|
18981
|
+
* @param when - Timestamp for context (used in backtest mode)
|
|
18982
|
+
* @param backtest - Whether running in backtest mode
|
|
18983
|
+
* @param limit - Optional maximum number of trades to fetch
|
|
18984
|
+
* @returns Promise resolving to array of aggregated trade data
|
|
18985
|
+
*/
|
|
18986
|
+
getAggregatedTrades: (symbol: string, when: Date, backtest: boolean, limit?: number) => Promise<IAggregatedTradeData[]>;
|
|
18656
18987
|
/**
|
|
18657
18988
|
* Fetches raw candles with flexible date/limit parameters and execution context.
|
|
18658
18989
|
*
|
|
@@ -21255,4 +21586,4 @@ declare const backtest: {
|
|
|
21255
21586
|
loggerService: LoggerService;
|
|
21256
21587
|
};
|
|
21257
21588
|
|
|
21258
|
-
export { ActionBase, type ActivateScheduledCommit, type ActivateScheduledCommitNotification, type ActivePingContract, type AverageBuyCommit, Backtest, type BacktestStatisticsModel, Breakeven, type BreakevenAvailableNotification, type BreakevenCommit, type BreakevenCommitNotification, type BreakevenContract, type BreakevenData, Cache, type CancelScheduledCommit, type CandleData, type CandleInterval, type ClosePendingCommit, type ColumnConfig, type ColumnModel, Constant, type CriticalErrorNotification, type DoneContract, type EntityId, Exchange, ExecutionContextService, type FrameInterval, type GlobalConfig, Heat, type HeatmapStatisticsModel, type IActionSchema, type IActivateScheduledCommitRow, type IBidData, type IBreakevenCommitRow, type ICandleData, type ICommitRow, type IExchangeSchema, type IFrameSchema, type IHeatmapRow, type IMarkdownDumpOptions, type INotificationUtils, type IOrderBookData, type IPartialLossCommitRow, type IPartialProfitCommitRow, type IPersistBase, type IPositionSizeATRParams, type IPositionSizeFixedPercentageParams, type IPositionSizeKellyParams, type IPublicAction, 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, Markdown, MarkdownFileBase, MarkdownFolderBase, type MarkdownName, 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, 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 SignalClosedNotification, type SignalData, type SignalInterval, type SignalOpenedNotification, type SignalScheduledNotification, Storage, StorageBacktest, type StorageData, StorageLive, Strategy, type StrategyActionType, type StrategyCancelReason, type StrategyCloseReason, type StrategyCommitContract, type StrategyEvent, type StrategyStatisticsModel, 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, commitPartialProfit, commitTrailingStop, commitTrailingTake, dumpMessages, emitters, formatPrice, formatQuantity, get, getActionSchema, getAveragePrice, getBacktestTimeframe, getCandles, getColumns, getConfig, getContext, getDate, getDefaultColumns, getDefaultConfig, getExchangeSchema, getFrameSchema, getMode, getNextCandles, getOrderBook, getRawCandles, getRiskSchema, getSizingSchema, getStrategySchema, getSymbol, getWalkerSchema, hasTradeContext, 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, listenValidation, listenWalker, listenWalkerComplete, listenWalkerOnce, listenWalkerProgress, overrideActionSchema, overrideExchangeSchema, overrideFrameSchema, overrideRiskSchema, overrideSizingSchema, overrideStrategySchema, overrideWalkerSchema, parseArgs, roundTicks, set, setColumns, setConfig, setLogger, stopStrategy, validate, waitForCandle, warmCandles };
|
|
21589
|
+
export { ActionBase, type ActivateScheduledCommit, type ActivateScheduledCommitNotification, type ActivePingContract, type AverageBuyCommit, Backtest, type BacktestStatisticsModel, Breakeven, type BreakevenAvailableNotification, type BreakevenCommit, type BreakevenCommitNotification, type BreakevenContract, type BreakevenData, Cache, type CancelScheduledCommit, type CandleData, type CandleInterval, type ClosePendingCommit, type ColumnConfig, type ColumnModel, Constant, type CriticalErrorNotification, type DoneContract, type EntityId, Exchange, ExecutionContextService, type FrameInterval, type GlobalConfig, Heat, type HeatmapStatisticsModel, type IActionSchema, type IActivateScheduledCommitRow, type IAggregatedTradeData, type IBidData, type IBreakevenCommitRow, type ICandleData, type ICommitRow, type IExchangeSchema, type IFrameSchema, type IHeatmapRow, type ILog, type ILogEntry, type ILogger, type IMarkdownDumpOptions, type INotificationUtils, type IOrderBookData, type IPartialLossCommitRow, type IPartialProfitCommitRow, type IPersistBase, type IPositionSizeATRParams, type IPositionSizeFixedPercentageParams, type IPositionSizeKellyParams, type IPublicAction, type IPublicCandleData, type IPublicSignalRow, type IReportDumpOptions, type IRiskActivePosition, type IRiskCheckArgs, type IRiskSchema, type IRiskSignalRow, type IRiskValidation, type IRiskValidationFn, type IRiskValidationPayload, type IScheduledSignalCancelRow, type IScheduledSignalRow, type ISignalDto, type ISignalRow, type ISizingCalculateParams, type ISizingCalculateParamsATR, type ISizingCalculateParamsFixedPercentage, type ISizingCalculateParamsKelly, type ISizingParams, type ISizingParamsATR, type ISizingParamsFixedPercentage, type ISizingParamsKelly, type ISizingSchema, type ISizingSchemaATR, type ISizingSchemaFixedPercentage, type ISizingSchemaKelly, type IStorageSignalRow, type IStorageUtils, type IStrategyPnL, type IStrategyResult, type IStrategySchema, type IStrategyTickResult, type IStrategyTickResultActive, type IStrategyTickResultCancelled, type IStrategyTickResultClosed, type IStrategyTickResultIdle, type IStrategyTickResultOpened, type IStrategyTickResultScheduled, type IStrategyTickResultWaiting, type ITrailingStopCommitRow, type ITrailingTakeCommitRow, type IWalkerResults, type IWalkerSchema, type IWalkerStrategyResult, type InfoErrorNotification, Live, type LiveStatisticsModel, Log, type LogData, Markdown, MarkdownFileBase, MarkdownFolderBase, type MarkdownName, 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, 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 SignalClosedNotification, type SignalData, type SignalInterval, type SignalOpenedNotification, type SignalScheduledNotification, Storage, StorageBacktest, type StorageData, StorageLive, Strategy, type StrategyActionType, type StrategyCancelReason, type StrategyCloseReason, type StrategyCommitContract, type StrategyEvent, type StrategyStatisticsModel, 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, commitPartialProfit, commitTrailingStop, commitTrailingTake, dumpMessages, emitters, formatPrice, formatQuantity, get, getActionSchema, getAggregatedTrades, getAveragePrice, getBacktestTimeframe, getCandles, getColumns, getConfig, getContext, getDate, getDefaultColumns, getDefaultConfig, getExchangeSchema, getFrameSchema, getMode, getNextCandles, getOrderBook, getRawCandles, getRiskSchema, getSizingSchema, getStrategySchema, getSymbol, getWalkerSchema, hasTradeContext, 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, listenValidation, listenWalker, listenWalkerComplete, listenWalkerOnce, listenWalkerProgress, overrideActionSchema, overrideExchangeSchema, overrideFrameSchema, overrideRiskSchema, overrideSizingSchema, overrideStrategySchema, overrideWalkerSchema, parseArgs, roundTicks, set, setColumns, setConfig, setLogger, stopStrategy, validate, waitForCandle, warmCandles };
|