backtest-kit 6.7.0 → 6.8.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 +4182 -3993
- package/build/index.mjs +4181 -3994
- package/package.json +3 -2
- package/types.d.ts +1193 -864
package/types.d.ts
CHANGED
|
@@ -272,6 +272,8 @@ interface IRiskParams extends IRiskSchema {
|
|
|
272
272
|
exchangeName: ExchangeName;
|
|
273
273
|
/** Logger service for debug output */
|
|
274
274
|
logger: ILogger;
|
|
275
|
+
/** Execution context service (symbol, when, backtest flag) */
|
|
276
|
+
execution: TExecutionContextService;
|
|
275
277
|
/** True if backtest mode, false if live mode */
|
|
276
278
|
backtest: boolean;
|
|
277
279
|
/**
|
|
@@ -1321,6 +1323,47 @@ type SignalSyncContract = SignalOpenContract | SignalCloseContract;
|
|
|
1321
1323
|
* ```
|
|
1322
1324
|
*/
|
|
1323
1325
|
type TActionCtor = new (strategyName: StrategyName, frameName: FrameName, actionName: ActionName, backtest: boolean) => Partial<IPublicAction>;
|
|
1326
|
+
/**
|
|
1327
|
+
* Strategy query interface exposed to action handlers via IActionParams.strategy.
|
|
1328
|
+
*
|
|
1329
|
+
* Provides read-only access to the current signal state needed for
|
|
1330
|
+
* guard checks inside ActionProxy before invoking user callbacks.
|
|
1331
|
+
*
|
|
1332
|
+
* Used by:
|
|
1333
|
+
* - ActionProxy.breakevenAvailable — skips if no pending signal
|
|
1334
|
+
* - ActionProxy.partialProfitAvailable — skips if no pending signal
|
|
1335
|
+
* - ActionProxy.partialLossAvailable — skips if no pending signal
|
|
1336
|
+
* - ActionProxy.pingActive — skips if no pending signal
|
|
1337
|
+
* - ActionProxy.pingScheduled — skips if no scheduled signal
|
|
1338
|
+
*/
|
|
1339
|
+
interface IActionStrategy {
|
|
1340
|
+
/**
|
|
1341
|
+
* Checks if there is an active pending signal (open position) for the symbol.
|
|
1342
|
+
*
|
|
1343
|
+
* @param backtest - Whether running in backtest mode
|
|
1344
|
+
* @param symbol - Trading pair symbol
|
|
1345
|
+
* @param context - Execution context with strategyName, exchangeName, frameName
|
|
1346
|
+
* @returns Promise resolving to true if a pending signal exists, false otherwise
|
|
1347
|
+
*/
|
|
1348
|
+
hasPendingSignal(backtest: boolean, symbol: string, context: {
|
|
1349
|
+
strategyName: StrategyName;
|
|
1350
|
+
exchangeName: ExchangeName;
|
|
1351
|
+
frameName: FrameName;
|
|
1352
|
+
}): Promise<boolean>;
|
|
1353
|
+
/**
|
|
1354
|
+
* Checks if there is a waiting scheduled signal for the symbol.
|
|
1355
|
+
*
|
|
1356
|
+
* @param backtest - Whether running in backtest mode
|
|
1357
|
+
* @param symbol - Trading pair symbol
|
|
1358
|
+
* @param context - Execution context with strategyName, exchangeName, frameName
|
|
1359
|
+
* @returns Promise resolving to true if a scheduled signal exists, false otherwise
|
|
1360
|
+
*/
|
|
1361
|
+
hasScheduledSignal(backtest: boolean, symbol: string, context: {
|
|
1362
|
+
strategyName: StrategyName;
|
|
1363
|
+
exchangeName: ExchangeName;
|
|
1364
|
+
frameName: FrameName;
|
|
1365
|
+
}): Promise<boolean>;
|
|
1366
|
+
}
|
|
1324
1367
|
/**
|
|
1325
1368
|
* Action parameters passed to ClientAction constructor.
|
|
1326
1369
|
* Combines schema with runtime dependencies and execution context.
|
|
@@ -1355,6 +1398,8 @@ interface IActionParams extends IActionSchema {
|
|
|
1355
1398
|
frameName: FrameName;
|
|
1356
1399
|
/** Whether running in backtest mode */
|
|
1357
1400
|
backtest: boolean;
|
|
1401
|
+
/** Strategy context object providing access to current signal and position state */
|
|
1402
|
+
strategy: IActionStrategy;
|
|
1358
1403
|
}
|
|
1359
1404
|
/**
|
|
1360
1405
|
* Lifecycle and event callbacks for action handlers.
|
|
@@ -12151,52 +12196,56 @@ declare class PersistMemoryUtils {
|
|
|
12151
12196
|
*/
|
|
12152
12197
|
declare const PersistMemoryAdapter: PersistMemoryUtils;
|
|
12153
12198
|
|
|
12154
|
-
/** Symbol key for the singleshot waitForInit function on ReportBase instances. */
|
|
12155
|
-
declare const WAIT_FOR_INIT_SYMBOL$1: unique symbol;
|
|
12156
|
-
/** Symbol key for the timeout-protected write function on ReportBase instances. */
|
|
12157
|
-
declare const WRITE_SAFE_SYMBOL$1: unique symbol;
|
|
12158
12199
|
/**
|
|
12159
|
-
* Configuration interface for selective
|
|
12160
|
-
* Controls which report services should be activated
|
|
12200
|
+
* Configuration interface for selective markdown service enablement.
|
|
12201
|
+
* Controls which markdown report services should be activated.
|
|
12161
12202
|
*/
|
|
12162
|
-
interface
|
|
12163
|
-
/** Enable strategy
|
|
12203
|
+
interface IMarkdownTarget {
|
|
12204
|
+
/** Enable strategy event tracking reports (entry/exit signals) */
|
|
12164
12205
|
strategy: boolean;
|
|
12165
|
-
/** Enable risk rejection
|
|
12206
|
+
/** Enable risk rejection tracking reports (signals blocked by risk limits) */
|
|
12166
12207
|
risk: boolean;
|
|
12167
|
-
/** Enable breakeven event
|
|
12208
|
+
/** Enable breakeven event tracking reports (when stop loss moves to entry) */
|
|
12168
12209
|
breakeven: boolean;
|
|
12169
|
-
/** Enable partial
|
|
12210
|
+
/** Enable partial profit/loss event tracking reports */
|
|
12170
12211
|
partial: boolean;
|
|
12171
|
-
/** Enable heatmap
|
|
12212
|
+
/** Enable portfolio heatmap analysis reports across all symbols */
|
|
12172
12213
|
heat: boolean;
|
|
12173
|
-
/** Enable walker
|
|
12214
|
+
/** Enable walker strategy comparison and optimization reports */
|
|
12174
12215
|
walker: boolean;
|
|
12175
|
-
/** Enable performance metrics
|
|
12216
|
+
/** Enable performance metrics and bottleneck analysis reports */
|
|
12176
12217
|
performance: boolean;
|
|
12177
|
-
/** Enable scheduled signal
|
|
12218
|
+
/** Enable scheduled signal tracking reports (signals waiting for trigger) */
|
|
12178
12219
|
schedule: boolean;
|
|
12179
|
-
/** Enable live trading event
|
|
12220
|
+
/** Enable live trading event reports (all tick events) */
|
|
12180
12221
|
live: boolean;
|
|
12181
|
-
/** Enable backtest
|
|
12222
|
+
/** Enable backtest markdown reports (main strategy results with full trade history) */
|
|
12182
12223
|
backtest: boolean;
|
|
12183
|
-
/** Enable signal
|
|
12224
|
+
/** Enable signal sync lifecycle reports (signal-open and signal-close events) */
|
|
12184
12225
|
sync: boolean;
|
|
12185
|
-
/** Enable highest profit milestone
|
|
12226
|
+
/** Enable highest profit milestone tracking reports */
|
|
12186
12227
|
highest_profit: boolean;
|
|
12187
|
-
/** Enable max drawdown milestone
|
|
12228
|
+
/** Enable max drawdown milestone tracking reports */
|
|
12188
12229
|
max_drawdown: boolean;
|
|
12189
12230
|
}
|
|
12231
|
+
/** Symbol key for the singleshot waitForInit function on MarkdownFileBase instances. */
|
|
12232
|
+
declare const WAIT_FOR_INIT_SYMBOL: unique symbol;
|
|
12233
|
+
/** Symbol key for the timeout-protected write function on MarkdownFileBase instances. */
|
|
12234
|
+
declare const WRITE_SAFE_SYMBOL: unique symbol;
|
|
12190
12235
|
/**
|
|
12191
|
-
* Union type of all valid report names.
|
|
12192
|
-
* Used for type-safe identification of
|
|
12236
|
+
* Union type of all valid markdown report names.
|
|
12237
|
+
* Used for type-safe identification of markdown services.
|
|
12193
12238
|
*/
|
|
12194
|
-
type
|
|
12239
|
+
type MarkdownName = keyof IMarkdownTarget;
|
|
12195
12240
|
/**
|
|
12196
|
-
* Options for
|
|
12197
|
-
* Contains metadata for
|
|
12241
|
+
* Options for markdown dump operations.
|
|
12242
|
+
* Contains path information and metadata for filtering.
|
|
12198
12243
|
*/
|
|
12199
|
-
interface
|
|
12244
|
+
interface IMarkdownDumpOptions {
|
|
12245
|
+
/** Directory path relative to process.cwd() */
|
|
12246
|
+
path: string;
|
|
12247
|
+
/** File name including extension */
|
|
12248
|
+
file: string;
|
|
12200
12249
|
/** Trading pair symbol (e.g., "BTCUSDT") */
|
|
12201
12250
|
symbol: string;
|
|
12202
12251
|
/** Strategy name */
|
|
@@ -12207,16 +12256,14 @@ interface IReportDumpOptions {
|
|
|
12207
12256
|
frameName: string;
|
|
12208
12257
|
/** Signal unique identifier */
|
|
12209
12258
|
signalId: string;
|
|
12210
|
-
/** Walker optimization name */
|
|
12211
|
-
walkerName: string;
|
|
12212
12259
|
}
|
|
12213
12260
|
/**
|
|
12214
|
-
* Base interface for
|
|
12215
|
-
* All
|
|
12261
|
+
* Base interface for markdown storage adapters.
|
|
12262
|
+
* All markdown adapters must implement this interface.
|
|
12216
12263
|
*/
|
|
12217
|
-
type
|
|
12264
|
+
type TMarkdownBase = {
|
|
12218
12265
|
/**
|
|
12219
|
-
* Initialize
|
|
12266
|
+
* Initialize markdown storage and prepare for writes.
|
|
12220
12267
|
* Uses singleshot to ensure one-time execution.
|
|
12221
12268
|
*
|
|
12222
12269
|
* @param initial - Whether this is the first initialization
|
|
@@ -12224,204 +12271,178 @@ type TReportBase = {
|
|
|
12224
12271
|
*/
|
|
12225
12272
|
waitForInit(initial: boolean): Promise<void>;
|
|
12226
12273
|
/**
|
|
12227
|
-
*
|
|
12274
|
+
* Dump markdown content to storage.
|
|
12228
12275
|
*
|
|
12229
|
-
* @param
|
|
12230
|
-
* @param options - Metadata options for
|
|
12276
|
+
* @param content - Markdown content to write
|
|
12277
|
+
* @param options - Metadata and path options for the dump
|
|
12231
12278
|
* @returns Promise that resolves when write is complete
|
|
12232
12279
|
* @throws Error if write fails or stream is not initialized
|
|
12233
12280
|
*/
|
|
12234
|
-
|
|
12281
|
+
dump(content: string, options: IMarkdownDumpOptions): Promise<void>;
|
|
12235
12282
|
};
|
|
12236
12283
|
/**
|
|
12237
|
-
* Constructor type for
|
|
12238
|
-
* Used for custom
|
|
12284
|
+
* Constructor type for markdown storage adapters.
|
|
12285
|
+
* Used for custom markdown storage implementations.
|
|
12239
12286
|
*/
|
|
12240
|
-
type
|
|
12287
|
+
type TMarkdownBaseCtor = new (markdownName: MarkdownName) => TMarkdownBase;
|
|
12241
12288
|
/**
|
|
12242
|
-
* JSONL-based
|
|
12289
|
+
* JSONL-based markdown adapter with append-only writes.
|
|
12243
12290
|
*
|
|
12244
12291
|
* Features:
|
|
12245
|
-
* - Writes
|
|
12292
|
+
* - Writes markdown reports as JSONL entries to a single file per markdown type
|
|
12246
12293
|
* - Stream-based writes with backpressure handling
|
|
12247
12294
|
* - 15-second timeout protection for write operations
|
|
12248
12295
|
* - Automatic directory creation
|
|
12249
12296
|
* - Error handling via exitEmitter
|
|
12250
|
-
* - Search metadata for filtering (symbol, strategy, exchange, frame, signalId
|
|
12297
|
+
* - Search metadata for filtering (symbol, strategy, exchange, frame, signalId)
|
|
12251
12298
|
*
|
|
12252
|
-
* File format: ./dump/
|
|
12253
|
-
* Each line contains:
|
|
12299
|
+
* File format: ./dump/markdown/{markdownName}.jsonl
|
|
12300
|
+
* Each line contains: markdownName, data, symbol, strategyName, exchangeName, frameName, signalId, timestamp
|
|
12254
12301
|
*
|
|
12255
|
-
* Use this adapter for
|
|
12302
|
+
* Use this adapter for centralized logging and post-processing with JSONL tools.
|
|
12256
12303
|
*/
|
|
12257
|
-
declare class
|
|
12258
|
-
readonly
|
|
12259
|
-
|
|
12260
|
-
/** Absolute path to the JSONL file for this report type */
|
|
12304
|
+
declare class MarkdownFileBase implements TMarkdownBase {
|
|
12305
|
+
readonly markdownName: MarkdownName;
|
|
12306
|
+
/** Absolute path to the JSONL file for this markdown type */
|
|
12261
12307
|
_filePath: string;
|
|
12262
12308
|
/** WriteStream instance for append-only writes, null until initialized */
|
|
12263
12309
|
_stream: WriteStream | null;
|
|
12310
|
+
/** Base directory for all JSONL markdown files */
|
|
12311
|
+
_baseDir: string;
|
|
12264
12312
|
/**
|
|
12265
|
-
* Creates a new JSONL
|
|
12313
|
+
* Creates a new JSONL markdown adapter instance.
|
|
12266
12314
|
*
|
|
12267
|
-
* @param
|
|
12268
|
-
* @param baseDir - Base directory for report files, defaults to ./dump/report
|
|
12315
|
+
* @param markdownName - Type of markdown report (backtest, live, walker, etc.)
|
|
12269
12316
|
*/
|
|
12270
|
-
constructor(
|
|
12317
|
+
constructor(markdownName: MarkdownName);
|
|
12271
12318
|
/**
|
|
12272
12319
|
* Singleshot initialization function that creates directory and stream.
|
|
12273
12320
|
* Protected by singleshot to ensure one-time execution.
|
|
12274
12321
|
* Sets up error handler that emits to exitEmitter.
|
|
12275
12322
|
*/
|
|
12276
|
-
[WAIT_FOR_INIT_SYMBOL
|
|
12323
|
+
[WAIT_FOR_INIT_SYMBOL]: (() => Promise<void>) & functools_kit.ISingleshotClearable;
|
|
12277
12324
|
/**
|
|
12278
12325
|
* Timeout-protected write function with backpressure handling.
|
|
12279
12326
|
* Waits for drain event if write buffer is full.
|
|
12280
12327
|
* Times out after 15 seconds and returns TIMEOUT_SYMBOL.
|
|
12281
12328
|
*/
|
|
12282
|
-
[WRITE_SAFE_SYMBOL
|
|
12329
|
+
[WRITE_SAFE_SYMBOL]: (line: string) => Promise<symbol | void>;
|
|
12283
12330
|
/**
|
|
12284
12331
|
* Initializes the JSONL file and write stream.
|
|
12285
12332
|
* Safe to call multiple times - singleshot ensures one-time execution.
|
|
12286
12333
|
*
|
|
12287
|
-
* @param initial - Whether this is the first initialization (informational only)
|
|
12288
12334
|
* @returns Promise that resolves when initialization is complete
|
|
12289
12335
|
*/
|
|
12290
|
-
waitForInit(
|
|
12336
|
+
waitForInit(): Promise<void>;
|
|
12291
12337
|
/**
|
|
12292
|
-
* Writes
|
|
12338
|
+
* Writes markdown content to JSONL file with metadata.
|
|
12293
12339
|
* Appends a single line with JSON object containing:
|
|
12294
|
-
* -
|
|
12295
|
-
* - data:
|
|
12296
|
-
* - Search flags: symbol, strategyName, exchangeName, frameName, signalId
|
|
12340
|
+
* - markdownName: Type of report
|
|
12341
|
+
* - data: Markdown content
|
|
12342
|
+
* - Search flags: symbol, strategyName, exchangeName, frameName, signalId
|
|
12297
12343
|
* - timestamp: Current timestamp in milliseconds
|
|
12298
12344
|
*
|
|
12299
|
-
* @param data -
|
|
12300
|
-
* @param options -
|
|
12345
|
+
* @param data - Markdown content to write
|
|
12346
|
+
* @param options - Path and metadata options
|
|
12301
12347
|
* @throws Error if stream not initialized or write timeout exceeded
|
|
12302
12348
|
*/
|
|
12303
|
-
|
|
12349
|
+
dump(data: string, options: IMarkdownDumpOptions): Promise<void>;
|
|
12304
12350
|
}
|
|
12305
12351
|
/**
|
|
12306
|
-
*
|
|
12352
|
+
* Folder-based markdown adapter with separate files per report.
|
|
12307
12353
|
*
|
|
12308
|
-
*
|
|
12309
|
-
*
|
|
12354
|
+
* Features:
|
|
12355
|
+
* - Writes each markdown report as a separate .md file
|
|
12356
|
+
* - File path based on options.path and options.file
|
|
12357
|
+
* - Automatic directory creation
|
|
12358
|
+
* - No stream management (direct writeFile)
|
|
12359
|
+
* - Suitable for human-readable report directories
|
|
12310
12360
|
*
|
|
12311
|
-
*
|
|
12361
|
+
* File format: {options.path}/{options.file}
|
|
12362
|
+
* Example: ./dump/backtest/BTCUSDT_my-strategy_binance_2024-Q1_backtest-1736601234567.md
|
|
12363
|
+
*
|
|
12364
|
+
* Use this adapter (default) for organized report directories and manual review.
|
|
12312
12365
|
*/
|
|
12313
|
-
declare class
|
|
12366
|
+
declare class MarkdownFolderBase implements TMarkdownBase {
|
|
12367
|
+
readonly markdownName: MarkdownName;
|
|
12314
12368
|
/**
|
|
12315
|
-
*
|
|
12316
|
-
*
|
|
12317
|
-
* Subscribes to specified report services and returns a cleanup function
|
|
12318
|
-
* that unsubscribes from all enabled services at once.
|
|
12319
|
-
*
|
|
12320
|
-
* Each enabled service will:
|
|
12321
|
-
* - Start listening to relevant events
|
|
12322
|
-
* - Write events to JSONL files in real-time
|
|
12323
|
-
* - Include metadata for filtering and analytics
|
|
12324
|
-
*
|
|
12325
|
-
* IMPORTANT: Always call the returned unsubscribe function to prevent memory leaks.
|
|
12326
|
-
*
|
|
12327
|
-
* @param config - Service configuration object. Defaults to enabling all services.
|
|
12328
|
-
* @param config.backtest - Enable backtest closed signal logging
|
|
12329
|
-
* @param config.breakeven - Enable breakeven event logging
|
|
12330
|
-
* @param config.partial - Enable partial close event logging
|
|
12331
|
-
* @param config.heat - Enable heatmap data logging
|
|
12332
|
-
* @param config.walker - Enable walker iteration logging
|
|
12333
|
-
* @param config.performance - Enable performance metrics logging
|
|
12334
|
-
* @param config.risk - Enable risk rejection logging
|
|
12335
|
-
* @param config.schedule - Enable scheduled signal logging
|
|
12336
|
-
* @param config.live - Enable live trading event logging
|
|
12369
|
+
* Creates a new folder-based markdown adapter instance.
|
|
12337
12370
|
*
|
|
12338
|
-
* @
|
|
12371
|
+
* @param markdownName - Type of markdown report (backtest, live, walker, etc.)
|
|
12339
12372
|
*/
|
|
12340
|
-
|
|
12373
|
+
constructor(markdownName: MarkdownName);
|
|
12341
12374
|
/**
|
|
12342
|
-
*
|
|
12343
|
-
*
|
|
12344
|
-
* Unsubscribes from specified report services to stop event logging.
|
|
12345
|
-
* Use this method to stop JSONL logging for specific services while keeping others active.
|
|
12346
|
-
*
|
|
12347
|
-
* Each disabled service will:
|
|
12348
|
-
* - Stop listening to events immediately
|
|
12349
|
-
* - Stop writing to JSONL files
|
|
12350
|
-
* - Free up event listener resources
|
|
12351
|
-
*
|
|
12352
|
-
* Unlike enable(), this method does NOT return an unsubscribe function.
|
|
12353
|
-
* Services are unsubscribed immediately upon calling this method.
|
|
12354
|
-
*
|
|
12355
|
-
* @param config - Service configuration object specifying which services to disable. Defaults to disabling all services.
|
|
12356
|
-
* @param config.backtest - Disable backtest closed signal logging
|
|
12357
|
-
* @param config.breakeven - Disable breakeven event logging
|
|
12358
|
-
* @param config.partial - Disable partial close event logging
|
|
12359
|
-
* @param config.heat - Disable heatmap data logging
|
|
12360
|
-
* @param config.walker - Disable walker iteration logging
|
|
12361
|
-
* @param config.performance - Disable performance metrics logging
|
|
12362
|
-
* @param config.risk - Disable risk rejection logging
|
|
12363
|
-
* @param config.schedule - Disable scheduled signal logging
|
|
12364
|
-
* @param config.live - Disable live trading event logging
|
|
12365
|
-
*
|
|
12366
|
-
* @example
|
|
12367
|
-
* ```typescript
|
|
12368
|
-
* import { Report } from "backtest-kit";
|
|
12375
|
+
* No-op initialization for folder adapter.
|
|
12376
|
+
* This adapter doesn't need initialization since it uses direct writeFile.
|
|
12369
12377
|
*
|
|
12370
|
-
*
|
|
12371
|
-
|
|
12378
|
+
* @returns Promise that resolves immediately
|
|
12379
|
+
*/
|
|
12380
|
+
waitForInit(): Promise<void>;
|
|
12381
|
+
/**
|
|
12382
|
+
* Writes markdown content to a separate file.
|
|
12383
|
+
* Creates directory structure automatically.
|
|
12384
|
+
* File path is determined by options.path and options.file.
|
|
12372
12385
|
*
|
|
12373
|
-
*
|
|
12374
|
-
*
|
|
12375
|
-
*
|
|
12386
|
+
* @param content - Markdown content to write
|
|
12387
|
+
* @param options - Path and file options for the dump
|
|
12388
|
+
* @throws Error if directory creation or file write fails
|
|
12376
12389
|
*/
|
|
12377
|
-
|
|
12390
|
+
dump(content: string, options: IMarkdownDumpOptions): Promise<void>;
|
|
12378
12391
|
}
|
|
12379
12392
|
/**
|
|
12380
|
-
*
|
|
12393
|
+
* Markdown writer with pluggable storage backend and instance memoization.
|
|
12381
12394
|
*
|
|
12382
12395
|
* Features:
|
|
12383
|
-
* - Adapter pattern for swappable storage implementations
|
|
12384
|
-
* - Memoized storage instances (one per
|
|
12385
|
-
* - Default adapter:
|
|
12396
|
+
* - Adapter pattern for swappable storage implementations (folder, JSONL, dummy)
|
|
12397
|
+
* - Memoized storage instances (one per markdown type)
|
|
12398
|
+
* - Default adapter: MarkdownFolderBase (one .md file per report)
|
|
12386
12399
|
* - Lazy initialization on first write
|
|
12387
|
-
* - Real-time event logging to JSONL files
|
|
12388
12400
|
*
|
|
12389
|
-
*
|
|
12401
|
+
* Use `useMd()` for human-readable folder output, `useJsonl()` for centralized
|
|
12402
|
+
* append-only logging, or `useDummy()` to suppress all markdown output.
|
|
12390
12403
|
*/
|
|
12391
|
-
declare class
|
|
12404
|
+
declare class MarkdownWriterAdapter {
|
|
12392
12405
|
/**
|
|
12393
|
-
* Current
|
|
12394
|
-
* Defaults to
|
|
12395
|
-
* Can be changed via
|
|
12406
|
+
* Current markdown storage adapter constructor.
|
|
12407
|
+
* Defaults to MarkdownFolderBase for per-file storage.
|
|
12408
|
+
* Can be changed via useMarkdownAdapter().
|
|
12396
12409
|
*/
|
|
12397
|
-
private
|
|
12410
|
+
private MarkdownFactory;
|
|
12398
12411
|
/**
|
|
12399
12412
|
* Memoized storage instances cache.
|
|
12400
|
-
* Key:
|
|
12401
|
-
* Value:
|
|
12402
|
-
* Ensures single instance per
|
|
12413
|
+
* Key: markdownName (backtest, live, walker, etc.)
|
|
12414
|
+
* Value: TMarkdownBase instance created with current MarkdownFactory.
|
|
12415
|
+
* Ensures single instance per markdown type for the lifetime of the application.
|
|
12403
12416
|
*/
|
|
12404
|
-
private
|
|
12417
|
+
private getMarkdownStorage;
|
|
12405
12418
|
/**
|
|
12406
|
-
* Sets the
|
|
12407
|
-
* All future
|
|
12419
|
+
* Sets the markdown storage adapter constructor.
|
|
12420
|
+
* All future markdown instances will use this adapter.
|
|
12408
12421
|
*
|
|
12409
|
-
* @param Ctor - Constructor for
|
|
12422
|
+
* @param Ctor - Constructor for markdown storage adapter
|
|
12410
12423
|
*/
|
|
12411
|
-
|
|
12424
|
+
useMarkdownAdapter(Ctor: TMarkdownBaseCtor): void;
|
|
12412
12425
|
/**
|
|
12413
|
-
* Writes
|
|
12414
|
-
* Automatically initializes storage on first write for each
|
|
12426
|
+
* Writes markdown content to storage using the configured adapter.
|
|
12427
|
+
* Automatically initializes storage on first write for each markdown type.
|
|
12415
12428
|
*
|
|
12416
|
-
* @param
|
|
12417
|
-
* @param
|
|
12418
|
-
* @param options -
|
|
12429
|
+
* @param markdownName - Type of markdown report (backtest, live, walker, etc.)
|
|
12430
|
+
* @param content - Markdown content to write
|
|
12431
|
+
* @param options - Path and metadata options for the dump
|
|
12419
12432
|
* @returns Promise that resolves when write is complete
|
|
12420
12433
|
* @throws Error if write fails or storage initialization fails
|
|
12421
|
-
*
|
|
12422
|
-
* @internal - Automatically called by report services, not for direct use
|
|
12423
12434
|
*/
|
|
12424
|
-
writeData
|
|
12435
|
+
writeData(markdownName: MarkdownName, content: string, options: IMarkdownDumpOptions): Promise<void>;
|
|
12436
|
+
/**
|
|
12437
|
+
* Switches to the folder-based markdown adapter (default).
|
|
12438
|
+
* Each report is written as a separate .md file.
|
|
12439
|
+
*/
|
|
12440
|
+
useMd(): void;
|
|
12441
|
+
/**
|
|
12442
|
+
* Switches to the JSONL markdown adapter.
|
|
12443
|
+
* All reports are appended to a single .jsonl file per markdown type.
|
|
12444
|
+
*/
|
|
12445
|
+
useJsonl(): void;
|
|
12425
12446
|
/**
|
|
12426
12447
|
* Clears the memoized storage cache.
|
|
12427
12448
|
* Call this when process.cwd() changes between strategy iterations
|
|
@@ -12429,72 +12450,54 @@ declare class ReportAdapter extends ReportUtils {
|
|
|
12429
12450
|
*/
|
|
12430
12451
|
clear(): void;
|
|
12431
12452
|
/**
|
|
12432
|
-
* Switches to a dummy
|
|
12433
|
-
* All future
|
|
12453
|
+
* Switches to a dummy markdown adapter that discards all writes.
|
|
12454
|
+
* All future markdown writes will be no-ops.
|
|
12434
12455
|
*/
|
|
12435
12456
|
useDummy(): void;
|
|
12436
|
-
/**
|
|
12437
|
-
* Switches to the default JSONL report adapter.
|
|
12438
|
-
* All future report writes will use JSONL storage.
|
|
12439
|
-
*/
|
|
12440
|
-
useJsonl(): void;
|
|
12441
12457
|
}
|
|
12458
|
+
declare const MarkdownWriter: MarkdownWriterAdapter;
|
|
12442
12459
|
/**
|
|
12443
|
-
*
|
|
12444
|
-
*
|
|
12445
|
-
*/
|
|
12446
|
-
declare const Report: ReportAdapter;
|
|
12447
|
-
|
|
12448
|
-
/**
|
|
12449
|
-
* Configuration interface for selective markdown service enablement.
|
|
12450
|
-
* Controls which markdown report services should be activated.
|
|
12460
|
+
* Configuration interface for selective report service enablement.
|
|
12461
|
+
* Controls which report services should be activated for JSONL event logging.
|
|
12451
12462
|
*/
|
|
12452
|
-
interface
|
|
12453
|
-
/** Enable strategy
|
|
12463
|
+
interface IReportTarget {
|
|
12464
|
+
/** Enable strategy commit actions */
|
|
12454
12465
|
strategy: boolean;
|
|
12455
|
-
/** Enable risk rejection
|
|
12466
|
+
/** Enable risk rejection event logging */
|
|
12456
12467
|
risk: boolean;
|
|
12457
|
-
/** Enable breakeven event
|
|
12468
|
+
/** Enable breakeven event logging */
|
|
12458
12469
|
breakeven: boolean;
|
|
12459
|
-
/** Enable partial
|
|
12470
|
+
/** Enable partial close event logging */
|
|
12460
12471
|
partial: boolean;
|
|
12461
|
-
/** Enable
|
|
12472
|
+
/** Enable heatmap data event logging */
|
|
12462
12473
|
heat: boolean;
|
|
12463
|
-
/** Enable walker
|
|
12474
|
+
/** Enable walker iteration event logging */
|
|
12464
12475
|
walker: boolean;
|
|
12465
|
-
/** Enable performance metrics
|
|
12476
|
+
/** Enable performance metrics event logging */
|
|
12466
12477
|
performance: boolean;
|
|
12467
|
-
/** Enable scheduled signal
|
|
12478
|
+
/** Enable scheduled signal event logging */
|
|
12468
12479
|
schedule: boolean;
|
|
12469
|
-
/** Enable live trading event
|
|
12480
|
+
/** Enable live trading event logging (all tick states) */
|
|
12470
12481
|
live: boolean;
|
|
12471
|
-
/** Enable backtest
|
|
12482
|
+
/** Enable backtest closed signal event logging */
|
|
12472
12483
|
backtest: boolean;
|
|
12473
|
-
/** Enable signal
|
|
12484
|
+
/** Enable signal synchronization event logging (signal-open, signal-close) */
|
|
12474
12485
|
sync: boolean;
|
|
12475
|
-
/** Enable highest profit milestone
|
|
12486
|
+
/** Enable highest profit milestone event logging */
|
|
12476
12487
|
highest_profit: boolean;
|
|
12477
|
-
/** Enable max drawdown milestone
|
|
12488
|
+
/** Enable max drawdown milestone event logging */
|
|
12478
12489
|
max_drawdown: boolean;
|
|
12479
12490
|
}
|
|
12480
|
-
/** Symbol key for the singleshot waitForInit function on MarkdownFileBase instances. */
|
|
12481
|
-
declare const WAIT_FOR_INIT_SYMBOL: unique symbol;
|
|
12482
|
-
/** Symbol key for the timeout-protected write function on MarkdownFileBase instances. */
|
|
12483
|
-
declare const WRITE_SAFE_SYMBOL: unique symbol;
|
|
12484
12491
|
/**
|
|
12485
|
-
* Union type of all valid
|
|
12486
|
-
* Used for type-safe identification of
|
|
12492
|
+
* Union type of all valid report names.
|
|
12493
|
+
* Used for type-safe identification of report services.
|
|
12487
12494
|
*/
|
|
12488
|
-
type
|
|
12495
|
+
type ReportName = keyof IReportTarget;
|
|
12489
12496
|
/**
|
|
12490
|
-
* Options for
|
|
12491
|
-
* Contains
|
|
12497
|
+
* Options for report data writes.
|
|
12498
|
+
* Contains metadata for event filtering and search.
|
|
12492
12499
|
*/
|
|
12493
|
-
interface
|
|
12494
|
-
/** Directory path relative to process.cwd() */
|
|
12495
|
-
path: string;
|
|
12496
|
-
/** File name including extension */
|
|
12497
|
-
file: string;
|
|
12500
|
+
interface IReportDumpOptions {
|
|
12498
12501
|
/** Trading pair symbol (e.g., "BTCUSDT") */
|
|
12499
12502
|
symbol: string;
|
|
12500
12503
|
/** Strategy name */
|
|
@@ -12505,14 +12508,16 @@ interface IMarkdownDumpOptions {
|
|
|
12505
12508
|
frameName: string;
|
|
12506
12509
|
/** Signal unique identifier */
|
|
12507
12510
|
signalId: string;
|
|
12511
|
+
/** Walker optimization name */
|
|
12512
|
+
walkerName: string;
|
|
12508
12513
|
}
|
|
12509
12514
|
/**
|
|
12510
|
-
* Base interface for
|
|
12511
|
-
* All
|
|
12515
|
+
* Base interface for report storage adapters.
|
|
12516
|
+
* All report adapters must implement this interface.
|
|
12512
12517
|
*/
|
|
12513
|
-
type
|
|
12518
|
+
type TReportBase = {
|
|
12514
12519
|
/**
|
|
12515
|
-
* Initialize
|
|
12520
|
+
* Initialize report storage and prepare for writes.
|
|
12516
12521
|
* Uses singleshot to ensure one-time execution.
|
|
12517
12522
|
*
|
|
12518
12523
|
* @param initial - Whether this is the first initialization
|
|
@@ -12520,50 +12525,50 @@ type TMarkdownBase = {
|
|
|
12520
12525
|
*/
|
|
12521
12526
|
waitForInit(initial: boolean): Promise<void>;
|
|
12522
12527
|
/**
|
|
12523
|
-
*
|
|
12528
|
+
* Write report data to storage.
|
|
12524
12529
|
*
|
|
12525
|
-
* @param
|
|
12526
|
-
* @param options - Metadata
|
|
12530
|
+
* @param data - Report data object to write
|
|
12531
|
+
* @param options - Metadata options for filtering and search
|
|
12527
12532
|
* @returns Promise that resolves when write is complete
|
|
12528
12533
|
* @throws Error if write fails or stream is not initialized
|
|
12529
12534
|
*/
|
|
12530
|
-
|
|
12535
|
+
write<T = any>(data: T, options: IReportDumpOptions): Promise<void>;
|
|
12531
12536
|
};
|
|
12532
12537
|
/**
|
|
12533
|
-
* Constructor type for
|
|
12534
|
-
* Used for custom
|
|
12538
|
+
* Constructor type for report storage adapters.
|
|
12539
|
+
* Used for custom report storage implementations.
|
|
12535
12540
|
*/
|
|
12536
|
-
type
|
|
12541
|
+
type TReportBaseCtor = new (reportName: ReportName, baseDir: string) => TReportBase;
|
|
12537
12542
|
/**
|
|
12538
|
-
* JSONL-based
|
|
12543
|
+
* JSONL-based report adapter with append-only writes.
|
|
12539
12544
|
*
|
|
12540
12545
|
* Features:
|
|
12541
|
-
* - Writes
|
|
12546
|
+
* - Writes events as JSONL entries to a single file per report type
|
|
12542
12547
|
* - Stream-based writes with backpressure handling
|
|
12543
12548
|
* - 15-second timeout protection for write operations
|
|
12544
12549
|
* - Automatic directory creation
|
|
12545
12550
|
* - Error handling via exitEmitter
|
|
12546
|
-
* - Search metadata for filtering (symbol, strategy, exchange, frame, signalId)
|
|
12551
|
+
* - Search metadata for filtering (symbol, strategy, exchange, frame, signalId, walkerName)
|
|
12547
12552
|
*
|
|
12548
|
-
* File format: ./dump/
|
|
12549
|
-
* Each line contains:
|
|
12553
|
+
* File format: ./dump/report/{reportName}.jsonl
|
|
12554
|
+
* Each line contains: reportName, data, metadata, timestamp
|
|
12550
12555
|
*
|
|
12551
|
-
* Use this adapter for
|
|
12556
|
+
* Use this adapter for event logging and post-processing analytics.
|
|
12552
12557
|
*/
|
|
12553
|
-
declare class
|
|
12554
|
-
readonly
|
|
12555
|
-
|
|
12558
|
+
declare class ReportBase implements TReportBase {
|
|
12559
|
+
readonly reportName: ReportName;
|
|
12560
|
+
readonly baseDir: string;
|
|
12561
|
+
/** Absolute path to the JSONL file for this report type */
|
|
12556
12562
|
_filePath: string;
|
|
12557
12563
|
/** WriteStream instance for append-only writes, null until initialized */
|
|
12558
12564
|
_stream: WriteStream | null;
|
|
12559
|
-
/** Base directory for all JSONL markdown files */
|
|
12560
|
-
_baseDir: string;
|
|
12561
12565
|
/**
|
|
12562
|
-
* Creates a new JSONL
|
|
12566
|
+
* Creates a new JSONL report adapter instance.
|
|
12563
12567
|
*
|
|
12564
|
-
* @param
|
|
12568
|
+
* @param reportName - Type of report (backtest, live, walker, etc.)
|
|
12569
|
+
* @param baseDir - Base directory for report files, defaults to ./dump/report
|
|
12565
12570
|
*/
|
|
12566
|
-
constructor(
|
|
12571
|
+
constructor(reportName: ReportName, baseDir?: string);
|
|
12567
12572
|
/**
|
|
12568
12573
|
* Singleshot initialization function that creates directory and stream.
|
|
12569
12574
|
* Protected by singleshot to ensure one-time execution.
|
|
@@ -12580,64 +12585,207 @@ declare class MarkdownFileBase implements TMarkdownBase {
|
|
|
12580
12585
|
* Initializes the JSONL file and write stream.
|
|
12581
12586
|
* Safe to call multiple times - singleshot ensures one-time execution.
|
|
12582
12587
|
*
|
|
12588
|
+
* @param initial - Whether this is the first initialization (informational only)
|
|
12583
12589
|
* @returns Promise that resolves when initialization is complete
|
|
12584
12590
|
*/
|
|
12585
|
-
waitForInit(): Promise<void>;
|
|
12591
|
+
waitForInit(initial: boolean): Promise<void>;
|
|
12586
12592
|
/**
|
|
12587
|
-
* Writes
|
|
12593
|
+
* Writes event data to JSONL file with metadata.
|
|
12588
12594
|
* Appends a single line with JSON object containing:
|
|
12589
|
-
* -
|
|
12590
|
-
* - data:
|
|
12591
|
-
* - Search flags: symbol, strategyName, exchangeName, frameName, signalId
|
|
12595
|
+
* - reportName: Type of report
|
|
12596
|
+
* - data: Event data object
|
|
12597
|
+
* - Search flags: symbol, strategyName, exchangeName, frameName, signalId, walkerName
|
|
12592
12598
|
* - timestamp: Current timestamp in milliseconds
|
|
12593
12599
|
*
|
|
12594
|
-
* @param data -
|
|
12595
|
-
* @param options -
|
|
12600
|
+
* @param data - Event data object to write
|
|
12601
|
+
* @param options - Metadata options for filtering and search
|
|
12596
12602
|
* @throws Error if stream not initialized or write timeout exceeded
|
|
12597
12603
|
*/
|
|
12598
|
-
|
|
12604
|
+
write<T = any>(data: T, options: IReportDumpOptions): Promise<void>;
|
|
12599
12605
|
}
|
|
12600
12606
|
/**
|
|
12601
|
-
*
|
|
12607
|
+
* Report adapter with pluggable storage backend and instance memoization.
|
|
12602
12608
|
*
|
|
12603
12609
|
* Features:
|
|
12604
|
-
* -
|
|
12605
|
-
* -
|
|
12606
|
-
* -
|
|
12607
|
-
* -
|
|
12608
|
-
* -
|
|
12610
|
+
* - Adapter pattern for swappable storage implementations
|
|
12611
|
+
* - Memoized storage instances (one per report type)
|
|
12612
|
+
* - Default adapter: ReportBase (JSONL append)
|
|
12613
|
+
* - Lazy initialization on first write
|
|
12614
|
+
* - Real-time event logging to JSONL files
|
|
12609
12615
|
*
|
|
12610
|
-
*
|
|
12611
|
-
|
|
12616
|
+
* Used for structured event logging and analytics pipelines.
|
|
12617
|
+
*/
|
|
12618
|
+
declare class ReportWriterAdapter {
|
|
12619
|
+
/**
|
|
12620
|
+
* Current report storage adapter constructor.
|
|
12621
|
+
* Defaults to ReportBase for JSONL storage.
|
|
12622
|
+
* Can be changed via useReportAdapter().
|
|
12623
|
+
*/
|
|
12624
|
+
private ReportFactory;
|
|
12625
|
+
/**
|
|
12626
|
+
* Memoized storage instances cache.
|
|
12627
|
+
* Key: reportName (backtest, live, walker, etc.)
|
|
12628
|
+
* Value: TReportBase instance created with current ReportFactory.
|
|
12629
|
+
* Ensures single instance per report type for the lifetime of the application.
|
|
12630
|
+
*/
|
|
12631
|
+
private getReportStorage;
|
|
12632
|
+
/**
|
|
12633
|
+
* Sets the report storage adapter constructor.
|
|
12634
|
+
* All future report instances will use this adapter.
|
|
12635
|
+
*
|
|
12636
|
+
* @param Ctor - Constructor for report storage adapter
|
|
12637
|
+
*/
|
|
12638
|
+
useReportAdapter(Ctor: TReportBaseCtor): void;
|
|
12639
|
+
/**
|
|
12640
|
+
* Writes report data to storage using the configured adapter.
|
|
12641
|
+
* Automatically initializes storage on first write for each report type.
|
|
12642
|
+
*
|
|
12643
|
+
* @param reportName - Type of report (backtest, live, walker, etc.)
|
|
12644
|
+
* @param data - Event data object to write
|
|
12645
|
+
* @param options - Metadata options for filtering and search
|
|
12646
|
+
* @returns Promise that resolves when write is complete
|
|
12647
|
+
* @throws Error if write fails or storage initialization fails
|
|
12648
|
+
*
|
|
12649
|
+
* @internal - Automatically called by report services, not for direct use
|
|
12650
|
+
*/
|
|
12651
|
+
writeData: <T = any>(reportName: ReportName, data: T, options: IReportDumpOptions) => Promise<void>;
|
|
12652
|
+
/**
|
|
12653
|
+
* Clears the memoized storage cache.
|
|
12654
|
+
* Call this when process.cwd() changes between strategy iterations
|
|
12655
|
+
* so new storage instances are created with the updated base path.
|
|
12656
|
+
*/
|
|
12657
|
+
clear(): void;
|
|
12658
|
+
/**
|
|
12659
|
+
* Switches to a dummy report adapter that discards all writes.
|
|
12660
|
+
* All future report writes will be no-ops.
|
|
12661
|
+
*/
|
|
12662
|
+
useDummy(): void;
|
|
12663
|
+
/**
|
|
12664
|
+
* Switches to the default JSONL report adapter.
|
|
12665
|
+
* All future report writes will use JSONL storage.
|
|
12666
|
+
*/
|
|
12667
|
+
useJsonl(): void;
|
|
12668
|
+
}
|
|
12669
|
+
|
|
12670
|
+
declare const ReportWriter: ReportWriterAdapter;
|
|
12671
|
+
|
|
12672
|
+
/**
|
|
12673
|
+
* Utility class for managing report services.
|
|
12612
12674
|
*
|
|
12613
|
-
*
|
|
12675
|
+
* Provides methods to enable/disable JSONL event logging across
|
|
12676
|
+
* different service types (backtest, live, walker, performance, etc.).
|
|
12677
|
+
*
|
|
12678
|
+
* Typically extended by ReportAdapter for additional functionality.
|
|
12614
12679
|
*/
|
|
12615
|
-
declare class
|
|
12616
|
-
readonly markdownName: MarkdownName;
|
|
12680
|
+
declare class ReportUtils {
|
|
12617
12681
|
/**
|
|
12618
|
-
*
|
|
12682
|
+
* Enables report services selectively.
|
|
12619
12683
|
*
|
|
12620
|
-
*
|
|
12684
|
+
* Subscribes to specified report services and returns a cleanup function
|
|
12685
|
+
* that unsubscribes from all enabled services at once.
|
|
12686
|
+
*
|
|
12687
|
+
* Each enabled service will:
|
|
12688
|
+
* - Start listening to relevant events
|
|
12689
|
+
* - Write events to JSONL files in real-time
|
|
12690
|
+
* - Include metadata for filtering and analytics
|
|
12691
|
+
*
|
|
12692
|
+
* IMPORTANT: Always call the returned unsubscribe function to prevent memory leaks.
|
|
12693
|
+
*
|
|
12694
|
+
* @param config - Service configuration object. Defaults to enabling all services.
|
|
12695
|
+
* @param config.backtest - Enable backtest closed signal logging
|
|
12696
|
+
* @param config.breakeven - Enable breakeven event logging
|
|
12697
|
+
* @param config.partial - Enable partial close event logging
|
|
12698
|
+
* @param config.heat - Enable heatmap data logging
|
|
12699
|
+
* @param config.walker - Enable walker iteration logging
|
|
12700
|
+
* @param config.performance - Enable performance metrics logging
|
|
12701
|
+
* @param config.risk - Enable risk rejection logging
|
|
12702
|
+
* @param config.schedule - Enable scheduled signal logging
|
|
12703
|
+
* @param config.live - Enable live trading event logging
|
|
12704
|
+
*
|
|
12705
|
+
* @returns Cleanup function that unsubscribes from all enabled services
|
|
12621
12706
|
*/
|
|
12622
|
-
|
|
12707
|
+
enable: ({ backtest: bt, breakeven, heat, live, partial, performance, risk, schedule, walker, strategy, sync, highest_profit, max_drawdown, }?: Partial<IReportTarget>) => (...args: any[]) => any;
|
|
12623
12708
|
/**
|
|
12624
|
-
*
|
|
12625
|
-
* This adapter doesn't need initialization since it uses direct writeFile.
|
|
12709
|
+
* Disables report services selectively.
|
|
12626
12710
|
*
|
|
12627
|
-
*
|
|
12711
|
+
* Unsubscribes from specified report services to stop event logging.
|
|
12712
|
+
* Use this method to stop JSONL logging for specific services while keeping others active.
|
|
12713
|
+
*
|
|
12714
|
+
* Each disabled service will:
|
|
12715
|
+
* - Stop listening to events immediately
|
|
12716
|
+
* - Stop writing to JSONL files
|
|
12717
|
+
* - Free up event listener resources
|
|
12718
|
+
*
|
|
12719
|
+
* Unlike enable(), this method does NOT return an unsubscribe function.
|
|
12720
|
+
* Services are unsubscribed immediately upon calling this method.
|
|
12721
|
+
*
|
|
12722
|
+
* @param config - Service configuration object specifying which services to disable. Defaults to disabling all services.
|
|
12723
|
+
* @param config.backtest - Disable backtest closed signal logging
|
|
12724
|
+
* @param config.breakeven - Disable breakeven event logging
|
|
12725
|
+
* @param config.partial - Disable partial close event logging
|
|
12726
|
+
* @param config.heat - Disable heatmap data logging
|
|
12727
|
+
* @param config.walker - Disable walker iteration logging
|
|
12728
|
+
* @param config.performance - Disable performance metrics logging
|
|
12729
|
+
* @param config.risk - Disable risk rejection logging
|
|
12730
|
+
* @param config.schedule - Disable scheduled signal logging
|
|
12731
|
+
* @param config.live - Disable live trading event logging
|
|
12732
|
+
*
|
|
12733
|
+
* @example
|
|
12734
|
+
* ```typescript
|
|
12735
|
+
* import { Report } from "backtest-kit";
|
|
12736
|
+
*
|
|
12737
|
+
* // Disable specific services
|
|
12738
|
+
* Report.disable({ backtest: true, live: true });
|
|
12739
|
+
*
|
|
12740
|
+
* // Disable all services
|
|
12741
|
+
* Report.disable();
|
|
12742
|
+
* ```
|
|
12628
12743
|
*/
|
|
12629
|
-
|
|
12744
|
+
disable: ({ backtest: bt, breakeven, heat, live, partial, performance, risk, schedule, walker, strategy, sync, highest_profit, max_drawdown, }?: Partial<IReportTarget>) => void;
|
|
12745
|
+
}
|
|
12746
|
+
/**
|
|
12747
|
+
* Report adapter with pluggable storage backend and instance memoization.
|
|
12748
|
+
*
|
|
12749
|
+
* Features:
|
|
12750
|
+
* - Adapter pattern for swappable storage implementations
|
|
12751
|
+
* - Memoized storage instances (one per report type)
|
|
12752
|
+
* - Default adapter: ReportBase (JSONL append)
|
|
12753
|
+
* - Lazy initialization on first write
|
|
12754
|
+
* - Real-time event logging to JSONL files
|
|
12755
|
+
*
|
|
12756
|
+
* Used for structured event logging and analytics pipelines.
|
|
12757
|
+
*/
|
|
12758
|
+
declare class ReportAdapter extends ReportUtils {
|
|
12630
12759
|
/**
|
|
12631
|
-
*
|
|
12632
|
-
*
|
|
12633
|
-
* File path is determined by options.path and options.file.
|
|
12760
|
+
* Sets the report storage adapter constructor.
|
|
12761
|
+
* All future report instances will use this adapter.
|
|
12634
12762
|
*
|
|
12635
|
-
* @param
|
|
12636
|
-
* @param options - Path and file options for the dump
|
|
12637
|
-
* @throws Error if directory creation or file write fails
|
|
12763
|
+
* @param Ctor - Constructor for report storage adapter
|
|
12638
12764
|
*/
|
|
12639
|
-
|
|
12765
|
+
useReportAdapter(Ctor: TReportBaseCtor): void;
|
|
12766
|
+
/**
|
|
12767
|
+
* Clears the memoized storage cache.
|
|
12768
|
+
* Call this when process.cwd() changes between strategy iterations
|
|
12769
|
+
* so new storage instances are created with the updated base path.
|
|
12770
|
+
*/
|
|
12771
|
+
clear(): void;
|
|
12772
|
+
/**
|
|
12773
|
+
* Switches to a dummy report adapter that discards all writes.
|
|
12774
|
+
* All future report writes will be no-ops.
|
|
12775
|
+
*/
|
|
12776
|
+
useDummy(): void;
|
|
12777
|
+
/**
|
|
12778
|
+
* Switches to the default JSONL report adapter.
|
|
12779
|
+
* All future report writes will use JSONL storage.
|
|
12780
|
+
*/
|
|
12781
|
+
useJsonl(): void;
|
|
12640
12782
|
}
|
|
12783
|
+
/**
|
|
12784
|
+
* Global singleton instance of ReportAdapter.
|
|
12785
|
+
* Provides JSONL event logging with pluggable storage backends.
|
|
12786
|
+
*/
|
|
12787
|
+
declare const Report: ReportAdapter;
|
|
12788
|
+
|
|
12641
12789
|
/**
|
|
12642
12790
|
* Utility class for managing markdown report services.
|
|
12643
12791
|
*
|
|
@@ -12725,19 +12873,6 @@ declare class MarkdownUtils {
|
|
|
12725
12873
|
* - Convenience methods: useMd(), useJsonl()
|
|
12726
12874
|
*/
|
|
12727
12875
|
declare class MarkdownAdapter extends MarkdownUtils {
|
|
12728
|
-
/**
|
|
12729
|
-
* Current markdown storage adapter constructor.
|
|
12730
|
-
* Defaults to MarkdownFolderBase for separate file storage.
|
|
12731
|
-
* Can be changed via useMarkdownAdapter().
|
|
12732
|
-
*/
|
|
12733
|
-
private MarkdownFactory;
|
|
12734
|
-
/**
|
|
12735
|
-
* Memoized storage instances cache.
|
|
12736
|
-
* Key: markdownName (backtest, live, walker, etc.)
|
|
12737
|
-
* Value: TMarkdownBase instance created with current MarkdownFactory.
|
|
12738
|
-
* Ensures single instance per markdown type for the lifetime of the application.
|
|
12739
|
-
*/
|
|
12740
|
-
private getMarkdownStorage;
|
|
12741
12876
|
/**
|
|
12742
12877
|
* Sets the markdown storage adapter constructor.
|
|
12743
12878
|
* All future markdown instances will use this adapter.
|
|
@@ -12745,19 +12880,6 @@ declare class MarkdownAdapter extends MarkdownUtils {
|
|
|
12745
12880
|
* @param Ctor - Constructor for markdown storage adapter
|
|
12746
12881
|
*/
|
|
12747
12882
|
useMarkdownAdapter(Ctor: TMarkdownBaseCtor): void;
|
|
12748
|
-
/**
|
|
12749
|
-
* Writes markdown data to storage using the configured adapter.
|
|
12750
|
-
* Automatically initializes storage on first write for each markdown type.
|
|
12751
|
-
*
|
|
12752
|
-
* @param markdownName - Type of markdown report (backtest, live, walker, etc.)
|
|
12753
|
-
* @param content - Markdown content to write
|
|
12754
|
-
* @param options - Path, file, and metadata options
|
|
12755
|
-
* @returns Promise that resolves when write is complete
|
|
12756
|
-
* @throws Error if write fails or storage initialization fails
|
|
12757
|
-
*
|
|
12758
|
-
* @internal - Use service-specific dump methods instead (e.g., Backtest.dump)
|
|
12759
|
-
*/
|
|
12760
|
-
writeData(markdownName: MarkdownName, content: string, options: IMarkdownDumpOptions): Promise<void>;
|
|
12761
12883
|
/**
|
|
12762
12884
|
* Switches to folder-based markdown storage (default).
|
|
12763
12885
|
* Shorthand for useMarkdownAdapter(MarkdownFolderBase).
|
|
@@ -18296,7 +18418,7 @@ type Columns$2 = ColumnModel<SyncEvent>;
|
|
|
18296
18418
|
* ```typescript
|
|
18297
18419
|
* import { Markdown } from "backtest-kit";
|
|
18298
18420
|
*
|
|
18299
|
-
* const unsubscribe =
|
|
18421
|
+
* const unsubscribe = MarkdownWriter.enable({ sync: true });
|
|
18300
18422
|
* // ... later
|
|
18301
18423
|
* unsubscribe();
|
|
18302
18424
|
* ```
|
|
@@ -20242,72 +20364,11 @@ declare class BreakevenUtils {
|
|
|
20242
20364
|
*
|
|
20243
20365
|
* // Usage same as BreakevenUtils methods
|
|
20244
20366
|
* const stats = await Breakeven.getData("BTCUSDT", "my-strategy");
|
|
20245
|
-
* const report = await Breakeven.getReport("BTCUSDT", "my-strategy");
|
|
20246
|
-
* await Breakeven.dump("BTCUSDT", "my-strategy");
|
|
20247
|
-
* ```
|
|
20248
|
-
*/
|
|
20249
|
-
declare const Breakeven: BreakevenUtils;
|
|
20250
|
-
|
|
20251
|
-
/**
|
|
20252
|
-
* Logger service with automatic context injection.
|
|
20253
|
-
*
|
|
20254
|
-
* Features:
|
|
20255
|
-
* - Delegates to user-provided logger via setLogger()
|
|
20256
|
-
* - Automatically appends method context (strategyName, exchangeName, frameName)
|
|
20257
|
-
* - Automatically appends execution context (symbol, when, backtest)
|
|
20258
|
-
* - Defaults to NOOP_LOGGER if no logger configured
|
|
20259
|
-
*
|
|
20260
|
-
* Used throughout the framework for consistent logging with context.
|
|
20261
|
-
*/
|
|
20262
|
-
declare class LoggerService implements ILogger {
|
|
20263
|
-
private readonly methodContextService;
|
|
20264
|
-
private readonly executionContextService;
|
|
20265
|
-
private _commonLogger;
|
|
20266
|
-
/**
|
|
20267
|
-
* Gets current method context if available.
|
|
20268
|
-
* Contains strategyName, exchangeName, frameName from MethodContextService.
|
|
20269
|
-
*/
|
|
20270
|
-
private get methodContext();
|
|
20271
|
-
/**
|
|
20272
|
-
* Gets current execution context if available.
|
|
20273
|
-
* Contains symbol, when, backtest from ExecutionContextService.
|
|
20274
|
-
*/
|
|
20275
|
-
private get executionContext();
|
|
20276
|
-
/**
|
|
20277
|
-
* Logs general-purpose message with automatic context injection.
|
|
20278
|
-
*
|
|
20279
|
-
* @param topic - Log topic/category
|
|
20280
|
-
* @param args - Additional log arguments
|
|
20281
|
-
*/
|
|
20282
|
-
log: (topic: string, ...args: any[]) => Promise<void>;
|
|
20283
|
-
/**
|
|
20284
|
-
* Logs debug-level message with automatic context injection.
|
|
20285
|
-
*
|
|
20286
|
-
* @param topic - Log topic/category
|
|
20287
|
-
* @param args - Additional log arguments
|
|
20288
|
-
*/
|
|
20289
|
-
debug: (topic: string, ...args: any[]) => Promise<void>;
|
|
20290
|
-
/**
|
|
20291
|
-
* Logs info-level message with automatic context injection.
|
|
20292
|
-
*
|
|
20293
|
-
* @param topic - Log topic/category
|
|
20294
|
-
* @param args - Additional log arguments
|
|
20295
|
-
*/
|
|
20296
|
-
info: (topic: string, ...args: any[]) => Promise<void>;
|
|
20297
|
-
/**
|
|
20298
|
-
* Logs warning-level message with automatic context injection.
|
|
20299
|
-
*
|
|
20300
|
-
* @param topic - Log topic/category
|
|
20301
|
-
* @param args - Additional log arguments
|
|
20302
|
-
*/
|
|
20303
|
-
warn: (topic: string, ...args: any[]) => Promise<void>;
|
|
20304
|
-
/**
|
|
20305
|
-
* Sets custom logger implementation.
|
|
20306
|
-
*
|
|
20307
|
-
* @param logger - Custom logger implementing ILogger interface
|
|
20308
|
-
*/
|
|
20309
|
-
setLogger: (logger: ILogger) => void;
|
|
20310
|
-
}
|
|
20367
|
+
* const report = await Breakeven.getReport("BTCUSDT", "my-strategy");
|
|
20368
|
+
* await Breakeven.dump("BTCUSDT", "my-strategy");
|
|
20369
|
+
* ```
|
|
20370
|
+
*/
|
|
20371
|
+
declare const Breakeven: BreakevenUtils;
|
|
20311
20372
|
|
|
20312
20373
|
/**
|
|
20313
20374
|
* Type alias for column configuration used in strategy markdown reports.
|
|
@@ -20363,7 +20424,22 @@ type Columns = ColumnModel<StrategyEvent>;
|
|
|
20363
20424
|
* @see Strategy for the high-level utility class that wraps this service
|
|
20364
20425
|
*/
|
|
20365
20426
|
declare class StrategyMarkdownService {
|
|
20366
|
-
readonly loggerService:
|
|
20427
|
+
readonly loggerService: {
|
|
20428
|
+
readonly methodContextService: {
|
|
20429
|
+
readonly context: IMethodContext;
|
|
20430
|
+
};
|
|
20431
|
+
readonly executionContextService: {
|
|
20432
|
+
readonly context: IExecutionContext;
|
|
20433
|
+
};
|
|
20434
|
+
_commonLogger: ILogger;
|
|
20435
|
+
readonly _methodContext: {};
|
|
20436
|
+
readonly _executionContext: {};
|
|
20437
|
+
log: (topic: string, ...args: any[]) => Promise<void>;
|
|
20438
|
+
debug: (topic: string, ...args: any[]) => Promise<void>;
|
|
20439
|
+
info: (topic: string, ...args: any[]) => Promise<void>;
|
|
20440
|
+
warn: (topic: string, ...args: any[]) => Promise<void>;
|
|
20441
|
+
setLogger: (logger: ILogger) => void;
|
|
20442
|
+
};
|
|
20367
20443
|
/**
|
|
20368
20444
|
* Memoized factory for ReportStorage instances.
|
|
20369
20445
|
*
|
|
@@ -20599,7 +20675,7 @@ declare class StrategyMarkdownService {
|
|
|
20599
20675
|
* Generates and saves a markdown report to disk.
|
|
20600
20676
|
*
|
|
20601
20677
|
* Creates the output directory if it doesn't exist and writes
|
|
20602
|
-
* the report with a timestamped filename via
|
|
20678
|
+
* the report with a timestamped filename via MarkdownWriter.writeData().
|
|
20603
20679
|
*
|
|
20604
20680
|
* Filename format: `{symbol}_{strategyName}_{exchangeName}[_{frameName}_backtest|_live]-{timestamp}.md`
|
|
20605
20681
|
*
|
|
@@ -20818,207 +20894,6 @@ declare class StrategyUtils {
|
|
|
20818
20894
|
*/
|
|
20819
20895
|
declare const Strategy: StrategyUtils;
|
|
20820
20896
|
|
|
20821
|
-
/**
|
|
20822
|
-
* Proxy wrapper for user-defined action handlers with automatic error capture.
|
|
20823
|
-
*
|
|
20824
|
-
* Wraps all IPublicAction methods with trycatch to prevent user code errors from crashing the system.
|
|
20825
|
-
* All errors are logged, sent to errorEmitter, and returned as null (non-breaking).
|
|
20826
|
-
*
|
|
20827
|
-
* Key features:
|
|
20828
|
-
* - Automatic error catching and logging for all action methods
|
|
20829
|
-
* - Safe execution of partial user implementations (missing methods return null)
|
|
20830
|
-
* - Consistent error capture across all action lifecycle events
|
|
20831
|
-
* - Non-breaking failure mode (errors logged but execution continues)
|
|
20832
|
-
*
|
|
20833
|
-
* Architecture:
|
|
20834
|
-
* - Private constructor enforces factory pattern via fromInstance()
|
|
20835
|
-
* - Each method checks if target implements the method before calling
|
|
20836
|
-
* - Errors caught with fallback handler (warn log + errorEmitter)
|
|
20837
|
-
* - Returns null on error to prevent undefined behavior
|
|
20838
|
-
*
|
|
20839
|
-
* Used by:
|
|
20840
|
-
* - ClientAction to wrap user-provided action handlers
|
|
20841
|
-
* - ActionCoreService to safely invoke action callbacks
|
|
20842
|
-
*
|
|
20843
|
-
* @example
|
|
20844
|
-
* ```typescript
|
|
20845
|
-
* // Create proxy from user implementation
|
|
20846
|
-
* const userAction = {
|
|
20847
|
-
* signal: async (event) => {
|
|
20848
|
-
* // User code that might throw
|
|
20849
|
-
* throw new Error('User error');
|
|
20850
|
-
* }
|
|
20851
|
-
* };
|
|
20852
|
-
*
|
|
20853
|
-
* const proxy = ActionProxy.fromInstance(userAction);
|
|
20854
|
-
*
|
|
20855
|
-
* // Error is caught and logged, execution continues
|
|
20856
|
-
* await proxy.signal(event); // Logs error, returns null
|
|
20857
|
-
* await proxy.dispose(); // Safe call even though not implemented
|
|
20858
|
-
* ```
|
|
20859
|
-
*
|
|
20860
|
-
* @example
|
|
20861
|
-
* ```typescript
|
|
20862
|
-
* // Partial implementation is safe
|
|
20863
|
-
* const partialAction = {
|
|
20864
|
-
* init: async () => console.log('Initialized'),
|
|
20865
|
-
* // Other methods not implemented
|
|
20866
|
-
* };
|
|
20867
|
-
*
|
|
20868
|
-
* const proxy = ActionProxy.fromInstance(partialAction);
|
|
20869
|
-
* await proxy.init(); // Works
|
|
20870
|
-
* await proxy.signal(event); // Returns null (not implemented)
|
|
20871
|
-
* ```
|
|
20872
|
-
*/
|
|
20873
|
-
declare class ActionProxy implements IPublicAction {
|
|
20874
|
-
readonly _target: Partial<IPublicAction>;
|
|
20875
|
-
/**
|
|
20876
|
-
* Creates a new ActionProxy instance.
|
|
20877
|
-
*
|
|
20878
|
-
* @param _target - Partial action implementation to wrap with error capture
|
|
20879
|
-
* @private Use ActionProxy.fromInstance() instead
|
|
20880
|
-
*/
|
|
20881
|
-
private constructor();
|
|
20882
|
-
/**
|
|
20883
|
-
* Initializes the action handler with error capture.
|
|
20884
|
-
*
|
|
20885
|
-
* Wraps the user's init() method in trycatch to prevent initialization errors from crashing the system.
|
|
20886
|
-
* If the target doesn't implement init(), this method safely returns undefined.
|
|
20887
|
-
*
|
|
20888
|
-
* @returns Promise resolving to user's init() result or undefined if not implemented
|
|
20889
|
-
*/
|
|
20890
|
-
init(): Promise<any>;
|
|
20891
|
-
/**
|
|
20892
|
-
* Handles signal events from all modes with error capture.
|
|
20893
|
-
*
|
|
20894
|
-
* Wraps the user's signal() method to catch and log any errors.
|
|
20895
|
-
* Called on every tick/candle when strategy is evaluated.
|
|
20896
|
-
*
|
|
20897
|
-
* @param event - Signal state result with action, state, signal data, and context
|
|
20898
|
-
* @returns Promise resolving to user's signal() result or null on error
|
|
20899
|
-
*/
|
|
20900
|
-
signal(event: IStrategyTickResult): Promise<any>;
|
|
20901
|
-
/**
|
|
20902
|
-
* Handles signal events from live trading only with error capture.
|
|
20903
|
-
*
|
|
20904
|
-
* Wraps the user's signalLive() method to catch and log any errors.
|
|
20905
|
-
* Called every tick in live mode.
|
|
20906
|
-
*
|
|
20907
|
-
* @param event - Signal state result from live trading
|
|
20908
|
-
* @returns Promise resolving to user's signalLive() result or null on error
|
|
20909
|
-
*/
|
|
20910
|
-
signalLive(event: IStrategyTickResult): Promise<any>;
|
|
20911
|
-
/**
|
|
20912
|
-
* Handles signal events from backtest only with error capture.
|
|
20913
|
-
*
|
|
20914
|
-
* Wraps the user's signalBacktest() method to catch and log any errors.
|
|
20915
|
-
* Called every candle in backtest mode.
|
|
20916
|
-
*
|
|
20917
|
-
* @param event - Signal state result from backtest
|
|
20918
|
-
* @returns Promise resolving to user's signalBacktest() result or null on error
|
|
20919
|
-
*/
|
|
20920
|
-
signalBacktest(event: IStrategyTickResult): Promise<any>;
|
|
20921
|
-
/**
|
|
20922
|
-
* Handles breakeven events with error capture.
|
|
20923
|
-
*
|
|
20924
|
-
* Wraps the user's breakevenAvailable() method to catch and log any errors.
|
|
20925
|
-
* Called once per signal when stop-loss is moved to entry price.
|
|
20926
|
-
*
|
|
20927
|
-
* @param event - Breakeven milestone data with signal info, current price, timestamp
|
|
20928
|
-
* @returns Promise resolving to user's breakevenAvailable() result or null on error
|
|
20929
|
-
*/
|
|
20930
|
-
breakevenAvailable(event: BreakevenContract): Promise<any>;
|
|
20931
|
-
/**
|
|
20932
|
-
* Handles partial profit level events with error capture.
|
|
20933
|
-
*
|
|
20934
|
-
* Wraps the user's partialProfitAvailable() method to catch and log any errors.
|
|
20935
|
-
* Called once per profit level per signal (10%, 20%, 30%, etc).
|
|
20936
|
-
*
|
|
20937
|
-
* @param event - Profit milestone data with signal info, level, price, timestamp
|
|
20938
|
-
* @returns Promise resolving to user's partialProfitAvailable() result or null on error
|
|
20939
|
-
*/
|
|
20940
|
-
partialProfitAvailable(event: PartialProfitContract): Promise<any>;
|
|
20941
|
-
/**
|
|
20942
|
-
* Handles partial loss level events with error capture.
|
|
20943
|
-
*
|
|
20944
|
-
* Wraps the user's partialLossAvailable() method to catch and log any errors.
|
|
20945
|
-
* Called once per loss level per signal (-10%, -20%, -30%, etc).
|
|
20946
|
-
*
|
|
20947
|
-
* @param event - Loss milestone data with signal info, level, price, timestamp
|
|
20948
|
-
* @returns Promise resolving to user's partialLossAvailable() result or null on error
|
|
20949
|
-
*/
|
|
20950
|
-
partialLossAvailable(event: PartialLossContract): Promise<any>;
|
|
20951
|
-
/**
|
|
20952
|
-
* Handles scheduled ping events with error capture.
|
|
20953
|
-
*
|
|
20954
|
-
* Wraps the user's pingScheduled() method to catch and log any errors.
|
|
20955
|
-
* Called every minute while a scheduled signal is waiting for activation.
|
|
20956
|
-
*
|
|
20957
|
-
* @param event - Scheduled signal monitoring data with symbol, strategy info, signal data, timestamp
|
|
20958
|
-
* @returns Promise resolving to user's pingScheduled() result or null on error
|
|
20959
|
-
*/
|
|
20960
|
-
pingScheduled(event: SchedulePingContract): Promise<any>;
|
|
20961
|
-
/**
|
|
20962
|
-
* Handles active ping events with error capture.
|
|
20963
|
-
*
|
|
20964
|
-
* Wraps the user's pingActive() method to catch and log any errors.
|
|
20965
|
-
* Called every minute while a pending signal is active (position open).
|
|
20966
|
-
*
|
|
20967
|
-
* @param event - Active pending signal monitoring data with symbol, strategy info, signal data, timestamp
|
|
20968
|
-
* @returns Promise resolving to user's pingActive() result or null on error
|
|
20969
|
-
*/
|
|
20970
|
-
pingActive(event: ActivePingContract): Promise<any>;
|
|
20971
|
-
/**
|
|
20972
|
-
* Handles risk rejection events with error capture.
|
|
20973
|
-
*
|
|
20974
|
-
* Wraps the user's riskRejection() method to catch and log any errors.
|
|
20975
|
-
* Called only when signal is rejected by risk management validation.
|
|
20976
|
-
*
|
|
20977
|
-
* @param event - Risk rejection data with symbol, pending signal, rejection reason, timestamp
|
|
20978
|
-
* @returns Promise resolving to user's riskRejection() result or null on error
|
|
20979
|
-
*/
|
|
20980
|
-
riskRejection(event: RiskContract): Promise<any>;
|
|
20981
|
-
/**
|
|
20982
|
-
* Gate for position open/close via limit order.
|
|
20983
|
-
* NOT wrapped in trycatch — exceptions propagate to CREATE_SYNC_FN.
|
|
20984
|
-
*
|
|
20985
|
-
* @param event - Sync event with action "signal-open" or "signal-close"
|
|
20986
|
-
*/
|
|
20987
|
-
signalSync(event: SignalSyncContract): Promise<void>;
|
|
20988
|
-
/**
|
|
20989
|
-
* Cleans up resources with error capture.
|
|
20990
|
-
*
|
|
20991
|
-
* Wraps the user's dispose() method to catch and log any errors.
|
|
20992
|
-
* Called once when strategy execution ends.
|
|
20993
|
-
*
|
|
20994
|
-
* @returns Promise resolving to user's dispose() result or null on error
|
|
20995
|
-
*/
|
|
20996
|
-
dispose(): Promise<any>;
|
|
20997
|
-
/**
|
|
20998
|
-
* Creates a new ActionProxy instance wrapping a user-provided action handler.
|
|
20999
|
-
*
|
|
21000
|
-
* Factory method enforcing the private constructor pattern.
|
|
21001
|
-
* Wraps all methods of the provided instance with error capture.
|
|
21002
|
-
*
|
|
21003
|
-
* @param instance - Partial action implementation to wrap
|
|
21004
|
-
* @returns New ActionProxy instance with error-safe method wrappers
|
|
21005
|
-
*
|
|
21006
|
-
* @example
|
|
21007
|
-
* ```typescript
|
|
21008
|
-
* const userAction = {
|
|
21009
|
-
* signal: async (event) => {
|
|
21010
|
-
* console.log('Signal received:', event);
|
|
21011
|
-
* },
|
|
21012
|
-
* dispose: async () => {
|
|
21013
|
-
* console.log('Cleanup complete');
|
|
21014
|
-
* }
|
|
21015
|
-
* };
|
|
21016
|
-
*
|
|
21017
|
-
* const proxy = ActionProxy.fromInstance(userAction);
|
|
21018
|
-
* ```
|
|
21019
|
-
*/
|
|
21020
|
-
static fromInstance(instance: Partial<IPublicAction>): ActionProxy;
|
|
21021
|
-
}
|
|
21022
20897
|
/**
|
|
21023
20898
|
* Base class for custom action handlers.
|
|
21024
20899
|
*
|
|
@@ -21032,7 +20907,7 @@ declare class ActionProxy implements IPublicAction {
|
|
|
21032
20907
|
*
|
|
21033
20908
|
* Key features:
|
|
21034
20909
|
* - All methods have default implementations (no need to implement unused methods)
|
|
21035
|
-
* - Automatic logging of all events via
|
|
20910
|
+
* - Automatic logging of all events via LOGGER_SERVICE
|
|
21036
20911
|
* - Access to strategy context (strategyName, frameName, actionName)
|
|
21037
20912
|
* - Implements full IPublicAction interface
|
|
21038
20913
|
*
|
|
@@ -23256,7 +23131,22 @@ declare class ExchangeConnectionService implements IExchange {
|
|
|
23256
23131
|
* Strategies are registered via addStrategy() and retrieved by name.
|
|
23257
23132
|
*/
|
|
23258
23133
|
declare class StrategySchemaService {
|
|
23259
|
-
readonly loggerService:
|
|
23134
|
+
readonly loggerService: {
|
|
23135
|
+
readonly methodContextService: {
|
|
23136
|
+
readonly context: IMethodContext;
|
|
23137
|
+
};
|
|
23138
|
+
readonly executionContextService: {
|
|
23139
|
+
readonly context: IExecutionContext;
|
|
23140
|
+
};
|
|
23141
|
+
_commonLogger: ILogger;
|
|
23142
|
+
readonly _methodContext: {};
|
|
23143
|
+
readonly _executionContext: {};
|
|
23144
|
+
log: (topic: string, ...args: any[]) => Promise<void>;
|
|
23145
|
+
debug: (topic: string, ...args: any[]) => Promise<void>;
|
|
23146
|
+
info: (topic: string, ...args: any[]) => Promise<void>;
|
|
23147
|
+
warn: (topic: string, ...args: any[]) => Promise<void>;
|
|
23148
|
+
setLogger: (logger: ILogger) => void;
|
|
23149
|
+
};
|
|
23260
23150
|
private _registry;
|
|
23261
23151
|
/**
|
|
23262
23152
|
* Registers a new strategy schema.
|
|
@@ -23379,7 +23269,68 @@ declare class ClientRisk implements IRisk {
|
|
|
23379
23269
|
* @param params - Risk check arguments (passthrough from ClientStrategy)
|
|
23380
23270
|
* @returns Promise resolving to true if allowed, false if rejected
|
|
23381
23271
|
*/
|
|
23382
|
-
checkSignal: (params: IRiskCheckArgs) => Promise<boolean>;
|
|
23272
|
+
checkSignal: (params: IRiskCheckArgs) => Promise<boolean>;
|
|
23273
|
+
}
|
|
23274
|
+
|
|
23275
|
+
/**
|
|
23276
|
+
* Service for managing risk schema registry.
|
|
23277
|
+
*
|
|
23278
|
+
* Uses ToolRegistry from functools-kit for type-safe schema storage.
|
|
23279
|
+
* Risk profiles are registered via addRisk() and retrieved by name.
|
|
23280
|
+
*/
|
|
23281
|
+
declare class RiskSchemaService {
|
|
23282
|
+
readonly loggerService: {
|
|
23283
|
+
readonly methodContextService: {
|
|
23284
|
+
readonly context: IMethodContext;
|
|
23285
|
+
};
|
|
23286
|
+
readonly executionContextService: {
|
|
23287
|
+
readonly context: IExecutionContext;
|
|
23288
|
+
};
|
|
23289
|
+
_commonLogger: ILogger;
|
|
23290
|
+
readonly _methodContext: {};
|
|
23291
|
+
readonly _executionContext: {};
|
|
23292
|
+
log: (topic: string, ...args: any[]) => Promise<void>;
|
|
23293
|
+
debug: (topic: string, ...args: any[]) => Promise<void>;
|
|
23294
|
+
info: (topic: string, ...args: any[]) => Promise<void>;
|
|
23295
|
+
warn: (topic: string, ...args: any[]) => Promise<void>;
|
|
23296
|
+
setLogger: (logger: ILogger) => void;
|
|
23297
|
+
};
|
|
23298
|
+
private _registry;
|
|
23299
|
+
/**
|
|
23300
|
+
* Registers a new risk schema.
|
|
23301
|
+
*
|
|
23302
|
+
* @param key - Unique risk profile name
|
|
23303
|
+
* @param value - Risk schema configuration
|
|
23304
|
+
* @throws Error if risk name already exists
|
|
23305
|
+
*/
|
|
23306
|
+
register: (key: RiskName, value: IRiskSchema) => void;
|
|
23307
|
+
/**
|
|
23308
|
+
* Validates risk schema structure for required properties.
|
|
23309
|
+
*
|
|
23310
|
+
* Performs shallow validation to ensure all required properties exist
|
|
23311
|
+
* and have correct types before registration in the registry.
|
|
23312
|
+
*
|
|
23313
|
+
* @param riskSchema - Risk schema to validate
|
|
23314
|
+
* @throws Error if riskName is missing or not a string
|
|
23315
|
+
*/
|
|
23316
|
+
private validateShallow;
|
|
23317
|
+
/**
|
|
23318
|
+
* Overrides an existing risk schema with partial updates.
|
|
23319
|
+
*
|
|
23320
|
+
* @param key - Risk name to override
|
|
23321
|
+
* @param value - Partial schema updates
|
|
23322
|
+
* @returns Updated risk schema
|
|
23323
|
+
* @throws Error if risk name doesn't exist
|
|
23324
|
+
*/
|
|
23325
|
+
override: (key: RiskName, value: Partial<IRiskSchema>) => IRiskSchema;
|
|
23326
|
+
/**
|
|
23327
|
+
* Retrieves a risk schema by name.
|
|
23328
|
+
*
|
|
23329
|
+
* @param key - Risk name
|
|
23330
|
+
* @returns Risk schema configuration
|
|
23331
|
+
* @throws Error if risk name doesn't exist
|
|
23332
|
+
*/
|
|
23333
|
+
get: (key: RiskName) => IRiskSchema;
|
|
23383
23334
|
}
|
|
23384
23335
|
|
|
23385
23336
|
/**
|
|
@@ -23668,8 +23619,26 @@ type TRisk$1 = {
|
|
|
23668
23619
|
* ```
|
|
23669
23620
|
*/
|
|
23670
23621
|
declare class RiskConnectionService implements TRisk$1 {
|
|
23671
|
-
|
|
23672
|
-
|
|
23622
|
+
readonly loggerService: {
|
|
23623
|
+
readonly methodContextService: {
|
|
23624
|
+
readonly context: IMethodContext;
|
|
23625
|
+
};
|
|
23626
|
+
readonly executionContextService: {
|
|
23627
|
+
readonly context: IExecutionContext;
|
|
23628
|
+
};
|
|
23629
|
+
_commonLogger: ILogger;
|
|
23630
|
+
readonly _methodContext: {};
|
|
23631
|
+
readonly _executionContext: {};
|
|
23632
|
+
log: (topic: string, ...args: any[]) => Promise<void>;
|
|
23633
|
+
debug: (topic: string, ...args: any[]) => Promise<void>;
|
|
23634
|
+
info: (topic: string, ...args: any[]) => Promise<void>;
|
|
23635
|
+
warn: (topic: string, ...args: any[]) => Promise<void>;
|
|
23636
|
+
setLogger: (logger: ILogger) => void;
|
|
23637
|
+
};
|
|
23638
|
+
readonly riskSchemaService: RiskSchemaService;
|
|
23639
|
+
readonly executionContextService: {
|
|
23640
|
+
readonly context: IExecutionContext;
|
|
23641
|
+
};
|
|
23673
23642
|
/**
|
|
23674
23643
|
* Action core service injected from DI container.
|
|
23675
23644
|
*/
|
|
@@ -23789,7 +23758,22 @@ declare class PartialConnectionService implements IPartial {
|
|
|
23789
23758
|
/**
|
|
23790
23759
|
* Logger service injected from DI container.
|
|
23791
23760
|
*/
|
|
23792
|
-
|
|
23761
|
+
readonly loggerService: {
|
|
23762
|
+
readonly methodContextService: {
|
|
23763
|
+
readonly context: IMethodContext;
|
|
23764
|
+
};
|
|
23765
|
+
readonly executionContextService: {
|
|
23766
|
+
readonly context: IExecutionContext;
|
|
23767
|
+
};
|
|
23768
|
+
_commonLogger: ILogger;
|
|
23769
|
+
readonly _methodContext: {};
|
|
23770
|
+
readonly _executionContext: {};
|
|
23771
|
+
log: (topic: string, ...args: any[]) => Promise<void>;
|
|
23772
|
+
debug: (topic: string, ...args: any[]) => Promise<void>;
|
|
23773
|
+
info: (topic: string, ...args: any[]) => Promise<void>;
|
|
23774
|
+
warn: (topic: string, ...args: any[]) => Promise<void>;
|
|
23775
|
+
setLogger: (logger: ILogger) => void;
|
|
23776
|
+
};
|
|
23793
23777
|
/**
|
|
23794
23778
|
* Action core service injected from DI container.
|
|
23795
23779
|
*/
|
|
@@ -23890,7 +23874,22 @@ declare class BreakevenConnectionService implements IBreakeven {
|
|
|
23890
23874
|
/**
|
|
23891
23875
|
* Logger service injected from DI container.
|
|
23892
23876
|
*/
|
|
23893
|
-
|
|
23877
|
+
readonly loggerService: {
|
|
23878
|
+
readonly methodContextService: {
|
|
23879
|
+
readonly context: IMethodContext;
|
|
23880
|
+
};
|
|
23881
|
+
readonly executionContextService: {
|
|
23882
|
+
readonly context: IExecutionContext;
|
|
23883
|
+
};
|
|
23884
|
+
_commonLogger: ILogger;
|
|
23885
|
+
readonly _methodContext: {};
|
|
23886
|
+
readonly _executionContext: {};
|
|
23887
|
+
log: (topic: string, ...args: any[]) => Promise<void>;
|
|
23888
|
+
debug: (topic: string, ...args: any[]) => Promise<void>;
|
|
23889
|
+
info: (topic: string, ...args: any[]) => Promise<void>;
|
|
23890
|
+
warn: (topic: string, ...args: any[]) => Promise<void>;
|
|
23891
|
+
setLogger: (logger: ILogger) => void;
|
|
23892
|
+
};
|
|
23894
23893
|
/**
|
|
23895
23894
|
* Action core service injected from DI container.
|
|
23896
23895
|
*/
|
|
@@ -24147,7 +24146,22 @@ type TStrategy$1 = {
|
|
|
24147
24146
|
* ```
|
|
24148
24147
|
*/
|
|
24149
24148
|
declare class StrategyConnectionService implements TStrategy$1 {
|
|
24150
|
-
readonly loggerService:
|
|
24149
|
+
readonly loggerService: {
|
|
24150
|
+
readonly methodContextService: {
|
|
24151
|
+
readonly context: IMethodContext;
|
|
24152
|
+
};
|
|
24153
|
+
readonly executionContextService: {
|
|
24154
|
+
readonly context: IExecutionContext;
|
|
24155
|
+
};
|
|
24156
|
+
_commonLogger: ILogger;
|
|
24157
|
+
readonly _methodContext: {};
|
|
24158
|
+
readonly _executionContext: {};
|
|
24159
|
+
log: (topic: string, ...args: any[]) => Promise<void>;
|
|
24160
|
+
debug: (topic: string, ...args: any[]) => Promise<void>;
|
|
24161
|
+
info: (topic: string, ...args: any[]) => Promise<void>;
|
|
24162
|
+
warn: (topic: string, ...args: any[]) => Promise<void>;
|
|
24163
|
+
setLogger: (logger: ILogger) => void;
|
|
24164
|
+
};
|
|
24151
24165
|
readonly executionContextService: {
|
|
24152
24166
|
readonly context: IExecutionContext;
|
|
24153
24167
|
};
|
|
@@ -25232,78 +25246,281 @@ declare class ClientSizing implements ISizing {
|
|
|
25232
25246
|
readonly params: ISizingParams;
|
|
25233
25247
|
constructor(params: ISizingParams);
|
|
25234
25248
|
/**
|
|
25235
|
-
* Calculates position size based on configured method and constraints.
|
|
25249
|
+
* Calculates position size based on configured method and constraints.
|
|
25250
|
+
*
|
|
25251
|
+
* @param params - Calculation parameters (symbol, balance, prices, etc.)
|
|
25252
|
+
* @returns Promise resolving to calculated position size
|
|
25253
|
+
* @throws Error if required parameters are missing or invalid
|
|
25254
|
+
*/
|
|
25255
|
+
calculate(params: ISizingCalculateParams): Promise<number>;
|
|
25256
|
+
}
|
|
25257
|
+
|
|
25258
|
+
/**
|
|
25259
|
+
* Type definition for sizing methods.
|
|
25260
|
+
* Maps all keys of ISizing to any type.
|
|
25261
|
+
* Used for dynamic method routing in SizingConnectionService.
|
|
25262
|
+
*/
|
|
25263
|
+
type TSizing$1 = {
|
|
25264
|
+
[key in keyof ISizing]: any;
|
|
25265
|
+
};
|
|
25266
|
+
/**
|
|
25267
|
+
* Connection service routing sizing operations to correct ClientSizing instance.
|
|
25268
|
+
*
|
|
25269
|
+
* Routes sizing method calls to the appropriate sizing implementation
|
|
25270
|
+
* based on the provided sizingName parameter. Uses memoization to cache
|
|
25271
|
+
* ClientSizing instances for performance.
|
|
25272
|
+
*
|
|
25273
|
+
* Key features:
|
|
25274
|
+
* - Explicit sizing routing via sizingName parameter
|
|
25275
|
+
* - Memoized ClientSizing instances by sizingName
|
|
25276
|
+
* - Position size calculation with risk management
|
|
25277
|
+
*
|
|
25278
|
+
* Note: sizingName is empty string for strategies without sizing configuration.
|
|
25279
|
+
*
|
|
25280
|
+
* @example
|
|
25281
|
+
* ```typescript
|
|
25282
|
+
* // Used internally by framework
|
|
25283
|
+
* const quantity = await sizingConnectionService.calculate(
|
|
25284
|
+
* {
|
|
25285
|
+
* symbol: "BTCUSDT",
|
|
25286
|
+
* accountBalance: 10000,
|
|
25287
|
+
* priceOpen: 50000,
|
|
25288
|
+
* priceStopLoss: 49000,
|
|
25289
|
+
* method: "fixed-percentage"
|
|
25290
|
+
* },
|
|
25291
|
+
* { sizingName: "conservative" }
|
|
25292
|
+
* );
|
|
25293
|
+
* ```
|
|
25294
|
+
*/
|
|
25295
|
+
declare class SizingConnectionService implements TSizing$1 {
|
|
25296
|
+
private readonly loggerService;
|
|
25297
|
+
private readonly sizingSchemaService;
|
|
25298
|
+
/**
|
|
25299
|
+
* Retrieves memoized ClientSizing instance for given sizing name.
|
|
25300
|
+
*
|
|
25301
|
+
* Creates ClientSizing on first call, returns cached instance on subsequent calls.
|
|
25302
|
+
* Cache key is sizingName string.
|
|
25303
|
+
*
|
|
25304
|
+
* @param sizingName - Name of registered sizing schema
|
|
25305
|
+
* @returns Configured ClientSizing instance
|
|
25306
|
+
*/
|
|
25307
|
+
getSizing: ((sizingName: SizingName) => ClientSizing) & functools_kit.IClearableMemoize<string> & functools_kit.IControlMemoize<string, ClientSizing>;
|
|
25308
|
+
/**
|
|
25309
|
+
* Calculates position size based on risk parameters and configured method.
|
|
25310
|
+
*
|
|
25311
|
+
* Routes to appropriate ClientSizing instance based on provided context.
|
|
25312
|
+
* Supports multiple sizing methods: fixed-percentage, kelly-criterion, atr-based.
|
|
25313
|
+
*
|
|
25314
|
+
* @param params - Calculation parameters (symbol, balance, prices, method-specific data)
|
|
25315
|
+
* @param context - Execution context with sizing name
|
|
25316
|
+
* @returns Promise resolving to calculated position size
|
|
25317
|
+
*/
|
|
25318
|
+
calculate: (params: ISizingCalculateParams, context: {
|
|
25319
|
+
sizingName: SizingName;
|
|
25320
|
+
}) => Promise<number>;
|
|
25321
|
+
}
|
|
25322
|
+
|
|
25323
|
+
/**
|
|
25324
|
+
* Proxy wrapper for user-defined action handlers with automatic error capture.
|
|
25325
|
+
*
|
|
25326
|
+
* Wraps all IPublicAction methods with trycatch to prevent user code errors from crashing the system.
|
|
25327
|
+
* All errors are logged, sent to errorEmitter, and returned as null (non-breaking).
|
|
25328
|
+
*
|
|
25329
|
+
* Key features:
|
|
25330
|
+
* - Automatic error catching and logging for all action methods
|
|
25331
|
+
* - Safe execution of partial user implementations (missing methods return null)
|
|
25332
|
+
* - Consistent error capture across all action lifecycle events
|
|
25333
|
+
* - Non-breaking failure mode (errors logged but execution continues)
|
|
25334
|
+
*
|
|
25335
|
+
* Architecture:
|
|
25336
|
+
* - Private constructor enforces factory pattern via fromInstance()
|
|
25337
|
+
* - Each method checks if target implements the method before calling
|
|
25338
|
+
* - Errors caught with fallback handler (warn log + errorEmitter)
|
|
25339
|
+
* - Returns null on error to prevent undefined behavior
|
|
25340
|
+
*
|
|
25341
|
+
* Used by:
|
|
25342
|
+
* - ClientAction to wrap user-provided action handlers
|
|
25343
|
+
* - ActionCoreService to safely invoke action callbacks
|
|
25344
|
+
*
|
|
25345
|
+
* @example
|
|
25346
|
+
* ```typescript
|
|
25347
|
+
* // Create proxy from user implementation
|
|
25348
|
+
* const userAction = {
|
|
25349
|
+
* signal: async (event) => {
|
|
25350
|
+
* // User code that might throw
|
|
25351
|
+
* throw new Error('User error');
|
|
25352
|
+
* }
|
|
25353
|
+
* };
|
|
25354
|
+
*
|
|
25355
|
+
* const proxy = ActionProxy.fromInstance(userAction);
|
|
25356
|
+
*
|
|
25357
|
+
* // Error is caught and logged, execution continues
|
|
25358
|
+
* await proxy.signal(event); // Logs error, returns null
|
|
25359
|
+
* await proxy.dispose(); // Safe call even though not implemented
|
|
25360
|
+
* ```
|
|
25361
|
+
*
|
|
25362
|
+
* @example
|
|
25363
|
+
* ```typescript
|
|
25364
|
+
* // Partial implementation is safe
|
|
25365
|
+
* const partialAction = {
|
|
25366
|
+
* init: async () => console.log('Initialized'),
|
|
25367
|
+
* // Other methods not implemented
|
|
25368
|
+
* };
|
|
25369
|
+
*
|
|
25370
|
+
* const proxy = ActionProxy.fromInstance(partialAction);
|
|
25371
|
+
* await proxy.init(); // Works
|
|
25372
|
+
* await proxy.signal(event); // Returns null (not implemented)
|
|
25373
|
+
* ```
|
|
25374
|
+
*/
|
|
25375
|
+
declare class ActionProxy implements IPublicAction {
|
|
25376
|
+
readonly _target: Partial<IPublicAction>;
|
|
25377
|
+
readonly params: IActionParams;
|
|
25378
|
+
/**
|
|
25379
|
+
* Creates a new ActionProxy instance.
|
|
25380
|
+
*
|
|
25381
|
+
* @param _target - Partial action implementation to wrap with error capture
|
|
25382
|
+
* @private Use ActionProxy.fromInstance() instead
|
|
25383
|
+
*/
|
|
25384
|
+
private constructor();
|
|
25385
|
+
/**
|
|
25386
|
+
* Initializes the action handler with error capture.
|
|
25387
|
+
*
|
|
25388
|
+
* Wraps the user's init() method in trycatch to prevent initialization errors from crashing the system.
|
|
25389
|
+
* If the target doesn't implement init(), this method safely returns undefined.
|
|
25390
|
+
*
|
|
25391
|
+
* @returns Promise resolving to user's init() result or undefined if not implemented
|
|
25392
|
+
*/
|
|
25393
|
+
init(): Promise<any>;
|
|
25394
|
+
/**
|
|
25395
|
+
* Handles signal events from all modes with error capture.
|
|
25396
|
+
*
|
|
25397
|
+
* Wraps the user's signal() method to catch and log any errors.
|
|
25398
|
+
* Called on every tick/candle when strategy is evaluated.
|
|
25399
|
+
*
|
|
25400
|
+
* @param event - Signal state result with action, state, signal data, and context
|
|
25401
|
+
* @returns Promise resolving to user's signal() result or null on error
|
|
25402
|
+
*/
|
|
25403
|
+
signal(event: IStrategyTickResult): Promise<any>;
|
|
25404
|
+
/**
|
|
25405
|
+
* Handles signal events from live trading only with error capture.
|
|
25406
|
+
*
|
|
25407
|
+
* Wraps the user's signalLive() method to catch and log any errors.
|
|
25408
|
+
* Called every tick in live mode.
|
|
25409
|
+
*
|
|
25410
|
+
* @param event - Signal state result from live trading
|
|
25411
|
+
* @returns Promise resolving to user's signalLive() result or null on error
|
|
25412
|
+
*/
|
|
25413
|
+
signalLive(event: IStrategyTickResult): Promise<any>;
|
|
25414
|
+
/**
|
|
25415
|
+
* Handles signal events from backtest only with error capture.
|
|
25416
|
+
*
|
|
25417
|
+
* Wraps the user's signalBacktest() method to catch and log any errors.
|
|
25418
|
+
* Called every candle in backtest mode.
|
|
25419
|
+
*
|
|
25420
|
+
* @param event - Signal state result from backtest
|
|
25421
|
+
* @returns Promise resolving to user's signalBacktest() result or null on error
|
|
25422
|
+
*/
|
|
25423
|
+
signalBacktest(event: IStrategyTickResult): Promise<any>;
|
|
25424
|
+
/**
|
|
25425
|
+
* Handles breakeven events with error capture.
|
|
25426
|
+
*
|
|
25427
|
+
* Wraps the user's breakevenAvailable() method to catch and log any errors.
|
|
25428
|
+
* Called once per signal when stop-loss is moved to entry price.
|
|
25429
|
+
*
|
|
25430
|
+
* @param event - Breakeven milestone data with signal info, current price, timestamp
|
|
25431
|
+
* @returns Promise resolving to user's breakevenAvailable() result or null on error
|
|
25432
|
+
*/
|
|
25433
|
+
breakevenAvailable(event: BreakevenContract): Promise<any>;
|
|
25434
|
+
/**
|
|
25435
|
+
* Handles partial profit level events with error capture.
|
|
25436
|
+
*
|
|
25437
|
+
* Wraps the user's partialProfitAvailable() method to catch and log any errors.
|
|
25438
|
+
* Called once per profit level per signal (10%, 20%, 30%, etc).
|
|
25439
|
+
*
|
|
25440
|
+
* @param event - Profit milestone data with signal info, level, price, timestamp
|
|
25441
|
+
* @returns Promise resolving to user's partialProfitAvailable() result or null on error
|
|
25442
|
+
*/
|
|
25443
|
+
partialProfitAvailable(event: PartialProfitContract): Promise<any>;
|
|
25444
|
+
/**
|
|
25445
|
+
* Handles partial loss level events with error capture.
|
|
25446
|
+
*
|
|
25447
|
+
* Wraps the user's partialLossAvailable() method to catch and log any errors.
|
|
25448
|
+
* Called once per loss level per signal (-10%, -20%, -30%, etc).
|
|
25449
|
+
*
|
|
25450
|
+
* @param event - Loss milestone data with signal info, level, price, timestamp
|
|
25451
|
+
* @returns Promise resolving to user's partialLossAvailable() result or null on error
|
|
25452
|
+
*/
|
|
25453
|
+
partialLossAvailable(event: PartialLossContract): Promise<any>;
|
|
25454
|
+
/**
|
|
25455
|
+
* Handles scheduled ping events with error capture.
|
|
25456
|
+
*
|
|
25457
|
+
* Wraps the user's pingScheduled() method to catch and log any errors.
|
|
25458
|
+
* Called every minute while a scheduled signal is waiting for activation.
|
|
25459
|
+
*
|
|
25460
|
+
* @param event - Scheduled signal monitoring data with symbol, strategy info, signal data, timestamp
|
|
25461
|
+
* @returns Promise resolving to user's pingScheduled() result or null on error
|
|
25462
|
+
*/
|
|
25463
|
+
pingScheduled(event: SchedulePingContract): Promise<any>;
|
|
25464
|
+
/**
|
|
25465
|
+
* Handles active ping events with error capture.
|
|
25466
|
+
*
|
|
25467
|
+
* Wraps the user's pingActive() method to catch and log any errors.
|
|
25468
|
+
* Called every minute while a pending signal is active (position open).
|
|
25469
|
+
*
|
|
25470
|
+
* @param event - Active pending signal monitoring data with symbol, strategy info, signal data, timestamp
|
|
25471
|
+
* @returns Promise resolving to user's pingActive() result or null on error
|
|
25472
|
+
*/
|
|
25473
|
+
pingActive(event: ActivePingContract): Promise<any>;
|
|
25474
|
+
/**
|
|
25475
|
+
* Handles risk rejection events with error capture.
|
|
25476
|
+
*
|
|
25477
|
+
* Wraps the user's riskRejection() method to catch and log any errors.
|
|
25478
|
+
* Called only when signal is rejected by risk management validation.
|
|
25479
|
+
*
|
|
25480
|
+
* @param event - Risk rejection data with symbol, pending signal, rejection reason, timestamp
|
|
25481
|
+
* @returns Promise resolving to user's riskRejection() result or null on error
|
|
25482
|
+
*/
|
|
25483
|
+
riskRejection(event: RiskContract): Promise<any>;
|
|
25484
|
+
/**
|
|
25485
|
+
* Gate for position open/close via limit order.
|
|
25486
|
+
* NOT wrapped in trycatch — exceptions propagate to CREATE_SYNC_FN.
|
|
25236
25487
|
*
|
|
25237
|
-
* @param
|
|
25238
|
-
* @returns Promise resolving to calculated position size
|
|
25239
|
-
* @throws Error if required parameters are missing or invalid
|
|
25488
|
+
* @param event - Sync event with action "signal-open" or "signal-close"
|
|
25240
25489
|
*/
|
|
25241
|
-
|
|
25242
|
-
}
|
|
25243
|
-
|
|
25244
|
-
/**
|
|
25245
|
-
* Type definition for sizing methods.
|
|
25246
|
-
* Maps all keys of ISizing to any type.
|
|
25247
|
-
* Used for dynamic method routing in SizingConnectionService.
|
|
25248
|
-
*/
|
|
25249
|
-
type TSizing$1 = {
|
|
25250
|
-
[key in keyof ISizing]: any;
|
|
25251
|
-
};
|
|
25252
|
-
/**
|
|
25253
|
-
* Connection service routing sizing operations to correct ClientSizing instance.
|
|
25254
|
-
*
|
|
25255
|
-
* Routes sizing method calls to the appropriate sizing implementation
|
|
25256
|
-
* based on the provided sizingName parameter. Uses memoization to cache
|
|
25257
|
-
* ClientSizing instances for performance.
|
|
25258
|
-
*
|
|
25259
|
-
* Key features:
|
|
25260
|
-
* - Explicit sizing routing via sizingName parameter
|
|
25261
|
-
* - Memoized ClientSizing instances by sizingName
|
|
25262
|
-
* - Position size calculation with risk management
|
|
25263
|
-
*
|
|
25264
|
-
* Note: sizingName is empty string for strategies without sizing configuration.
|
|
25265
|
-
*
|
|
25266
|
-
* @example
|
|
25267
|
-
* ```typescript
|
|
25268
|
-
* // Used internally by framework
|
|
25269
|
-
* const quantity = await sizingConnectionService.calculate(
|
|
25270
|
-
* {
|
|
25271
|
-
* symbol: "BTCUSDT",
|
|
25272
|
-
* accountBalance: 10000,
|
|
25273
|
-
* priceOpen: 50000,
|
|
25274
|
-
* priceStopLoss: 49000,
|
|
25275
|
-
* method: "fixed-percentage"
|
|
25276
|
-
* },
|
|
25277
|
-
* { sizingName: "conservative" }
|
|
25278
|
-
* );
|
|
25279
|
-
* ```
|
|
25280
|
-
*/
|
|
25281
|
-
declare class SizingConnectionService implements TSizing$1 {
|
|
25282
|
-
private readonly loggerService;
|
|
25283
|
-
private readonly sizingSchemaService;
|
|
25490
|
+
signalSync(event: SignalSyncContract): Promise<void>;
|
|
25284
25491
|
/**
|
|
25285
|
-
*
|
|
25492
|
+
* Cleans up resources with error capture.
|
|
25286
25493
|
*
|
|
25287
|
-
*
|
|
25288
|
-
*
|
|
25494
|
+
* Wraps the user's dispose() method to catch and log any errors.
|
|
25495
|
+
* Called once when strategy execution ends.
|
|
25289
25496
|
*
|
|
25290
|
-
* @
|
|
25291
|
-
* @returns Configured ClientSizing instance
|
|
25497
|
+
* @returns Promise resolving to user's dispose() result or null on error
|
|
25292
25498
|
*/
|
|
25293
|
-
|
|
25499
|
+
dispose(): Promise<any>;
|
|
25294
25500
|
/**
|
|
25295
|
-
*
|
|
25501
|
+
* Creates a new ActionProxy instance wrapping a user-provided action handler.
|
|
25296
25502
|
*
|
|
25297
|
-
*
|
|
25298
|
-
*
|
|
25503
|
+
* Factory method enforcing the private constructor pattern.
|
|
25504
|
+
* Wraps all methods of the provided instance with error capture.
|
|
25299
25505
|
*
|
|
25300
|
-
* @param
|
|
25301
|
-
* @
|
|
25302
|
-
*
|
|
25506
|
+
* @param instance - Partial action implementation to wrap
|
|
25507
|
+
* @returns New ActionProxy instance with error-safe method wrappers
|
|
25508
|
+
*
|
|
25509
|
+
* @example
|
|
25510
|
+
* ```typescript
|
|
25511
|
+
* const userAction = {
|
|
25512
|
+
* signal: async (event) => {
|
|
25513
|
+
* console.log('Signal received:', event);
|
|
25514
|
+
* },
|
|
25515
|
+
* dispose: async () => {
|
|
25516
|
+
* console.log('Cleanup complete');
|
|
25517
|
+
* }
|
|
25518
|
+
* };
|
|
25519
|
+
*
|
|
25520
|
+
* const proxy = ActionProxy.fromInstance(userAction);
|
|
25521
|
+
* ```
|
|
25303
25522
|
*/
|
|
25304
|
-
|
|
25305
|
-
sizingName: SizingName;
|
|
25306
|
-
}) => Promise<number>;
|
|
25523
|
+
static fromInstance(instance: Partial<IPublicAction>, params: IActionParams): ActionProxy;
|
|
25307
25524
|
}
|
|
25308
25525
|
|
|
25309
25526
|
/**
|
|
@@ -25463,6 +25680,7 @@ type TAction = {
|
|
|
25463
25680
|
declare class ActionConnectionService implements TAction {
|
|
25464
25681
|
private readonly loggerService;
|
|
25465
25682
|
private readonly actionSchemaService;
|
|
25683
|
+
private readonly strategyCoreService;
|
|
25466
25684
|
/**
|
|
25467
25685
|
* Retrieves memoized ClientAction instance for given action name, strategy, exchange, frame and backtest mode.
|
|
25468
25686
|
*
|
|
@@ -26860,30 +27078,212 @@ declare class RiskGlobalService implements TRisk {
|
|
|
26860
27078
|
openTimestamp: number;
|
|
26861
27079
|
}) => Promise<void>;
|
|
26862
27080
|
/**
|
|
26863
|
-
* Removes a closed signal from the risk management system.
|
|
27081
|
+
* Removes a closed signal from the risk management system.
|
|
27082
|
+
*
|
|
27083
|
+
* @param symbol - Trading pair symbol
|
|
27084
|
+
* @param payload - Payload information (strategyName, riskName, exchangeName, frameName, backtest)
|
|
27085
|
+
*/
|
|
27086
|
+
removeSignal: (symbol: string, payload: {
|
|
27087
|
+
strategyName: StrategyName;
|
|
27088
|
+
riskName: RiskName;
|
|
27089
|
+
exchangeName: ExchangeName;
|
|
27090
|
+
frameName: FrameName;
|
|
27091
|
+
backtest: boolean;
|
|
27092
|
+
}) => Promise<void>;
|
|
27093
|
+
/**
|
|
27094
|
+
* Clears risk data.
|
|
27095
|
+
* If payload is provided, clears data for that specific risk instance.
|
|
27096
|
+
* If no payload is provided, clears all risk data.
|
|
27097
|
+
* @param payload - Optional payload with riskName, exchangeName, frameName, backtest (clears all if not provided)
|
|
27098
|
+
*/
|
|
27099
|
+
clear: (payload?: {
|
|
27100
|
+
riskName: RiskName;
|
|
27101
|
+
exchangeName: ExchangeName;
|
|
27102
|
+
frameName: FrameName;
|
|
27103
|
+
backtest: boolean;
|
|
27104
|
+
}) => Promise<void>;
|
|
27105
|
+
}
|
|
27106
|
+
|
|
27107
|
+
/**
|
|
27108
|
+
* Private service for backtest orchestration using async generators.
|
|
27109
|
+
*
|
|
27110
|
+
* Flow:
|
|
27111
|
+
* 1. Get timeframes from frame service
|
|
27112
|
+
* 2. Iterate through timeframes calling tick()
|
|
27113
|
+
* 3. When signal opens: fetch candles and call backtest()
|
|
27114
|
+
* 4. Skip timeframes until signal closes
|
|
27115
|
+
* 5. Yield closed result and continue
|
|
27116
|
+
*
|
|
27117
|
+
* Memory efficient: streams results without array accumulation.
|
|
27118
|
+
* Supports early termination via break in consumer.
|
|
27119
|
+
*/
|
|
27120
|
+
declare class BacktestLogicPrivateService {
|
|
27121
|
+
readonly loggerService: {
|
|
27122
|
+
readonly methodContextService: {
|
|
27123
|
+
readonly context: IMethodContext;
|
|
27124
|
+
};
|
|
27125
|
+
readonly executionContextService: {
|
|
27126
|
+
readonly context: IExecutionContext;
|
|
27127
|
+
};
|
|
27128
|
+
_commonLogger: ILogger;
|
|
27129
|
+
readonly _methodContext: {};
|
|
27130
|
+
readonly _executionContext: {};
|
|
27131
|
+
log: (topic: string, ...args: any[]) => Promise<void>;
|
|
27132
|
+
debug: (topic: string, ...args: any[]) => Promise<void>;
|
|
27133
|
+
info: (topic: string, ...args: any[]) => Promise<void>;
|
|
27134
|
+
warn: (topic: string, ...args: any[]) => Promise<void>;
|
|
27135
|
+
setLogger: (logger: ILogger) => void;
|
|
27136
|
+
};
|
|
27137
|
+
readonly strategyCoreService: StrategyCoreService;
|
|
27138
|
+
readonly exchangeCoreService: ExchangeCoreService;
|
|
27139
|
+
readonly frameCoreService: FrameCoreService;
|
|
27140
|
+
readonly methodContextService: {
|
|
27141
|
+
readonly context: IMethodContext;
|
|
27142
|
+
};
|
|
27143
|
+
readonly actionCoreService: ActionCoreService;
|
|
27144
|
+
/**
|
|
27145
|
+
* Runs backtest for a symbol, streaming closed signals as async generator.
|
|
27146
|
+
*
|
|
27147
|
+
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
27148
|
+
* @yields Closed signal results with PNL
|
|
27149
|
+
*
|
|
27150
|
+
* @example
|
|
27151
|
+
* ```typescript
|
|
27152
|
+
* for await (const result of backtestLogic.run("BTCUSDT")) {
|
|
27153
|
+
* console.log(result.closeReason, result.pnl.pnlPercentage);
|
|
27154
|
+
* if (result.pnl.pnlPercentage < -10) break; // Early termination
|
|
27155
|
+
* }
|
|
27156
|
+
* ```
|
|
27157
|
+
*/
|
|
27158
|
+
run(symbol: string): AsyncGenerator<IStrategyTickResultScheduled | IStrategyTickResultOpened | IStrategyTickResultClosed | IStrategyTickResultCancelled, void, any>;
|
|
27159
|
+
}
|
|
27160
|
+
|
|
27161
|
+
/**
|
|
27162
|
+
* Type definition for public BacktestLogic service.
|
|
27163
|
+
* Omits private dependencies from BacktestLogicPrivateService.
|
|
27164
|
+
*/
|
|
27165
|
+
type IBacktestLogicPrivateService = Omit<BacktestLogicPrivateService, keyof {
|
|
27166
|
+
loggerService: never;
|
|
27167
|
+
strategyCoreService: never;
|
|
27168
|
+
exchangeCoreService: never;
|
|
27169
|
+
frameCoreService: never;
|
|
27170
|
+
actionCoreService: never;
|
|
27171
|
+
methodContextService: never;
|
|
27172
|
+
}>;
|
|
27173
|
+
/**
|
|
27174
|
+
* Type definition for BacktestLogicPublicService.
|
|
27175
|
+
* Maps all keys of IBacktestLogicPrivateService to any type.
|
|
27176
|
+
*/
|
|
27177
|
+
type TBacktestLogicPrivateService = {
|
|
27178
|
+
[key in keyof IBacktestLogicPrivateService]: any;
|
|
27179
|
+
};
|
|
27180
|
+
/**
|
|
27181
|
+
* Public service for backtest orchestration with context management.
|
|
27182
|
+
*
|
|
27183
|
+
* Wraps BacktestLogicPrivateService with MethodContextService to provide
|
|
27184
|
+
* implicit context propagation for strategyName, exchangeName, and frameName.
|
|
27185
|
+
*
|
|
27186
|
+
* This allows getCandles(), getSignal(), and other functions to work without
|
|
27187
|
+
* explicit context parameters.
|
|
27188
|
+
*
|
|
27189
|
+
* @example
|
|
27190
|
+
* ```typescript
|
|
27191
|
+
* const backtestLogicPublicService = inject(TYPES.backtestLogicPublicService);
|
|
27192
|
+
*
|
|
27193
|
+
* for await (const result of backtestLogicPublicService.run("BTCUSDT", {
|
|
27194
|
+
* strategyName: "my-strategy",
|
|
27195
|
+
* exchangeName: "my-exchange",
|
|
27196
|
+
* frameName: "1d-backtest",
|
|
27197
|
+
* })) {
|
|
27198
|
+
* if (result.action === "closed") {
|
|
27199
|
+
* console.log("PNL:", result.pnl.profit);
|
|
27200
|
+
* }
|
|
27201
|
+
* }
|
|
27202
|
+
* ```
|
|
27203
|
+
*/
|
|
27204
|
+
declare class BacktestLogicPublicService implements TBacktestLogicPrivateService {
|
|
27205
|
+
private readonly loggerService;
|
|
27206
|
+
private readonly backtestLogicPrivateService;
|
|
27207
|
+
/**
|
|
27208
|
+
* Runs backtest for a symbol with context propagation.
|
|
27209
|
+
*
|
|
27210
|
+
* Streams closed signals as async generator. Context is automatically
|
|
27211
|
+
* injected into all framework functions called during iteration.
|
|
27212
|
+
*
|
|
27213
|
+
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
27214
|
+
* @param context - Execution context with strategy, exchange, and frame names
|
|
27215
|
+
* @returns Async generator yielding closed signals with PNL
|
|
27216
|
+
*/
|
|
27217
|
+
run: (symbol: string, context: {
|
|
27218
|
+
strategyName: StrategyName;
|
|
27219
|
+
exchangeName: ExchangeName;
|
|
27220
|
+
frameName: FrameName;
|
|
27221
|
+
}) => AsyncGenerator<IStrategyTickResultScheduled | IStrategyTickResultOpened | IStrategyTickResultClosed | IStrategyTickResultCancelled, void, any>;
|
|
27222
|
+
}
|
|
27223
|
+
|
|
27224
|
+
/**
|
|
27225
|
+
* Service for managing walker schema registry.
|
|
27226
|
+
*
|
|
27227
|
+
* Uses ToolRegistry from functools-kit for type-safe schema storage.
|
|
27228
|
+
* Walkers are registered via addWalker() and retrieved by name.
|
|
27229
|
+
*/
|
|
27230
|
+
declare class WalkerSchemaService {
|
|
27231
|
+
readonly loggerService: {
|
|
27232
|
+
readonly methodContextService: {
|
|
27233
|
+
readonly context: IMethodContext;
|
|
27234
|
+
};
|
|
27235
|
+
readonly executionContextService: {
|
|
27236
|
+
readonly context: IExecutionContext;
|
|
27237
|
+
};
|
|
27238
|
+
_commonLogger: ILogger;
|
|
27239
|
+
readonly _methodContext: {};
|
|
27240
|
+
readonly _executionContext: {};
|
|
27241
|
+
log: (topic: string, ...args: any[]) => Promise<void>;
|
|
27242
|
+
debug: (topic: string, ...args: any[]) => Promise<void>;
|
|
27243
|
+
info: (topic: string, ...args: any[]) => Promise<void>;
|
|
27244
|
+
warn: (topic: string, ...args: any[]) => Promise<void>;
|
|
27245
|
+
setLogger: (logger: ILogger) => void;
|
|
27246
|
+
};
|
|
27247
|
+
private _registry;
|
|
27248
|
+
/**
|
|
27249
|
+
* Registers a new walker schema.
|
|
27250
|
+
*
|
|
27251
|
+
* @param key - Unique walker name
|
|
27252
|
+
* @param value - Walker schema configuration
|
|
27253
|
+
* @throws Error if walker name already exists
|
|
27254
|
+
*/
|
|
27255
|
+
register: (key: WalkerName, value: IWalkerSchema) => void;
|
|
27256
|
+
/**
|
|
27257
|
+
* Validates walker schema structure for required properties.
|
|
27258
|
+
*
|
|
27259
|
+
* Performs shallow validation to ensure all required properties exist
|
|
27260
|
+
* and have correct types before registration in the registry.
|
|
27261
|
+
*
|
|
27262
|
+
* @param walkerSchema - Walker schema to validate
|
|
27263
|
+
* @throws Error if walkerName is missing or not a string
|
|
27264
|
+
* @throws Error if exchangeName is missing or not a string
|
|
27265
|
+
* @throws Error if frameName is missing or not a string
|
|
27266
|
+
* @throws Error if strategies is missing or not an array
|
|
27267
|
+
* @throws Error if strategies array is empty
|
|
27268
|
+
*/
|
|
27269
|
+
private validateShallow;
|
|
27270
|
+
/**
|
|
27271
|
+
* Overrides an existing walker schema with partial updates.
|
|
26864
27272
|
*
|
|
26865
|
-
* @param
|
|
26866
|
-
* @param
|
|
27273
|
+
* @param key - Walker name to override
|
|
27274
|
+
* @param value - Partial schema updates
|
|
27275
|
+
* @returns Updated walker schema
|
|
27276
|
+
* @throws Error if walker name doesn't exist
|
|
26867
27277
|
*/
|
|
26868
|
-
|
|
26869
|
-
strategyName: StrategyName;
|
|
26870
|
-
riskName: RiskName;
|
|
26871
|
-
exchangeName: ExchangeName;
|
|
26872
|
-
frameName: FrameName;
|
|
26873
|
-
backtest: boolean;
|
|
26874
|
-
}) => Promise<void>;
|
|
27278
|
+
override: (key: WalkerName, value: Partial<IWalkerSchema>) => IWalkerSchema;
|
|
26875
27279
|
/**
|
|
26876
|
-
*
|
|
26877
|
-
*
|
|
26878
|
-
*
|
|
26879
|
-
* @
|
|
27280
|
+
* Retrieves a walker schema by name.
|
|
27281
|
+
*
|
|
27282
|
+
* @param key - Walker name
|
|
27283
|
+
* @returns Walker schema configuration
|
|
27284
|
+
* @throws Error if walker name doesn't exist
|
|
26880
27285
|
*/
|
|
26881
|
-
|
|
26882
|
-
riskName: RiskName;
|
|
26883
|
-
exchangeName: ExchangeName;
|
|
26884
|
-
frameName: FrameName;
|
|
26885
|
-
backtest: boolean;
|
|
26886
|
-
}) => Promise<void>;
|
|
27286
|
+
get: (key: WalkerName) => IWalkerSchema;
|
|
26887
27287
|
}
|
|
26888
27288
|
|
|
26889
27289
|
/**
|
|
@@ -26897,10 +27297,25 @@ declare class RiskGlobalService implements TRisk {
|
|
|
26897
27297
|
* Uses BacktestLogicPublicService internally for each strategy.
|
|
26898
27298
|
*/
|
|
26899
27299
|
declare class WalkerLogicPrivateService {
|
|
26900
|
-
|
|
26901
|
-
|
|
26902
|
-
|
|
26903
|
-
|
|
27300
|
+
readonly loggerService: {
|
|
27301
|
+
readonly methodContextService: {
|
|
27302
|
+
readonly context: IMethodContext;
|
|
27303
|
+
};
|
|
27304
|
+
readonly executionContextService: {
|
|
27305
|
+
readonly context: IExecutionContext;
|
|
27306
|
+
};
|
|
27307
|
+
_commonLogger: ILogger;
|
|
27308
|
+
readonly _methodContext: {};
|
|
27309
|
+
readonly _executionContext: {};
|
|
27310
|
+
log: (topic: string, ...args: any[]) => Promise<void>;
|
|
27311
|
+
debug: (topic: string, ...args: any[]) => Promise<void>;
|
|
27312
|
+
info: (topic: string, ...args: any[]) => Promise<void>;
|
|
27313
|
+
warn: (topic: string, ...args: any[]) => Promise<void>;
|
|
27314
|
+
setLogger: (logger: ILogger) => void;
|
|
27315
|
+
};
|
|
27316
|
+
readonly backtestLogicPublicService: BacktestLogicPublicService;
|
|
27317
|
+
readonly backtestMarkdownService: BacktestMarkdownService;
|
|
27318
|
+
readonly walkerSchemaService: WalkerSchemaService;
|
|
26904
27319
|
/**
|
|
26905
27320
|
* Runs walker comparison for a symbol.
|
|
26906
27321
|
*
|
|
@@ -27037,7 +27452,22 @@ declare class WalkerCommandService implements TWalkerLogicPublicService {
|
|
|
27037
27452
|
* Exchanges are registered via addExchange() and retrieved by name.
|
|
27038
27453
|
*/
|
|
27039
27454
|
declare class ExchangeSchemaService {
|
|
27040
|
-
readonly loggerService:
|
|
27455
|
+
readonly loggerService: {
|
|
27456
|
+
readonly methodContextService: {
|
|
27457
|
+
readonly context: IMethodContext;
|
|
27458
|
+
};
|
|
27459
|
+
readonly executionContextService: {
|
|
27460
|
+
readonly context: IExecutionContext;
|
|
27461
|
+
};
|
|
27462
|
+
_commonLogger: ILogger;
|
|
27463
|
+
readonly _methodContext: {};
|
|
27464
|
+
readonly _executionContext: {};
|
|
27465
|
+
log: (topic: string, ...args: any[]) => Promise<void>;
|
|
27466
|
+
debug: (topic: string, ...args: any[]) => Promise<void>;
|
|
27467
|
+
info: (topic: string, ...args: any[]) => Promise<void>;
|
|
27468
|
+
warn: (topic: string, ...args: any[]) => Promise<void>;
|
|
27469
|
+
setLogger: (logger: ILogger) => void;
|
|
27470
|
+
};
|
|
27041
27471
|
private _registry;
|
|
27042
27472
|
/**
|
|
27043
27473
|
* Registers a new exchange schema.
|
|
@@ -27086,7 +27516,22 @@ declare class ExchangeSchemaService {
|
|
|
27086
27516
|
* Frames are registered via addFrame() and retrieved by name.
|
|
27087
27517
|
*/
|
|
27088
27518
|
declare class FrameSchemaService {
|
|
27089
|
-
readonly loggerService:
|
|
27519
|
+
readonly loggerService: {
|
|
27520
|
+
readonly methodContextService: {
|
|
27521
|
+
readonly context: IMethodContext;
|
|
27522
|
+
};
|
|
27523
|
+
readonly executionContextService: {
|
|
27524
|
+
readonly context: IExecutionContext;
|
|
27525
|
+
};
|
|
27526
|
+
_commonLogger: ILogger;
|
|
27527
|
+
readonly _methodContext: {};
|
|
27528
|
+
readonly _executionContext: {};
|
|
27529
|
+
log: (topic: string, ...args: any[]) => Promise<void>;
|
|
27530
|
+
debug: (topic: string, ...args: any[]) => Promise<void>;
|
|
27531
|
+
info: (topic: string, ...args: any[]) => Promise<void>;
|
|
27532
|
+
warn: (topic: string, ...args: any[]) => Promise<void>;
|
|
27533
|
+
setLogger: (logger: ILogger) => void;
|
|
27534
|
+
};
|
|
27090
27535
|
private _registry;
|
|
27091
27536
|
/**
|
|
27092
27537
|
* Registers a new frame schema.
|
|
@@ -27134,7 +27579,22 @@ declare class FrameSchemaService {
|
|
|
27134
27579
|
* Sizing schemas are registered via addSizing() and retrieved by name.
|
|
27135
27580
|
*/
|
|
27136
27581
|
declare class SizingSchemaService {
|
|
27137
|
-
readonly loggerService:
|
|
27582
|
+
readonly loggerService: {
|
|
27583
|
+
readonly methodContextService: {
|
|
27584
|
+
readonly context: IMethodContext;
|
|
27585
|
+
};
|
|
27586
|
+
readonly executionContextService: {
|
|
27587
|
+
readonly context: IExecutionContext;
|
|
27588
|
+
};
|
|
27589
|
+
_commonLogger: ILogger;
|
|
27590
|
+
readonly _methodContext: {};
|
|
27591
|
+
readonly _executionContext: {};
|
|
27592
|
+
log: (topic: string, ...args: any[]) => Promise<void>;
|
|
27593
|
+
debug: (topic: string, ...args: any[]) => Promise<void>;
|
|
27594
|
+
info: (topic: string, ...args: any[]) => Promise<void>;
|
|
27595
|
+
warn: (topic: string, ...args: any[]) => Promise<void>;
|
|
27596
|
+
setLogger: (logger: ILogger) => void;
|
|
27597
|
+
};
|
|
27138
27598
|
private _registry;
|
|
27139
27599
|
/**
|
|
27140
27600
|
* Registers a new sizing schema.
|
|
@@ -27174,52 +27634,6 @@ declare class SizingSchemaService {
|
|
|
27174
27634
|
get(key: SizingName): ISizingSchema;
|
|
27175
27635
|
}
|
|
27176
27636
|
|
|
27177
|
-
/**
|
|
27178
|
-
* Service for managing risk schema registry.
|
|
27179
|
-
*
|
|
27180
|
-
* Uses ToolRegistry from functools-kit for type-safe schema storage.
|
|
27181
|
-
* Risk profiles are registered via addRisk() and retrieved by name.
|
|
27182
|
-
*/
|
|
27183
|
-
declare class RiskSchemaService {
|
|
27184
|
-
readonly loggerService: LoggerService;
|
|
27185
|
-
private _registry;
|
|
27186
|
-
/**
|
|
27187
|
-
* Registers a new risk schema.
|
|
27188
|
-
*
|
|
27189
|
-
* @param key - Unique risk profile name
|
|
27190
|
-
* @param value - Risk schema configuration
|
|
27191
|
-
* @throws Error if risk name already exists
|
|
27192
|
-
*/
|
|
27193
|
-
register: (key: RiskName, value: IRiskSchema) => void;
|
|
27194
|
-
/**
|
|
27195
|
-
* Validates risk schema structure for required properties.
|
|
27196
|
-
*
|
|
27197
|
-
* Performs shallow validation to ensure all required properties exist
|
|
27198
|
-
* and have correct types before registration in the registry.
|
|
27199
|
-
*
|
|
27200
|
-
* @param riskSchema - Risk schema to validate
|
|
27201
|
-
* @throws Error if riskName is missing or not a string
|
|
27202
|
-
*/
|
|
27203
|
-
private validateShallow;
|
|
27204
|
-
/**
|
|
27205
|
-
* Overrides an existing risk schema with partial updates.
|
|
27206
|
-
*
|
|
27207
|
-
* @param key - Risk name to override
|
|
27208
|
-
* @param value - Partial schema updates
|
|
27209
|
-
* @returns Updated risk schema
|
|
27210
|
-
* @throws Error if risk name doesn't exist
|
|
27211
|
-
*/
|
|
27212
|
-
override: (key: RiskName, value: Partial<IRiskSchema>) => IRiskSchema;
|
|
27213
|
-
/**
|
|
27214
|
-
* Retrieves a risk schema by name.
|
|
27215
|
-
*
|
|
27216
|
-
* @param key - Risk name
|
|
27217
|
-
* @returns Risk schema configuration
|
|
27218
|
-
* @throws Error if risk name doesn't exist
|
|
27219
|
-
*/
|
|
27220
|
-
get: (key: RiskName) => IRiskSchema;
|
|
27221
|
-
}
|
|
27222
|
-
|
|
27223
27637
|
/**
|
|
27224
27638
|
* Service for managing action schema registry.
|
|
27225
27639
|
*
|
|
@@ -27254,7 +27668,22 @@ declare class RiskSchemaService {
|
|
|
27254
27668
|
* ```
|
|
27255
27669
|
*/
|
|
27256
27670
|
declare class ActionSchemaService {
|
|
27257
|
-
readonly loggerService:
|
|
27671
|
+
readonly loggerService: {
|
|
27672
|
+
readonly methodContextService: {
|
|
27673
|
+
readonly context: IMethodContext;
|
|
27674
|
+
};
|
|
27675
|
+
readonly executionContextService: {
|
|
27676
|
+
readonly context: IExecutionContext;
|
|
27677
|
+
};
|
|
27678
|
+
_commonLogger: ILogger;
|
|
27679
|
+
readonly _methodContext: {};
|
|
27680
|
+
readonly _executionContext: {};
|
|
27681
|
+
log: (topic: string, ...args: any[]) => Promise<void>;
|
|
27682
|
+
debug: (topic: string, ...args: any[]) => Promise<void>;
|
|
27683
|
+
info: (topic: string, ...args: any[]) => Promise<void>;
|
|
27684
|
+
warn: (topic: string, ...args: any[]) => Promise<void>;
|
|
27685
|
+
setLogger: (logger: ILogger) => void;
|
|
27686
|
+
};
|
|
27258
27687
|
private _registry;
|
|
27259
27688
|
/**
|
|
27260
27689
|
* Registers a new action schema.
|
|
@@ -27307,95 +27736,6 @@ declare class ActionSchemaService {
|
|
|
27307
27736
|
get: (key: ActionName) => IActionSchema;
|
|
27308
27737
|
}
|
|
27309
27738
|
|
|
27310
|
-
/**
|
|
27311
|
-
* Service for managing walker schema registry.
|
|
27312
|
-
*
|
|
27313
|
-
* Uses ToolRegistry from functools-kit for type-safe schema storage.
|
|
27314
|
-
* Walkers are registered via addWalker() and retrieved by name.
|
|
27315
|
-
*/
|
|
27316
|
-
declare class WalkerSchemaService {
|
|
27317
|
-
readonly loggerService: LoggerService;
|
|
27318
|
-
private _registry;
|
|
27319
|
-
/**
|
|
27320
|
-
* Registers a new walker schema.
|
|
27321
|
-
*
|
|
27322
|
-
* @param key - Unique walker name
|
|
27323
|
-
* @param value - Walker schema configuration
|
|
27324
|
-
* @throws Error if walker name already exists
|
|
27325
|
-
*/
|
|
27326
|
-
register: (key: WalkerName, value: IWalkerSchema) => void;
|
|
27327
|
-
/**
|
|
27328
|
-
* Validates walker schema structure for required properties.
|
|
27329
|
-
*
|
|
27330
|
-
* Performs shallow validation to ensure all required properties exist
|
|
27331
|
-
* and have correct types before registration in the registry.
|
|
27332
|
-
*
|
|
27333
|
-
* @param walkerSchema - Walker schema to validate
|
|
27334
|
-
* @throws Error if walkerName is missing or not a string
|
|
27335
|
-
* @throws Error if exchangeName is missing or not a string
|
|
27336
|
-
* @throws Error if frameName is missing or not a string
|
|
27337
|
-
* @throws Error if strategies is missing or not an array
|
|
27338
|
-
* @throws Error if strategies array is empty
|
|
27339
|
-
*/
|
|
27340
|
-
private validateShallow;
|
|
27341
|
-
/**
|
|
27342
|
-
* Overrides an existing walker schema with partial updates.
|
|
27343
|
-
*
|
|
27344
|
-
* @param key - Walker name to override
|
|
27345
|
-
* @param value - Partial schema updates
|
|
27346
|
-
* @returns Updated walker schema
|
|
27347
|
-
* @throws Error if walker name doesn't exist
|
|
27348
|
-
*/
|
|
27349
|
-
override: (key: WalkerName, value: Partial<IWalkerSchema>) => IWalkerSchema;
|
|
27350
|
-
/**
|
|
27351
|
-
* Retrieves a walker schema by name.
|
|
27352
|
-
*
|
|
27353
|
-
* @param key - Walker name
|
|
27354
|
-
* @returns Walker schema configuration
|
|
27355
|
-
* @throws Error if walker name doesn't exist
|
|
27356
|
-
*/
|
|
27357
|
-
get: (key: WalkerName) => IWalkerSchema;
|
|
27358
|
-
}
|
|
27359
|
-
|
|
27360
|
-
/**
|
|
27361
|
-
* Private service for backtest orchestration using async generators.
|
|
27362
|
-
*
|
|
27363
|
-
* Flow:
|
|
27364
|
-
* 1. Get timeframes from frame service
|
|
27365
|
-
* 2. Iterate through timeframes calling tick()
|
|
27366
|
-
* 3. When signal opens: fetch candles and call backtest()
|
|
27367
|
-
* 4. Skip timeframes until signal closes
|
|
27368
|
-
* 5. Yield closed result and continue
|
|
27369
|
-
*
|
|
27370
|
-
* Memory efficient: streams results without array accumulation.
|
|
27371
|
-
* Supports early termination via break in consumer.
|
|
27372
|
-
*/
|
|
27373
|
-
declare class BacktestLogicPrivateService {
|
|
27374
|
-
readonly loggerService: LoggerService;
|
|
27375
|
-
readonly strategyCoreService: StrategyCoreService;
|
|
27376
|
-
readonly exchangeCoreService: ExchangeCoreService;
|
|
27377
|
-
readonly frameCoreService: FrameCoreService;
|
|
27378
|
-
readonly methodContextService: {
|
|
27379
|
-
readonly context: IMethodContext;
|
|
27380
|
-
};
|
|
27381
|
-
readonly actionCoreService: ActionCoreService;
|
|
27382
|
-
/**
|
|
27383
|
-
* Runs backtest for a symbol, streaming closed signals as async generator.
|
|
27384
|
-
*
|
|
27385
|
-
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
27386
|
-
* @yields Closed signal results with PNL
|
|
27387
|
-
*
|
|
27388
|
-
* @example
|
|
27389
|
-
* ```typescript
|
|
27390
|
-
* for await (const result of backtestLogic.run("BTCUSDT")) {
|
|
27391
|
-
* console.log(result.closeReason, result.pnl.pnlPercentage);
|
|
27392
|
-
* if (result.pnl.pnlPercentage < -10) break; // Early termination
|
|
27393
|
-
* }
|
|
27394
|
-
* ```
|
|
27395
|
-
*/
|
|
27396
|
-
run(symbol: string): AsyncGenerator<IStrategyTickResultScheduled | IStrategyTickResultOpened | IStrategyTickResultClosed | IStrategyTickResultCancelled, void, any>;
|
|
27397
|
-
}
|
|
27398
|
-
|
|
27399
27739
|
/**
|
|
27400
27740
|
* Private service for live trading orchestration using async generators.
|
|
27401
27741
|
*
|
|
@@ -27441,69 +27781,6 @@ declare class LiveLogicPrivateService {
|
|
|
27441
27781
|
run(symbol: string): AsyncGenerator<IStrategyTickResultOpened | IStrategyTickResultClosed | IStrategyTickResultCancelled, void, unknown>;
|
|
27442
27782
|
}
|
|
27443
27783
|
|
|
27444
|
-
/**
|
|
27445
|
-
* Type definition for public BacktestLogic service.
|
|
27446
|
-
* Omits private dependencies from BacktestLogicPrivateService.
|
|
27447
|
-
*/
|
|
27448
|
-
type IBacktestLogicPrivateService = Omit<BacktestLogicPrivateService, keyof {
|
|
27449
|
-
loggerService: never;
|
|
27450
|
-
strategyCoreService: never;
|
|
27451
|
-
exchangeCoreService: never;
|
|
27452
|
-
frameCoreService: never;
|
|
27453
|
-
actionCoreService: never;
|
|
27454
|
-
methodContextService: never;
|
|
27455
|
-
}>;
|
|
27456
|
-
/**
|
|
27457
|
-
* Type definition for BacktestLogicPublicService.
|
|
27458
|
-
* Maps all keys of IBacktestLogicPrivateService to any type.
|
|
27459
|
-
*/
|
|
27460
|
-
type TBacktestLogicPrivateService = {
|
|
27461
|
-
[key in keyof IBacktestLogicPrivateService]: any;
|
|
27462
|
-
};
|
|
27463
|
-
/**
|
|
27464
|
-
* Public service for backtest orchestration with context management.
|
|
27465
|
-
*
|
|
27466
|
-
* Wraps BacktestLogicPrivateService with MethodContextService to provide
|
|
27467
|
-
* implicit context propagation for strategyName, exchangeName, and frameName.
|
|
27468
|
-
*
|
|
27469
|
-
* This allows getCandles(), getSignal(), and other functions to work without
|
|
27470
|
-
* explicit context parameters.
|
|
27471
|
-
*
|
|
27472
|
-
* @example
|
|
27473
|
-
* ```typescript
|
|
27474
|
-
* const backtestLogicPublicService = inject(TYPES.backtestLogicPublicService);
|
|
27475
|
-
*
|
|
27476
|
-
* for await (const result of backtestLogicPublicService.run("BTCUSDT", {
|
|
27477
|
-
* strategyName: "my-strategy",
|
|
27478
|
-
* exchangeName: "my-exchange",
|
|
27479
|
-
* frameName: "1d-backtest",
|
|
27480
|
-
* })) {
|
|
27481
|
-
* if (result.action === "closed") {
|
|
27482
|
-
* console.log("PNL:", result.pnl.profit);
|
|
27483
|
-
* }
|
|
27484
|
-
* }
|
|
27485
|
-
* ```
|
|
27486
|
-
*/
|
|
27487
|
-
declare class BacktestLogicPublicService implements TBacktestLogicPrivateService {
|
|
27488
|
-
private readonly loggerService;
|
|
27489
|
-
private readonly backtestLogicPrivateService;
|
|
27490
|
-
/**
|
|
27491
|
-
* Runs backtest for a symbol with context propagation.
|
|
27492
|
-
*
|
|
27493
|
-
* Streams closed signals as async generator. Context is automatically
|
|
27494
|
-
* injected into all framework functions called during iteration.
|
|
27495
|
-
*
|
|
27496
|
-
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
27497
|
-
* @param context - Execution context with strategy, exchange, and frame names
|
|
27498
|
-
* @returns Async generator yielding closed signals with PNL
|
|
27499
|
-
*/
|
|
27500
|
-
run: (symbol: string, context: {
|
|
27501
|
-
strategyName: StrategyName;
|
|
27502
|
-
exchangeName: ExchangeName;
|
|
27503
|
-
frameName: FrameName;
|
|
27504
|
-
}) => AsyncGenerator<IStrategyTickResultScheduled | IStrategyTickResultOpened | IStrategyTickResultClosed | IStrategyTickResultCancelled, void, any>;
|
|
27505
|
-
}
|
|
27506
|
-
|
|
27507
27784
|
/**
|
|
27508
27785
|
* Type definition for public LiveLogic service.
|
|
27509
27786
|
* Omits private dependencies from LiveLogicPrivateService.
|
|
@@ -28387,7 +28664,7 @@ declare class ColumnValidationService {
|
|
|
28387
28664
|
* Features:
|
|
28388
28665
|
* - Listens to backtest signal events via signalBacktestEmitter
|
|
28389
28666
|
* - Logs all tick event types with full signal details
|
|
28390
|
-
* - Stores events in
|
|
28667
|
+
* - Stores events in ReportWriter.writeData() for persistence
|
|
28391
28668
|
* - Protected against multiple subscriptions using singleshot
|
|
28392
28669
|
*
|
|
28393
28670
|
* @example
|
|
@@ -28459,7 +28736,7 @@ declare class BacktestReportService {
|
|
|
28459
28736
|
* Features:
|
|
28460
28737
|
* - Listens to live signal events via signalLiveEmitter
|
|
28461
28738
|
* - Logs all tick event types with full signal details
|
|
28462
|
-
* - Stores events in
|
|
28739
|
+
* - Stores events in ReportWriter.writeData() for persistence
|
|
28463
28740
|
* - Protected against multiple subscriptions using singleshot
|
|
28464
28741
|
*
|
|
28465
28742
|
* @example
|
|
@@ -28532,7 +28809,7 @@ declare class LiveReportService {
|
|
|
28532
28809
|
* - Listens to signal events via signalEmitter
|
|
28533
28810
|
* - Logs scheduled, opened (from scheduled), and cancelled events
|
|
28534
28811
|
* - Calculates duration between scheduling and execution/cancellation
|
|
28535
|
-
* - Stores events in
|
|
28812
|
+
* - Stores events in ReportWriter.writeData() for schedule tracking
|
|
28536
28813
|
* - Protected against multiple subscriptions using singleshot
|
|
28537
28814
|
*
|
|
28538
28815
|
* @example
|
|
@@ -28604,7 +28881,7 @@ declare class ScheduleReportService {
|
|
|
28604
28881
|
* Features:
|
|
28605
28882
|
* - Listens to performance events via performanceEmitter
|
|
28606
28883
|
* - Logs all timing metrics with duration and metadata
|
|
28607
|
-
* - Stores events in
|
|
28884
|
+
* - Stores events in ReportWriter.writeData() for performance analysis
|
|
28608
28885
|
* - Protected against multiple subscriptions using singleshot
|
|
28609
28886
|
*
|
|
28610
28887
|
* @example
|
|
@@ -28676,7 +28953,7 @@ declare class PerformanceReportService {
|
|
|
28676
28953
|
* - Listens to walker events via walkerEmitter
|
|
28677
28954
|
* - Logs each strategy test result with metrics and statistics
|
|
28678
28955
|
* - Tracks best strategy and optimization progress
|
|
28679
|
-
* - Stores events in
|
|
28956
|
+
* - Stores events in ReportWriter.writeData() for optimization analysis
|
|
28680
28957
|
* - Protected against multiple subscriptions using singleshot
|
|
28681
28958
|
*
|
|
28682
28959
|
* @example
|
|
@@ -28747,7 +29024,7 @@ declare class WalkerReportService {
|
|
|
28747
29024
|
* Features:
|
|
28748
29025
|
* - Listens to signal events via signalEmitter
|
|
28749
29026
|
* - Logs only closed signals with PNL data
|
|
28750
|
-
* - Stores events in
|
|
29027
|
+
* - Stores events in ReportWriter.writeData() for heatmap generation
|
|
28751
29028
|
* - Protected against multiple subscriptions using singleshot
|
|
28752
29029
|
*
|
|
28753
29030
|
* @example
|
|
@@ -28820,7 +29097,7 @@ declare class HeatReportService {
|
|
|
28820
29097
|
* - Listens to partial profit events via partialProfitSubject
|
|
28821
29098
|
* - Listens to partial loss events via partialLossSubject
|
|
28822
29099
|
* - Logs all partial exit events with level and price information
|
|
28823
|
-
* - Stores events in
|
|
29100
|
+
* - Stores events in ReportWriter.writeData() for persistence
|
|
28824
29101
|
* - Protected against multiple subscriptions using singleshot
|
|
28825
29102
|
*
|
|
28826
29103
|
* @example
|
|
@@ -28899,7 +29176,7 @@ declare class PartialReportService {
|
|
|
28899
29176
|
* Features:
|
|
28900
29177
|
* - Listens to breakeven events via breakevenSubject
|
|
28901
29178
|
* - Logs all breakeven achievements with full signal details
|
|
28902
|
-
* - Stores events in
|
|
29179
|
+
* - Stores events in ReportWriter.writeData() for persistence
|
|
28903
29180
|
* - Protected against multiple subscriptions using singleshot
|
|
28904
29181
|
*
|
|
28905
29182
|
* @example
|
|
@@ -28970,7 +29247,7 @@ declare class BreakevenReportService {
|
|
|
28970
29247
|
* Features:
|
|
28971
29248
|
* - Listens to risk rejection events via riskSubject
|
|
28972
29249
|
* - Logs all rejected signals with reason and pending signal details
|
|
28973
|
-
* - Stores events in
|
|
29250
|
+
* - Stores events in ReportWriter.writeData() for risk tracking
|
|
28974
29251
|
* - Protected against multiple subscriptions using singleshot
|
|
28975
29252
|
*
|
|
28976
29253
|
* @example
|
|
@@ -29044,14 +29321,29 @@ declare class RiskReportService {
|
|
|
29044
29321
|
*
|
|
29045
29322
|
* Lifecycle:
|
|
29046
29323
|
* - Call subscribe() to enable event logging
|
|
29047
|
-
* - Events are written via
|
|
29324
|
+
* - Events are written via ReportWriter.writeData() with "strategy" category
|
|
29048
29325
|
* - Call unsubscribe() to disable event logging
|
|
29049
29326
|
*
|
|
29050
29327
|
* @see StrategyMarkdownService for in-memory event accumulation and markdown report generation
|
|
29051
29328
|
* @see Report for the underlying persistence mechanism
|
|
29052
29329
|
*/
|
|
29053
29330
|
declare class StrategyReportService {
|
|
29054
|
-
readonly loggerService:
|
|
29331
|
+
readonly loggerService: {
|
|
29332
|
+
readonly methodContextService: {
|
|
29333
|
+
readonly context: IMethodContext;
|
|
29334
|
+
};
|
|
29335
|
+
readonly executionContextService: {
|
|
29336
|
+
readonly context: IExecutionContext;
|
|
29337
|
+
};
|
|
29338
|
+
_commonLogger: ILogger;
|
|
29339
|
+
readonly _methodContext: {};
|
|
29340
|
+
readonly _executionContext: {};
|
|
29341
|
+
log: (topic: string, ...args: any[]) => Promise<void>;
|
|
29342
|
+
debug: (topic: string, ...args: any[]) => Promise<void>;
|
|
29343
|
+
info: (topic: string, ...args: any[]) => Promise<void>;
|
|
29344
|
+
warn: (topic: string, ...args: any[]) => Promise<void>;
|
|
29345
|
+
setLogger: (logger: ILogger) => void;
|
|
29346
|
+
};
|
|
29055
29347
|
/**
|
|
29056
29348
|
* Logs a cancel-scheduled event when a scheduled signal is cancelled.
|
|
29057
29349
|
*/
|
|
@@ -29152,7 +29444,7 @@ declare class StrategyReportService {
|
|
|
29152
29444
|
* - Listens to sync events via syncSubject
|
|
29153
29445
|
* - Logs signal-open events (scheduled limit order filled) with full signal details
|
|
29154
29446
|
* - Logs signal-close events (position exited) with PNL and close reason
|
|
29155
|
-
* - Stores events in
|
|
29447
|
+
* - Stores events in ReportWriter.writeData() for persistence
|
|
29156
29448
|
* - Protected against multiple subscriptions using singleshot
|
|
29157
29449
|
*
|
|
29158
29450
|
* @example
|
|
@@ -29219,7 +29511,7 @@ declare class SyncReportService {
|
|
|
29219
29511
|
* Service for logging highest profit events to the JSONL report database.
|
|
29220
29512
|
*
|
|
29221
29513
|
* Listens to highestProfitSubject and writes each new price record to
|
|
29222
|
-
*
|
|
29514
|
+
* ReportWriter.writeData() for persistence and analytics.
|
|
29223
29515
|
*/
|
|
29224
29516
|
declare class HighestProfitReportService {
|
|
29225
29517
|
private readonly loggerService;
|
|
@@ -29227,7 +29519,7 @@ declare class HighestProfitReportService {
|
|
|
29227
29519
|
* Handles a single `HighestProfitContract` event emitted by `highestProfitSubject`.
|
|
29228
29520
|
*
|
|
29229
29521
|
* Writes a JSONL record to the `"highest_profit"` report database via
|
|
29230
|
-
* `
|
|
29522
|
+
* `ReportWriter.writeData`, capturing the full signal snapshot at the moment
|
|
29231
29523
|
* the new profit record was set:
|
|
29232
29524
|
* - `timestamp`, `symbol`, `strategyName`, `exchangeName`, `frameName`, `backtest`
|
|
29233
29525
|
* - `signalId`, `position`, `currentPrice`
|
|
@@ -29281,7 +29573,7 @@ declare class HighestProfitReportService {
|
|
|
29281
29573
|
* Service for logging max drawdown events to the JSONL report database.
|
|
29282
29574
|
*
|
|
29283
29575
|
* Listens to maxDrawdownSubject and writes each new drawdown record to
|
|
29284
|
-
*
|
|
29576
|
+
* ReportWriter.writeData() for persistence and analytics.
|
|
29285
29577
|
*/
|
|
29286
29578
|
declare class MaxDrawdownReportService {
|
|
29287
29579
|
private readonly loggerService;
|
|
@@ -29289,7 +29581,7 @@ declare class MaxDrawdownReportService {
|
|
|
29289
29581
|
* Handles a single `MaxDrawdownContract` event emitted by `maxDrawdownSubject`.
|
|
29290
29582
|
*
|
|
29291
29583
|
* Writes a JSONL record to the `"max_drawdown"` report database via
|
|
29292
|
-
* `
|
|
29584
|
+
* `ReportWriter.writeData`, capturing the full signal snapshot at the moment
|
|
29293
29585
|
* the new drawdown record was set:
|
|
29294
29586
|
* - `timestamp`, `symbol`, `strategyName`, `exchangeName`, `frameName`, `backtest`
|
|
29295
29587
|
* - `signalId`, `position`, `currentPrice`
|
|
@@ -29374,6 +29666,28 @@ declare const backtest: {
|
|
|
29374
29666
|
breakevenGlobalService: BreakevenGlobalService;
|
|
29375
29667
|
timeMetaService: TimeMetaService;
|
|
29376
29668
|
priceMetaService: PriceMetaService;
|
|
29669
|
+
contextMetaService: {
|
|
29670
|
+
readonly loggerService: {
|
|
29671
|
+
readonly methodContextService: {
|
|
29672
|
+
readonly context: IMethodContext;
|
|
29673
|
+
};
|
|
29674
|
+
readonly executionContextService: {
|
|
29675
|
+
readonly context: IExecutionContext;
|
|
29676
|
+
};
|
|
29677
|
+
_commonLogger: ILogger;
|
|
29678
|
+
readonly _methodContext: {};
|
|
29679
|
+
readonly _executionContext: {};
|
|
29680
|
+
log: (topic: string, ...args: any[]) => Promise<void>;
|
|
29681
|
+
debug: (topic: string, ...args: any[]) => Promise<void>;
|
|
29682
|
+
info: (topic: string, ...args: any[]) => Promise<void>;
|
|
29683
|
+
warn: (topic: string, ...args: any[]) => Promise<void>;
|
|
29684
|
+
setLogger: (logger: ILogger) => void;
|
|
29685
|
+
};
|
|
29686
|
+
readonly executionContextService: {
|
|
29687
|
+
readonly context: IExecutionContext;
|
|
29688
|
+
};
|
|
29689
|
+
getContextTimestamp: () => number;
|
|
29690
|
+
};
|
|
29377
29691
|
exchangeCoreService: ExchangeCoreService;
|
|
29378
29692
|
strategyCoreService: StrategyCoreService;
|
|
29379
29693
|
actionCoreService: ActionCoreService;
|
|
@@ -29399,7 +29713,22 @@ declare const backtest: {
|
|
|
29399
29713
|
methodContextService: {
|
|
29400
29714
|
readonly context: IMethodContext;
|
|
29401
29715
|
};
|
|
29402
|
-
loggerService:
|
|
29716
|
+
loggerService: {
|
|
29717
|
+
readonly methodContextService: {
|
|
29718
|
+
readonly context: IMethodContext;
|
|
29719
|
+
};
|
|
29720
|
+
readonly executionContextService: {
|
|
29721
|
+
readonly context: IExecutionContext;
|
|
29722
|
+
};
|
|
29723
|
+
_commonLogger: ILogger;
|
|
29724
|
+
readonly _methodContext: {};
|
|
29725
|
+
readonly _executionContext: {};
|
|
29726
|
+
log: (topic: string, ...args: any[]) => Promise<void>;
|
|
29727
|
+
debug: (topic: string, ...args: any[]) => Promise<void>;
|
|
29728
|
+
info: (topic: string, ...args: any[]) => Promise<void>;
|
|
29729
|
+
warn: (topic: string, ...args: any[]) => Promise<void>;
|
|
29730
|
+
setLogger: (logger: ILogger) => void;
|
|
29731
|
+
};
|
|
29403
29732
|
};
|
|
29404
29733
|
|
|
29405
29734
|
interface Signal$2 extends ISignalDto {
|
|
@@ -29478,4 +29807,4 @@ declare const getTotalClosed: (signal: Signal) => {
|
|
|
29478
29807
|
remainingCostBasis: number;
|
|
29479
29808
|
};
|
|
29480
29809
|
|
|
29481
|
-
export { ActionBase, type ActivateScheduledCommit, type ActivateScheduledCommitNotification, type ActivePingContract, type AverageBuyCommit, type AverageBuyCommitNotification, Backtest, type BacktestStatisticsModel, Breakeven, type BreakevenAvailableNotification, type BreakevenCommit, type BreakevenCommitNotification, type BreakevenContract, type BreakevenData, type BreakevenEvent, type BreakevenStatisticsModel, Broker, type BrokerAverageBuyPayload, BrokerBase, type BrokerBreakevenPayload, type BrokerPartialLossPayload, type BrokerPartialProfitPayload, type BrokerSignalClosePayload, type BrokerSignalOpenPayload, type BrokerTrailingStopPayload, type BrokerTrailingTakePayload, Cache, type CancelScheduledCommit, type CancelScheduledCommitNotification, type CandleData, type CandleInterval, type ClosePendingCommit, type ClosePendingCommitNotification, type ColumnConfig, type ColumnModel, Constant, type CriticalErrorNotification, type DoneContract, Dump, type EntityId, Exchange, ExecutionContextService, type FrameInterval, type GlobalConfig, Heat, type HeatmapStatisticsModel, HighestProfit, type HighestProfitContract, type HighestProfitEvent, type HighestProfitStatisticsModel, type IActionSchema, type IActivateScheduledCommitRow, type IAggregatedTradeData, type IBidData, type IBreakevenCommitRow, type IBroker, type ICandleData, type ICommitRow, type IDumpContext, type IDumpInstance, type IExchangeSchema, type IFrameSchema, type IHeatmapRow, type ILog, type ILogEntry, type ILogger, type IMarkdownDumpOptions, type IMemoryInstance, type INotificationUtils, type IOrderBookData, type IPartialLossCommitRow, type IPartialProfitCommitRow, type IPersistBase, type IPositionSizeATRParams, type IPositionSizeFixedPercentageParams, type IPositionSizeKellyParams, type IPublicAction, type IPublicCandleData, type IPublicSignalRow, type IReportDumpOptions, type IRiskActivePosition, type IRiskCheckArgs, type IRiskSchema, type IRiskSignalRow, type IRiskValidation, type IRiskValidationFn, type IRiskValidationPayload, type IScheduledSignalCancelRow, type IScheduledSignalRow, type ISignalDto, type ISignalRow, type ISizingCalculateParams, type ISizingCalculateParamsATR, type ISizingCalculateParamsFixedPercentage, type ISizingCalculateParamsKelly, type ISizingParams, type ISizingParamsATR, type ISizingParamsFixedPercentage, type ISizingParamsKelly, type ISizingSchema, type ISizingSchemaATR, type ISizingSchemaFixedPercentage, type ISizingSchemaKelly, type IStorageSignalRow, type IStorageUtils, type IStrategyPnL, type IStrategyResult, type IStrategySchema, type IStrategyTickResult, type IStrategyTickResultActive, type IStrategyTickResultCancelled, type IStrategyTickResultClosed, type IStrategyTickResultIdle, type IStrategyTickResultOpened, type IStrategyTickResultScheduled, type IStrategyTickResultWaiting, type ITrailingStopCommitRow, type ITrailingTakeCommitRow, type IWalkerResults, type IWalkerSchema, type IWalkerStrategyResult, type InfoErrorNotification, Live, type LiveStatisticsModel, Log, type LogData, Markdown, MarkdownFileBase, MarkdownFolderBase, type MarkdownName, MaxDrawdown, type MaxDrawdownContract, type MaxDrawdownEvent, type MaxDrawdownStatisticsModel, type MeasureData, Memory, type MemoryData, type MessageModel, type MessageRole, type MessageToolCall, MethodContextService, type MetricStats, Notification, NotificationBacktest, type NotificationData, NotificationLive, type NotificationModel, Partial$1 as Partial, type PartialData, type PartialEvent, type PartialLossAvailableNotification, type PartialLossCommit, type PartialLossCommitNotification, type PartialLossContract, type PartialProfitAvailableNotification, type PartialProfitCommit, type PartialProfitCommitNotification, type PartialProfitContract, type PartialStatisticsModel, Performance, type PerformanceContract, type PerformanceMetricType, type PerformanceStatisticsModel, PersistBase, PersistBreakevenAdapter, PersistCandleAdapter, PersistLogAdapter, PersistMeasureAdapter, PersistMemoryAdapter, PersistNotificationAdapter, PersistPartialAdapter, PersistRiskAdapter, PersistScheduleAdapter, PersistSignalAdapter, PersistStorageAdapter, PositionSize, type ProgressBacktestContract, type ProgressWalkerContract, Report, ReportBase, type ReportName, Risk, type RiskContract, type RiskData, type RiskEvent, type RiskRejectionNotification, type RiskStatisticsModel, Schedule, type ScheduleData, type SchedulePingContract, type ScheduleStatisticsModel, type ScheduledEvent, type SignalCancelledNotification, type SignalCloseContract, type SignalClosedNotification, type SignalData, type SignalInterval, type SignalOpenContract, type SignalOpenedNotification, type SignalScheduledNotification, type SignalSyncCloseNotification, type SignalSyncContract, type SignalSyncOpenNotification, Storage, StorageBacktest, type StorageData, StorageLive, Strategy, type StrategyActionType, type StrategyCancelReason, type StrategyCloseReason, type StrategyCommitContract, type StrategyEvent, type StrategyStatisticsModel, Sync, type SyncEvent, type SyncStatisticsModel, type TBrokerCtor, type TDumpInstanceCtor, type TLogCtor, type TMarkdownBase, type TMemoryInstanceCtor, type TNotificationUtilsCtor, type TPersistBase, type TPersistBaseCtor, type TReportBase, type TStorageUtilsCtor, type TickEvent, type TrailingStopCommit, type TrailingStopCommitNotification, type TrailingTakeCommit, type TrailingTakeCommitNotification, type ValidationErrorNotification, Walker, type WalkerCompleteContract, type WalkerContract, type WalkerMetric, type SignalData$1 as WalkerSignalData, type WalkerStatisticsModel, addActionSchema, addExchangeSchema, addFrameSchema, addRiskSchema, addSizingSchema, addStrategySchema, addWalkerSchema, alignToInterval, checkCandles, commitActivateScheduled, commitAverageBuy, commitBreakeven, commitCancelScheduled, commitClosePending, commitPartialLoss, commitPartialLossCost, commitPartialProfit, commitPartialProfitCost, commitTrailingStop, commitTrailingStopCost, commitTrailingTake, commitTrailingTakeCost, dumpAgentAnswer, dumpError, dumpJson, dumpRecord, dumpTable, dumpText, emitters, formatPrice, formatQuantity, get, getActionSchema, getAggregatedTrades, getAveragePrice, getBacktestTimeframe, getBreakeven, getCandles, getColumns, getConfig, getContext, getDate, getDefaultColumns, getDefaultConfig, getEffectivePriceOpen, getExchangeSchema, getFrameSchema, getMode, getNextCandles, getOrderBook, getPendingSignal, getPositionCountdownMinutes, getPositionDrawdownMinutes, getPositionEffectivePrice, getPositionEntries, getPositionEntryOverlap, getPositionEstimateMinutes, getPositionHighestPnlCost, getPositionHighestPnlPercentage, getPositionHighestProfitBreakeven, getPositionHighestProfitMinutes, getPositionHighestProfitPrice, getPositionHighestProfitTimestamp, getPositionInvestedCost, getPositionInvestedCount, getPositionLevels, getPositionMaxDrawdownMinutes, getPositionMaxDrawdownPnlCost, getPositionMaxDrawdownPnlPercentage, getPositionMaxDrawdownPrice, getPositionMaxDrawdownTimestamp, getPositionPartialOverlap, getPositionPartials, getPositionPnlCost, getPositionPnlPercent, getRawCandles, getRiskSchema, getScheduledSignal, getSizingSchema, getStrategySchema, getSymbol, getTimestamp, getTotalClosed, getTotalCostClosed, getTotalPercentClosed, getWalkerSchema, hasNoPendingSignal, hasNoScheduledSignal, hasTradeContext, investedCostToPercent, backtest as lib, listExchangeSchema, listFrameSchema, listMemory, listRiskSchema, listSizingSchema, listStrategySchema, listWalkerSchema, listenActivePing, listenActivePingOnce, listenBacktestProgress, listenBreakevenAvailable, listenBreakevenAvailableOnce, listenDoneBacktest, listenDoneBacktestOnce, listenDoneLive, listenDoneLiveOnce, listenDoneWalker, listenDoneWalkerOnce, listenError, listenExit, listenHighestProfit, listenHighestProfitOnce, listenMaxDrawdown, listenMaxDrawdownOnce, listenPartialLossAvailable, listenPartialLossAvailableOnce, listenPartialProfitAvailable, listenPartialProfitAvailableOnce, listenPerformance, listenRisk, listenRiskOnce, listenSchedulePing, listenSchedulePingOnce, listenSignal, listenSignalBacktest, listenSignalBacktestOnce, listenSignalLive, listenSignalLiveOnce, listenSignalOnce, listenStrategyCommit, listenStrategyCommitOnce, listenSync, listenSyncOnce, listenValidation, listenWalker, listenWalkerComplete, listenWalkerOnce, listenWalkerProgress, overrideActionSchema, overrideExchangeSchema, overrideFrameSchema, overrideRiskSchema, overrideSizingSchema, overrideStrategySchema, overrideWalkerSchema, parseArgs, percentDiff, percentToCloseCost, percentValue, readMemory, removeMemory, roundTicks, runInMockContext, searchMemory, set, setColumns, setConfig, setLogger, shutdown, slPercentShiftToPrice, slPriceToPercentShift, stopStrategy, toProfitLossDto, tpPercentShiftToPrice, tpPriceToPercentShift, validate, validateCommonSignal, validatePendingSignal, validateScheduledSignal, validateSignal, waitForCandle, warmCandles, writeMemory };
|
|
29810
|
+
export { ActionBase, type ActivateScheduledCommit, type ActivateScheduledCommitNotification, type ActivePingContract, type AverageBuyCommit, type AverageBuyCommitNotification, Backtest, type BacktestStatisticsModel, Breakeven, type BreakevenAvailableNotification, type BreakevenCommit, type BreakevenCommitNotification, type BreakevenContract, type BreakevenData, type BreakevenEvent, type BreakevenStatisticsModel, Broker, type BrokerAverageBuyPayload, BrokerBase, type BrokerBreakevenPayload, type BrokerPartialLossPayload, type BrokerPartialProfitPayload, type BrokerSignalClosePayload, type BrokerSignalOpenPayload, type BrokerTrailingStopPayload, type BrokerTrailingTakePayload, Cache, type CancelScheduledCommit, type CancelScheduledCommitNotification, type CandleData, type CandleInterval, type ClosePendingCommit, type ClosePendingCommitNotification, type ColumnConfig, type ColumnModel, Constant, type CriticalErrorNotification, type DoneContract, Dump, type EntityId, Exchange, ExecutionContextService, type FrameInterval, type GlobalConfig, Heat, type HeatmapStatisticsModel, HighestProfit, type HighestProfitContract, type HighestProfitEvent, type HighestProfitStatisticsModel, type IActionSchema, type IActivateScheduledCommitRow, type IAggregatedTradeData, type IBidData, type IBreakevenCommitRow, type IBroker, type ICandleData, type ICommitRow, type IDumpContext, type IDumpInstance, type IExchangeSchema, type IFrameSchema, type IHeatmapRow, type ILog, type ILogEntry, type ILogger, type IMarkdownDumpOptions, type IMemoryInstance, type INotificationUtils, type IOrderBookData, type IPartialLossCommitRow, type IPartialProfitCommitRow, type IPersistBase, type IPositionSizeATRParams, type IPositionSizeFixedPercentageParams, type IPositionSizeKellyParams, type IPublicAction, type IPublicCandleData, type IPublicSignalRow, type IReportDumpOptions, type IRiskActivePosition, type IRiskCheckArgs, type IRiskSchema, type IRiskSignalRow, type IRiskValidation, type IRiskValidationFn, type IRiskValidationPayload, type IScheduledSignalCancelRow, type IScheduledSignalRow, type ISignalDto, type ISignalRow, type ISizingCalculateParams, type ISizingCalculateParamsATR, type ISizingCalculateParamsFixedPercentage, type ISizingCalculateParamsKelly, type ISizingParams, type ISizingParamsATR, type ISizingParamsFixedPercentage, type ISizingParamsKelly, type ISizingSchema, type ISizingSchemaATR, type ISizingSchemaFixedPercentage, type ISizingSchemaKelly, type IStorageSignalRow, type IStorageUtils, type IStrategyPnL, type IStrategyResult, type IStrategySchema, type IStrategyTickResult, type IStrategyTickResultActive, type IStrategyTickResultCancelled, type IStrategyTickResultClosed, type IStrategyTickResultIdle, type IStrategyTickResultOpened, type IStrategyTickResultScheduled, type IStrategyTickResultWaiting, type ITrailingStopCommitRow, type ITrailingTakeCommitRow, type IWalkerResults, type IWalkerSchema, type IWalkerStrategyResult, type InfoErrorNotification, Live, type LiveStatisticsModel, Log, type LogData, Markdown, MarkdownFileBase, MarkdownFolderBase, type MarkdownName, MarkdownWriter, MaxDrawdown, type MaxDrawdownContract, type MaxDrawdownEvent, type MaxDrawdownStatisticsModel, type MeasureData, Memory, type MemoryData, type MessageModel, type MessageRole, type MessageToolCall, MethodContextService, type MetricStats, Notification, NotificationBacktest, type NotificationData, NotificationLive, type NotificationModel, Partial$1 as Partial, type PartialData, type PartialEvent, type PartialLossAvailableNotification, type PartialLossCommit, type PartialLossCommitNotification, type PartialLossContract, type PartialProfitAvailableNotification, type PartialProfitCommit, type PartialProfitCommitNotification, type PartialProfitContract, type PartialStatisticsModel, Performance, type PerformanceContract, type PerformanceMetricType, type PerformanceStatisticsModel, PersistBase, PersistBreakevenAdapter, PersistCandleAdapter, PersistLogAdapter, PersistMeasureAdapter, PersistMemoryAdapter, PersistNotificationAdapter, PersistPartialAdapter, PersistRiskAdapter, PersistScheduleAdapter, PersistSignalAdapter, PersistStorageAdapter, PositionSize, type ProgressBacktestContract, type ProgressWalkerContract, Report, ReportBase, type ReportName, ReportWriter, Risk, type RiskContract, type RiskData, type RiskEvent, type RiskRejectionNotification, type RiskStatisticsModel, Schedule, type ScheduleData, type SchedulePingContract, type ScheduleStatisticsModel, type ScheduledEvent, type SignalCancelledNotification, type SignalCloseContract, type SignalClosedNotification, type SignalData, type SignalInterval, type SignalOpenContract, type SignalOpenedNotification, type SignalScheduledNotification, type SignalSyncCloseNotification, type SignalSyncContract, type SignalSyncOpenNotification, Storage, StorageBacktest, type StorageData, StorageLive, Strategy, type StrategyActionType, type StrategyCancelReason, type StrategyCloseReason, type StrategyCommitContract, type StrategyEvent, type StrategyStatisticsModel, Sync, type SyncEvent, type SyncStatisticsModel, type TBrokerCtor, type TDumpInstanceCtor, type TLogCtor, type TMarkdownBase, type TMemoryInstanceCtor, type TNotificationUtilsCtor, type TPersistBase, type TPersistBaseCtor, type TReportBase, type TStorageUtilsCtor, type TickEvent, type TrailingStopCommit, type TrailingStopCommitNotification, type TrailingTakeCommit, type TrailingTakeCommitNotification, type ValidationErrorNotification, Walker, type WalkerCompleteContract, type WalkerContract, type WalkerMetric, type SignalData$1 as WalkerSignalData, type WalkerStatisticsModel, addActionSchema, addExchangeSchema, addFrameSchema, addRiskSchema, addSizingSchema, addStrategySchema, addWalkerSchema, alignToInterval, checkCandles, commitActivateScheduled, commitAverageBuy, commitBreakeven, commitCancelScheduled, commitClosePending, commitPartialLoss, commitPartialLossCost, commitPartialProfit, commitPartialProfitCost, commitTrailingStop, commitTrailingStopCost, commitTrailingTake, commitTrailingTakeCost, dumpAgentAnswer, dumpError, dumpJson, dumpRecord, dumpTable, dumpText, emitters, formatPrice, formatQuantity, get, getActionSchema, getAggregatedTrades, getAveragePrice, getBacktestTimeframe, getBreakeven, getCandles, getColumns, getConfig, getContext, getDate, getDefaultColumns, getDefaultConfig, getEffectivePriceOpen, getExchangeSchema, getFrameSchema, getMode, getNextCandles, getOrderBook, getPendingSignal, getPositionCountdownMinutes, getPositionDrawdownMinutes, getPositionEffectivePrice, getPositionEntries, getPositionEntryOverlap, getPositionEstimateMinutes, getPositionHighestPnlCost, getPositionHighestPnlPercentage, getPositionHighestProfitBreakeven, getPositionHighestProfitMinutes, getPositionHighestProfitPrice, getPositionHighestProfitTimestamp, getPositionInvestedCost, getPositionInvestedCount, getPositionLevels, getPositionMaxDrawdownMinutes, getPositionMaxDrawdownPnlCost, getPositionMaxDrawdownPnlPercentage, getPositionMaxDrawdownPrice, getPositionMaxDrawdownTimestamp, getPositionPartialOverlap, getPositionPartials, getPositionPnlCost, getPositionPnlPercent, getRawCandles, getRiskSchema, getScheduledSignal, getSizingSchema, getStrategySchema, getSymbol, getTimestamp, getTotalClosed, getTotalCostClosed, getTotalPercentClosed, getWalkerSchema, hasNoPendingSignal, hasNoScheduledSignal, hasTradeContext, investedCostToPercent, backtest as lib, listExchangeSchema, listFrameSchema, listMemory, listRiskSchema, listSizingSchema, listStrategySchema, listWalkerSchema, listenActivePing, listenActivePingOnce, listenBacktestProgress, listenBreakevenAvailable, listenBreakevenAvailableOnce, listenDoneBacktest, listenDoneBacktestOnce, listenDoneLive, listenDoneLiveOnce, listenDoneWalker, listenDoneWalkerOnce, listenError, listenExit, listenHighestProfit, listenHighestProfitOnce, listenMaxDrawdown, listenMaxDrawdownOnce, listenPartialLossAvailable, listenPartialLossAvailableOnce, listenPartialProfitAvailable, listenPartialProfitAvailableOnce, listenPerformance, listenRisk, listenRiskOnce, listenSchedulePing, listenSchedulePingOnce, listenSignal, listenSignalBacktest, listenSignalBacktestOnce, listenSignalLive, listenSignalLiveOnce, listenSignalOnce, listenStrategyCommit, listenStrategyCommitOnce, listenSync, listenSyncOnce, listenValidation, listenWalker, listenWalkerComplete, listenWalkerOnce, listenWalkerProgress, overrideActionSchema, overrideExchangeSchema, overrideFrameSchema, overrideRiskSchema, overrideSizingSchema, overrideStrategySchema, overrideWalkerSchema, parseArgs, percentDiff, percentToCloseCost, percentValue, readMemory, removeMemory, roundTicks, runInMockContext, searchMemory, set, setColumns, setConfig, setLogger, shutdown, slPercentShiftToPrice, slPriceToPercentShift, stopStrategy, toProfitLossDto, tpPercentShiftToPrice, tpPriceToPercentShift, validate, validateCommonSignal, validatePendingSignal, validateScheduledSignal, validateSignal, waitForCandle, warmCandles, writeMemory };
|