backtest-kit 1.6.8 → 1.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/index.cjs +983 -569
- package/build/index.mjs +983 -569
- package/package.json +1 -1
- package/types.d.ts +1002 -653
package/types.d.ts
CHANGED
|
@@ -111,50 +111,198 @@ interface ValidateArgs<T = Enum> {
|
|
|
111
111
|
declare function validate(args?: Partial<Args>): Promise<void>;
|
|
112
112
|
|
|
113
113
|
/**
|
|
114
|
-
*
|
|
114
|
+
* Stops the strategy from generating new signals.
|
|
115
115
|
*
|
|
116
|
-
*
|
|
117
|
-
*
|
|
116
|
+
* Sets internal flag to prevent strategy from opening new signals.
|
|
117
|
+
* Current active signal (if any) will complete normally.
|
|
118
|
+
* Backtest/Live mode will stop at the next safe point (idle state or after signal closes).
|
|
119
|
+
*
|
|
120
|
+
* Automatically detects backtest/live mode from execution context.
|
|
121
|
+
*
|
|
122
|
+
* @param symbol - Trading pair symbol
|
|
123
|
+
* @param strategyName - Strategy name to stop
|
|
124
|
+
* @returns Promise that resolves when stop flag is set
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* ```typescript
|
|
128
|
+
* import { stop } from "backtest-kit";
|
|
129
|
+
*
|
|
130
|
+
* // Stop strategy after some condition
|
|
131
|
+
* await stop("BTCUSDT", "my-strategy");
|
|
132
|
+
* ```
|
|
118
133
|
*/
|
|
119
|
-
|
|
120
|
-
/** Trading pair symbol (e.g., "BTCUSDT") */
|
|
121
|
-
symbol: string;
|
|
122
|
-
/** Current timestamp for operation */
|
|
123
|
-
when: Date;
|
|
124
|
-
/** Whether running in backtest mode (true) or live mode (false) */
|
|
125
|
-
backtest: boolean;
|
|
126
|
-
}
|
|
134
|
+
declare function stop(symbol: string): Promise<void>;
|
|
127
135
|
/**
|
|
128
|
-
*
|
|
136
|
+
* Cancels the scheduled signal without stopping the strategy.
|
|
129
137
|
*
|
|
130
|
-
*
|
|
131
|
-
*
|
|
138
|
+
* Clears the scheduled signal (waiting for priceOpen activation).
|
|
139
|
+
* Does NOT affect active pending signals or strategy operation.
|
|
140
|
+
* Does NOT set stop flag - strategy can continue generating new signals.
|
|
132
141
|
*
|
|
133
|
-
*
|
|
142
|
+
* Automatically detects backtest/live mode from execution context.
|
|
143
|
+
*
|
|
144
|
+
* @param symbol - Trading pair symbol
|
|
145
|
+
* @param strategyName - Strategy name
|
|
146
|
+
* @param cancelId - Optional cancellation ID for tracking user-initiated cancellations
|
|
147
|
+
* @returns Promise that resolves when scheduled signal is cancelled
|
|
134
148
|
*
|
|
135
149
|
* @example
|
|
136
150
|
* ```typescript
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
*
|
|
141
|
-
* },
|
|
142
|
-
* { symbol: "BTCUSDT", when: new Date(), backtest: true }
|
|
143
|
-
* );
|
|
151
|
+
* import { cancel } from "backtest-kit";
|
|
152
|
+
*
|
|
153
|
+
* // Cancel scheduled signal with custom ID
|
|
154
|
+
* await cancel("BTCUSDT", "my-strategy", "manual-cancel-001");
|
|
144
155
|
* ```
|
|
145
156
|
*/
|
|
146
|
-
declare
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
157
|
+
declare function cancel(symbol: string, cancelId?: string): Promise<void>;
|
|
158
|
+
|
|
159
|
+
declare const GLOBAL_CONFIG: {
|
|
160
|
+
/**
|
|
161
|
+
* Time to wait for scheduled signal to activate (in minutes)
|
|
162
|
+
* If signal does not activate within this time, it will be cancelled.
|
|
163
|
+
*/
|
|
164
|
+
CC_SCHEDULE_AWAIT_MINUTES: number;
|
|
165
|
+
/**
|
|
166
|
+
* Number of candles to use for average price calculation (VWAP)
|
|
167
|
+
* Default: 5 candles (last 5 minutes when using 1m interval)
|
|
168
|
+
*/
|
|
169
|
+
CC_AVG_PRICE_CANDLES_COUNT: number;
|
|
170
|
+
/**
|
|
171
|
+
* Slippage percentage applied to entry and exit prices.
|
|
172
|
+
* Simulates market impact and order book depth.
|
|
173
|
+
* Applied twice (entry and exit) for realistic execution simulation.
|
|
174
|
+
* Default: 0.1% per transaction
|
|
175
|
+
*/
|
|
176
|
+
CC_PERCENT_SLIPPAGE: number;
|
|
177
|
+
/**
|
|
178
|
+
* Fee percentage charged per transaction.
|
|
179
|
+
* Applied twice (entry and exit) for total fee calculation.
|
|
180
|
+
* Default: 0.1% per transaction (total 0.2%)
|
|
181
|
+
*/
|
|
182
|
+
CC_PERCENT_FEE: number;
|
|
183
|
+
/**
|
|
184
|
+
* Minimum TakeProfit distance from priceOpen (percentage)
|
|
185
|
+
* Must be greater than (slippage + fees) to ensure profitable trades
|
|
186
|
+
*
|
|
187
|
+
* Calculation:
|
|
188
|
+
* - Slippage effect: ~0.2% (0.1% × 2 transactions)
|
|
189
|
+
* - Fees: 0.2% (0.1% × 2 transactions)
|
|
190
|
+
* - Minimum profit buffer: 0.1%
|
|
191
|
+
* - Total: 0.5%
|
|
192
|
+
*
|
|
193
|
+
* Default: 0.5% (covers all costs + minimum profit margin)
|
|
194
|
+
*/
|
|
195
|
+
CC_MIN_TAKEPROFIT_DISTANCE_PERCENT: number;
|
|
196
|
+
/**
|
|
197
|
+
* Minimum StopLoss distance from priceOpen (percentage)
|
|
198
|
+
* Prevents signals from being immediately stopped out due to price volatility
|
|
199
|
+
* Default: 0.5% (buffer to avoid instant stop loss on normal market fluctuations)
|
|
200
|
+
*/
|
|
201
|
+
CC_MIN_STOPLOSS_DISTANCE_PERCENT: number;
|
|
202
|
+
/**
|
|
203
|
+
* Maximum StopLoss distance from priceOpen (percentage)
|
|
204
|
+
* Prevents catastrophic losses from extreme StopLoss values
|
|
205
|
+
* Default: 20% (one signal cannot lose more than 20% of position)
|
|
206
|
+
*/
|
|
207
|
+
CC_MAX_STOPLOSS_DISTANCE_PERCENT: number;
|
|
208
|
+
/**
|
|
209
|
+
* Maximum signal lifetime in minutes
|
|
210
|
+
* Prevents eternal signals that block risk limits for weeks/months
|
|
211
|
+
* Default: 1440 minutes (1 day)
|
|
212
|
+
*/
|
|
213
|
+
CC_MAX_SIGNAL_LIFETIME_MINUTES: number;
|
|
214
|
+
/**
|
|
215
|
+
* Maximum time allowed for signal generation (in seconds).
|
|
216
|
+
* Prevents long-running or stuck signal generation routines from blocking
|
|
217
|
+
* execution or consuming resources indefinitely. If generation exceeds this
|
|
218
|
+
* threshold the attempt should be aborted, logged and optionally retried.
|
|
219
|
+
*
|
|
220
|
+
* Default: 180 seconds (3 minutes)
|
|
221
|
+
*/
|
|
222
|
+
CC_MAX_SIGNAL_GENERATION_SECONDS: number;
|
|
223
|
+
/**
|
|
224
|
+
* Number of retries for getCandles function
|
|
225
|
+
* Default: 3 retries
|
|
226
|
+
*/
|
|
227
|
+
CC_GET_CANDLES_RETRY_COUNT: number;
|
|
228
|
+
/**
|
|
229
|
+
* Delay between retries for getCandles function (in milliseconds)
|
|
230
|
+
* Default: 5000 ms (5 seconds)
|
|
231
|
+
*/
|
|
232
|
+
CC_GET_CANDLES_RETRY_DELAY_MS: number;
|
|
233
|
+
/**
|
|
234
|
+
* Maximum allowed deviation factor for price anomaly detection.
|
|
235
|
+
* Price should not be more than this factor lower than reference price.
|
|
236
|
+
*
|
|
237
|
+
* Reasoning:
|
|
238
|
+
* - Incomplete candles from Binance API typically have prices near 0 (e.g., $0.01-1)
|
|
239
|
+
* - Normal BTC price ranges: $20,000-100,000
|
|
240
|
+
* - Factor 1000 catches prices below $20-100 when median is $20,000-100,000
|
|
241
|
+
* - Factor 100 would be too permissive (allows $200 when median is $20,000)
|
|
242
|
+
* - Factor 10000 might be too strict for low-cap altcoins
|
|
243
|
+
*
|
|
244
|
+
* Example: BTC at $50,000 median → threshold $50 (catches $0.01-1 anomalies)
|
|
245
|
+
*/
|
|
246
|
+
CC_GET_CANDLES_PRICE_ANOMALY_THRESHOLD_FACTOR: number;
|
|
247
|
+
/**
|
|
248
|
+
* Minimum number of candles required for reliable median calculation.
|
|
249
|
+
* Below this threshold, use simple average instead of median.
|
|
250
|
+
*
|
|
251
|
+
* Reasoning:
|
|
252
|
+
* - Each candle provides 4 price points (OHLC)
|
|
253
|
+
* - 5 candles = 20 price points, sufficient for robust median calculation
|
|
254
|
+
* - Below 5 candles, single anomaly can heavily skew median
|
|
255
|
+
* - Statistical rule of thumb: minimum 7-10 data points for median stability
|
|
256
|
+
* - Average is more stable than median for small datasets (n < 20)
|
|
257
|
+
*
|
|
258
|
+
* Example: 3 candles = 12 points (use average), 5 candles = 20 points (use median)
|
|
259
|
+
*/
|
|
260
|
+
CC_GET_CANDLES_MIN_CANDLES_FOR_MEDIAN: number;
|
|
261
|
+
/**
|
|
262
|
+
* Controls visibility of signal notes in markdown report tables.
|
|
263
|
+
* When enabled, the "Note" column will be displayed in all markdown reports
|
|
264
|
+
* (backtest, live, schedule, risk, etc.)
|
|
265
|
+
*
|
|
266
|
+
* Default: false (notes are hidden to reduce table width and improve readability)
|
|
267
|
+
*/
|
|
268
|
+
CC_REPORT_SHOW_SIGNAL_NOTE: boolean;
|
|
269
|
+
};
|
|
153
270
|
/**
|
|
154
|
-
* Type
|
|
155
|
-
* Used for dependency injection type annotations.
|
|
271
|
+
* Type for global configuration object.
|
|
156
272
|
*/
|
|
157
|
-
type
|
|
273
|
+
type GlobalConfig = typeof GLOBAL_CONFIG;
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* Mapping of available table/markdown reports to their column definitions.
|
|
277
|
+
*
|
|
278
|
+
* Each property references a column definition object imported from
|
|
279
|
+
* `src/assets/*.columns`. These are used by markdown/report generators
|
|
280
|
+
* (backtest, live, schedule, risk, heat, performance, partial, walker).
|
|
281
|
+
*/
|
|
282
|
+
declare const COLUMN_CONFIG: {
|
|
283
|
+
/** Columns used in backtest markdown tables and reports */
|
|
284
|
+
backtest_columns: ColumnModel<IStrategyTickResultClosed>[];
|
|
285
|
+
/** Columns used by heatmap / heat reports */
|
|
286
|
+
heat_columns: ColumnModel<IHeatmapRow>[];
|
|
287
|
+
/** Columns for live trading reports and logs */
|
|
288
|
+
live_columns: ColumnModel<TickEvent>[];
|
|
289
|
+
/** Columns for partial-results / incremental reports */
|
|
290
|
+
partial_columns: ColumnModel<PartialEvent>[];
|
|
291
|
+
/** Columns for performance summary reports */
|
|
292
|
+
performance_columns: ColumnModel<MetricStats>[];
|
|
293
|
+
/** Columns for risk-related reports */
|
|
294
|
+
risk_columns: ColumnModel<RiskEvent>[];
|
|
295
|
+
/** Columns for scheduled report output */
|
|
296
|
+
schedule_columns: ColumnModel<ScheduledEvent>[];
|
|
297
|
+
/** Walker: PnL summary columns */
|
|
298
|
+
walker_pnl_columns: ColumnModel<SignalData$1>[];
|
|
299
|
+
/** Walker: strategy-level summary columns */
|
|
300
|
+
walker_strategy_columns: ColumnModel<IStrategyResult>[];
|
|
301
|
+
};
|
|
302
|
+
/**
|
|
303
|
+
* Type for the column configuration object.
|
|
304
|
+
*/
|
|
305
|
+
type ColumnConfig = typeof COLUMN_CONFIG;
|
|
158
306
|
|
|
159
307
|
/**
|
|
160
308
|
* Interface representing a logging mechanism for the swarm system.
|
|
@@ -185,29 +333,243 @@ interface ILogger {
|
|
|
185
333
|
}
|
|
186
334
|
|
|
187
335
|
/**
|
|
188
|
-
*
|
|
336
|
+
* Sets custom logger implementation for the framework.
|
|
337
|
+
*
|
|
338
|
+
* All log messages from internal services will be forwarded to the provided logger
|
|
339
|
+
* with automatic context injection (strategyName, exchangeName, symbol, etc.).
|
|
340
|
+
*
|
|
341
|
+
* @param logger - Custom logger implementing ILogger interface
|
|
342
|
+
*
|
|
343
|
+
* @example
|
|
344
|
+
* ```typescript
|
|
345
|
+
* setLogger({
|
|
346
|
+
* log: (topic, ...args) => console.log(topic, args),
|
|
347
|
+
* debug: (topic, ...args) => console.debug(topic, args),
|
|
348
|
+
* info: (topic, ...args) => console.info(topic, args),
|
|
349
|
+
* });
|
|
350
|
+
* ```
|
|
189
351
|
*/
|
|
190
|
-
|
|
352
|
+
declare function setLogger(logger: ILogger): void;
|
|
191
353
|
/**
|
|
192
|
-
*
|
|
193
|
-
*
|
|
354
|
+
* Sets global configuration parameters for the framework.
|
|
355
|
+
* @param config - Partial configuration object to override default settings
|
|
356
|
+
* @param _unsafe - Skip config validations - required for testbed
|
|
357
|
+
*
|
|
358
|
+
* @example
|
|
359
|
+
* ```typescript
|
|
360
|
+
* setConfig({
|
|
361
|
+
* CC_SCHEDULE_AWAIT_MINUTES: 90,
|
|
362
|
+
* });
|
|
363
|
+
* ```
|
|
194
364
|
*/
|
|
195
|
-
|
|
196
|
-
/** Unix timestamp in milliseconds when candle opened */
|
|
197
|
-
timestamp: number;
|
|
198
|
-
/** Opening price at candle start */
|
|
199
|
-
open: number;
|
|
200
|
-
/** Highest price during candle period */
|
|
201
|
-
high: number;
|
|
202
|
-
/** Lowest price during candle period */
|
|
203
|
-
low: number;
|
|
204
|
-
/** Closing price at candle end */
|
|
205
|
-
close: number;
|
|
206
|
-
/** Trading volume during candle period */
|
|
207
|
-
volume: number;
|
|
208
|
-
}
|
|
365
|
+
declare function setConfig(config: Partial<GlobalConfig>, _unsafe?: boolean): void;
|
|
209
366
|
/**
|
|
210
|
-
*
|
|
367
|
+
* Retrieves a copy of the current global configuration.
|
|
368
|
+
*
|
|
369
|
+
* Returns a shallow copy of the current GLOBAL_CONFIG to prevent accidental mutations.
|
|
370
|
+
* Use this to inspect the current configuration state without modifying it.
|
|
371
|
+
*
|
|
372
|
+
* @returns {GlobalConfig} A copy of the current global configuration object
|
|
373
|
+
*
|
|
374
|
+
* @example
|
|
375
|
+
* ```typescript
|
|
376
|
+
* const currentConfig = getConfig();
|
|
377
|
+
* console.log(currentConfig.CC_SCHEDULE_AWAIT_MINUTES);
|
|
378
|
+
* ```
|
|
379
|
+
*/
|
|
380
|
+
declare function getConfig(): {
|
|
381
|
+
CC_SCHEDULE_AWAIT_MINUTES: number;
|
|
382
|
+
CC_AVG_PRICE_CANDLES_COUNT: number;
|
|
383
|
+
CC_PERCENT_SLIPPAGE: number;
|
|
384
|
+
CC_PERCENT_FEE: number;
|
|
385
|
+
CC_MIN_TAKEPROFIT_DISTANCE_PERCENT: number;
|
|
386
|
+
CC_MIN_STOPLOSS_DISTANCE_PERCENT: number;
|
|
387
|
+
CC_MAX_STOPLOSS_DISTANCE_PERCENT: number;
|
|
388
|
+
CC_MAX_SIGNAL_LIFETIME_MINUTES: number;
|
|
389
|
+
CC_MAX_SIGNAL_GENERATION_SECONDS: number;
|
|
390
|
+
CC_GET_CANDLES_RETRY_COUNT: number;
|
|
391
|
+
CC_GET_CANDLES_RETRY_DELAY_MS: number;
|
|
392
|
+
CC_GET_CANDLES_PRICE_ANOMALY_THRESHOLD_FACTOR: number;
|
|
393
|
+
CC_GET_CANDLES_MIN_CANDLES_FOR_MEDIAN: number;
|
|
394
|
+
CC_REPORT_SHOW_SIGNAL_NOTE: boolean;
|
|
395
|
+
};
|
|
396
|
+
/**
|
|
397
|
+
* Retrieves the default configuration object for the framework.
|
|
398
|
+
*
|
|
399
|
+
* Returns a reference to the default configuration with all preset values.
|
|
400
|
+
* Use this to see what configuration options are available and their default values.
|
|
401
|
+
*
|
|
402
|
+
* @returns {GlobalConfig} The default configuration object
|
|
403
|
+
*
|
|
404
|
+
* @example
|
|
405
|
+
* ```typescript
|
|
406
|
+
* const defaultConfig = getDefaultConfig();
|
|
407
|
+
* console.log(defaultConfig.CC_SCHEDULE_AWAIT_MINUTES);
|
|
408
|
+
* ```
|
|
409
|
+
*/
|
|
410
|
+
declare function getDefaultConfig(): Readonly<{
|
|
411
|
+
CC_SCHEDULE_AWAIT_MINUTES: number;
|
|
412
|
+
CC_AVG_PRICE_CANDLES_COUNT: number;
|
|
413
|
+
CC_PERCENT_SLIPPAGE: number;
|
|
414
|
+
CC_PERCENT_FEE: number;
|
|
415
|
+
CC_MIN_TAKEPROFIT_DISTANCE_PERCENT: number;
|
|
416
|
+
CC_MIN_STOPLOSS_DISTANCE_PERCENT: number;
|
|
417
|
+
CC_MAX_STOPLOSS_DISTANCE_PERCENT: number;
|
|
418
|
+
CC_MAX_SIGNAL_LIFETIME_MINUTES: number;
|
|
419
|
+
CC_MAX_SIGNAL_GENERATION_SECONDS: number;
|
|
420
|
+
CC_GET_CANDLES_RETRY_COUNT: number;
|
|
421
|
+
CC_GET_CANDLES_RETRY_DELAY_MS: number;
|
|
422
|
+
CC_GET_CANDLES_PRICE_ANOMALY_THRESHOLD_FACTOR: number;
|
|
423
|
+
CC_GET_CANDLES_MIN_CANDLES_FOR_MEDIAN: number;
|
|
424
|
+
CC_REPORT_SHOW_SIGNAL_NOTE: boolean;
|
|
425
|
+
}>;
|
|
426
|
+
/**
|
|
427
|
+
* Sets custom column configurations for markdown report generation.
|
|
428
|
+
*
|
|
429
|
+
* Allows overriding default column definitions for any report type.
|
|
430
|
+
* All columns are validated before assignment to ensure structural correctness.
|
|
431
|
+
*
|
|
432
|
+
* @param columns - Partial column configuration object to override default column settings
|
|
433
|
+
* @param _unsafe - Skip column validations - required for testbed
|
|
434
|
+
*
|
|
435
|
+
* @example
|
|
436
|
+
* ```typescript
|
|
437
|
+
* setColumns({
|
|
438
|
+
* backtest_columns: [
|
|
439
|
+
* {
|
|
440
|
+
* key: "customId",
|
|
441
|
+
* label: "Custom ID",
|
|
442
|
+
* format: (data) => data.signal.id,
|
|
443
|
+
* isVisible: () => true
|
|
444
|
+
* }
|
|
445
|
+
* ],
|
|
446
|
+
* });
|
|
447
|
+
* ```
|
|
448
|
+
*
|
|
449
|
+
* @throws {Error} If column configuration is invalid
|
|
450
|
+
*/
|
|
451
|
+
declare function setColumns(columns: Partial<ColumnConfig>, _unsafe?: boolean): void;
|
|
452
|
+
/**
|
|
453
|
+
* Retrieves a copy of the current column configuration for markdown report generation.
|
|
454
|
+
*
|
|
455
|
+
* Returns a shallow copy of the current COLUMN_CONFIG to prevent accidental mutations.
|
|
456
|
+
* Use this to inspect the current column definitions without modifying them.
|
|
457
|
+
*
|
|
458
|
+
* @returns {ColumnConfig} A copy of the current column configuration object
|
|
459
|
+
*
|
|
460
|
+
* @example
|
|
461
|
+
* ```typescript
|
|
462
|
+
* const currentColumns = getColumns();
|
|
463
|
+
* console.log(currentColumns.backtest_columns.length);
|
|
464
|
+
* ```
|
|
465
|
+
*/
|
|
466
|
+
declare function getColumns(): {
|
|
467
|
+
backtest_columns: ColumnModel<IStrategyTickResultClosed>[];
|
|
468
|
+
heat_columns: ColumnModel<IHeatmapRow>[];
|
|
469
|
+
live_columns: ColumnModel<TickEvent>[];
|
|
470
|
+
partial_columns: ColumnModel<PartialEvent>[];
|
|
471
|
+
performance_columns: ColumnModel<MetricStats>[];
|
|
472
|
+
risk_columns: ColumnModel<RiskEvent>[];
|
|
473
|
+
schedule_columns: ColumnModel<ScheduledEvent>[];
|
|
474
|
+
walker_pnl_columns: ColumnModel<SignalData$1>[];
|
|
475
|
+
walker_strategy_columns: ColumnModel<IStrategyResult>[];
|
|
476
|
+
};
|
|
477
|
+
/**
|
|
478
|
+
* Retrieves the default column configuration object for markdown report generation.
|
|
479
|
+
*
|
|
480
|
+
* Returns a reference to the default column definitions with all preset values.
|
|
481
|
+
* Use this to see what column options are available and their default definitions.
|
|
482
|
+
*
|
|
483
|
+
* @returns {ColumnConfig} The default column configuration object
|
|
484
|
+
*
|
|
485
|
+
* @example
|
|
486
|
+
* ```typescript
|
|
487
|
+
* const defaultColumns = getDefaultColumns();
|
|
488
|
+
* console.log(defaultColumns.backtest_columns);
|
|
489
|
+
* ```
|
|
490
|
+
*/
|
|
491
|
+
declare function getDefaultColumns(): Readonly<{
|
|
492
|
+
backtest_columns: ColumnModel<IStrategyTickResultClosed>[];
|
|
493
|
+
heat_columns: ColumnModel<IHeatmapRow>[];
|
|
494
|
+
live_columns: ColumnModel<TickEvent>[];
|
|
495
|
+
partial_columns: ColumnModel<PartialEvent>[];
|
|
496
|
+
performance_columns: ColumnModel<MetricStats>[];
|
|
497
|
+
risk_columns: ColumnModel<RiskEvent>[];
|
|
498
|
+
schedule_columns: ColumnModel<ScheduledEvent>[];
|
|
499
|
+
walker_pnl_columns: ColumnModel<SignalData$1>[];
|
|
500
|
+
walker_strategy_columns: ColumnModel<IStrategyResult>[];
|
|
501
|
+
}>;
|
|
502
|
+
|
|
503
|
+
/**
|
|
504
|
+
* Execution context containing runtime parameters for strategy/exchange operations.
|
|
505
|
+
*
|
|
506
|
+
* Propagated through ExecutionContextService to provide implicit context
|
|
507
|
+
* for getCandles(), tick(), backtest() and other operations.
|
|
508
|
+
*/
|
|
509
|
+
interface IExecutionContext {
|
|
510
|
+
/** Trading pair symbol (e.g., "BTCUSDT") */
|
|
511
|
+
symbol: string;
|
|
512
|
+
/** Current timestamp for operation */
|
|
513
|
+
when: Date;
|
|
514
|
+
/** Whether running in backtest mode (true) or live mode (false) */
|
|
515
|
+
backtest: boolean;
|
|
516
|
+
}
|
|
517
|
+
/**
|
|
518
|
+
* Scoped service for execution context propagation.
|
|
519
|
+
*
|
|
520
|
+
* Uses di-scoped for implicit context passing without explicit parameters.
|
|
521
|
+
* Context includes symbol, when (timestamp), and backtest flag.
|
|
522
|
+
*
|
|
523
|
+
* Used by GlobalServices to inject context into operations.
|
|
524
|
+
*
|
|
525
|
+
* @example
|
|
526
|
+
* ```typescript
|
|
527
|
+
* ExecutionContextService.runInContext(
|
|
528
|
+
* async () => {
|
|
529
|
+
* // Inside this callback, context is automatically available
|
|
530
|
+
* return await someOperation();
|
|
531
|
+
* },
|
|
532
|
+
* { symbol: "BTCUSDT", when: new Date(), backtest: true }
|
|
533
|
+
* );
|
|
534
|
+
* ```
|
|
535
|
+
*/
|
|
536
|
+
declare const ExecutionContextService: (new () => {
|
|
537
|
+
readonly context: IExecutionContext;
|
|
538
|
+
}) & Omit<{
|
|
539
|
+
new (context: IExecutionContext): {
|
|
540
|
+
readonly context: IExecutionContext;
|
|
541
|
+
};
|
|
542
|
+
}, "prototype"> & di_scoped.IScopedClassRun<[context: IExecutionContext]>;
|
|
543
|
+
/**
|
|
544
|
+
* Type helper for ExecutionContextService instance.
|
|
545
|
+
* Used for dependency injection type annotations.
|
|
546
|
+
*/
|
|
547
|
+
type TExecutionContextService = InstanceType<typeof ExecutionContextService>;
|
|
548
|
+
|
|
549
|
+
/**
|
|
550
|
+
* Candle time interval for fetching historical data.
|
|
551
|
+
*/
|
|
552
|
+
type CandleInterval = "1m" | "3m" | "5m" | "15m" | "30m" | "1h" | "2h" | "4h" | "6h" | "8h";
|
|
553
|
+
/**
|
|
554
|
+
* Single OHLCV candle data point.
|
|
555
|
+
* Used for VWAP calculation and backtesting.
|
|
556
|
+
*/
|
|
557
|
+
interface ICandleData {
|
|
558
|
+
/** Unix timestamp in milliseconds when candle opened */
|
|
559
|
+
timestamp: number;
|
|
560
|
+
/** Opening price at candle start */
|
|
561
|
+
open: number;
|
|
562
|
+
/** Highest price during candle period */
|
|
563
|
+
high: number;
|
|
564
|
+
/** Lowest price during candle period */
|
|
565
|
+
low: number;
|
|
566
|
+
/** Closing price at candle end */
|
|
567
|
+
close: number;
|
|
568
|
+
/** Trading volume during candle period */
|
|
569
|
+
volume: number;
|
|
570
|
+
}
|
|
571
|
+
/**
|
|
572
|
+
* Exchange parameters passed to ClientExchange constructor.
|
|
211
573
|
* Combines schema with runtime dependencies.
|
|
212
574
|
*/
|
|
213
575
|
interface IExchangeParams extends IExchangeSchema {
|
|
@@ -462,6 +824,8 @@ interface IRiskCheckArgs {
|
|
|
462
824
|
strategyName: StrategyName;
|
|
463
825
|
/** Exchange name */
|
|
464
826
|
exchangeName: ExchangeName;
|
|
827
|
+
/** Frame name */
|
|
828
|
+
frameName: string;
|
|
465
829
|
/** Current VWAP price */
|
|
466
830
|
currentPrice: number;
|
|
467
831
|
/** Current timestamp */
|
|
@@ -471,8 +835,6 @@ interface IRiskCheckArgs {
|
|
|
471
835
|
* Active position tracked by ClientRisk for cross-strategy analysis.
|
|
472
836
|
*/
|
|
473
837
|
interface IRiskActivePosition {
|
|
474
|
-
/** Signal details for the active position */
|
|
475
|
-
signal: ISignalRow;
|
|
476
838
|
/** Strategy name owning the position */
|
|
477
839
|
strategyName: string;
|
|
478
840
|
/** Exchange name */
|
|
@@ -587,21 +949,25 @@ interface IRisk {
|
|
|
587
949
|
* Register a new opened signal/position.
|
|
588
950
|
*
|
|
589
951
|
* @param symbol - Trading pair symbol
|
|
590
|
-
* @param context - Context information (strategyName, riskName)
|
|
952
|
+
* @param context - Context information (strategyName, riskName, exchangeName, frameName)
|
|
591
953
|
*/
|
|
592
954
|
addSignal: (symbol: string, context: {
|
|
593
955
|
strategyName: string;
|
|
594
956
|
riskName: string;
|
|
957
|
+
exchangeName: string;
|
|
958
|
+
frameName: string;
|
|
595
959
|
}) => Promise<void>;
|
|
596
960
|
/**
|
|
597
961
|
* Remove a closed signal/position.
|
|
598
962
|
*
|
|
599
963
|
* @param symbol - Trading pair symbol
|
|
600
|
-
* @param context - Context information (strategyName, riskName)
|
|
964
|
+
* @param context - Context information (strategyName, riskName, exchangeName, frameName)
|
|
601
965
|
*/
|
|
602
966
|
removeSignal: (symbol: string, context: {
|
|
603
967
|
strategyName: string;
|
|
604
968
|
riskName: string;
|
|
969
|
+
exchangeName: string;
|
|
970
|
+
frameName: string;
|
|
605
971
|
}) => Promise<void>;
|
|
606
972
|
}
|
|
607
973
|
/**
|
|
@@ -803,6 +1169,8 @@ interface ISignalRow extends ISignalDto {
|
|
|
803
1169
|
exchangeName: ExchangeName;
|
|
804
1170
|
/** Unique strategy identifier for execution */
|
|
805
1171
|
strategyName: StrategyName;
|
|
1172
|
+
/** Unique frame identifier for execution (empty string for live mode) */
|
|
1173
|
+
frameName: FrameName;
|
|
806
1174
|
/** Signal creation timestamp in milliseconds (when signal was first created/scheduled) */
|
|
807
1175
|
scheduledAt: number;
|
|
808
1176
|
/** Pending timestamp in milliseconds (when position became pending/active at priceOpen) */
|
|
@@ -916,6 +1284,8 @@ interface IStrategyTickResultIdle {
|
|
|
916
1284
|
strategyName: StrategyName;
|
|
917
1285
|
/** Exchange name for tracking idle events */
|
|
918
1286
|
exchangeName: ExchangeName;
|
|
1287
|
+
/** Time frame name for tracking (e.g., "1m", "5m") */
|
|
1288
|
+
frameName: FrameName;
|
|
919
1289
|
/** Trading pair symbol (e.g., "BTCUSDT") */
|
|
920
1290
|
symbol: string;
|
|
921
1291
|
/** Current VWAP price during idle state */
|
|
@@ -936,6 +1306,8 @@ interface IStrategyTickResultScheduled {
|
|
|
936
1306
|
strategyName: StrategyName;
|
|
937
1307
|
/** Exchange name for tracking */
|
|
938
1308
|
exchangeName: ExchangeName;
|
|
1309
|
+
/** Time frame name for tracking (e.g., "1m", "5m") */
|
|
1310
|
+
frameName: FrameName;
|
|
939
1311
|
/** Trading pair symbol (e.g., "BTCUSDT") */
|
|
940
1312
|
symbol: string;
|
|
941
1313
|
/** Current VWAP price when scheduled signal created */
|
|
@@ -956,6 +1328,8 @@ interface IStrategyTickResultOpened {
|
|
|
956
1328
|
strategyName: StrategyName;
|
|
957
1329
|
/** Exchange name for tracking */
|
|
958
1330
|
exchangeName: ExchangeName;
|
|
1331
|
+
/** Time frame name for tracking (e.g., "1m", "5m") */
|
|
1332
|
+
frameName: FrameName;
|
|
959
1333
|
/** Trading pair symbol (e.g., "BTCUSDT") */
|
|
960
1334
|
symbol: string;
|
|
961
1335
|
/** Current VWAP price at signal open */
|
|
@@ -978,6 +1352,8 @@ interface IStrategyTickResultActive {
|
|
|
978
1352
|
strategyName: StrategyName;
|
|
979
1353
|
/** Exchange name for tracking */
|
|
980
1354
|
exchangeName: ExchangeName;
|
|
1355
|
+
/** Time frame name for tracking (e.g., "1m", "5m") */
|
|
1356
|
+
frameName: FrameName;
|
|
981
1357
|
/** Trading pair symbol (e.g., "BTCUSDT") */
|
|
982
1358
|
symbol: string;
|
|
983
1359
|
/** Percentage progress towards take profit (0-100%, 0 if moving towards SL) */
|
|
@@ -1008,6 +1384,8 @@ interface IStrategyTickResultClosed {
|
|
|
1008
1384
|
strategyName: StrategyName;
|
|
1009
1385
|
/** Exchange name for tracking */
|
|
1010
1386
|
exchangeName: ExchangeName;
|
|
1387
|
+
/** Time frame name for tracking (e.g., "1m", "5m") */
|
|
1388
|
+
frameName: FrameName;
|
|
1011
1389
|
/** Trading pair symbol (e.g., "BTCUSDT") */
|
|
1012
1390
|
symbol: string;
|
|
1013
1391
|
/** Whether this event is from backtest mode (true) or live mode (false) */
|
|
@@ -1030,6 +1408,8 @@ interface IStrategyTickResultCancelled {
|
|
|
1030
1408
|
strategyName: StrategyName;
|
|
1031
1409
|
/** Exchange name for tracking */
|
|
1032
1410
|
exchangeName: ExchangeName;
|
|
1411
|
+
/** Time frame name for tracking (e.g., "1m", "5m") */
|
|
1412
|
+
frameName: FrameName;
|
|
1033
1413
|
/** Trading pair symbol (e.g., "BTCUSDT") */
|
|
1034
1414
|
symbol: string;
|
|
1035
1415
|
/** Whether this event is from backtest mode (true) or live mode (false) */
|
|
@@ -1038,382 +1418,20 @@ interface IStrategyTickResultCancelled {
|
|
|
1038
1418
|
reason: StrategyCancelReason;
|
|
1039
1419
|
/** Optional cancellation ID (provided when user calls Backtest.cancel() or Live.cancel()) */
|
|
1040
1420
|
cancelId?: string;
|
|
1041
|
-
}
|
|
1042
|
-
/**
|
|
1043
|
-
* Discriminated union of all tick results.
|
|
1044
|
-
* Use type guards: `result.action === "closed"` for type safety.
|
|
1045
|
-
*/
|
|
1046
|
-
type IStrategyTickResult = IStrategyTickResultIdle | IStrategyTickResultScheduled | IStrategyTickResultOpened | IStrategyTickResultActive | IStrategyTickResultClosed | IStrategyTickResultCancelled;
|
|
1047
|
-
/**
|
|
1048
|
-
* Backtest returns closed result (TP/SL or time_expired) or cancelled result (scheduled signal never activated).
|
|
1049
|
-
*/
|
|
1050
|
-
type IStrategyBacktestResult = IStrategyTickResultClosed | IStrategyTickResultCancelled;
|
|
1051
|
-
/**
|
|
1052
|
-
* Unique strategy identifier.
|
|
1053
|
-
*/
|
|
1054
|
-
type StrategyName = string;
|
|
1055
|
-
|
|
1056
|
-
/**
|
|
1057
|
-
* Stops the strategy from generating new signals.
|
|
1058
|
-
*
|
|
1059
|
-
* Sets internal flag to prevent strategy from opening new signals.
|
|
1060
|
-
* Current active signal (if any) will complete normally.
|
|
1061
|
-
* Backtest/Live mode will stop at the next safe point (idle state or after signal closes).
|
|
1062
|
-
*
|
|
1063
|
-
* Automatically detects backtest/live mode from execution context.
|
|
1064
|
-
*
|
|
1065
|
-
* @param symbol - Trading pair symbol
|
|
1066
|
-
* @param strategyName - Strategy name to stop
|
|
1067
|
-
* @returns Promise that resolves when stop flag is set
|
|
1068
|
-
*
|
|
1069
|
-
* @example
|
|
1070
|
-
* ```typescript
|
|
1071
|
-
* import { stop } from "backtest-kit";
|
|
1072
|
-
*
|
|
1073
|
-
* // Stop strategy after some condition
|
|
1074
|
-
* await stop("BTCUSDT", "my-strategy");
|
|
1075
|
-
* ```
|
|
1076
|
-
*/
|
|
1077
|
-
declare function stop(symbol: string, strategyName: StrategyName): Promise<void>;
|
|
1078
|
-
/**
|
|
1079
|
-
* Cancels the scheduled signal without stopping the strategy.
|
|
1080
|
-
*
|
|
1081
|
-
* Clears the scheduled signal (waiting for priceOpen activation).
|
|
1082
|
-
* Does NOT affect active pending signals or strategy operation.
|
|
1083
|
-
* Does NOT set stop flag - strategy can continue generating new signals.
|
|
1084
|
-
*
|
|
1085
|
-
* Automatically detects backtest/live mode from execution context.
|
|
1086
|
-
*
|
|
1087
|
-
* @param symbol - Trading pair symbol
|
|
1088
|
-
* @param strategyName - Strategy name
|
|
1089
|
-
* @param cancelId - Optional cancellation ID for tracking user-initiated cancellations
|
|
1090
|
-
* @returns Promise that resolves when scheduled signal is cancelled
|
|
1091
|
-
*
|
|
1092
|
-
* @example
|
|
1093
|
-
* ```typescript
|
|
1094
|
-
* import { cancel } from "backtest-kit";
|
|
1095
|
-
*
|
|
1096
|
-
* // Cancel scheduled signal with custom ID
|
|
1097
|
-
* await cancel("BTCUSDT", "my-strategy", "manual-cancel-001");
|
|
1098
|
-
* ```
|
|
1099
|
-
*/
|
|
1100
|
-
declare function cancel(symbol: string, strategyName: StrategyName, cancelId?: string): Promise<void>;
|
|
1101
|
-
|
|
1102
|
-
declare const GLOBAL_CONFIG: {
|
|
1103
|
-
/**
|
|
1104
|
-
* Time to wait for scheduled signal to activate (in minutes)
|
|
1105
|
-
* If signal does not activate within this time, it will be cancelled.
|
|
1106
|
-
*/
|
|
1107
|
-
CC_SCHEDULE_AWAIT_MINUTES: number;
|
|
1108
|
-
/**
|
|
1109
|
-
* Number of candles to use for average price calculation (VWAP)
|
|
1110
|
-
* Default: 5 candles (last 5 minutes when using 1m interval)
|
|
1111
|
-
*/
|
|
1112
|
-
CC_AVG_PRICE_CANDLES_COUNT: number;
|
|
1113
|
-
/**
|
|
1114
|
-
* Slippage percentage applied to entry and exit prices.
|
|
1115
|
-
* Simulates market impact and order book depth.
|
|
1116
|
-
* Applied twice (entry and exit) for realistic execution simulation.
|
|
1117
|
-
* Default: 0.1% per transaction
|
|
1118
|
-
*/
|
|
1119
|
-
CC_PERCENT_SLIPPAGE: number;
|
|
1120
|
-
/**
|
|
1121
|
-
* Fee percentage charged per transaction.
|
|
1122
|
-
* Applied twice (entry and exit) for total fee calculation.
|
|
1123
|
-
* Default: 0.1% per transaction (total 0.2%)
|
|
1124
|
-
*/
|
|
1125
|
-
CC_PERCENT_FEE: number;
|
|
1126
|
-
/**
|
|
1127
|
-
* Minimum TakeProfit distance from priceOpen (percentage)
|
|
1128
|
-
* Must be greater than (slippage + fees) to ensure profitable trades
|
|
1129
|
-
*
|
|
1130
|
-
* Calculation:
|
|
1131
|
-
* - Slippage effect: ~0.2% (0.1% × 2 transactions)
|
|
1132
|
-
* - Fees: 0.2% (0.1% × 2 transactions)
|
|
1133
|
-
* - Minimum profit buffer: 0.1%
|
|
1134
|
-
* - Total: 0.5%
|
|
1135
|
-
*
|
|
1136
|
-
* Default: 0.5% (covers all costs + minimum profit margin)
|
|
1137
|
-
*/
|
|
1138
|
-
CC_MIN_TAKEPROFIT_DISTANCE_PERCENT: number;
|
|
1139
|
-
/**
|
|
1140
|
-
* Minimum StopLoss distance from priceOpen (percentage)
|
|
1141
|
-
* Prevents signals from being immediately stopped out due to price volatility
|
|
1142
|
-
* Default: 0.5% (buffer to avoid instant stop loss on normal market fluctuations)
|
|
1143
|
-
*/
|
|
1144
|
-
CC_MIN_STOPLOSS_DISTANCE_PERCENT: number;
|
|
1145
|
-
/**
|
|
1146
|
-
* Maximum StopLoss distance from priceOpen (percentage)
|
|
1147
|
-
* Prevents catastrophic losses from extreme StopLoss values
|
|
1148
|
-
* Default: 20% (one signal cannot lose more than 20% of position)
|
|
1149
|
-
*/
|
|
1150
|
-
CC_MAX_STOPLOSS_DISTANCE_PERCENT: number;
|
|
1151
|
-
/**
|
|
1152
|
-
* Maximum signal lifetime in minutes
|
|
1153
|
-
* Prevents eternal signals that block risk limits for weeks/months
|
|
1154
|
-
* Default: 1440 minutes (1 day)
|
|
1155
|
-
*/
|
|
1156
|
-
CC_MAX_SIGNAL_LIFETIME_MINUTES: number;
|
|
1157
|
-
/**
|
|
1158
|
-
* Maximum time allowed for signal generation (in seconds).
|
|
1159
|
-
* Prevents long-running or stuck signal generation routines from blocking
|
|
1160
|
-
* execution or consuming resources indefinitely. If generation exceeds this
|
|
1161
|
-
* threshold the attempt should be aborted, logged and optionally retried.
|
|
1162
|
-
*
|
|
1163
|
-
* Default: 180 seconds (3 minutes)
|
|
1164
|
-
*/
|
|
1165
|
-
CC_MAX_SIGNAL_GENERATION_SECONDS: number;
|
|
1166
|
-
/**
|
|
1167
|
-
* Number of retries for getCandles function
|
|
1168
|
-
* Default: 3 retries
|
|
1169
|
-
*/
|
|
1170
|
-
CC_GET_CANDLES_RETRY_COUNT: number;
|
|
1171
|
-
/**
|
|
1172
|
-
* Delay between retries for getCandles function (in milliseconds)
|
|
1173
|
-
* Default: 5000 ms (5 seconds)
|
|
1174
|
-
*/
|
|
1175
|
-
CC_GET_CANDLES_RETRY_DELAY_MS: number;
|
|
1176
|
-
/**
|
|
1177
|
-
* Maximum allowed deviation factor for price anomaly detection.
|
|
1178
|
-
* Price should not be more than this factor lower than reference price.
|
|
1179
|
-
*
|
|
1180
|
-
* Reasoning:
|
|
1181
|
-
* - Incomplete candles from Binance API typically have prices near 0 (e.g., $0.01-1)
|
|
1182
|
-
* - Normal BTC price ranges: $20,000-100,000
|
|
1183
|
-
* - Factor 1000 catches prices below $20-100 when median is $20,000-100,000
|
|
1184
|
-
* - Factor 100 would be too permissive (allows $200 when median is $20,000)
|
|
1185
|
-
* - Factor 10000 might be too strict for low-cap altcoins
|
|
1186
|
-
*
|
|
1187
|
-
* Example: BTC at $50,000 median → threshold $50 (catches $0.01-1 anomalies)
|
|
1188
|
-
*/
|
|
1189
|
-
CC_GET_CANDLES_PRICE_ANOMALY_THRESHOLD_FACTOR: number;
|
|
1190
|
-
/**
|
|
1191
|
-
* Minimum number of candles required for reliable median calculation.
|
|
1192
|
-
* Below this threshold, use simple average instead of median.
|
|
1193
|
-
*
|
|
1194
|
-
* Reasoning:
|
|
1195
|
-
* - Each candle provides 4 price points (OHLC)
|
|
1196
|
-
* - 5 candles = 20 price points, sufficient for robust median calculation
|
|
1197
|
-
* - Below 5 candles, single anomaly can heavily skew median
|
|
1198
|
-
* - Statistical rule of thumb: minimum 7-10 data points for median stability
|
|
1199
|
-
* - Average is more stable than median for small datasets (n < 20)
|
|
1200
|
-
*
|
|
1201
|
-
* Example: 3 candles = 12 points (use average), 5 candles = 20 points (use median)
|
|
1202
|
-
*/
|
|
1203
|
-
CC_GET_CANDLES_MIN_CANDLES_FOR_MEDIAN: number;
|
|
1204
|
-
/**
|
|
1205
|
-
* Controls visibility of signal notes in markdown report tables.
|
|
1206
|
-
* When enabled, the "Note" column will be displayed in all markdown reports
|
|
1207
|
-
* (backtest, live, schedule, risk, etc.)
|
|
1208
|
-
*
|
|
1209
|
-
* Default: false (notes are hidden to reduce table width and improve readability)
|
|
1210
|
-
*/
|
|
1211
|
-
CC_REPORT_SHOW_SIGNAL_NOTE: boolean;
|
|
1212
|
-
};
|
|
1213
|
-
/**
|
|
1214
|
-
* Type for global configuration object.
|
|
1215
|
-
*/
|
|
1216
|
-
type GlobalConfig = typeof GLOBAL_CONFIG;
|
|
1217
|
-
|
|
1218
|
-
/**
|
|
1219
|
-
* Mapping of available table/markdown reports to their column definitions.
|
|
1220
|
-
*
|
|
1221
|
-
* Each property references a column definition object imported from
|
|
1222
|
-
* `src/assets/*.columns`. These are used by markdown/report generators
|
|
1223
|
-
* (backtest, live, schedule, risk, heat, performance, partial, walker).
|
|
1224
|
-
*/
|
|
1225
|
-
declare const COLUMN_CONFIG: {
|
|
1226
|
-
/** Columns used in backtest markdown tables and reports */
|
|
1227
|
-
backtest_columns: ColumnModel<IStrategyTickResultClosed>[];
|
|
1228
|
-
/** Columns used by heatmap / heat reports */
|
|
1229
|
-
heat_columns: ColumnModel<IHeatmapRow>[];
|
|
1230
|
-
/** Columns for live trading reports and logs */
|
|
1231
|
-
live_columns: ColumnModel<TickEvent>[];
|
|
1232
|
-
/** Columns for partial-results / incremental reports */
|
|
1233
|
-
partial_columns: ColumnModel<PartialEvent>[];
|
|
1234
|
-
/** Columns for performance summary reports */
|
|
1235
|
-
performance_columns: ColumnModel<MetricStats>[];
|
|
1236
|
-
/** Columns for risk-related reports */
|
|
1237
|
-
risk_columns: ColumnModel<RiskEvent>[];
|
|
1238
|
-
/** Columns for scheduled report output */
|
|
1239
|
-
schedule_columns: ColumnModel<ScheduledEvent>[];
|
|
1240
|
-
/** Walker: PnL summary columns */
|
|
1241
|
-
walker_pnl_columns: ColumnModel<SignalData$1>[];
|
|
1242
|
-
/** Walker: strategy-level summary columns */
|
|
1243
|
-
walker_strategy_columns: ColumnModel<IStrategyResult>[];
|
|
1244
|
-
};
|
|
1245
|
-
/**
|
|
1246
|
-
* Type for the column configuration object.
|
|
1247
|
-
*/
|
|
1248
|
-
type ColumnConfig = typeof COLUMN_CONFIG;
|
|
1249
|
-
|
|
1250
|
-
/**
|
|
1251
|
-
* Sets custom logger implementation for the framework.
|
|
1252
|
-
*
|
|
1253
|
-
* All log messages from internal services will be forwarded to the provided logger
|
|
1254
|
-
* with automatic context injection (strategyName, exchangeName, symbol, etc.).
|
|
1255
|
-
*
|
|
1256
|
-
* @param logger - Custom logger implementing ILogger interface
|
|
1257
|
-
*
|
|
1258
|
-
* @example
|
|
1259
|
-
* ```typescript
|
|
1260
|
-
* setLogger({
|
|
1261
|
-
* log: (topic, ...args) => console.log(topic, args),
|
|
1262
|
-
* debug: (topic, ...args) => console.debug(topic, args),
|
|
1263
|
-
* info: (topic, ...args) => console.info(topic, args),
|
|
1264
|
-
* });
|
|
1265
|
-
* ```
|
|
1266
|
-
*/
|
|
1267
|
-
declare function setLogger(logger: ILogger): void;
|
|
1268
|
-
/**
|
|
1269
|
-
* Sets global configuration parameters for the framework.
|
|
1270
|
-
* @param config - Partial configuration object to override default settings
|
|
1271
|
-
* @param _unsafe - Skip config validations - required for testbed
|
|
1272
|
-
*
|
|
1273
|
-
* @example
|
|
1274
|
-
* ```typescript
|
|
1275
|
-
* setConfig({
|
|
1276
|
-
* CC_SCHEDULE_AWAIT_MINUTES: 90,
|
|
1277
|
-
* });
|
|
1278
|
-
* ```
|
|
1279
|
-
*/
|
|
1280
|
-
declare function setConfig(config: Partial<GlobalConfig>, _unsafe?: boolean): void;
|
|
1281
|
-
/**
|
|
1282
|
-
* Retrieves a copy of the current global configuration.
|
|
1283
|
-
*
|
|
1284
|
-
* Returns a shallow copy of the current GLOBAL_CONFIG to prevent accidental mutations.
|
|
1285
|
-
* Use this to inspect the current configuration state without modifying it.
|
|
1286
|
-
*
|
|
1287
|
-
* @returns {GlobalConfig} A copy of the current global configuration object
|
|
1288
|
-
*
|
|
1289
|
-
* @example
|
|
1290
|
-
* ```typescript
|
|
1291
|
-
* const currentConfig = getConfig();
|
|
1292
|
-
* console.log(currentConfig.CC_SCHEDULE_AWAIT_MINUTES);
|
|
1293
|
-
* ```
|
|
1294
|
-
*/
|
|
1295
|
-
declare function getConfig(): {
|
|
1296
|
-
CC_SCHEDULE_AWAIT_MINUTES: number;
|
|
1297
|
-
CC_AVG_PRICE_CANDLES_COUNT: number;
|
|
1298
|
-
CC_PERCENT_SLIPPAGE: number;
|
|
1299
|
-
CC_PERCENT_FEE: number;
|
|
1300
|
-
CC_MIN_TAKEPROFIT_DISTANCE_PERCENT: number;
|
|
1301
|
-
CC_MIN_STOPLOSS_DISTANCE_PERCENT: number;
|
|
1302
|
-
CC_MAX_STOPLOSS_DISTANCE_PERCENT: number;
|
|
1303
|
-
CC_MAX_SIGNAL_LIFETIME_MINUTES: number;
|
|
1304
|
-
CC_MAX_SIGNAL_GENERATION_SECONDS: number;
|
|
1305
|
-
CC_GET_CANDLES_RETRY_COUNT: number;
|
|
1306
|
-
CC_GET_CANDLES_RETRY_DELAY_MS: number;
|
|
1307
|
-
CC_GET_CANDLES_PRICE_ANOMALY_THRESHOLD_FACTOR: number;
|
|
1308
|
-
CC_GET_CANDLES_MIN_CANDLES_FOR_MEDIAN: number;
|
|
1309
|
-
CC_REPORT_SHOW_SIGNAL_NOTE: boolean;
|
|
1310
|
-
};
|
|
1311
|
-
/**
|
|
1312
|
-
* Retrieves the default configuration object for the framework.
|
|
1313
|
-
*
|
|
1314
|
-
* Returns a reference to the default configuration with all preset values.
|
|
1315
|
-
* Use this to see what configuration options are available and their default values.
|
|
1316
|
-
*
|
|
1317
|
-
* @returns {GlobalConfig} The default configuration object
|
|
1318
|
-
*
|
|
1319
|
-
* @example
|
|
1320
|
-
* ```typescript
|
|
1321
|
-
* const defaultConfig = getDefaultConfig();
|
|
1322
|
-
* console.log(defaultConfig.CC_SCHEDULE_AWAIT_MINUTES);
|
|
1323
|
-
* ```
|
|
1324
|
-
*/
|
|
1325
|
-
declare function getDefaultConfig(): Readonly<{
|
|
1326
|
-
CC_SCHEDULE_AWAIT_MINUTES: number;
|
|
1327
|
-
CC_AVG_PRICE_CANDLES_COUNT: number;
|
|
1328
|
-
CC_PERCENT_SLIPPAGE: number;
|
|
1329
|
-
CC_PERCENT_FEE: number;
|
|
1330
|
-
CC_MIN_TAKEPROFIT_DISTANCE_PERCENT: number;
|
|
1331
|
-
CC_MIN_STOPLOSS_DISTANCE_PERCENT: number;
|
|
1332
|
-
CC_MAX_STOPLOSS_DISTANCE_PERCENT: number;
|
|
1333
|
-
CC_MAX_SIGNAL_LIFETIME_MINUTES: number;
|
|
1334
|
-
CC_MAX_SIGNAL_GENERATION_SECONDS: number;
|
|
1335
|
-
CC_GET_CANDLES_RETRY_COUNT: number;
|
|
1336
|
-
CC_GET_CANDLES_RETRY_DELAY_MS: number;
|
|
1337
|
-
CC_GET_CANDLES_PRICE_ANOMALY_THRESHOLD_FACTOR: number;
|
|
1338
|
-
CC_GET_CANDLES_MIN_CANDLES_FOR_MEDIAN: number;
|
|
1339
|
-
CC_REPORT_SHOW_SIGNAL_NOTE: boolean;
|
|
1340
|
-
}>;
|
|
1341
|
-
/**
|
|
1342
|
-
* Sets custom column configurations for markdown report generation.
|
|
1343
|
-
*
|
|
1344
|
-
* Allows overriding default column definitions for any report type.
|
|
1345
|
-
* All columns are validated before assignment to ensure structural correctness.
|
|
1346
|
-
*
|
|
1347
|
-
* @param columns - Partial column configuration object to override default column settings
|
|
1348
|
-
* @param _unsafe - Skip column validations - required for testbed
|
|
1349
|
-
*
|
|
1350
|
-
* @example
|
|
1351
|
-
* ```typescript
|
|
1352
|
-
* setColumns({
|
|
1353
|
-
* backtest_columns: [
|
|
1354
|
-
* {
|
|
1355
|
-
* key: "customId",
|
|
1356
|
-
* label: "Custom ID",
|
|
1357
|
-
* format: (data) => data.signal.id,
|
|
1358
|
-
* isVisible: () => true
|
|
1359
|
-
* }
|
|
1360
|
-
* ],
|
|
1361
|
-
* });
|
|
1362
|
-
* ```
|
|
1363
|
-
*
|
|
1364
|
-
* @throws {Error} If column configuration is invalid
|
|
1365
|
-
*/
|
|
1366
|
-
declare function setColumns(columns: Partial<ColumnConfig>, _unsafe?: boolean): void;
|
|
1367
|
-
/**
|
|
1368
|
-
* Retrieves a copy of the current column configuration for markdown report generation.
|
|
1369
|
-
*
|
|
1370
|
-
* Returns a shallow copy of the current COLUMN_CONFIG to prevent accidental mutations.
|
|
1371
|
-
* Use this to inspect the current column definitions without modifying them.
|
|
1372
|
-
*
|
|
1373
|
-
* @returns {ColumnConfig} A copy of the current column configuration object
|
|
1374
|
-
*
|
|
1375
|
-
* @example
|
|
1376
|
-
* ```typescript
|
|
1377
|
-
* const currentColumns = getColumns();
|
|
1378
|
-
* console.log(currentColumns.backtest_columns.length);
|
|
1379
|
-
* ```
|
|
1380
|
-
*/
|
|
1381
|
-
declare function getColumns(): {
|
|
1382
|
-
backtest_columns: ColumnModel<IStrategyTickResultClosed>[];
|
|
1383
|
-
heat_columns: ColumnModel<IHeatmapRow>[];
|
|
1384
|
-
live_columns: ColumnModel<TickEvent>[];
|
|
1385
|
-
partial_columns: ColumnModel<PartialEvent>[];
|
|
1386
|
-
performance_columns: ColumnModel<MetricStats>[];
|
|
1387
|
-
risk_columns: ColumnModel<RiskEvent>[];
|
|
1388
|
-
schedule_columns: ColumnModel<ScheduledEvent>[];
|
|
1389
|
-
walker_pnl_columns: ColumnModel<SignalData$1>[];
|
|
1390
|
-
walker_strategy_columns: ColumnModel<IStrategyResult>[];
|
|
1391
|
-
};
|
|
1392
|
-
/**
|
|
1393
|
-
* Retrieves the default column configuration object for markdown report generation.
|
|
1394
|
-
*
|
|
1395
|
-
* Returns a reference to the default column definitions with all preset values.
|
|
1396
|
-
* Use this to see what column options are available and their default definitions.
|
|
1397
|
-
*
|
|
1398
|
-
* @returns {ColumnConfig} The default column configuration object
|
|
1399
|
-
*
|
|
1400
|
-
* @example
|
|
1401
|
-
* ```typescript
|
|
1402
|
-
* const defaultColumns = getDefaultColumns();
|
|
1403
|
-
* console.log(defaultColumns.backtest_columns);
|
|
1404
|
-
* ```
|
|
1421
|
+
}
|
|
1422
|
+
/**
|
|
1423
|
+
* Discriminated union of all tick results.
|
|
1424
|
+
* Use type guards: `result.action === "closed"` for type safety.
|
|
1405
1425
|
*/
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
walker_strategy_columns: ColumnModel<IStrategyResult>[];
|
|
1416
|
-
}>;
|
|
1426
|
+
type IStrategyTickResult = IStrategyTickResultIdle | IStrategyTickResultScheduled | IStrategyTickResultOpened | IStrategyTickResultActive | IStrategyTickResultClosed | IStrategyTickResultCancelled;
|
|
1427
|
+
/**
|
|
1428
|
+
* Backtest returns closed result (TP/SL or time_expired) or cancelled result (scheduled signal never activated).
|
|
1429
|
+
*/
|
|
1430
|
+
type IStrategyBacktestResult = IStrategyTickResultClosed | IStrategyTickResultCancelled;
|
|
1431
|
+
/**
|
|
1432
|
+
* Unique strategy identifier.
|
|
1433
|
+
*/
|
|
1434
|
+
type StrategyName = string;
|
|
1417
1435
|
|
|
1418
1436
|
/**
|
|
1419
1437
|
* Statistical data calculated from backtest results.
|
|
@@ -2908,6 +2926,8 @@ interface PerformanceContract {
|
|
|
2908
2926
|
strategyName: string;
|
|
2909
2927
|
/** Exchange name associated with this metric */
|
|
2910
2928
|
exchangeName: string;
|
|
2929
|
+
/** Frame name associated with this metric (empty string for live mode) */
|
|
2930
|
+
frameName: string;
|
|
2911
2931
|
/** Trading symbol associated with this metric */
|
|
2912
2932
|
symbol: string;
|
|
2913
2933
|
/** Whether this metric is from backtest mode (true) or live mode (false) */
|
|
@@ -2992,6 +3012,11 @@ interface PartialProfitContract {
|
|
|
2992
3012
|
* Identifies which exchange this profit event belongs to.
|
|
2993
3013
|
*/
|
|
2994
3014
|
exchangeName: string;
|
|
3015
|
+
/**
|
|
3016
|
+
* Frame name where this signal is being executed.
|
|
3017
|
+
* Identifies which frame this profit event belongs to (empty string for live mode).
|
|
3018
|
+
*/
|
|
3019
|
+
frameName: string;
|
|
2995
3020
|
/**
|
|
2996
3021
|
* Complete signal row data.
|
|
2997
3022
|
* Contains all signal information: id, position, priceOpen, priceTakeProfit, priceStopLoss, etc.
|
|
@@ -3087,6 +3112,11 @@ interface PartialLossContract {
|
|
|
3087
3112
|
* Identifies which exchange this loss event belongs to.
|
|
3088
3113
|
*/
|
|
3089
3114
|
exchangeName: string;
|
|
3115
|
+
/**
|
|
3116
|
+
* Frame name where this signal is being executed.
|
|
3117
|
+
* Identifies which frame this loss event belongs to (empty string for live mode).
|
|
3118
|
+
*/
|
|
3119
|
+
frameName: string;
|
|
3090
3120
|
/**
|
|
3091
3121
|
* Complete signal row data.
|
|
3092
3122
|
* Contains all signal information: id, position, priceOpen, priceTakeProfit, priceStopLoss, etc.
|
|
@@ -3189,6 +3219,11 @@ interface RiskContract {
|
|
|
3189
3219
|
* Identifies which strategy attempted to create the signal.
|
|
3190
3220
|
*/
|
|
3191
3221
|
strategyName: StrategyName;
|
|
3222
|
+
/**
|
|
3223
|
+
* Frame name used in backtest execution.
|
|
3224
|
+
* Identifies which frame this signal was for in backtest execution.
|
|
3225
|
+
*/
|
|
3226
|
+
frameName: FrameName;
|
|
3192
3227
|
/**
|
|
3193
3228
|
* Exchange name.
|
|
3194
3229
|
* Identifies which exchange this signal was for.
|
|
@@ -5002,6 +5037,8 @@ interface RiskEvent {
|
|
|
5002
5037
|
strategyName: string;
|
|
5003
5038
|
/** Exchange name */
|
|
5004
5039
|
exchangeName: string;
|
|
5040
|
+
/** Time frame name */
|
|
5041
|
+
frameName: string;
|
|
5005
5042
|
/** Current market price */
|
|
5006
5043
|
currentPrice: number;
|
|
5007
5044
|
/** Number of active positions at rejection time */
|
|
@@ -5552,8 +5589,8 @@ declare class BacktestMarkdownService {
|
|
|
5552
5589
|
/** Logger service for debug output */
|
|
5553
5590
|
private readonly loggerService;
|
|
5554
5591
|
/**
|
|
5555
|
-
* Memoized function to get or create ReportStorage for a symbol-strategy-backtest
|
|
5556
|
-
* Each
|
|
5592
|
+
* Memoized function to get or create ReportStorage for a symbol-strategy-exchange-frame-backtest combination.
|
|
5593
|
+
* Each combination gets its own isolated storage instance.
|
|
5557
5594
|
*/
|
|
5558
5595
|
private getStorage;
|
|
5559
5596
|
/**
|
|
@@ -5562,7 +5599,7 @@ declare class BacktestMarkdownService {
|
|
|
5562
5599
|
*
|
|
5563
5600
|
* Only processes closed signals - opened signals are ignored.
|
|
5564
5601
|
*
|
|
5565
|
-
* @param data - Tick result from strategy execution (opened or closed)
|
|
5602
|
+
* @param data - Tick result from strategy execution (opened or closed) with frameName wrapper
|
|
5566
5603
|
*
|
|
5567
5604
|
* @example
|
|
5568
5605
|
* ```typescript
|
|
@@ -5582,23 +5619,27 @@ declare class BacktestMarkdownService {
|
|
|
5582
5619
|
*
|
|
5583
5620
|
* @param symbol - Trading pair symbol
|
|
5584
5621
|
* @param strategyName - Strategy name to get data for
|
|
5622
|
+
* @param exchangeName - Exchange name
|
|
5623
|
+
* @param frameName - Frame name
|
|
5585
5624
|
* @param backtest - True if backtest mode, false if live mode
|
|
5586
5625
|
* @returns Statistical data object with all metrics
|
|
5587
5626
|
*
|
|
5588
5627
|
* @example
|
|
5589
5628
|
* ```typescript
|
|
5590
5629
|
* const service = new BacktestMarkdownService();
|
|
5591
|
-
* const stats = await service.getData("BTCUSDT", "my-strategy", true);
|
|
5630
|
+
* const stats = await service.getData("BTCUSDT", "my-strategy", "binance", "1h", true);
|
|
5592
5631
|
* console.log(stats.sharpeRatio, stats.winRate);
|
|
5593
5632
|
* ```
|
|
5594
5633
|
*/
|
|
5595
|
-
getData: (symbol: string, strategyName: StrategyName, backtest: boolean) => Promise<BacktestStatisticsModel>;
|
|
5634
|
+
getData: (symbol: string, strategyName: StrategyName, exchangeName: string, frameName: string, backtest: boolean) => Promise<BacktestStatisticsModel>;
|
|
5596
5635
|
/**
|
|
5597
5636
|
* Generates markdown report with all closed signals for a symbol-strategy pair.
|
|
5598
5637
|
* Delegates to ReportStorage.generateReport().
|
|
5599
5638
|
*
|
|
5600
5639
|
* @param symbol - Trading pair symbol
|
|
5601
5640
|
* @param strategyName - Strategy name to generate report for
|
|
5641
|
+
* @param exchangeName - Exchange name
|
|
5642
|
+
* @param frameName - Frame name
|
|
5602
5643
|
* @param backtest - True if backtest mode, false if live mode
|
|
5603
5644
|
* @param columns - Column configuration for formatting the table
|
|
5604
5645
|
* @returns Markdown formatted report string with table of all closed signals
|
|
@@ -5606,11 +5647,11 @@ declare class BacktestMarkdownService {
|
|
|
5606
5647
|
* @example
|
|
5607
5648
|
* ```typescript
|
|
5608
5649
|
* const service = new BacktestMarkdownService();
|
|
5609
|
-
* const markdown = await service.getReport("BTCUSDT", "my-strategy", true);
|
|
5650
|
+
* const markdown = await service.getReport("BTCUSDT", "my-strategy", "binance", "1h", true);
|
|
5610
5651
|
* console.log(markdown);
|
|
5611
5652
|
* ```
|
|
5612
5653
|
*/
|
|
5613
|
-
getReport: (symbol: string, strategyName: StrategyName, backtest: boolean, columns?: Columns$6[]) => Promise<string>;
|
|
5654
|
+
getReport: (symbol: string, strategyName: StrategyName, exchangeName: string, frameName: string, backtest: boolean, columns?: Columns$6[]) => Promise<string>;
|
|
5614
5655
|
/**
|
|
5615
5656
|
* Saves symbol-strategy report to disk.
|
|
5616
5657
|
* Creates directory if it doesn't exist.
|
|
@@ -5618,6 +5659,8 @@ declare class BacktestMarkdownService {
|
|
|
5618
5659
|
*
|
|
5619
5660
|
* @param symbol - Trading pair symbol
|
|
5620
5661
|
* @param strategyName - Strategy name to save report for
|
|
5662
|
+
* @param exchangeName - Exchange name
|
|
5663
|
+
* @param frameName - Frame name
|
|
5621
5664
|
* @param backtest - True if backtest mode, false if live mode
|
|
5622
5665
|
* @param path - Directory path to save report (default: "./dump/backtest")
|
|
5623
5666
|
* @param columns - Column configuration for formatting the table
|
|
@@ -5627,35 +5670,37 @@ declare class BacktestMarkdownService {
|
|
|
5627
5670
|
* const service = new BacktestMarkdownService();
|
|
5628
5671
|
*
|
|
5629
5672
|
* // Save to default path: ./dump/backtest/my-strategy.md
|
|
5630
|
-
* await service.dump("BTCUSDT", "my-strategy", true);
|
|
5673
|
+
* await service.dump("BTCUSDT", "my-strategy", "binance", "1h", true);
|
|
5631
5674
|
*
|
|
5632
5675
|
* // Save to custom path: ./custom/path/my-strategy.md
|
|
5633
|
-
* await service.dump("BTCUSDT", "my-strategy", true, "./custom/path");
|
|
5676
|
+
* await service.dump("BTCUSDT", "my-strategy", "binance", "1h", true, "./custom/path");
|
|
5634
5677
|
* ```
|
|
5635
5678
|
*/
|
|
5636
|
-
dump: (symbol: string, strategyName: StrategyName, backtest: boolean, path?: string, columns?: Columns$6[]) => Promise<void>;
|
|
5679
|
+
dump: (symbol: string, strategyName: StrategyName, exchangeName: string, frameName: string, backtest: boolean, path?: string, columns?: Columns$6[]) => Promise<void>;
|
|
5637
5680
|
/**
|
|
5638
5681
|
* Clears accumulated signal data from storage.
|
|
5639
|
-
* If
|
|
5682
|
+
* If payload is provided, clears only that specific symbol-strategy-exchange-frame-backtest combination's data.
|
|
5640
5683
|
* If nothing is provided, clears all data.
|
|
5641
5684
|
*
|
|
5642
|
-
* @param
|
|
5643
|
-
* @param ctx - Optional context with symbol and strategyName
|
|
5685
|
+
* @param payload - Optional payload with symbol, strategyName, exchangeName, frameName, backtest
|
|
5644
5686
|
*
|
|
5645
5687
|
* @example
|
|
5646
5688
|
* ```typescript
|
|
5647
5689
|
* const service = new BacktestMarkdownService();
|
|
5648
5690
|
*
|
|
5649
|
-
* // Clear specific
|
|
5650
|
-
* await service.clear(
|
|
5691
|
+
* // Clear specific combination
|
|
5692
|
+
* await service.clear({ symbol: "BTCUSDT", strategyName: "my-strategy", exchangeName: "binance", frameName: "1h", backtest: true });
|
|
5651
5693
|
*
|
|
5652
5694
|
* // Clear all data
|
|
5653
5695
|
* await service.clear();
|
|
5654
5696
|
* ```
|
|
5655
5697
|
*/
|
|
5656
|
-
clear: (
|
|
5698
|
+
clear: (payload?: {
|
|
5657
5699
|
symbol: string;
|
|
5658
5700
|
strategyName: StrategyName;
|
|
5701
|
+
exchangeName: string;
|
|
5702
|
+
frameName: string;
|
|
5703
|
+
backtest: boolean;
|
|
5659
5704
|
}) => Promise<void>;
|
|
5660
5705
|
/**
|
|
5661
5706
|
* Initializes the service by subscribing to backtest signal events.
|
|
@@ -5750,7 +5795,11 @@ declare class BacktestUtils {
|
|
|
5750
5795
|
* }
|
|
5751
5796
|
* ```
|
|
5752
5797
|
*/
|
|
5753
|
-
getPendingSignal: (symbol: string,
|
|
5798
|
+
getPendingSignal: (symbol: string, context: {
|
|
5799
|
+
strategyName: string;
|
|
5800
|
+
exchangeName: string;
|
|
5801
|
+
frameName: string;
|
|
5802
|
+
}) => Promise<ISignalRow>;
|
|
5754
5803
|
/**
|
|
5755
5804
|
* Retrieves the currently active scheduled signal for the strategy.
|
|
5756
5805
|
* If no scheduled signal exists, returns null.
|
|
@@ -5767,7 +5816,11 @@ declare class BacktestUtils {
|
|
|
5767
5816
|
* }
|
|
5768
5817
|
* ```
|
|
5769
5818
|
*/
|
|
5770
|
-
getScheduledSignal: (symbol: string,
|
|
5819
|
+
getScheduledSignal: (symbol: string, context: {
|
|
5820
|
+
strategyName: string;
|
|
5821
|
+
exchangeName: string;
|
|
5822
|
+
frameName: string;
|
|
5823
|
+
}) => Promise<IScheduledSignalRow>;
|
|
5771
5824
|
/**
|
|
5772
5825
|
* Stops the strategy from generating new signals.
|
|
5773
5826
|
*
|
|
@@ -5777,15 +5830,24 @@ declare class BacktestUtils {
|
|
|
5777
5830
|
*
|
|
5778
5831
|
* @param symbol - Trading pair symbol
|
|
5779
5832
|
* @param strategyName - Strategy name to stop
|
|
5833
|
+
* @param context - Execution context with exchangeName and frameName
|
|
5780
5834
|
* @returns Promise that resolves when stop flag is set
|
|
5781
5835
|
*
|
|
5782
5836
|
* @example
|
|
5783
5837
|
* ```typescript
|
|
5784
5838
|
* // Stop strategy after some condition
|
|
5785
|
-
* await Backtest.stop("BTCUSDT", "my-strategy"
|
|
5839
|
+
* await Backtest.stop("BTCUSDT", "my-strategy", {
|
|
5840
|
+
* exchangeName: "binance",
|
|
5841
|
+
* frameName: "frame1",
|
|
5842
|
+
* strategyName: "my-strategy"
|
|
5843
|
+
* });
|
|
5786
5844
|
* ```
|
|
5787
5845
|
*/
|
|
5788
|
-
stop: (symbol: string,
|
|
5846
|
+
stop: (symbol: string, context: {
|
|
5847
|
+
strategyName: string;
|
|
5848
|
+
exchangeName: string;
|
|
5849
|
+
frameName: string;
|
|
5850
|
+
}) => Promise<void>;
|
|
5789
5851
|
/**
|
|
5790
5852
|
* Cancels the scheduled signal without stopping the strategy.
|
|
5791
5853
|
*
|
|
@@ -5795,63 +5857,103 @@ declare class BacktestUtils {
|
|
|
5795
5857
|
*
|
|
5796
5858
|
* @param symbol - Trading pair symbol
|
|
5797
5859
|
* @param strategyName - Strategy name
|
|
5860
|
+
* @param context - Execution context with exchangeName and frameName
|
|
5798
5861
|
* @param cancelId - Optional cancellation ID for tracking user-initiated cancellations
|
|
5799
5862
|
* @returns Promise that resolves when scheduled signal is cancelled
|
|
5800
5863
|
*
|
|
5801
5864
|
* @example
|
|
5802
5865
|
* ```typescript
|
|
5803
5866
|
* // Cancel scheduled signal with custom ID
|
|
5804
|
-
* await Backtest.cancel("BTCUSDT", "my-strategy",
|
|
5867
|
+
* await Backtest.cancel("BTCUSDT", "my-strategy", {
|
|
5868
|
+
* exchangeName: "binance",
|
|
5869
|
+
* frameName: "frame1",
|
|
5870
|
+
* strategyName: "my-strategy"
|
|
5871
|
+
* }, "manual-cancel-001");
|
|
5805
5872
|
* ```
|
|
5806
5873
|
*/
|
|
5807
|
-
cancel: (symbol: string,
|
|
5874
|
+
cancel: (symbol: string, context: {
|
|
5875
|
+
strategyName: string;
|
|
5876
|
+
exchangeName: string;
|
|
5877
|
+
frameName: string;
|
|
5878
|
+
}, cancelId?: string) => Promise<void>;
|
|
5808
5879
|
/**
|
|
5809
5880
|
* Gets statistical data from all closed signals for a symbol-strategy pair.
|
|
5810
5881
|
*
|
|
5811
5882
|
* @param symbol - Trading pair symbol
|
|
5812
5883
|
* @param strategyName - Strategy name to get data for
|
|
5884
|
+
* @param context - Execution context with exchangeName and frameName
|
|
5813
5885
|
* @returns Promise resolving to statistical data object
|
|
5814
5886
|
*
|
|
5815
5887
|
* @example
|
|
5816
5888
|
* ```typescript
|
|
5817
|
-
* const stats = await Backtest.getData("BTCUSDT", "my-strategy"
|
|
5889
|
+
* const stats = await Backtest.getData("BTCUSDT", "my-strategy", {
|
|
5890
|
+
* exchangeName: "binance",
|
|
5891
|
+
* frameName: "frame1",
|
|
5892
|
+
* strategyName: "my-strategy"
|
|
5893
|
+
* });
|
|
5818
5894
|
* console.log(stats.sharpeRatio, stats.winRate);
|
|
5819
5895
|
* ```
|
|
5820
5896
|
*/
|
|
5821
|
-
getData: (symbol: string,
|
|
5897
|
+
getData: (symbol: string, context: {
|
|
5898
|
+
strategyName: string;
|
|
5899
|
+
exchangeName: string;
|
|
5900
|
+
frameName: string;
|
|
5901
|
+
}) => Promise<BacktestStatisticsModel>;
|
|
5822
5902
|
/**
|
|
5823
5903
|
* Generates markdown report with all closed signals for a symbol-strategy pair.
|
|
5824
5904
|
*
|
|
5825
5905
|
* @param symbol - Trading pair symbol
|
|
5826
5906
|
* @param strategyName - Strategy name to generate report for
|
|
5907
|
+
* @param context - Execution context with exchangeName and frameName
|
|
5827
5908
|
* @param columns - Optional columns configuration for the report
|
|
5828
5909
|
* @returns Promise resolving to markdown formatted report string
|
|
5829
5910
|
*
|
|
5830
5911
|
* @example
|
|
5831
5912
|
* ```typescript
|
|
5832
|
-
* const markdown = await Backtest.getReport("BTCUSDT", "my-strategy"
|
|
5913
|
+
* const markdown = await Backtest.getReport("BTCUSDT", "my-strategy", {
|
|
5914
|
+
* exchangeName: "binance",
|
|
5915
|
+
* frameName: "frame1",
|
|
5916
|
+
* strategyName: "my-strategy"
|
|
5917
|
+
* });
|
|
5833
5918
|
* console.log(markdown);
|
|
5834
5919
|
* ```
|
|
5835
5920
|
*/
|
|
5836
|
-
getReport: (symbol: string,
|
|
5921
|
+
getReport: (symbol: string, context: {
|
|
5922
|
+
strategyName: string;
|
|
5923
|
+
exchangeName: string;
|
|
5924
|
+
frameName: string;
|
|
5925
|
+
}, columns?: Columns$6[]) => Promise<string>;
|
|
5837
5926
|
/**
|
|
5838
5927
|
* Saves strategy report to disk.
|
|
5839
5928
|
*
|
|
5840
5929
|
* @param symbol - Trading pair symbol
|
|
5841
5930
|
* @param strategyName - Strategy name to save report for
|
|
5931
|
+
* @param context - Execution context with exchangeName and frameName
|
|
5842
5932
|
* @param path - Optional directory path to save report (default: "./dump/backtest")
|
|
5843
5933
|
* @param columns - Optional columns configuration for the report
|
|
5844
5934
|
*
|
|
5845
5935
|
* @example
|
|
5846
5936
|
* ```typescript
|
|
5847
5937
|
* // Save to default path: ./dump/backtest/my-strategy.md
|
|
5848
|
-
* await Backtest.dump("BTCUSDT", "my-strategy"
|
|
5938
|
+
* await Backtest.dump("BTCUSDT", "my-strategy", {
|
|
5939
|
+
* exchangeName: "binance",
|
|
5940
|
+
* frameName: "frame1",
|
|
5941
|
+
* strategyName: "my-strategy"
|
|
5942
|
+
* });
|
|
5849
5943
|
*
|
|
5850
5944
|
* // Save to custom path: ./custom/path/my-strategy.md
|
|
5851
|
-
* await Backtest.dump("BTCUSDT", "my-strategy",
|
|
5945
|
+
* await Backtest.dump("BTCUSDT", "my-strategy", {
|
|
5946
|
+
* exchangeName: "binance",
|
|
5947
|
+
* frameName: "frame1",
|
|
5948
|
+
* strategyName: "my-strategy"
|
|
5949
|
+
* }, "./custom/path");
|
|
5852
5950
|
* ```
|
|
5853
5951
|
*/
|
|
5854
|
-
dump: (symbol: string,
|
|
5952
|
+
dump: (symbol: string, context: {
|
|
5953
|
+
strategyName: string;
|
|
5954
|
+
exchangeName: string;
|
|
5955
|
+
frameName: string;
|
|
5956
|
+
}, path?: string, columns?: Columns$6[]) => Promise<void>;
|
|
5855
5957
|
/**
|
|
5856
5958
|
* Lists all active backtest instances with their current status.
|
|
5857
5959
|
*
|
|
@@ -5960,8 +6062,8 @@ declare class LiveMarkdownService {
|
|
|
5960
6062
|
/** Logger service for debug output */
|
|
5961
6063
|
private readonly loggerService;
|
|
5962
6064
|
/**
|
|
5963
|
-
* Memoized function to get or create ReportStorage for a symbol-strategy-backtest
|
|
5964
|
-
* Each
|
|
6065
|
+
* Memoized function to get or create ReportStorage for a symbol-strategy-exchange-frame-backtest combination.
|
|
6066
|
+
* Each combination gets its own isolated storage instance.
|
|
5965
6067
|
*/
|
|
5966
6068
|
private getStorage;
|
|
5967
6069
|
/**
|
|
@@ -5970,7 +6072,7 @@ declare class LiveMarkdownService {
|
|
|
5970
6072
|
*
|
|
5971
6073
|
* Processes all event types: idle, opened, active, closed.
|
|
5972
6074
|
*
|
|
5973
|
-
* @param data - Tick result from strategy execution
|
|
6075
|
+
* @param data - Tick result from strategy execution with frameName wrapper
|
|
5974
6076
|
*
|
|
5975
6077
|
* @example
|
|
5976
6078
|
* ```typescript
|
|
@@ -5992,23 +6094,27 @@ declare class LiveMarkdownService {
|
|
|
5992
6094
|
*
|
|
5993
6095
|
* @param symbol - Trading pair symbol
|
|
5994
6096
|
* @param strategyName - Strategy name to get data for
|
|
6097
|
+
* @param exchangeName - Exchange name
|
|
6098
|
+
* @param frameName - Frame name
|
|
5995
6099
|
* @param backtest - True if backtest mode, false if live mode
|
|
5996
6100
|
* @returns Statistical data object with all metrics
|
|
5997
6101
|
*
|
|
5998
6102
|
* @example
|
|
5999
6103
|
* ```typescript
|
|
6000
6104
|
* const service = new LiveMarkdownService();
|
|
6001
|
-
* const stats = await service.getData("BTCUSDT", "my-strategy", false);
|
|
6105
|
+
* const stats = await service.getData("BTCUSDT", "my-strategy", "binance", "1h", false);
|
|
6002
6106
|
* console.log(stats.sharpeRatio, stats.winRate);
|
|
6003
6107
|
* ```
|
|
6004
6108
|
*/
|
|
6005
|
-
getData: (symbol: string, strategyName: StrategyName, backtest: boolean) => Promise<LiveStatisticsModel>;
|
|
6109
|
+
getData: (symbol: string, strategyName: StrategyName, exchangeName: string, frameName: string, backtest: boolean) => Promise<LiveStatisticsModel>;
|
|
6006
6110
|
/**
|
|
6007
6111
|
* Generates markdown report with all events for a symbol-strategy pair.
|
|
6008
6112
|
* Delegates to ReportStorage.getReport().
|
|
6009
6113
|
*
|
|
6010
6114
|
* @param symbol - Trading pair symbol
|
|
6011
6115
|
* @param strategyName - Strategy name to generate report for
|
|
6116
|
+
* @param exchangeName - Exchange name
|
|
6117
|
+
* @param frameName - Frame name
|
|
6012
6118
|
* @param backtest - True if backtest mode, false if live mode
|
|
6013
6119
|
* @param columns - Column configuration for formatting the table
|
|
6014
6120
|
* @returns Markdown formatted report string with table of all events
|
|
@@ -6016,11 +6122,11 @@ declare class LiveMarkdownService {
|
|
|
6016
6122
|
* @example
|
|
6017
6123
|
* ```typescript
|
|
6018
6124
|
* const service = new LiveMarkdownService();
|
|
6019
|
-
* const markdown = await service.getReport("BTCUSDT", "my-strategy", false);
|
|
6125
|
+
* const markdown = await service.getReport("BTCUSDT", "my-strategy", "binance", "1h", false);
|
|
6020
6126
|
* console.log(markdown);
|
|
6021
6127
|
* ```
|
|
6022
6128
|
*/
|
|
6023
|
-
getReport: (symbol: string, strategyName: StrategyName, backtest: boolean, columns?: Columns$5[]) => Promise<string>;
|
|
6129
|
+
getReport: (symbol: string, strategyName: StrategyName, exchangeName: string, frameName: string, backtest: boolean, columns?: Columns$5[]) => Promise<string>;
|
|
6024
6130
|
/**
|
|
6025
6131
|
* Saves symbol-strategy report to disk.
|
|
6026
6132
|
* Creates directory if it doesn't exist.
|
|
@@ -6028,6 +6134,8 @@ declare class LiveMarkdownService {
|
|
|
6028
6134
|
*
|
|
6029
6135
|
* @param symbol - Trading pair symbol
|
|
6030
6136
|
* @param strategyName - Strategy name to save report for
|
|
6137
|
+
* @param exchangeName - Exchange name
|
|
6138
|
+
* @param frameName - Frame name
|
|
6031
6139
|
* @param backtest - True if backtest mode, false if live mode
|
|
6032
6140
|
* @param path - Directory path to save report (default: "./dump/live")
|
|
6033
6141
|
* @param columns - Column configuration for formatting the table
|
|
@@ -6037,35 +6145,37 @@ declare class LiveMarkdownService {
|
|
|
6037
6145
|
* const service = new LiveMarkdownService();
|
|
6038
6146
|
*
|
|
6039
6147
|
* // Save to default path: ./dump/live/my-strategy.md
|
|
6040
|
-
* await service.dump("BTCUSDT", "my-strategy", false);
|
|
6148
|
+
* await service.dump("BTCUSDT", "my-strategy", "binance", "1h", false);
|
|
6041
6149
|
*
|
|
6042
6150
|
* // Save to custom path: ./custom/path/my-strategy.md
|
|
6043
|
-
* await service.dump("BTCUSDT", "my-strategy", false, "./custom/path");
|
|
6151
|
+
* await service.dump("BTCUSDT", "my-strategy", "binance", "1h", false, "./custom/path");
|
|
6044
6152
|
* ```
|
|
6045
6153
|
*/
|
|
6046
|
-
dump: (symbol: string, strategyName: StrategyName, backtest: boolean, path?: string, columns?: Columns$5[]) => Promise<void>;
|
|
6154
|
+
dump: (symbol: string, strategyName: StrategyName, exchangeName: string, frameName: string, backtest: boolean, path?: string, columns?: Columns$5[]) => Promise<void>;
|
|
6047
6155
|
/**
|
|
6048
6156
|
* Clears accumulated event data from storage.
|
|
6049
|
-
* If
|
|
6157
|
+
* If payload is provided, clears only that specific symbol-strategy-exchange-frame-backtest combination's data.
|
|
6050
6158
|
* If nothing is provided, clears all data.
|
|
6051
6159
|
*
|
|
6052
|
-
* @param
|
|
6053
|
-
* @param ctx - Optional context with symbol and strategyName
|
|
6160
|
+
* @param payload - Optional payload with symbol, strategyName, exchangeName, frameName, backtest
|
|
6054
6161
|
*
|
|
6055
6162
|
* @example
|
|
6056
6163
|
* ```typescript
|
|
6057
6164
|
* const service = new LiveMarkdownService();
|
|
6058
6165
|
*
|
|
6059
|
-
* // Clear specific
|
|
6060
|
-
* await service.clear(
|
|
6166
|
+
* // Clear specific combination
|
|
6167
|
+
* await service.clear({ symbol: "BTCUSDT", strategyName: "my-strategy", exchangeName: "binance", frameName: "1h", backtest: false });
|
|
6061
6168
|
*
|
|
6062
6169
|
* // Clear all data
|
|
6063
6170
|
* await service.clear();
|
|
6064
6171
|
* ```
|
|
6065
6172
|
*/
|
|
6066
|
-
clear: (
|
|
6173
|
+
clear: (payload?: {
|
|
6067
6174
|
symbol: string;
|
|
6068
6175
|
strategyName: StrategyName;
|
|
6176
|
+
exchangeName: string;
|
|
6177
|
+
frameName: string;
|
|
6178
|
+
backtest: boolean;
|
|
6069
6179
|
}) => Promise<void>;
|
|
6070
6180
|
/**
|
|
6071
6181
|
* Initializes the service by subscribing to live signal events.
|
|
@@ -6171,7 +6281,10 @@ declare class LiveUtils {
|
|
|
6171
6281
|
* }
|
|
6172
6282
|
* ```
|
|
6173
6283
|
*/
|
|
6174
|
-
getPendingSignal: (symbol: string,
|
|
6284
|
+
getPendingSignal: (symbol: string, context: {
|
|
6285
|
+
strategyName: string;
|
|
6286
|
+
exchangeName: string;
|
|
6287
|
+
}) => Promise<ISignalRow>;
|
|
6175
6288
|
/**
|
|
6176
6289
|
* Retrieves the currently active scheduled signal for the strategy.
|
|
6177
6290
|
* If no scheduled signal exists, returns null.
|
|
@@ -6188,7 +6301,10 @@ declare class LiveUtils {
|
|
|
6188
6301
|
* }
|
|
6189
6302
|
* ```
|
|
6190
6303
|
*/
|
|
6191
|
-
getScheduledSignal: (symbol: string,
|
|
6304
|
+
getScheduledSignal: (symbol: string, context: {
|
|
6305
|
+
strategyName: string;
|
|
6306
|
+
exchangeName: string;
|
|
6307
|
+
}) => Promise<IScheduledSignalRow>;
|
|
6192
6308
|
/**
|
|
6193
6309
|
* Stops the strategy from generating new signals.
|
|
6194
6310
|
*
|
|
@@ -6206,7 +6322,10 @@ declare class LiveUtils {
|
|
|
6206
6322
|
* await Live.stop("BTCUSDT", "my-strategy");
|
|
6207
6323
|
* ```
|
|
6208
6324
|
*/
|
|
6209
|
-
stop: (symbol: string,
|
|
6325
|
+
stop: (symbol: string, context: {
|
|
6326
|
+
strategyName: string;
|
|
6327
|
+
exchangeName: string;
|
|
6328
|
+
}) => Promise<void>;
|
|
6210
6329
|
/**
|
|
6211
6330
|
* Cancels the scheduled signal without stopping the strategy.
|
|
6212
6331
|
*
|
|
@@ -6216,63 +6335,99 @@ declare class LiveUtils {
|
|
|
6216
6335
|
*
|
|
6217
6336
|
* @param symbol - Trading pair symbol
|
|
6218
6337
|
* @param strategyName - Strategy name
|
|
6338
|
+
* @param context - Execution context with exchangeName and frameName
|
|
6219
6339
|
* @param cancelId - Optional cancellation ID for tracking user-initiated cancellations
|
|
6220
6340
|
* @returns Promise that resolves when scheduled signal is cancelled
|
|
6221
6341
|
*
|
|
6222
6342
|
* @example
|
|
6223
6343
|
* ```typescript
|
|
6224
6344
|
* // Cancel scheduled signal in live trading with custom ID
|
|
6225
|
-
* await Live.cancel("BTCUSDT", "my-strategy",
|
|
6345
|
+
* await Live.cancel("BTCUSDT", "my-strategy", {
|
|
6346
|
+
* exchangeName: "binance",
|
|
6347
|
+
* frameName: "",
|
|
6348
|
+
* strategyName: "my-strategy"
|
|
6349
|
+
* }, "manual-cancel-001");
|
|
6226
6350
|
* ```
|
|
6227
6351
|
*/
|
|
6228
|
-
cancel: (symbol: string,
|
|
6352
|
+
cancel: (symbol: string, context: {
|
|
6353
|
+
strategyName: string;
|
|
6354
|
+
exchangeName: string;
|
|
6355
|
+
}, cancelId?: string) => Promise<void>;
|
|
6229
6356
|
/**
|
|
6230
6357
|
* Gets statistical data from all live trading events for a symbol-strategy pair.
|
|
6231
6358
|
*
|
|
6232
6359
|
* @param symbol - Trading pair symbol
|
|
6233
6360
|
* @param strategyName - Strategy name to get data for
|
|
6361
|
+
* @param context - Execution context with exchangeName and frameName
|
|
6234
6362
|
* @returns Promise resolving to statistical data object
|
|
6235
6363
|
*
|
|
6236
6364
|
* @example
|
|
6237
6365
|
* ```typescript
|
|
6238
|
-
* const stats = await Live.getData("BTCUSDT", "my-strategy"
|
|
6366
|
+
* const stats = await Live.getData("BTCUSDT", "my-strategy", {
|
|
6367
|
+
* exchangeName: "binance",
|
|
6368
|
+
* frameName: "",
|
|
6369
|
+
* strategyName: "my-strategy"
|
|
6370
|
+
* });
|
|
6239
6371
|
* console.log(stats.sharpeRatio, stats.winRate);
|
|
6240
6372
|
* ```
|
|
6241
6373
|
*/
|
|
6242
|
-
getData: (symbol: string,
|
|
6374
|
+
getData: (symbol: string, context: {
|
|
6375
|
+
strategyName: string;
|
|
6376
|
+
exchangeName: string;
|
|
6377
|
+
}) => Promise<LiveStatisticsModel>;
|
|
6243
6378
|
/**
|
|
6244
6379
|
* Generates markdown report with all events for a symbol-strategy pair.
|
|
6245
6380
|
*
|
|
6246
6381
|
* @param symbol - Trading pair symbol
|
|
6247
6382
|
* @param strategyName - Strategy name to generate report for
|
|
6383
|
+
* @param context - Execution context with exchangeName and frameName
|
|
6248
6384
|
* @param columns - Optional columns configuration for the report
|
|
6249
6385
|
* @returns Promise resolving to markdown formatted report string
|
|
6250
6386
|
*
|
|
6251
6387
|
* @example
|
|
6252
6388
|
* ```typescript
|
|
6253
|
-
* const markdown = await Live.getReport("BTCUSDT", "my-strategy"
|
|
6389
|
+
* const markdown = await Live.getReport("BTCUSDT", "my-strategy", {
|
|
6390
|
+
* exchangeName: "binance",
|
|
6391
|
+
* frameName: "",
|
|
6392
|
+
* strategyName: "my-strategy"
|
|
6393
|
+
* });
|
|
6254
6394
|
* console.log(markdown);
|
|
6255
6395
|
* ```
|
|
6256
6396
|
*/
|
|
6257
|
-
getReport: (symbol: string,
|
|
6397
|
+
getReport: (symbol: string, context: {
|
|
6398
|
+
strategyName: string;
|
|
6399
|
+
exchangeName: string;
|
|
6400
|
+
}, columns?: Columns$5[]) => Promise<string>;
|
|
6258
6401
|
/**
|
|
6259
6402
|
* Saves strategy report to disk.
|
|
6260
6403
|
*
|
|
6261
6404
|
* @param symbol - Trading pair symbol
|
|
6262
6405
|
* @param strategyName - Strategy name to save report for
|
|
6406
|
+
* @param context - Execution context with exchangeName and frameName
|
|
6263
6407
|
* @param path - Optional directory path to save report (default: "./dump/live")
|
|
6264
6408
|
* @param columns - Optional columns configuration for the report
|
|
6265
6409
|
*
|
|
6266
6410
|
* @example
|
|
6267
6411
|
* ```typescript
|
|
6268
6412
|
* // Save to default path: ./dump/live/my-strategy.md
|
|
6269
|
-
* await Live.dump("BTCUSDT", "my-strategy"
|
|
6413
|
+
* await Live.dump("BTCUSDT", "my-strategy", {
|
|
6414
|
+
* exchangeName: "binance",
|
|
6415
|
+
* frameName: "",
|
|
6416
|
+
* strategyName: "my-strategy"
|
|
6417
|
+
* });
|
|
6270
6418
|
*
|
|
6271
6419
|
* // Save to custom path: ./custom/path/my-strategy.md
|
|
6272
|
-
* await Live.dump("BTCUSDT", "my-strategy",
|
|
6420
|
+
* await Live.dump("BTCUSDT", "my-strategy", {
|
|
6421
|
+
* exchangeName: "binance",
|
|
6422
|
+
* frameName: "",
|
|
6423
|
+
* strategyName: "my-strategy"
|
|
6424
|
+
* }, "./custom/path");
|
|
6273
6425
|
* ```
|
|
6274
6426
|
*/
|
|
6275
|
-
dump: (symbol: string,
|
|
6427
|
+
dump: (symbol: string, context: {
|
|
6428
|
+
strategyName: string;
|
|
6429
|
+
exchangeName: string;
|
|
6430
|
+
}, path?: string, columns?: Columns$5[]) => Promise<void>;
|
|
6276
6431
|
/**
|
|
6277
6432
|
* Lists all active live trading instances with their current status.
|
|
6278
6433
|
*
|
|
@@ -6368,8 +6523,8 @@ declare class ScheduleMarkdownService {
|
|
|
6368
6523
|
/** Logger service for debug output */
|
|
6369
6524
|
private readonly loggerService;
|
|
6370
6525
|
/**
|
|
6371
|
-
* Memoized function to get or create ReportStorage for a symbol-strategy-backtest
|
|
6372
|
-
* Each
|
|
6526
|
+
* Memoized function to get or create ReportStorage for a symbol-strategy-exchange-frame-backtest combination.
|
|
6527
|
+
* Each combination gets its own isolated storage instance.
|
|
6373
6528
|
*/
|
|
6374
6529
|
private getStorage;
|
|
6375
6530
|
/**
|
|
@@ -6378,7 +6533,7 @@ declare class ScheduleMarkdownService {
|
|
|
6378
6533
|
*
|
|
6379
6534
|
* Processes only scheduled, opened and cancelled event types.
|
|
6380
6535
|
*
|
|
6381
|
-
* @param data - Tick result from strategy execution
|
|
6536
|
+
* @param data - Tick result from strategy execution with frameName wrapper
|
|
6382
6537
|
*
|
|
6383
6538
|
* @example
|
|
6384
6539
|
* ```typescript
|
|
@@ -6393,23 +6548,27 @@ declare class ScheduleMarkdownService {
|
|
|
6393
6548
|
*
|
|
6394
6549
|
* @param symbol - Trading pair symbol
|
|
6395
6550
|
* @param strategyName - Strategy name to get data for
|
|
6551
|
+
* @param exchangeName - Exchange name
|
|
6552
|
+
* @param frameName - Frame name
|
|
6396
6553
|
* @param backtest - True if backtest mode, false if live mode
|
|
6397
6554
|
* @returns Statistical data object with all metrics
|
|
6398
6555
|
*
|
|
6399
6556
|
* @example
|
|
6400
6557
|
* ```typescript
|
|
6401
6558
|
* const service = new ScheduleMarkdownService();
|
|
6402
|
-
* const stats = await service.getData("BTCUSDT", "my-strategy", false);
|
|
6559
|
+
* const stats = await service.getData("BTCUSDT", "my-strategy", "binance", "1h", false);
|
|
6403
6560
|
* console.log(stats.cancellationRate, stats.avgWaitTime);
|
|
6404
6561
|
* ```
|
|
6405
6562
|
*/
|
|
6406
|
-
getData: (symbol: string, strategyName: StrategyName, backtest: boolean) => Promise<ScheduleStatisticsModel>;
|
|
6563
|
+
getData: (symbol: string, strategyName: StrategyName, exchangeName: string, frameName: string, backtest: boolean) => Promise<ScheduleStatisticsModel>;
|
|
6407
6564
|
/**
|
|
6408
6565
|
* Generates markdown report with all scheduled events for a symbol-strategy pair.
|
|
6409
6566
|
* Delegates to ReportStorage.getReport().
|
|
6410
6567
|
*
|
|
6411
6568
|
* @param symbol - Trading pair symbol
|
|
6412
6569
|
* @param strategyName - Strategy name to generate report for
|
|
6570
|
+
* @param exchangeName - Exchange name
|
|
6571
|
+
* @param frameName - Frame name
|
|
6413
6572
|
* @param backtest - True if backtest mode, false if live mode
|
|
6414
6573
|
* @param columns - Column configuration for formatting the table
|
|
6415
6574
|
* @returns Markdown formatted report string with table of all events
|
|
@@ -6417,11 +6576,11 @@ declare class ScheduleMarkdownService {
|
|
|
6417
6576
|
* @example
|
|
6418
6577
|
* ```typescript
|
|
6419
6578
|
* const service = new ScheduleMarkdownService();
|
|
6420
|
-
* const markdown = await service.getReport("BTCUSDT", "my-strategy", false);
|
|
6579
|
+
* const markdown = await service.getReport("BTCUSDT", "my-strategy", "binance", "1h", false);
|
|
6421
6580
|
* console.log(markdown);
|
|
6422
6581
|
* ```
|
|
6423
6582
|
*/
|
|
6424
|
-
getReport: (symbol: string, strategyName: StrategyName, backtest: boolean, columns?: Columns$4[]) => Promise<string>;
|
|
6583
|
+
getReport: (symbol: string, strategyName: StrategyName, exchangeName: string, frameName: string, backtest: boolean, columns?: Columns$4[]) => Promise<string>;
|
|
6425
6584
|
/**
|
|
6426
6585
|
* Saves symbol-strategy report to disk.
|
|
6427
6586
|
* Creates directory if it doesn't exist.
|
|
@@ -6429,6 +6588,8 @@ declare class ScheduleMarkdownService {
|
|
|
6429
6588
|
*
|
|
6430
6589
|
* @param symbol - Trading pair symbol
|
|
6431
6590
|
* @param strategyName - Strategy name to save report for
|
|
6591
|
+
* @param exchangeName - Exchange name
|
|
6592
|
+
* @param frameName - Frame name
|
|
6432
6593
|
* @param backtest - True if backtest mode, false if live mode
|
|
6433
6594
|
* @param path - Directory path to save report (default: "./dump/schedule")
|
|
6434
6595
|
* @param columns - Column configuration for formatting the table
|
|
@@ -6438,35 +6599,37 @@ declare class ScheduleMarkdownService {
|
|
|
6438
6599
|
* const service = new ScheduleMarkdownService();
|
|
6439
6600
|
*
|
|
6440
6601
|
* // Save to default path: ./dump/schedule/my-strategy.md
|
|
6441
|
-
* await service.dump("BTCUSDT", "my-strategy", false);
|
|
6602
|
+
* await service.dump("BTCUSDT", "my-strategy", "binance", "1h", false);
|
|
6442
6603
|
*
|
|
6443
6604
|
* // Save to custom path: ./custom/path/my-strategy.md
|
|
6444
|
-
* await service.dump("BTCUSDT", "my-strategy", false, "./custom/path");
|
|
6605
|
+
* await service.dump("BTCUSDT", "my-strategy", "binance", "1h", false, "./custom/path");
|
|
6445
6606
|
* ```
|
|
6446
6607
|
*/
|
|
6447
|
-
dump: (symbol: string, strategyName: StrategyName, backtest: boolean, path?: string, columns?: Columns$4[]) => Promise<void>;
|
|
6608
|
+
dump: (symbol: string, strategyName: StrategyName, exchangeName: string, frameName: string, backtest: boolean, path?: string, columns?: Columns$4[]) => Promise<void>;
|
|
6448
6609
|
/**
|
|
6449
6610
|
* Clears accumulated event data from storage.
|
|
6450
|
-
* If
|
|
6611
|
+
* If payload is provided, clears only that specific symbol-strategy-exchange-frame-backtest combination's data.
|
|
6451
6612
|
* If nothing is provided, clears all data.
|
|
6452
6613
|
*
|
|
6453
|
-
* @param
|
|
6454
|
-
* @param ctx - Optional context with symbol and strategyName
|
|
6614
|
+
* @param payload - Optional payload with symbol, strategyName, exchangeName, frameName, backtest
|
|
6455
6615
|
*
|
|
6456
6616
|
* @example
|
|
6457
6617
|
* ```typescript
|
|
6458
6618
|
* const service = new ScheduleMarkdownService();
|
|
6459
6619
|
*
|
|
6460
|
-
* // Clear specific
|
|
6461
|
-
* await service.clear(
|
|
6620
|
+
* // Clear specific combination
|
|
6621
|
+
* await service.clear({ symbol: "BTCUSDT", strategyName: "my-strategy", exchangeName: "binance", frameName: "1h", backtest: false });
|
|
6462
6622
|
*
|
|
6463
6623
|
* // Clear all data
|
|
6464
6624
|
* await service.clear();
|
|
6465
6625
|
* ```
|
|
6466
6626
|
*/
|
|
6467
|
-
clear: (
|
|
6627
|
+
clear: (payload?: {
|
|
6468
6628
|
symbol: string;
|
|
6469
6629
|
strategyName: StrategyName;
|
|
6630
|
+
exchangeName: string;
|
|
6631
|
+
frameName: string;
|
|
6632
|
+
backtest: boolean;
|
|
6470
6633
|
}) => Promise<void>;
|
|
6471
6634
|
/**
|
|
6472
6635
|
* Initializes the service by subscribing to live signal events.
|
|
@@ -6521,7 +6684,11 @@ declare class ScheduleUtils {
|
|
|
6521
6684
|
* console.log(stats.cancellationRate, stats.avgWaitTime);
|
|
6522
6685
|
* ```
|
|
6523
6686
|
*/
|
|
6524
|
-
getData: (symbol: string,
|
|
6687
|
+
getData: (symbol: string, context: {
|
|
6688
|
+
strategyName: string;
|
|
6689
|
+
exchangeName: string;
|
|
6690
|
+
frameName: string;
|
|
6691
|
+
}, backtest?: boolean) => Promise<ScheduleStatisticsModel>;
|
|
6525
6692
|
/**
|
|
6526
6693
|
* Generates markdown report with all scheduled events for a symbol-strategy pair.
|
|
6527
6694
|
*
|
|
@@ -6536,7 +6703,11 @@ declare class ScheduleUtils {
|
|
|
6536
6703
|
* console.log(markdown);
|
|
6537
6704
|
* ```
|
|
6538
6705
|
*/
|
|
6539
|
-
getReport: (symbol: string,
|
|
6706
|
+
getReport: (symbol: string, context: {
|
|
6707
|
+
strategyName: string;
|
|
6708
|
+
exchangeName: string;
|
|
6709
|
+
frameName: string;
|
|
6710
|
+
}, backtest?: boolean, columns?: Columns$4[]) => Promise<string>;
|
|
6540
6711
|
/**
|
|
6541
6712
|
* Saves strategy report to disk.
|
|
6542
6713
|
*
|
|
@@ -6554,7 +6725,11 @@ declare class ScheduleUtils {
|
|
|
6554
6725
|
* await Schedule.dump("BTCUSDT", "my-strategy", "./custom/path");
|
|
6555
6726
|
* ```
|
|
6556
6727
|
*/
|
|
6557
|
-
dump: (symbol: string,
|
|
6728
|
+
dump: (symbol: string, context: {
|
|
6729
|
+
strategyName: string;
|
|
6730
|
+
exchangeName: string;
|
|
6731
|
+
frameName: string;
|
|
6732
|
+
}, backtest?: boolean, path?: string, columns?: Columns$4[]) => Promise<void>;
|
|
6558
6733
|
}
|
|
6559
6734
|
/**
|
|
6560
6735
|
* Singleton instance of ScheduleUtils for convenient scheduled signals reporting.
|
|
@@ -6632,8 +6807,8 @@ declare class PerformanceMarkdownService {
|
|
|
6632
6807
|
/** Logger service for debug output */
|
|
6633
6808
|
private readonly loggerService;
|
|
6634
6809
|
/**
|
|
6635
|
-
* Memoized function to get or create PerformanceStorage for a symbol-strategy-backtest
|
|
6636
|
-
* Each
|
|
6810
|
+
* Memoized function to get or create PerformanceStorage for a symbol-strategy-exchange-frame-backtest combination.
|
|
6811
|
+
* Each combination gets its own isolated storage instance.
|
|
6637
6812
|
*/
|
|
6638
6813
|
private getStorage;
|
|
6639
6814
|
/**
|
|
@@ -6648,39 +6823,45 @@ declare class PerformanceMarkdownService {
|
|
|
6648
6823
|
*
|
|
6649
6824
|
* @param symbol - Trading pair symbol
|
|
6650
6825
|
* @param strategyName - Strategy name to get data for
|
|
6826
|
+
* @param exchangeName - Exchange name
|
|
6827
|
+
* @param frameName - Frame name
|
|
6651
6828
|
* @param backtest - True if backtest mode, false if live mode
|
|
6652
6829
|
* @returns Performance statistics with aggregated metrics
|
|
6653
6830
|
*
|
|
6654
6831
|
* @example
|
|
6655
6832
|
* ```typescript
|
|
6656
|
-
* const stats = await performanceService.getData("BTCUSDT", "my-strategy", false);
|
|
6833
|
+
* const stats = await performanceService.getData("BTCUSDT", "my-strategy", "binance", "1h", false);
|
|
6657
6834
|
* console.log("Total time:", stats.totalDuration);
|
|
6658
6835
|
* console.log("Slowest operation:", Object.values(stats.metricStats)
|
|
6659
6836
|
* .sort((a, b) => b.avgDuration - a.avgDuration)[0]);
|
|
6660
6837
|
* ```
|
|
6661
6838
|
*/
|
|
6662
|
-
getData: (symbol: string, strategyName: string, backtest: boolean) => Promise<PerformanceStatisticsModel>;
|
|
6839
|
+
getData: (symbol: string, strategyName: string, exchangeName: string, frameName: string, backtest: boolean) => Promise<PerformanceStatisticsModel>;
|
|
6663
6840
|
/**
|
|
6664
6841
|
* Generates markdown report with performance analysis.
|
|
6665
6842
|
*
|
|
6666
6843
|
* @param symbol - Trading pair symbol
|
|
6667
6844
|
* @param strategyName - Strategy name to generate report for
|
|
6845
|
+
* @param exchangeName - Exchange name
|
|
6846
|
+
* @param frameName - Frame name
|
|
6668
6847
|
* @param backtest - True if backtest mode, false if live mode
|
|
6669
6848
|
* @param columns - Column configuration for formatting the table
|
|
6670
6849
|
* @returns Markdown formatted report string
|
|
6671
6850
|
*
|
|
6672
6851
|
* @example
|
|
6673
6852
|
* ```typescript
|
|
6674
|
-
* const markdown = await performanceService.getReport("BTCUSDT", "my-strategy", false);
|
|
6853
|
+
* const markdown = await performanceService.getReport("BTCUSDT", "my-strategy", "binance", "1h", false);
|
|
6675
6854
|
* console.log(markdown);
|
|
6676
6855
|
* ```
|
|
6677
6856
|
*/
|
|
6678
|
-
getReport: (symbol: string, strategyName: string, backtest: boolean, columns?: Columns$3[]) => Promise<string>;
|
|
6857
|
+
getReport: (symbol: string, strategyName: string, exchangeName: string, frameName: string, backtest: boolean, columns?: Columns$3[]) => Promise<string>;
|
|
6679
6858
|
/**
|
|
6680
6859
|
* Saves performance report to disk.
|
|
6681
6860
|
*
|
|
6682
6861
|
* @param symbol - Trading pair symbol
|
|
6683
6862
|
* @param strategyName - Strategy name to save report for
|
|
6863
|
+
* @param exchangeName - Exchange name
|
|
6864
|
+
* @param frameName - Frame name
|
|
6684
6865
|
* @param backtest - True if backtest mode, false if live mode
|
|
6685
6866
|
* @param path - Directory path to save report
|
|
6686
6867
|
* @param columns - Column configuration for formatting the table
|
|
@@ -6688,22 +6869,24 @@ declare class PerformanceMarkdownService {
|
|
|
6688
6869
|
* @example
|
|
6689
6870
|
* ```typescript
|
|
6690
6871
|
* // Save to default path: ./dump/performance/my-strategy.md
|
|
6691
|
-
* await performanceService.dump("BTCUSDT", "my-strategy", false);
|
|
6872
|
+
* await performanceService.dump("BTCUSDT", "my-strategy", "binance", "1h", false);
|
|
6692
6873
|
*
|
|
6693
6874
|
* // Save to custom path
|
|
6694
|
-
* await performanceService.dump("BTCUSDT", "my-strategy", false, "./custom/path");
|
|
6875
|
+
* await performanceService.dump("BTCUSDT", "my-strategy", "binance", "1h", false, "./custom/path");
|
|
6695
6876
|
* ```
|
|
6696
6877
|
*/
|
|
6697
|
-
dump: (symbol: string, strategyName: string, backtest: boolean, path?: string, columns?: Columns$3[]) => Promise<void>;
|
|
6878
|
+
dump: (symbol: string, strategyName: string, exchangeName: string, frameName: string, backtest: boolean, path?: string, columns?: Columns$3[]) => Promise<void>;
|
|
6698
6879
|
/**
|
|
6699
6880
|
* Clears accumulated performance data from storage.
|
|
6700
6881
|
*
|
|
6701
|
-
* @param
|
|
6702
|
-
* @param ctx - Optional context with symbol and strategyName
|
|
6882
|
+
* @param payload - Optional payload with symbol, strategyName, exchangeName, frameName, backtest
|
|
6703
6883
|
*/
|
|
6704
|
-
clear: (
|
|
6884
|
+
clear: (payload?: {
|
|
6705
6885
|
symbol: string;
|
|
6706
6886
|
strategyName: string;
|
|
6887
|
+
exchangeName: string;
|
|
6888
|
+
frameName: string;
|
|
6889
|
+
backtest: boolean;
|
|
6707
6890
|
}) => Promise<void>;
|
|
6708
6891
|
/**
|
|
6709
6892
|
* Initializes the service by subscribing to performance events.
|
|
@@ -6773,7 +6956,11 @@ declare class Performance {
|
|
|
6773
6956
|
* }
|
|
6774
6957
|
* ```
|
|
6775
6958
|
*/
|
|
6776
|
-
static getData(symbol: string,
|
|
6959
|
+
static getData(symbol: string, context: {
|
|
6960
|
+
strategyName: string;
|
|
6961
|
+
exchangeName: string;
|
|
6962
|
+
frameName: string;
|
|
6963
|
+
}, backtest?: boolean): Promise<PerformanceStatisticsModel>;
|
|
6777
6964
|
/**
|
|
6778
6965
|
* Generates markdown report with performance analysis.
|
|
6779
6966
|
*
|
|
@@ -6797,7 +6984,11 @@ declare class Performance {
|
|
|
6797
6984
|
* await fs.writeFile("performance-report.md", markdown);
|
|
6798
6985
|
* ```
|
|
6799
6986
|
*/
|
|
6800
|
-
static getReport(symbol: string,
|
|
6987
|
+
static getReport(symbol: string, context: {
|
|
6988
|
+
strategyName: string;
|
|
6989
|
+
exchangeName: string;
|
|
6990
|
+
frameName: string;
|
|
6991
|
+
}, backtest?: boolean, columns?: Columns$3[]): Promise<string>;
|
|
6801
6992
|
/**
|
|
6802
6993
|
* Saves performance report to disk.
|
|
6803
6994
|
*
|
|
@@ -6818,7 +7009,11 @@ declare class Performance {
|
|
|
6818
7009
|
* await Performance.dump("BTCUSDT", "my-strategy", "./reports/perf");
|
|
6819
7010
|
* ```
|
|
6820
7011
|
*/
|
|
6821
|
-
static dump(symbol: string,
|
|
7012
|
+
static dump(symbol: string, context: {
|
|
7013
|
+
strategyName: string;
|
|
7014
|
+
exchangeName: string;
|
|
7015
|
+
frameName: string;
|
|
7016
|
+
}, backtest?: boolean, path?: string, columns?: Columns$3[]): Promise<void>;
|
|
6822
7017
|
}
|
|
6823
7018
|
|
|
6824
7019
|
/**
|
|
@@ -7256,8 +7451,8 @@ declare class HeatMarkdownService {
|
|
|
7256
7451
|
/** Logger service for debug output */
|
|
7257
7452
|
private readonly loggerService;
|
|
7258
7453
|
/**
|
|
7259
|
-
* Memoized function to get or create HeatmapStorage for
|
|
7260
|
-
* Each
|
|
7454
|
+
* Memoized function to get or create HeatmapStorage for exchange, frame and backtest mode.
|
|
7455
|
+
* Each exchangeName + frameName + backtest mode combination gets its own isolated heatmap storage instance.
|
|
7261
7456
|
*/
|
|
7262
7457
|
private getStorage;
|
|
7263
7458
|
/**
|
|
@@ -7270,16 +7465,17 @@ declare class HeatMarkdownService {
|
|
|
7270
7465
|
*/
|
|
7271
7466
|
private tick;
|
|
7272
7467
|
/**
|
|
7273
|
-
* Gets aggregated portfolio heatmap statistics
|
|
7468
|
+
* Gets aggregated portfolio heatmap statistics.
|
|
7274
7469
|
*
|
|
7275
|
-
* @param
|
|
7470
|
+
* @param exchangeName - Exchange name
|
|
7471
|
+
* @param frameName - Frame name
|
|
7276
7472
|
* @param backtest - True if backtest mode, false if live mode
|
|
7277
7473
|
* @returns Promise resolving to heatmap statistics with per-symbol and portfolio-wide metrics
|
|
7278
7474
|
*
|
|
7279
7475
|
* @example
|
|
7280
7476
|
* ```typescript
|
|
7281
7477
|
* const service = new HeatMarkdownService();
|
|
7282
|
-
* const stats = await service.getData("
|
|
7478
|
+
* const stats = await service.getData("binance", "frame1", true);
|
|
7283
7479
|
*
|
|
7284
7480
|
* console.log(`Total symbols: ${stats.totalSymbols}`);
|
|
7285
7481
|
* console.log(`Portfolio PNL: ${stats.portfolioTotalPnl}%`);
|
|
@@ -7289,11 +7485,13 @@ declare class HeatMarkdownService {
|
|
|
7289
7485
|
* });
|
|
7290
7486
|
* ```
|
|
7291
7487
|
*/
|
|
7292
|
-
getData: (
|
|
7488
|
+
getData: (exchangeName: string, frameName: string, backtest: boolean) => Promise<HeatmapStatisticsModel>;
|
|
7293
7489
|
/**
|
|
7294
|
-
* Generates markdown report with portfolio heatmap table
|
|
7490
|
+
* Generates markdown report with portfolio heatmap table.
|
|
7295
7491
|
*
|
|
7296
|
-
* @param strategyName - Strategy name
|
|
7492
|
+
* @param strategyName - Strategy name for report title
|
|
7493
|
+
* @param exchangeName - Exchange name
|
|
7494
|
+
* @param frameName - Frame name
|
|
7297
7495
|
* @param backtest - True if backtest mode, false if live mode
|
|
7298
7496
|
* @param columns - Column configuration for formatting the table
|
|
7299
7497
|
* @returns Promise resolving to markdown formatted report string
|
|
@@ -7301,7 +7499,7 @@ declare class HeatMarkdownService {
|
|
|
7301
7499
|
* @example
|
|
7302
7500
|
* ```typescript
|
|
7303
7501
|
* const service = new HeatMarkdownService();
|
|
7304
|
-
* const markdown = await service.getReport("my-strategy", true);
|
|
7502
|
+
* const markdown = await service.getReport("my-strategy", "binance", "frame1", true);
|
|
7305
7503
|
* console.log(markdown);
|
|
7306
7504
|
* // Output:
|
|
7307
7505
|
* // # Portfolio Heatmap: my-strategy
|
|
@@ -7315,14 +7513,16 @@ declare class HeatMarkdownService {
|
|
|
7315
7513
|
* // ...
|
|
7316
7514
|
* ```
|
|
7317
7515
|
*/
|
|
7318
|
-
getReport: (strategyName: StrategyName, backtest: boolean, columns?: Columns$2[]) => Promise<string>;
|
|
7516
|
+
getReport: (strategyName: StrategyName, exchangeName: string, frameName: string, backtest: boolean, columns?: Columns$2[]) => Promise<string>;
|
|
7319
7517
|
/**
|
|
7320
|
-
* Saves heatmap report to disk
|
|
7518
|
+
* Saves heatmap report to disk.
|
|
7321
7519
|
*
|
|
7322
7520
|
* Creates directory if it doesn't exist.
|
|
7323
7521
|
* Default filename: {strategyName}.md
|
|
7324
7522
|
*
|
|
7325
|
-
* @param strategyName - Strategy name
|
|
7523
|
+
* @param strategyName - Strategy name for report filename
|
|
7524
|
+
* @param exchangeName - Exchange name
|
|
7525
|
+
* @param frameName - Frame name
|
|
7326
7526
|
* @param backtest - True if backtest mode, false if live mode
|
|
7327
7527
|
* @param path - Optional directory path to save report (default: "./dump/heatmap")
|
|
7328
7528
|
* @param columns - Column configuration for formatting the table
|
|
@@ -7332,34 +7532,35 @@ declare class HeatMarkdownService {
|
|
|
7332
7532
|
* const service = new HeatMarkdownService();
|
|
7333
7533
|
*
|
|
7334
7534
|
* // Save to default path: ./dump/heatmap/my-strategy.md
|
|
7335
|
-
* await service.dump("my-strategy", true);
|
|
7535
|
+
* await service.dump("my-strategy", "binance", "frame1", true);
|
|
7336
7536
|
*
|
|
7337
7537
|
* // Save to custom path: ./reports/my-strategy.md
|
|
7338
|
-
* await service.dump("my-strategy", true, "./reports");
|
|
7538
|
+
* await service.dump("my-strategy", "binance", "frame1", true, "./reports");
|
|
7339
7539
|
* ```
|
|
7340
7540
|
*/
|
|
7341
|
-
dump: (strategyName: StrategyName, backtest: boolean, path?: string, columns?: Columns$2[]) => Promise<void>;
|
|
7541
|
+
dump: (strategyName: StrategyName, exchangeName: string, frameName: string, backtest: boolean, path?: string, columns?: Columns$2[]) => Promise<void>;
|
|
7342
7542
|
/**
|
|
7343
7543
|
* Clears accumulated heatmap data from storage.
|
|
7344
|
-
* If
|
|
7345
|
-
* If
|
|
7544
|
+
* If payload is provided, clears only that exchangeName+frameName+backtest combination's data.
|
|
7545
|
+
* If payload is omitted, clears all data.
|
|
7346
7546
|
*
|
|
7347
|
-
* @param
|
|
7348
|
-
* @param ctx - Optional context with strategyName to clear specific data
|
|
7547
|
+
* @param payload - Optional payload with exchangeName, frameName, backtest to clear specific data
|
|
7349
7548
|
*
|
|
7350
7549
|
* @example
|
|
7351
7550
|
* ```typescript
|
|
7352
7551
|
* const service = new HeatMarkdownService();
|
|
7353
7552
|
*
|
|
7354
|
-
* // Clear specific
|
|
7355
|
-
* await service.clear(
|
|
7553
|
+
* // Clear specific exchange+frame+backtest data
|
|
7554
|
+
* await service.clear({ exchangeName: "binance", frameName: "frame1", backtest: true });
|
|
7356
7555
|
*
|
|
7357
7556
|
* // Clear all data
|
|
7358
7557
|
* await service.clear();
|
|
7359
7558
|
* ```
|
|
7360
7559
|
*/
|
|
7361
|
-
clear: (
|
|
7362
|
-
|
|
7560
|
+
clear: (payload?: {
|
|
7561
|
+
exchangeName: string;
|
|
7562
|
+
frameName: string;
|
|
7563
|
+
backtest: boolean;
|
|
7363
7564
|
}) => Promise<void>;
|
|
7364
7565
|
/**
|
|
7365
7566
|
* Initializes the service by subscribing to signal events.
|
|
@@ -7406,11 +7607,16 @@ declare class HeatUtils {
|
|
|
7406
7607
|
* Data is automatically collected from all closed signals for the strategy.
|
|
7407
7608
|
*
|
|
7408
7609
|
* @param strategyName - Strategy name to get heatmap data for
|
|
7610
|
+
* @param context - Execution context with exchangeName and frameName
|
|
7611
|
+
* @param backtest - True if backtest mode, false if live mode (default: false)
|
|
7409
7612
|
* @returns Promise resolving to heatmap statistics object
|
|
7410
7613
|
*
|
|
7411
7614
|
* @example
|
|
7412
7615
|
* ```typescript
|
|
7413
|
-
* const stats = await Heat.getData("my-strategy"
|
|
7616
|
+
* const stats = await Heat.getData("my-strategy", {
|
|
7617
|
+
* exchangeName: "binance",
|
|
7618
|
+
* frameName: "frame1"
|
|
7619
|
+
* });
|
|
7414
7620
|
*
|
|
7415
7621
|
* console.log(`Total symbols: ${stats.totalSymbols}`);
|
|
7416
7622
|
* console.log(`Portfolio Total PNL: ${stats.portfolioTotalPnl}%`);
|
|
@@ -7422,7 +7628,10 @@ declare class HeatUtils {
|
|
|
7422
7628
|
* });
|
|
7423
7629
|
* ```
|
|
7424
7630
|
*/
|
|
7425
|
-
getData: (strategyName: StrategyName,
|
|
7631
|
+
getData: (strategyName: StrategyName, context: {
|
|
7632
|
+
exchangeName: string;
|
|
7633
|
+
frameName: string;
|
|
7634
|
+
}, backtest?: boolean) => Promise<HeatmapStatisticsModel>;
|
|
7426
7635
|
/**
|
|
7427
7636
|
* Generates markdown report with portfolio heatmap table for a strategy.
|
|
7428
7637
|
*
|
|
@@ -7430,12 +7639,17 @@ declare class HeatUtils {
|
|
|
7430
7639
|
* Symbols are sorted by Total PNL descending.
|
|
7431
7640
|
*
|
|
7432
7641
|
* @param strategyName - Strategy name to generate heatmap report for
|
|
7642
|
+
* @param context - Execution context with exchangeName and frameName
|
|
7643
|
+
* @param backtest - True if backtest mode, false if live mode (default: false)
|
|
7433
7644
|
* @param columns - Optional columns configuration for the report
|
|
7434
7645
|
* @returns Promise resolving to markdown formatted report string
|
|
7435
7646
|
*
|
|
7436
7647
|
* @example
|
|
7437
7648
|
* ```typescript
|
|
7438
|
-
* const markdown = await Heat.getReport("my-strategy"
|
|
7649
|
+
* const markdown = await Heat.getReport("my-strategy", {
|
|
7650
|
+
* exchangeName: "binance",
|
|
7651
|
+
* frameName: "frame1"
|
|
7652
|
+
* });
|
|
7439
7653
|
* console.log(markdown);
|
|
7440
7654
|
* // Output:
|
|
7441
7655
|
* // # Portfolio Heatmap: my-strategy
|
|
@@ -7449,7 +7663,10 @@ declare class HeatUtils {
|
|
|
7449
7663
|
* // ...
|
|
7450
7664
|
* ```
|
|
7451
7665
|
*/
|
|
7452
|
-
getReport: (strategyName: StrategyName,
|
|
7666
|
+
getReport: (strategyName: StrategyName, context: {
|
|
7667
|
+
exchangeName: string;
|
|
7668
|
+
frameName: string;
|
|
7669
|
+
}, backtest?: boolean, columns?: Columns$2[]) => Promise<string>;
|
|
7453
7670
|
/**
|
|
7454
7671
|
* Saves heatmap report to disk for a strategy.
|
|
7455
7672
|
*
|
|
@@ -7457,19 +7674,30 @@ declare class HeatUtils {
|
|
|
7457
7674
|
* Default filename: {strategyName}.md
|
|
7458
7675
|
*
|
|
7459
7676
|
* @param strategyName - Strategy name to save heatmap report for
|
|
7677
|
+
* @param context - Execution context with exchangeName and frameName
|
|
7678
|
+
* @param backtest - True if backtest mode, false if live mode (default: false)
|
|
7460
7679
|
* @param path - Optional directory path to save report (default: "./dump/heatmap")
|
|
7461
7680
|
* @param columns - Optional columns configuration for the report
|
|
7462
7681
|
*
|
|
7463
7682
|
* @example
|
|
7464
7683
|
* ```typescript
|
|
7465
7684
|
* // Save to default path: ./dump/heatmap/my-strategy.md
|
|
7466
|
-
* await Heat.dump("my-strategy"
|
|
7685
|
+
* await Heat.dump("my-strategy", {
|
|
7686
|
+
* exchangeName: "binance",
|
|
7687
|
+
* frameName: "frame1"
|
|
7688
|
+
* });
|
|
7467
7689
|
*
|
|
7468
7690
|
* // Save to custom path: ./reports/my-strategy.md
|
|
7469
|
-
* await Heat.dump("my-strategy",
|
|
7691
|
+
* await Heat.dump("my-strategy", {
|
|
7692
|
+
* exchangeName: "binance",
|
|
7693
|
+
* frameName: "frame1"
|
|
7694
|
+
* }, false, "./reports");
|
|
7470
7695
|
* ```
|
|
7471
7696
|
*/
|
|
7472
|
-
dump: (strategyName: StrategyName,
|
|
7697
|
+
dump: (strategyName: StrategyName, context: {
|
|
7698
|
+
exchangeName: string;
|
|
7699
|
+
frameName: string;
|
|
7700
|
+
}, backtest?: boolean, path?: string, columns?: Columns$2[]) => Promise<void>;
|
|
7473
7701
|
}
|
|
7474
7702
|
/**
|
|
7475
7703
|
* Singleton instance of HeatUtils for convenient heatmap operations.
|
|
@@ -7718,15 +7946,15 @@ declare class PartialMarkdownService {
|
|
|
7718
7946
|
/** Logger service for debug output */
|
|
7719
7947
|
private readonly loggerService;
|
|
7720
7948
|
/**
|
|
7721
|
-
* Memoized function to get or create ReportStorage for a symbol-strategy-backtest
|
|
7722
|
-
* Each
|
|
7949
|
+
* Memoized function to get or create ReportStorage for a symbol-strategy-exchange-frame-backtest combination.
|
|
7950
|
+
* Each combination gets its own isolated storage instance.
|
|
7723
7951
|
*/
|
|
7724
7952
|
private getStorage;
|
|
7725
7953
|
/**
|
|
7726
7954
|
* Processes profit events and accumulates them.
|
|
7727
7955
|
* Should be called from partialProfitSubject subscription.
|
|
7728
7956
|
*
|
|
7729
|
-
* @param data - Profit event data
|
|
7957
|
+
* @param data - Profit event data with frameName wrapper
|
|
7730
7958
|
*
|
|
7731
7959
|
* @example
|
|
7732
7960
|
* ```typescript
|
|
@@ -7739,7 +7967,7 @@ declare class PartialMarkdownService {
|
|
|
7739
7967
|
* Processes loss events and accumulates them.
|
|
7740
7968
|
* Should be called from partialLossSubject subscription.
|
|
7741
7969
|
*
|
|
7742
|
-
* @param data - Loss event data
|
|
7970
|
+
* @param data - Loss event data with frameName wrapper
|
|
7743
7971
|
*
|
|
7744
7972
|
* @example
|
|
7745
7973
|
* ```typescript
|
|
@@ -7754,23 +7982,27 @@ declare class PartialMarkdownService {
|
|
|
7754
7982
|
*
|
|
7755
7983
|
* @param symbol - Trading pair symbol to get data for
|
|
7756
7984
|
* @param strategyName - Strategy name to get data for
|
|
7985
|
+
* @param exchangeName - Exchange name
|
|
7986
|
+
* @param frameName - Frame name
|
|
7757
7987
|
* @param backtest - True if backtest mode, false if live mode
|
|
7758
7988
|
* @returns Statistical data object with all metrics
|
|
7759
7989
|
*
|
|
7760
7990
|
* @example
|
|
7761
7991
|
* ```typescript
|
|
7762
7992
|
* const service = new PartialMarkdownService();
|
|
7763
|
-
* const stats = await service.getData("BTCUSDT", "my-strategy", false);
|
|
7993
|
+
* const stats = await service.getData("BTCUSDT", "my-strategy", "binance", "1h", false);
|
|
7764
7994
|
* console.log(stats.totalProfit, stats.totalLoss);
|
|
7765
7995
|
* ```
|
|
7766
7996
|
*/
|
|
7767
|
-
getData: (symbol: string, strategyName: string, backtest: boolean) => Promise<PartialStatisticsModel>;
|
|
7997
|
+
getData: (symbol: string, strategyName: string, exchangeName: string, frameName: string, backtest: boolean) => Promise<PartialStatisticsModel>;
|
|
7768
7998
|
/**
|
|
7769
7999
|
* Generates markdown report with all partial events for a symbol-strategy pair.
|
|
7770
8000
|
* Delegates to ReportStorage.getReport().
|
|
7771
8001
|
*
|
|
7772
8002
|
* @param symbol - Trading pair symbol to generate report for
|
|
7773
8003
|
* @param strategyName - Strategy name to generate report for
|
|
8004
|
+
* @param exchangeName - Exchange name
|
|
8005
|
+
* @param frameName - Frame name
|
|
7774
8006
|
* @param backtest - True if backtest mode, false if live mode
|
|
7775
8007
|
* @param columns - Column configuration for formatting the table
|
|
7776
8008
|
* @returns Markdown formatted report string with table of all events
|
|
@@ -7778,11 +8010,11 @@ declare class PartialMarkdownService {
|
|
|
7778
8010
|
* @example
|
|
7779
8011
|
* ```typescript
|
|
7780
8012
|
* const service = new PartialMarkdownService();
|
|
7781
|
-
* const markdown = await service.getReport("BTCUSDT", "my-strategy", false);
|
|
8013
|
+
* const markdown = await service.getReport("BTCUSDT", "my-strategy", "binance", "1h", false);
|
|
7782
8014
|
* console.log(markdown);
|
|
7783
8015
|
* ```
|
|
7784
8016
|
*/
|
|
7785
|
-
getReport: (symbol: string, strategyName: string, backtest: boolean, columns?: Columns$1[]) => Promise<string>;
|
|
8017
|
+
getReport: (symbol: string, strategyName: string, exchangeName: string, frameName: string, backtest: boolean, columns?: Columns$1[]) => Promise<string>;
|
|
7786
8018
|
/**
|
|
7787
8019
|
* Saves symbol-strategy report to disk.
|
|
7788
8020
|
* Creates directory if it doesn't exist.
|
|
@@ -7790,6 +8022,8 @@ declare class PartialMarkdownService {
|
|
|
7790
8022
|
*
|
|
7791
8023
|
* @param symbol - Trading pair symbol to save report for
|
|
7792
8024
|
* @param strategyName - Strategy name to save report for
|
|
8025
|
+
* @param exchangeName - Exchange name
|
|
8026
|
+
* @param frameName - Frame name
|
|
7793
8027
|
* @param backtest - True if backtest mode, false if live mode
|
|
7794
8028
|
* @param path - Directory path to save report (default: "./dump/partial")
|
|
7795
8029
|
* @param columns - Column configuration for formatting the table
|
|
@@ -7799,35 +8033,37 @@ declare class PartialMarkdownService {
|
|
|
7799
8033
|
* const service = new PartialMarkdownService();
|
|
7800
8034
|
*
|
|
7801
8035
|
* // Save to default path: ./dump/partial/BTCUSDT_my-strategy.md
|
|
7802
|
-
* await service.dump("BTCUSDT", "my-strategy", false);
|
|
8036
|
+
* await service.dump("BTCUSDT", "my-strategy", "binance", "1h", false);
|
|
7803
8037
|
*
|
|
7804
8038
|
* // Save to custom path: ./custom/path/BTCUSDT_my-strategy.md
|
|
7805
|
-
* await service.dump("BTCUSDT", "my-strategy", false, "./custom/path");
|
|
8039
|
+
* await service.dump("BTCUSDT", "my-strategy", "binance", "1h", false, "./custom/path");
|
|
7806
8040
|
* ```
|
|
7807
8041
|
*/
|
|
7808
|
-
dump: (symbol: string, strategyName: string, backtest: boolean, path?: string, columns?: Columns$1[]) => Promise<void>;
|
|
8042
|
+
dump: (symbol: string, strategyName: string, exchangeName: string, frameName: string, backtest: boolean, path?: string, columns?: Columns$1[]) => Promise<void>;
|
|
7809
8043
|
/**
|
|
7810
8044
|
* Clears accumulated event data from storage.
|
|
7811
|
-
* If
|
|
8045
|
+
* If payload is provided, clears only that specific symbol-strategy-exchange-frame-backtest combination's data.
|
|
7812
8046
|
* If nothing is provided, clears all data.
|
|
7813
8047
|
*
|
|
7814
|
-
* @param
|
|
7815
|
-
* @param ctx - Optional context with symbol and strategyName
|
|
8048
|
+
* @param payload - Optional payload with symbol, strategyName, exchangeName, frameName, backtest
|
|
7816
8049
|
*
|
|
7817
8050
|
* @example
|
|
7818
8051
|
* ```typescript
|
|
7819
8052
|
* const service = new PartialMarkdownService();
|
|
7820
8053
|
*
|
|
7821
|
-
* // Clear specific
|
|
7822
|
-
* await service.clear(
|
|
8054
|
+
* // Clear specific combination
|
|
8055
|
+
* await service.clear({ symbol: "BTCUSDT", strategyName: "my-strategy", exchangeName: "binance", frameName: "1h", backtest: false });
|
|
7823
8056
|
*
|
|
7824
8057
|
* // Clear all data
|
|
7825
8058
|
* await service.clear();
|
|
7826
8059
|
* ```
|
|
7827
8060
|
*/
|
|
7828
|
-
clear: (
|
|
8061
|
+
clear: (payload?: {
|
|
7829
8062
|
symbol: string;
|
|
7830
8063
|
strategyName: string;
|
|
8064
|
+
exchangeName: string;
|
|
8065
|
+
frameName: string;
|
|
8066
|
+
backtest: boolean;
|
|
7831
8067
|
}) => Promise<void>;
|
|
7832
8068
|
/**
|
|
7833
8069
|
* Initializes the service by subscribing to partial profit/loss events.
|
|
@@ -7903,7 +8139,11 @@ declare class PartialUtils {
|
|
|
7903
8139
|
* }
|
|
7904
8140
|
* ```
|
|
7905
8141
|
*/
|
|
7906
|
-
getData: (symbol: string,
|
|
8142
|
+
getData: (symbol: string, context: {
|
|
8143
|
+
strategyName: string;
|
|
8144
|
+
exchangeName: string;
|
|
8145
|
+
frameName: string;
|
|
8146
|
+
}, backtest?: boolean) => Promise<PartialStatisticsModel>;
|
|
7907
8147
|
/**
|
|
7908
8148
|
* Generates markdown report with all partial profit/loss events for a symbol-strategy pair.
|
|
7909
8149
|
*
|
|
@@ -7943,7 +8183,11 @@ declare class PartialUtils {
|
|
|
7943
8183
|
* // **Loss events:** 1
|
|
7944
8184
|
* ```
|
|
7945
8185
|
*/
|
|
7946
|
-
getReport: (symbol: string,
|
|
8186
|
+
getReport: (symbol: string, context: {
|
|
8187
|
+
strategyName: string;
|
|
8188
|
+
exchangeName: string;
|
|
8189
|
+
frameName: string;
|
|
8190
|
+
}, backtest?: boolean, columns?: Columns$1[]) => Promise<string>;
|
|
7947
8191
|
/**
|
|
7948
8192
|
* Generates and saves markdown report to file.
|
|
7949
8193
|
*
|
|
@@ -7976,7 +8220,11 @@ declare class PartialUtils {
|
|
|
7976
8220
|
* }
|
|
7977
8221
|
* ```
|
|
7978
8222
|
*/
|
|
7979
|
-
dump: (symbol: string,
|
|
8223
|
+
dump: (symbol: string, context: {
|
|
8224
|
+
strategyName: string;
|
|
8225
|
+
exchangeName: string;
|
|
8226
|
+
frameName: string;
|
|
8227
|
+
}, backtest?: boolean, path?: string, columns?: Columns$1[]) => Promise<void>;
|
|
7980
8228
|
}
|
|
7981
8229
|
/**
|
|
7982
8230
|
* Global singleton instance of PartialUtils.
|
|
@@ -8130,15 +8378,15 @@ declare class RiskMarkdownService {
|
|
|
8130
8378
|
/** Logger service for debug output */
|
|
8131
8379
|
private readonly loggerService;
|
|
8132
8380
|
/**
|
|
8133
|
-
* Memoized function to get or create ReportStorage for a symbol-strategy-backtest
|
|
8134
|
-
* Each
|
|
8381
|
+
* Memoized function to get or create ReportStorage for a symbol-strategy-exchange-frame-backtest combination.
|
|
8382
|
+
* Each combination gets its own isolated storage instance.
|
|
8135
8383
|
*/
|
|
8136
8384
|
private getStorage;
|
|
8137
8385
|
/**
|
|
8138
8386
|
* Processes risk rejection events and accumulates them.
|
|
8139
8387
|
* Should be called from riskSubject subscription.
|
|
8140
8388
|
*
|
|
8141
|
-
* @param data - Risk rejection event data
|
|
8389
|
+
* @param data - Risk rejection event data with frameName wrapper
|
|
8142
8390
|
*
|
|
8143
8391
|
* @example
|
|
8144
8392
|
* ```typescript
|
|
@@ -8153,23 +8401,27 @@ declare class RiskMarkdownService {
|
|
|
8153
8401
|
*
|
|
8154
8402
|
* @param symbol - Trading pair symbol to get data for
|
|
8155
8403
|
* @param strategyName - Strategy name to get data for
|
|
8404
|
+
* @param exchangeName - Exchange name
|
|
8405
|
+
* @param frameName - Frame name
|
|
8156
8406
|
* @param backtest - True if backtest mode, false if live mode
|
|
8157
8407
|
* @returns Statistical data object with all metrics
|
|
8158
8408
|
*
|
|
8159
8409
|
* @example
|
|
8160
8410
|
* ```typescript
|
|
8161
8411
|
* const service = new RiskMarkdownService();
|
|
8162
|
-
* const stats = await service.getData("BTCUSDT", "my-strategy", false);
|
|
8412
|
+
* const stats = await service.getData("BTCUSDT", "my-strategy", "binance", "1h", false);
|
|
8163
8413
|
* console.log(stats.totalRejections, stats.bySymbol);
|
|
8164
8414
|
* ```
|
|
8165
8415
|
*/
|
|
8166
|
-
getData: (symbol: string, strategyName: string, backtest: boolean) => Promise<RiskStatisticsModel>;
|
|
8416
|
+
getData: (symbol: string, strategyName: string, exchangeName: string, frameName: string, backtest: boolean) => Promise<RiskStatisticsModel>;
|
|
8167
8417
|
/**
|
|
8168
8418
|
* Generates markdown report with all risk rejection events for a symbol-strategy pair.
|
|
8169
8419
|
* Delegates to ReportStorage.getReport().
|
|
8170
8420
|
*
|
|
8171
8421
|
* @param symbol - Trading pair symbol to generate report for
|
|
8172
8422
|
* @param strategyName - Strategy name to generate report for
|
|
8423
|
+
* @param exchangeName - Exchange name
|
|
8424
|
+
* @param frameName - Frame name
|
|
8173
8425
|
* @param backtest - True if backtest mode, false if live mode
|
|
8174
8426
|
* @param columns - Column configuration for formatting the table
|
|
8175
8427
|
* @returns Markdown formatted report string with table of all events
|
|
@@ -8177,11 +8429,11 @@ declare class RiskMarkdownService {
|
|
|
8177
8429
|
* @example
|
|
8178
8430
|
* ```typescript
|
|
8179
8431
|
* const service = new RiskMarkdownService();
|
|
8180
|
-
* const markdown = await service.getReport("BTCUSDT", "my-strategy", false);
|
|
8432
|
+
* const markdown = await service.getReport("BTCUSDT", "my-strategy", "binance", "1h", false);
|
|
8181
8433
|
* console.log(markdown);
|
|
8182
8434
|
* ```
|
|
8183
8435
|
*/
|
|
8184
|
-
getReport: (symbol: string, strategyName: string, backtest: boolean, columns?: Columns[]) => Promise<string>;
|
|
8436
|
+
getReport: (symbol: string, strategyName: string, exchangeName: string, frameName: string, backtest: boolean, columns?: Columns[]) => Promise<string>;
|
|
8185
8437
|
/**
|
|
8186
8438
|
* Saves symbol-strategy report to disk.
|
|
8187
8439
|
* Creates directory if it doesn't exist.
|
|
@@ -8189,6 +8441,8 @@ declare class RiskMarkdownService {
|
|
|
8189
8441
|
*
|
|
8190
8442
|
* @param symbol - Trading pair symbol to save report for
|
|
8191
8443
|
* @param strategyName - Strategy name to save report for
|
|
8444
|
+
* @param exchangeName - Exchange name
|
|
8445
|
+
* @param frameName - Frame name
|
|
8192
8446
|
* @param backtest - True if backtest mode, false if live mode
|
|
8193
8447
|
* @param path - Directory path to save report (default: "./dump/risk")
|
|
8194
8448
|
* @param columns - Column configuration for formatting the table
|
|
@@ -8198,35 +8452,37 @@ declare class RiskMarkdownService {
|
|
|
8198
8452
|
* const service = new RiskMarkdownService();
|
|
8199
8453
|
*
|
|
8200
8454
|
* // Save to default path: ./dump/risk/BTCUSDT_my-strategy.md
|
|
8201
|
-
* await service.dump("BTCUSDT", "my-strategy", false);
|
|
8455
|
+
* await service.dump("BTCUSDT", "my-strategy", "binance", "1h", false);
|
|
8202
8456
|
*
|
|
8203
8457
|
* // Save to custom path: ./custom/path/BTCUSDT_my-strategy.md
|
|
8204
|
-
* await service.dump("BTCUSDT", "my-strategy", false, "./custom/path");
|
|
8458
|
+
* await service.dump("BTCUSDT", "my-strategy", "binance", "1h", false, "./custom/path");
|
|
8205
8459
|
* ```
|
|
8206
8460
|
*/
|
|
8207
|
-
dump: (symbol: string, strategyName: string, backtest: boolean, path?: string, columns?: Columns[]) => Promise<void>;
|
|
8461
|
+
dump: (symbol: string, strategyName: string, exchangeName: string, frameName: string, backtest: boolean, path?: string, columns?: Columns[]) => Promise<void>;
|
|
8208
8462
|
/**
|
|
8209
8463
|
* Clears accumulated event data from storage.
|
|
8210
|
-
* If
|
|
8464
|
+
* If payload is provided, clears only that specific symbol-strategy-exchange-frame-backtest combination's data.
|
|
8211
8465
|
* If nothing is provided, clears all data.
|
|
8212
8466
|
*
|
|
8213
|
-
* @param
|
|
8214
|
-
* @param ctx - Optional context with symbol and strategyName
|
|
8467
|
+
* @param payload - Optional payload with symbol, strategyName, exchangeName, frameName, backtest
|
|
8215
8468
|
*
|
|
8216
8469
|
* @example
|
|
8217
8470
|
* ```typescript
|
|
8218
8471
|
* const service = new RiskMarkdownService();
|
|
8219
8472
|
*
|
|
8220
|
-
* // Clear specific
|
|
8221
|
-
* await service.clear(
|
|
8473
|
+
* // Clear specific combination
|
|
8474
|
+
* await service.clear({ symbol: "BTCUSDT", strategyName: "my-strategy", exchangeName: "binance", frameName: "1h", backtest: false });
|
|
8222
8475
|
*
|
|
8223
8476
|
* // Clear all data
|
|
8224
8477
|
* await service.clear();
|
|
8225
8478
|
* ```
|
|
8226
8479
|
*/
|
|
8227
|
-
clear: (
|
|
8480
|
+
clear: (payload?: {
|
|
8228
8481
|
symbol: string;
|
|
8229
8482
|
strategyName: string;
|
|
8483
|
+
exchangeName: string;
|
|
8484
|
+
frameName: string;
|
|
8485
|
+
backtest: boolean;
|
|
8230
8486
|
}) => Promise<void>;
|
|
8231
8487
|
/**
|
|
8232
8488
|
* Initializes the service by subscribing to risk rejection events.
|
|
@@ -8302,7 +8558,11 @@ declare class RiskUtils {
|
|
|
8302
8558
|
* }
|
|
8303
8559
|
* ```
|
|
8304
8560
|
*/
|
|
8305
|
-
getData: (symbol: string,
|
|
8561
|
+
getData: (symbol: string, context: {
|
|
8562
|
+
strategyName: string;
|
|
8563
|
+
exchangeName: string;
|
|
8564
|
+
frameName: string;
|
|
8565
|
+
}, backtest?: boolean) => Promise<RiskStatisticsModel>;
|
|
8306
8566
|
/**
|
|
8307
8567
|
* Generates markdown report with all risk rejection events for a symbol-strategy pair.
|
|
8308
8568
|
*
|
|
@@ -8344,7 +8604,11 @@ declare class RiskUtils {
|
|
|
8344
8604
|
* // - my-strategy: 1
|
|
8345
8605
|
* ```
|
|
8346
8606
|
*/
|
|
8347
|
-
getReport: (symbol: string,
|
|
8607
|
+
getReport: (symbol: string, context: {
|
|
8608
|
+
strategyName: string;
|
|
8609
|
+
exchangeName: string;
|
|
8610
|
+
frameName: string;
|
|
8611
|
+
}, backtest?: boolean, columns?: Columns[]) => Promise<string>;
|
|
8348
8612
|
/**
|
|
8349
8613
|
* Generates and saves markdown report to file.
|
|
8350
8614
|
*
|
|
@@ -8377,7 +8641,11 @@ declare class RiskUtils {
|
|
|
8377
8641
|
* }
|
|
8378
8642
|
* ```
|
|
8379
8643
|
*/
|
|
8380
|
-
dump: (symbol: string,
|
|
8644
|
+
dump: (symbol: string, context: {
|
|
8645
|
+
strategyName: string;
|
|
8646
|
+
exchangeName: string;
|
|
8647
|
+
frameName: string;
|
|
8648
|
+
}, backtest?: boolean, path?: string, columns?: Columns[]) => Promise<void>;
|
|
8381
8649
|
}
|
|
8382
8650
|
/**
|
|
8383
8651
|
* Global singleton instance of RiskUtils.
|
|
@@ -9209,6 +9477,7 @@ declare class ClientRisk implements IRisk {
|
|
|
9209
9477
|
addSignal(symbol: string, context: {
|
|
9210
9478
|
strategyName: string;
|
|
9211
9479
|
riskName: string;
|
|
9480
|
+
exchangeName: string;
|
|
9212
9481
|
}): Promise<void>;
|
|
9213
9482
|
/**
|
|
9214
9483
|
* Removes a closed signal.
|
|
@@ -9217,6 +9486,7 @@ declare class ClientRisk implements IRisk {
|
|
|
9217
9486
|
removeSignal(symbol: string, context: {
|
|
9218
9487
|
strategyName: string;
|
|
9219
9488
|
riskName: string;
|
|
9489
|
+
exchangeName: string;
|
|
9220
9490
|
}): Promise<void>;
|
|
9221
9491
|
/**
|
|
9222
9492
|
* Checks if a signal should be allowed based on risk limits.
|
|
@@ -9270,16 +9540,18 @@ declare class RiskConnectionService {
|
|
|
9270
9540
|
private readonly loggerService;
|
|
9271
9541
|
private readonly riskSchemaService;
|
|
9272
9542
|
/**
|
|
9273
|
-
* Retrieves memoized ClientRisk instance for given risk name and backtest mode.
|
|
9543
|
+
* Retrieves memoized ClientRisk instance for given risk name, exchange, frame and backtest mode.
|
|
9274
9544
|
*
|
|
9275
9545
|
* Creates ClientRisk on first call, returns cached instance on subsequent calls.
|
|
9276
|
-
* Cache key
|
|
9546
|
+
* Cache key includes exchangeName and frameName to isolate risk per exchange+frame.
|
|
9277
9547
|
*
|
|
9278
9548
|
* @param riskName - Name of registered risk schema
|
|
9549
|
+
* @param exchangeName - Exchange name
|
|
9550
|
+
* @param frameName - Frame name (empty string for live)
|
|
9279
9551
|
* @param backtest - True if backtest mode, false if live mode
|
|
9280
9552
|
* @returns Configured ClientRisk instance
|
|
9281
9553
|
*/
|
|
9282
|
-
getRisk: ((riskName: RiskName, backtest: boolean) => ClientRisk) & functools_kit.IClearableMemoize
|
|
9554
|
+
getRisk: ((riskName: RiskName, exchangeName: string, frameName: string, backtest: boolean) => ClientRisk) & functools_kit.IClearableMemoize<string> & functools_kit.IControlMemoize<string, ClientRisk>;
|
|
9283
9555
|
/**
|
|
9284
9556
|
* Checks if a signal should be allowed based on risk limits.
|
|
9285
9557
|
*
|
|
@@ -9288,11 +9560,13 @@ declare class RiskConnectionService {
|
|
|
9288
9560
|
* ClientRisk will emit riskSubject event via onRejected callback when signal is rejected.
|
|
9289
9561
|
*
|
|
9290
9562
|
* @param params - Risk check arguments (portfolio state, position details)
|
|
9291
|
-
* @param
|
|
9563
|
+
* @param payload - Execution payload with risk name, exchangeName, frameName and backtest mode
|
|
9292
9564
|
* @returns Promise resolving to risk check result
|
|
9293
9565
|
*/
|
|
9294
|
-
checkSignal: (params: IRiskCheckArgs,
|
|
9566
|
+
checkSignal: (params: IRiskCheckArgs, payload: {
|
|
9295
9567
|
riskName: RiskName;
|
|
9568
|
+
exchangeName: string;
|
|
9569
|
+
frameName: string;
|
|
9296
9570
|
backtest: boolean;
|
|
9297
9571
|
}) => Promise<boolean>;
|
|
9298
9572
|
/**
|
|
@@ -9300,11 +9574,13 @@ declare class RiskConnectionService {
|
|
|
9300
9574
|
* Routes to appropriate ClientRisk instance.
|
|
9301
9575
|
*
|
|
9302
9576
|
* @param symbol - Trading pair symbol
|
|
9303
|
-
* @param
|
|
9577
|
+
* @param payload - Payload information (strategyName, riskName, exchangeName, frameName, backtest)
|
|
9304
9578
|
*/
|
|
9305
|
-
addSignal: (symbol: string,
|
|
9579
|
+
addSignal: (symbol: string, payload: {
|
|
9306
9580
|
strategyName: string;
|
|
9307
9581
|
riskName: RiskName;
|
|
9582
|
+
exchangeName: string;
|
|
9583
|
+
frameName: string;
|
|
9308
9584
|
backtest: boolean;
|
|
9309
9585
|
}) => Promise<void>;
|
|
9310
9586
|
/**
|
|
@@ -9312,21 +9588,25 @@ declare class RiskConnectionService {
|
|
|
9312
9588
|
* Routes to appropriate ClientRisk instance.
|
|
9313
9589
|
*
|
|
9314
9590
|
* @param symbol - Trading pair symbol
|
|
9315
|
-
* @param
|
|
9591
|
+
* @param payload - Payload information (strategyName, riskName, exchangeName, frameName, backtest)
|
|
9316
9592
|
*/
|
|
9317
|
-
removeSignal: (symbol: string,
|
|
9593
|
+
removeSignal: (symbol: string, payload: {
|
|
9318
9594
|
strategyName: string;
|
|
9319
9595
|
riskName: RiskName;
|
|
9596
|
+
exchangeName: string;
|
|
9597
|
+
frameName: string;
|
|
9320
9598
|
backtest: boolean;
|
|
9321
9599
|
}) => Promise<void>;
|
|
9322
9600
|
/**
|
|
9323
9601
|
* Clears the cached ClientRisk instance for the given risk name.
|
|
9324
9602
|
*
|
|
9325
|
-
* @param
|
|
9326
|
-
* @param ctx - Optional context with riskName (clears all if not provided)
|
|
9603
|
+
* @param payload - Optional payload with riskName, exchangeName, frameName, backtest (clears all if not provided)
|
|
9327
9604
|
*/
|
|
9328
|
-
clear: (
|
|
9605
|
+
clear: (payload?: {
|
|
9329
9606
|
riskName: RiskName;
|
|
9607
|
+
exchangeName: string;
|
|
9608
|
+
frameName: string;
|
|
9609
|
+
backtest: boolean;
|
|
9330
9610
|
}) => Promise<void>;
|
|
9331
9611
|
}
|
|
9332
9612
|
|
|
@@ -9455,18 +9735,18 @@ declare class StrategyConnectionService {
|
|
|
9455
9735
|
readonly strategySchemaService: StrategySchemaService;
|
|
9456
9736
|
readonly riskConnectionService: RiskConnectionService;
|
|
9457
9737
|
readonly exchangeConnectionService: ExchangeConnectionService;
|
|
9458
|
-
readonly methodContextService: {
|
|
9459
|
-
readonly context: IMethodContext;
|
|
9460
|
-
};
|
|
9461
9738
|
readonly partialConnectionService: PartialConnectionService;
|
|
9462
9739
|
/**
|
|
9463
|
-
* Retrieves memoized ClientStrategy instance for given symbol-strategy pair.
|
|
9740
|
+
* Retrieves memoized ClientStrategy instance for given symbol-strategy pair with exchange and frame isolation.
|
|
9464
9741
|
*
|
|
9465
9742
|
* Creates ClientStrategy on first call, returns cached instance on subsequent calls.
|
|
9466
|
-
* Cache key
|
|
9743
|
+
* Cache key includes exchangeName and frameName for proper isolation.
|
|
9467
9744
|
*
|
|
9468
9745
|
* @param symbol - Trading pair symbol
|
|
9469
9746
|
* @param strategyName - Name of registered strategy schema
|
|
9747
|
+
* @param exchangeName - Exchange name
|
|
9748
|
+
* @param frameName - Frame name (empty string for live)
|
|
9749
|
+
* @param backtest - Whether running in backtest mode
|
|
9470
9750
|
* @returns Configured ClientStrategy instance
|
|
9471
9751
|
*/
|
|
9472
9752
|
private getStrategy;
|
|
@@ -9475,34 +9755,49 @@ declare class StrategyConnectionService {
|
|
|
9475
9755
|
* If no active signal exists, returns null.
|
|
9476
9756
|
* Used internally for monitoring TP/SL and time expiration.
|
|
9477
9757
|
*
|
|
9758
|
+
* @param backtest - Whether running in backtest mode
|
|
9478
9759
|
* @param symbol - Trading pair symbol
|
|
9479
|
-
* @param
|
|
9760
|
+
* @param context - Execution context with strategyName, exchangeName, frameName
|
|
9480
9761
|
*
|
|
9481
9762
|
* @returns Promise resolving to pending signal or null
|
|
9482
9763
|
*/
|
|
9483
|
-
getPendingSignal: (backtest: boolean, symbol: string,
|
|
9764
|
+
getPendingSignal: (backtest: boolean, symbol: string, context: {
|
|
9765
|
+
strategyName: StrategyName;
|
|
9766
|
+
exchangeName: string;
|
|
9767
|
+
frameName: string;
|
|
9768
|
+
}) => Promise<ISignalRow | null>;
|
|
9484
9769
|
/**
|
|
9485
9770
|
* Retrieves the currently active scheduled signal for the strategy.
|
|
9486
9771
|
* If no scheduled signal exists, returns null.
|
|
9487
9772
|
* Used internally for monitoring scheduled signal activation.
|
|
9488
9773
|
*
|
|
9774
|
+
* @param backtest - Whether running in backtest mode
|
|
9489
9775
|
* @param symbol - Trading pair symbol
|
|
9490
|
-
* @param
|
|
9776
|
+
* @param context - Execution context with strategyName, exchangeName, frameName
|
|
9491
9777
|
*
|
|
9492
9778
|
* @returns Promise resolving to scheduled signal or null
|
|
9493
9779
|
*/
|
|
9494
|
-
getScheduledSignal: (backtest: boolean, symbol: string,
|
|
9780
|
+
getScheduledSignal: (backtest: boolean, symbol: string, context: {
|
|
9781
|
+
strategyName: StrategyName;
|
|
9782
|
+
exchangeName: string;
|
|
9783
|
+
frameName: string;
|
|
9784
|
+
}) => Promise<IScheduledSignalRow | null>;
|
|
9495
9785
|
/**
|
|
9496
9786
|
* Retrieves the stopped state of the strategy.
|
|
9497
9787
|
*
|
|
9498
9788
|
* Delegates to the underlying strategy instance to check if it has been
|
|
9499
9789
|
* marked as stopped and should cease operation.
|
|
9500
9790
|
*
|
|
9791
|
+
* @param backtest - Whether running in backtest mode
|
|
9501
9792
|
* @param symbol - Trading pair symbol
|
|
9502
|
-
* @param
|
|
9793
|
+
* @param context - Execution context with strategyName, exchangeName, frameName
|
|
9503
9794
|
* @returns Promise resolving to true if strategy is stopped, false otherwise
|
|
9504
9795
|
*/
|
|
9505
|
-
getStopped: (backtest: boolean, symbol: string,
|
|
9796
|
+
getStopped: (backtest: boolean, symbol: string, context: {
|
|
9797
|
+
strategyName: StrategyName;
|
|
9798
|
+
exchangeName: string;
|
|
9799
|
+
frameName: string;
|
|
9800
|
+
}) => Promise<boolean>;
|
|
9506
9801
|
/**
|
|
9507
9802
|
* Executes live trading tick for current strategy.
|
|
9508
9803
|
*
|
|
@@ -9510,10 +9805,14 @@ declare class StrategyConnectionService {
|
|
|
9510
9805
|
* Evaluates current market conditions and returns signal state.
|
|
9511
9806
|
*
|
|
9512
9807
|
* @param symbol - Trading pair symbol
|
|
9513
|
-
* @param
|
|
9808
|
+
* @param context - Execution context with strategyName, exchangeName, frameName
|
|
9514
9809
|
* @returns Promise resolving to tick result (idle, opened, active, closed)
|
|
9515
9810
|
*/
|
|
9516
|
-
tick: (symbol: string,
|
|
9811
|
+
tick: (symbol: string, context: {
|
|
9812
|
+
strategyName: StrategyName;
|
|
9813
|
+
exchangeName: string;
|
|
9814
|
+
frameName: string;
|
|
9815
|
+
}) => Promise<IStrategyTickResult>;
|
|
9517
9816
|
/**
|
|
9518
9817
|
* Executes backtest for current strategy with provided candles.
|
|
9519
9818
|
*
|
|
@@ -9521,24 +9820,30 @@ declare class StrategyConnectionService {
|
|
|
9521
9820
|
* Evaluates strategy signals against historical data.
|
|
9522
9821
|
*
|
|
9523
9822
|
* @param symbol - Trading pair symbol
|
|
9524
|
-
* @param
|
|
9823
|
+
* @param context - Execution context with strategyName, exchangeName, frameName
|
|
9525
9824
|
* @param candles - Array of historical candle data to backtest
|
|
9526
9825
|
* @returns Promise resolving to backtest result (signal or idle)
|
|
9527
9826
|
*/
|
|
9528
|
-
backtest: (symbol: string,
|
|
9827
|
+
backtest: (symbol: string, context: {
|
|
9828
|
+
strategyName: StrategyName;
|
|
9829
|
+
exchangeName: string;
|
|
9830
|
+
frameName: string;
|
|
9831
|
+
}, candles: ICandleData[]) => Promise<IStrategyBacktestResult>;
|
|
9529
9832
|
/**
|
|
9530
9833
|
* Stops the specified strategy from generating new signals.
|
|
9531
9834
|
*
|
|
9532
9835
|
* Delegates to ClientStrategy.stop() which sets internal flag to prevent
|
|
9533
9836
|
* getSignal from being called on subsequent ticks.
|
|
9534
9837
|
*
|
|
9838
|
+
* @param backtest - Whether running in backtest mode
|
|
9535
9839
|
* @param symbol - Trading pair symbol
|
|
9536
|
-
* @param
|
|
9840
|
+
* @param ctx - Context with strategyName, exchangeName, frameName
|
|
9537
9841
|
* @returns Promise that resolves when stop flag is set
|
|
9538
9842
|
*/
|
|
9539
|
-
stop: (backtest: boolean,
|
|
9540
|
-
symbol: string;
|
|
9843
|
+
stop: (backtest: boolean, symbol: string, context: {
|
|
9541
9844
|
strategyName: StrategyName;
|
|
9845
|
+
exchangeName: string;
|
|
9846
|
+
frameName: string;
|
|
9542
9847
|
}) => Promise<void>;
|
|
9543
9848
|
/**
|
|
9544
9849
|
* Clears the memoized ClientStrategy instance from cache.
|
|
@@ -9546,11 +9851,14 @@ declare class StrategyConnectionService {
|
|
|
9546
9851
|
* Forces re-initialization of strategy on next getStrategy call.
|
|
9547
9852
|
* Useful for resetting strategy state or releasing resources.
|
|
9548
9853
|
*
|
|
9549
|
-
* @param
|
|
9854
|
+
* @param payload - Optional payload with symbol, context and backtest flag (clears all if not provided)
|
|
9550
9855
|
*/
|
|
9551
|
-
clear: (
|
|
9856
|
+
clear: (payload?: {
|
|
9552
9857
|
symbol: string;
|
|
9553
9858
|
strategyName: StrategyName;
|
|
9859
|
+
exchangeName: string;
|
|
9860
|
+
frameName: string;
|
|
9861
|
+
backtest: boolean;
|
|
9554
9862
|
}) => Promise<void>;
|
|
9555
9863
|
/**
|
|
9556
9864
|
* Cancels the scheduled signal for the specified strategy.
|
|
@@ -9562,13 +9870,15 @@ declare class StrategyConnectionService {
|
|
|
9562
9870
|
* detects the scheduled signal was cancelled.
|
|
9563
9871
|
*
|
|
9564
9872
|
* @param backtest - Whether running in backtest mode
|
|
9565
|
-
* @param
|
|
9873
|
+
* @param symbol - Trading pair symbol
|
|
9874
|
+
* @param ctx - Context with strategyName, exchangeName, frameName
|
|
9566
9875
|
* @param cancelId - Optional cancellation ID for user-initiated cancellations
|
|
9567
9876
|
* @returns Promise that resolves when scheduled signal is cancelled
|
|
9568
9877
|
*/
|
|
9569
|
-
cancel: (backtest: boolean,
|
|
9570
|
-
symbol: string;
|
|
9878
|
+
cancel: (backtest: boolean, symbol: string, context: {
|
|
9571
9879
|
strategyName: StrategyName;
|
|
9880
|
+
exchangeName: string;
|
|
9881
|
+
frameName: string;
|
|
9572
9882
|
}, cancelId?: string) => Promise<void>;
|
|
9573
9883
|
}
|
|
9574
9884
|
|
|
@@ -9814,7 +10124,6 @@ declare class StrategyCoreService {
|
|
|
9814
10124
|
private readonly strategySchemaService;
|
|
9815
10125
|
private readonly riskValidationService;
|
|
9816
10126
|
private readonly strategyValidationService;
|
|
9817
|
-
private readonly methodContextService;
|
|
9818
10127
|
/**
|
|
9819
10128
|
* Validates strategy and associated risk configuration.
|
|
9820
10129
|
*
|
|
@@ -9830,32 +10139,47 @@ declare class StrategyCoreService {
|
|
|
9830
10139
|
* If no active signal exists, returns null.
|
|
9831
10140
|
* Used internally for monitoring TP/SL and time expiration.
|
|
9832
10141
|
*
|
|
10142
|
+
* @param backtest - Whether running in backtest mode
|
|
9833
10143
|
* @param symbol - Trading pair symbol
|
|
9834
|
-
* @param
|
|
10144
|
+
* @param context - Execution context with strategyName, exchangeName, frameName
|
|
9835
10145
|
* @returns Promise resolving to pending signal or null
|
|
9836
10146
|
*/
|
|
9837
|
-
getPendingSignal: (backtest: boolean, symbol: string,
|
|
10147
|
+
getPendingSignal: (backtest: boolean, symbol: string, context: {
|
|
10148
|
+
strategyName: StrategyName;
|
|
10149
|
+
exchangeName: string;
|
|
10150
|
+
frameName: string;
|
|
10151
|
+
}) => Promise<ISignalRow | null>;
|
|
9838
10152
|
/**
|
|
9839
10153
|
* Retrieves the currently active scheduled signal for the symbol.
|
|
9840
10154
|
* If no scheduled signal exists, returns null.
|
|
9841
10155
|
* Used internally for monitoring scheduled signal activation.
|
|
9842
10156
|
*
|
|
10157
|
+
* @param backtest - Whether running in backtest mode
|
|
9843
10158
|
* @param symbol - Trading pair symbol
|
|
9844
|
-
* @param
|
|
10159
|
+
* @param context - Execution context with strategyName, exchangeName, frameName
|
|
9845
10160
|
* @returns Promise resolving to scheduled signal or null
|
|
9846
10161
|
*/
|
|
9847
|
-
getScheduledSignal: (backtest: boolean, symbol: string,
|
|
10162
|
+
getScheduledSignal: (backtest: boolean, symbol: string, context: {
|
|
10163
|
+
strategyName: StrategyName;
|
|
10164
|
+
exchangeName: string;
|
|
10165
|
+
frameName: string;
|
|
10166
|
+
}) => Promise<IScheduledSignalRow | null>;
|
|
9848
10167
|
/**
|
|
9849
10168
|
* Checks if the strategy has been stopped.
|
|
9850
10169
|
*
|
|
9851
10170
|
* Validates strategy existence and delegates to connection service
|
|
9852
10171
|
* to retrieve the stopped state from the strategy instance.
|
|
9853
10172
|
*
|
|
10173
|
+
* @param backtest - Whether running in backtest mode
|
|
9854
10174
|
* @param symbol - Trading pair symbol
|
|
9855
|
-
* @param
|
|
10175
|
+
* @param context - Execution context with strategyName, exchangeName, frameName
|
|
9856
10176
|
* @returns Promise resolving to true if strategy is stopped, false otherwise
|
|
9857
10177
|
*/
|
|
9858
|
-
getStopped: (backtest: boolean, symbol: string,
|
|
10178
|
+
getStopped: (backtest: boolean, symbol: string, context: {
|
|
10179
|
+
strategyName: StrategyName;
|
|
10180
|
+
exchangeName: string;
|
|
10181
|
+
frameName: string;
|
|
10182
|
+
}) => Promise<boolean>;
|
|
9859
10183
|
/**
|
|
9860
10184
|
* Checks signal status at a specific timestamp.
|
|
9861
10185
|
*
|
|
@@ -9865,9 +10189,14 @@ declare class StrategyCoreService {
|
|
|
9865
10189
|
* @param symbol - Trading pair symbol
|
|
9866
10190
|
* @param when - Timestamp for tick evaluation
|
|
9867
10191
|
* @param backtest - Whether running in backtest mode
|
|
10192
|
+
* @param context - Execution context with strategyName, exchangeName, frameName
|
|
9868
10193
|
* @returns Discriminated union of tick result (idle, opened, active, closed)
|
|
9869
10194
|
*/
|
|
9870
|
-
tick: (symbol: string, when: Date, backtest: boolean
|
|
10195
|
+
tick: (symbol: string, when: Date, backtest: boolean, context: {
|
|
10196
|
+
strategyName: StrategyName;
|
|
10197
|
+
exchangeName: string;
|
|
10198
|
+
frameName: string;
|
|
10199
|
+
}) => Promise<IStrategyTickResult>;
|
|
9871
10200
|
/**
|
|
9872
10201
|
* Runs fast backtest against candle array.
|
|
9873
10202
|
*
|
|
@@ -9878,22 +10207,29 @@ declare class StrategyCoreService {
|
|
|
9878
10207
|
* @param candles - Array of historical candles to test against
|
|
9879
10208
|
* @param when - Starting timestamp for backtest
|
|
9880
10209
|
* @param backtest - Whether running in backtest mode (typically true)
|
|
10210
|
+
* @param context - Execution context with strategyName, exchangeName, frameName
|
|
9881
10211
|
* @returns Closed signal result with PNL
|
|
9882
10212
|
*/
|
|
9883
|
-
backtest: (symbol: string, candles: ICandleData[], when: Date, backtest: boolean
|
|
10213
|
+
backtest: (symbol: string, candles: ICandleData[], when: Date, backtest: boolean, context: {
|
|
10214
|
+
strategyName: StrategyName;
|
|
10215
|
+
exchangeName: string;
|
|
10216
|
+
frameName: string;
|
|
10217
|
+
}) => Promise<IStrategyBacktestResult>;
|
|
9884
10218
|
/**
|
|
9885
10219
|
* Stops the strategy from generating new signals.
|
|
9886
10220
|
*
|
|
9887
10221
|
* Delegates to StrategyConnectionService.stop() to set internal flag.
|
|
9888
10222
|
* Does not require execution context.
|
|
9889
10223
|
*
|
|
10224
|
+
* @param backtest - Whether running in backtest mode
|
|
9890
10225
|
* @param symbol - Trading pair symbol
|
|
9891
|
-
* @param
|
|
10226
|
+
* @param ctx - Context with strategyName, exchangeName, frameName
|
|
9892
10227
|
* @returns Promise that resolves when stop flag is set
|
|
9893
10228
|
*/
|
|
9894
|
-
stop: (backtest: boolean,
|
|
9895
|
-
symbol: string;
|
|
10229
|
+
stop: (backtest: boolean, symbol: string, context: {
|
|
9896
10230
|
strategyName: StrategyName;
|
|
10231
|
+
exchangeName: string;
|
|
10232
|
+
frameName: string;
|
|
9897
10233
|
}) => Promise<void>;
|
|
9898
10234
|
/**
|
|
9899
10235
|
* Cancels the scheduled signal without stopping the strategy.
|
|
@@ -9903,13 +10239,15 @@ declare class StrategyCoreService {
|
|
|
9903
10239
|
* Does not require execution context.
|
|
9904
10240
|
*
|
|
9905
10241
|
* @param backtest - Whether running in backtest mode
|
|
9906
|
-
* @param
|
|
10242
|
+
* @param symbol - Trading pair symbol
|
|
10243
|
+
* @param ctx - Context with strategyName, exchangeName, frameName
|
|
9907
10244
|
* @param cancelId - Optional cancellation ID for user-initiated cancellations
|
|
9908
10245
|
* @returns Promise that resolves when scheduled signal is cancelled
|
|
9909
10246
|
*/
|
|
9910
|
-
cancel: (backtest: boolean,
|
|
9911
|
-
symbol: string;
|
|
10247
|
+
cancel: (backtest: boolean, symbol: string, context: {
|
|
9912
10248
|
strategyName: StrategyName;
|
|
10249
|
+
exchangeName: string;
|
|
10250
|
+
frameName: string;
|
|
9913
10251
|
}, cancelId?: string) => Promise<void>;
|
|
9914
10252
|
/**
|
|
9915
10253
|
* Clears the memoized ClientStrategy instance from cache.
|
|
@@ -9917,11 +10255,14 @@ declare class StrategyCoreService {
|
|
|
9917
10255
|
* Delegates to StrategyConnectionService.clear() to remove strategy from cache.
|
|
9918
10256
|
* Forces re-initialization of strategy on next operation.
|
|
9919
10257
|
*
|
|
9920
|
-
* @param
|
|
10258
|
+
* @param payload - Optional payload with symbol, context and backtest flag (clears all if not provided)
|
|
9921
10259
|
*/
|
|
9922
|
-
clear: (
|
|
10260
|
+
clear: (payload?: {
|
|
9923
10261
|
symbol: string;
|
|
9924
10262
|
strategyName: StrategyName;
|
|
10263
|
+
exchangeName: string;
|
|
10264
|
+
frameName: string;
|
|
10265
|
+
backtest: boolean;
|
|
9925
10266
|
}) => Promise<void>;
|
|
9926
10267
|
}
|
|
9927
10268
|
|
|
@@ -9988,44 +10329,52 @@ declare class RiskGlobalService {
|
|
|
9988
10329
|
* Checks if a signal should be allowed based on risk limits.
|
|
9989
10330
|
*
|
|
9990
10331
|
* @param params - Risk check arguments (portfolio state, position details)
|
|
9991
|
-
* @param
|
|
10332
|
+
* @param payload - Execution payload with risk name, exchangeName, frameName and backtest mode
|
|
9992
10333
|
* @returns Promise resolving to risk check result
|
|
9993
10334
|
*/
|
|
9994
|
-
checkSignal: (params: IRiskCheckArgs,
|
|
10335
|
+
checkSignal: (params: IRiskCheckArgs, payload: {
|
|
9995
10336
|
riskName: RiskName;
|
|
10337
|
+
exchangeName: string;
|
|
10338
|
+
frameName: string;
|
|
9996
10339
|
backtest: boolean;
|
|
9997
10340
|
}) => Promise<boolean>;
|
|
9998
10341
|
/**
|
|
9999
10342
|
* Registers an opened signal with the risk management system.
|
|
10000
10343
|
*
|
|
10001
10344
|
* @param symbol - Trading pair symbol
|
|
10002
|
-
* @param
|
|
10345
|
+
* @param payload - Payload information (strategyName, riskName, exchangeName, frameName, backtest)
|
|
10003
10346
|
*/
|
|
10004
|
-
addSignal: (symbol: string,
|
|
10347
|
+
addSignal: (symbol: string, payload: {
|
|
10005
10348
|
strategyName: string;
|
|
10006
10349
|
riskName: RiskName;
|
|
10350
|
+
exchangeName: string;
|
|
10351
|
+
frameName: string;
|
|
10007
10352
|
backtest: boolean;
|
|
10008
10353
|
}) => Promise<void>;
|
|
10009
10354
|
/**
|
|
10010
10355
|
* Removes a closed signal from the risk management system.
|
|
10011
10356
|
*
|
|
10012
10357
|
* @param symbol - Trading pair symbol
|
|
10013
|
-
* @param
|
|
10358
|
+
* @param payload - Payload information (strategyName, riskName, exchangeName, frameName, backtest)
|
|
10014
10359
|
*/
|
|
10015
|
-
removeSignal: (symbol: string,
|
|
10360
|
+
removeSignal: (symbol: string, payload: {
|
|
10016
10361
|
strategyName: string;
|
|
10017
10362
|
riskName: RiskName;
|
|
10363
|
+
exchangeName: string;
|
|
10364
|
+
frameName: string;
|
|
10018
10365
|
backtest: boolean;
|
|
10019
10366
|
}) => Promise<void>;
|
|
10020
10367
|
/**
|
|
10021
10368
|
* Clears risk data.
|
|
10022
|
-
* If
|
|
10023
|
-
* If no
|
|
10024
|
-
* @param
|
|
10025
|
-
* @param ctx - Optional context with riskName (clears all if not provided)
|
|
10369
|
+
* If payload is provided, clears data for that specific risk instance.
|
|
10370
|
+
* If no payload is provided, clears all risk data.
|
|
10371
|
+
* @param payload - Optional payload with riskName, exchangeName, frameName, backtest (clears all if not provided)
|
|
10026
10372
|
*/
|
|
10027
|
-
clear: (
|
|
10373
|
+
clear: (payload?: {
|
|
10028
10374
|
riskName: RiskName;
|
|
10375
|
+
exchangeName: string;
|
|
10376
|
+
frameName: string;
|
|
10377
|
+
backtest: boolean;
|
|
10029
10378
|
}) => Promise<void>;
|
|
10030
10379
|
}
|
|
10031
10380
|
|