backtest-kit 6.5.2 → 6.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/index.cjs +5897 -4069
- package/build/index.mjs +5889 -4070
- package/package.json +3 -2
- package/types.d.ts +1994 -944
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.
|
|
@@ -2235,6 +2280,19 @@ interface ISignalRow extends ISignalDto {
|
|
|
2235
2280
|
pnlPercentage: number;
|
|
2236
2281
|
pnlCost: number;
|
|
2237
2282
|
};
|
|
2283
|
+
/**
|
|
2284
|
+
* Worst price seen in loss direction during the life of this position.
|
|
2285
|
+
* Initialized at position open with priceOpen/pendingAt (pnl = 0).
|
|
2286
|
+
* Updated on every tick/candle when price moves toward SL (currentDistance < 0).
|
|
2287
|
+
* - For LONG: minimum VWAP price seen below effective entry
|
|
2288
|
+
* - For SHORT: maximum VWAP price seen above effective entry
|
|
2289
|
+
*/
|
|
2290
|
+
_fall: {
|
|
2291
|
+
price: number;
|
|
2292
|
+
timestamp: number;
|
|
2293
|
+
pnlPercentage: number;
|
|
2294
|
+
pnlCost: number;
|
|
2295
|
+
};
|
|
2238
2296
|
/** Unix timestamp in milliseconds when this signal was created/scheduled in backtest context or when getSignal was called in live context (before validation) */
|
|
2239
2297
|
timestamp: number;
|
|
2240
2298
|
}
|
|
@@ -3502,6 +3560,68 @@ interface IStrategy {
|
|
|
3502
3560
|
* @returns Promise resolving to drawdown duration in minutes or null
|
|
3503
3561
|
*/
|
|
3504
3562
|
getPositionDrawdownMinutes: (symbol: string, timestamp: number) => Promise<number | null>;
|
|
3563
|
+
/**
|
|
3564
|
+
* Returns the number of minutes elapsed since the highest profit price was recorded.
|
|
3565
|
+
*
|
|
3566
|
+
* Alias for getPositionDrawdownMinutes — measures how long the position has been
|
|
3567
|
+
* pulling back from its peak profit level.
|
|
3568
|
+
*
|
|
3569
|
+
* Returns null if no pending signal exists.
|
|
3570
|
+
*
|
|
3571
|
+
* @param symbol - Trading pair symbol
|
|
3572
|
+
* @param timestamp - Current Unix timestamp in milliseconds
|
|
3573
|
+
* @returns Promise resolving to minutes since last profit peak or null
|
|
3574
|
+
*/
|
|
3575
|
+
getPositionHighestProfitMinutes: (symbol: string, timestamp: number) => Promise<number | null>;
|
|
3576
|
+
/**
|
|
3577
|
+
* Returns the number of minutes elapsed since the worst loss price was recorded.
|
|
3578
|
+
*
|
|
3579
|
+
* Measures how long ago the deepest drawdown point occurred.
|
|
3580
|
+
* Zero when called at the exact moment the trough was set.
|
|
3581
|
+
*
|
|
3582
|
+
* Returns null if no pending signal exists.
|
|
3583
|
+
*
|
|
3584
|
+
* @param symbol - Trading pair symbol
|
|
3585
|
+
* @param timestamp - Current Unix timestamp in milliseconds
|
|
3586
|
+
* @returns Promise resolving to minutes since last drawdown trough or null
|
|
3587
|
+
*/
|
|
3588
|
+
getPositionMaxDrawdownMinutes: (symbol: string, timestamp: number) => Promise<number | null>;
|
|
3589
|
+
/**
|
|
3590
|
+
* Returns the worst price reached in the loss direction during this position's life.
|
|
3591
|
+
*
|
|
3592
|
+
* Returns null if no pending signal exists.
|
|
3593
|
+
*
|
|
3594
|
+
* @param symbol - Trading pair symbol
|
|
3595
|
+
* @returns Promise resolving to price or null
|
|
3596
|
+
*/
|
|
3597
|
+
getPositionMaxDrawdownPrice: (symbol: string) => Promise<number | null>;
|
|
3598
|
+
/**
|
|
3599
|
+
* Returns the timestamp when the worst loss price was recorded during this position's life.
|
|
3600
|
+
*
|
|
3601
|
+
* Returns null if no pending signal exists.
|
|
3602
|
+
*
|
|
3603
|
+
* @param symbol - Trading pair symbol
|
|
3604
|
+
* @returns Promise resolving to timestamp in milliseconds or null
|
|
3605
|
+
*/
|
|
3606
|
+
getPositionMaxDrawdownTimestamp: (symbol: string) => Promise<number | null>;
|
|
3607
|
+
/**
|
|
3608
|
+
* Returns the PnL percentage at the moment the worst loss price was recorded during this position's life.
|
|
3609
|
+
*
|
|
3610
|
+
* Returns null if no pending signal exists.
|
|
3611
|
+
*
|
|
3612
|
+
* @param symbol - Trading pair symbol
|
|
3613
|
+
* @returns Promise resolving to PnL percentage or null
|
|
3614
|
+
*/
|
|
3615
|
+
getPositionMaxDrawdownPnlPercentage: (symbol: string) => Promise<number | null>;
|
|
3616
|
+
/**
|
|
3617
|
+
* Returns the PnL cost (in quote currency) at the moment the worst loss price was recorded during this position's life.
|
|
3618
|
+
*
|
|
3619
|
+
* Returns null if no pending signal exists.
|
|
3620
|
+
*
|
|
3621
|
+
* @param symbol - Trading pair symbol
|
|
3622
|
+
* @returns Promise resolving to PnL cost or null
|
|
3623
|
+
*/
|
|
3624
|
+
getPositionMaxDrawdownPnlCost: (symbol: string) => Promise<number | null>;
|
|
3505
3625
|
/**
|
|
3506
3626
|
* Disposes the strategy instance and cleans up resources.
|
|
3507
3627
|
*
|
|
@@ -4106,6 +4226,10 @@ interface BacktestStatisticsModel {
|
|
|
4106
4226
|
certaintyRatio: number | null;
|
|
4107
4227
|
/** Expected yearly returns based on average trade duration and PNL, null if unsafe. Higher is better. */
|
|
4108
4228
|
expectedYearlyReturns: number | null;
|
|
4229
|
+
/** Average peak PNL percentage across all signals (_peak.pnlPercentage), null if unsafe. Higher is better. */
|
|
4230
|
+
avgPeakPnl: number | null;
|
|
4231
|
+
/** Average fall PNL percentage across all signals (_fall.pnlPercentage), null if unsafe. Lower (more negative) means deeper drawdowns. */
|
|
4232
|
+
avgFallPnl: number | null;
|
|
4109
4233
|
}
|
|
4110
4234
|
|
|
4111
4235
|
/**
|
|
@@ -5349,6 +5473,115 @@ declare function getPositionHighestProfitBreakeven(symbol: string): Promise<bool
|
|
|
5349
5473
|
* ```
|
|
5350
5474
|
*/
|
|
5351
5475
|
declare function getPositionDrawdownMinutes(symbol: string): Promise<number>;
|
|
5476
|
+
/**
|
|
5477
|
+
* Returns the number of minutes elapsed since the highest profit price was recorded.
|
|
5478
|
+
*
|
|
5479
|
+
* Alias for getPositionDrawdownMinutes — measures how long the position has been
|
|
5480
|
+
* pulling back from its peak profit level.
|
|
5481
|
+
* Zero when called at the exact moment the peak was set.
|
|
5482
|
+
*
|
|
5483
|
+
* Returns null if no pending signal exists.
|
|
5484
|
+
*
|
|
5485
|
+
* @param symbol - Trading pair symbol
|
|
5486
|
+
* @returns Promise resolving to minutes since last profit peak or null
|
|
5487
|
+
*
|
|
5488
|
+
* @example
|
|
5489
|
+
* ```typescript
|
|
5490
|
+
* import { getPositionHighestProfitMinutes } from "backtest-kit";
|
|
5491
|
+
*
|
|
5492
|
+
* const minutes = await getPositionHighestProfitMinutes("BTCUSDT");
|
|
5493
|
+
* // e.g. 30 (30 minutes since the highest profit price)
|
|
5494
|
+
* ```
|
|
5495
|
+
*/
|
|
5496
|
+
declare function getPositionHighestProfitMinutes(symbol: string): Promise<number>;
|
|
5497
|
+
/**
|
|
5498
|
+
* Returns the number of minutes elapsed since the worst loss price was recorded.
|
|
5499
|
+
*
|
|
5500
|
+
* Measures how long ago the deepest drawdown point occurred.
|
|
5501
|
+
* Zero when called at the exact moment the trough was set.
|
|
5502
|
+
*
|
|
5503
|
+
* Returns null if no pending signal exists.
|
|
5504
|
+
*
|
|
5505
|
+
* @param symbol - Trading pair symbol
|
|
5506
|
+
* @returns Promise resolving to minutes since last drawdown trough or null
|
|
5507
|
+
*
|
|
5508
|
+
* @example
|
|
5509
|
+
* ```typescript
|
|
5510
|
+
* import { getPositionMaxDrawdownMinutes } from "backtest-kit";
|
|
5511
|
+
*
|
|
5512
|
+
* const minutes = await getPositionMaxDrawdownMinutes("BTCUSDT");
|
|
5513
|
+
* // e.g. 15 (15 minutes since the worst loss price)
|
|
5514
|
+
* ```
|
|
5515
|
+
*/
|
|
5516
|
+
declare function getPositionMaxDrawdownMinutes(symbol: string): Promise<number>;
|
|
5517
|
+
/**
|
|
5518
|
+
* Returns the worst price reached in the loss direction during this position's life.
|
|
5519
|
+
*
|
|
5520
|
+
* Returns null if no pending signal exists.
|
|
5521
|
+
*
|
|
5522
|
+
* @param symbol - Trading pair symbol
|
|
5523
|
+
* @returns Promise resolving to price or null
|
|
5524
|
+
*
|
|
5525
|
+
* @example
|
|
5526
|
+
* ```typescript
|
|
5527
|
+
* import { getPositionMaxDrawdownPrice } from "backtest-kit";
|
|
5528
|
+
*
|
|
5529
|
+
* const price = await getPositionMaxDrawdownPrice("BTCUSDT");
|
|
5530
|
+
* // e.g. 41000 (lowest price seen for a LONG position)
|
|
5531
|
+
* ```
|
|
5532
|
+
*/
|
|
5533
|
+
declare function getPositionMaxDrawdownPrice(symbol: string): Promise<number>;
|
|
5534
|
+
/**
|
|
5535
|
+
* Returns the timestamp when the worst loss price was recorded during this position's life.
|
|
5536
|
+
*
|
|
5537
|
+
* Returns null if no pending signal exists.
|
|
5538
|
+
*
|
|
5539
|
+
* @param symbol - Trading pair symbol
|
|
5540
|
+
* @returns Promise resolving to timestamp in milliseconds or null
|
|
5541
|
+
*
|
|
5542
|
+
* @example
|
|
5543
|
+
* ```typescript
|
|
5544
|
+
* import { getPositionMaxDrawdownTimestamp } from "backtest-kit";
|
|
5545
|
+
*
|
|
5546
|
+
* const ts = await getPositionMaxDrawdownTimestamp("BTCUSDT");
|
|
5547
|
+
* // e.g. 1700000000000
|
|
5548
|
+
* ```
|
|
5549
|
+
*/
|
|
5550
|
+
declare function getPositionMaxDrawdownTimestamp(symbol: string): Promise<number>;
|
|
5551
|
+
/**
|
|
5552
|
+
* Returns the PnL percentage at the moment the worst loss price was recorded during this position's life.
|
|
5553
|
+
*
|
|
5554
|
+
* Returns null if no pending signal exists.
|
|
5555
|
+
*
|
|
5556
|
+
* @param symbol - Trading pair symbol
|
|
5557
|
+
* @returns Promise resolving to PnL percentage or null
|
|
5558
|
+
*
|
|
5559
|
+
* @example
|
|
5560
|
+
* ```typescript
|
|
5561
|
+
* import { getPositionMaxDrawdownPnlPercentage } from "backtest-kit";
|
|
5562
|
+
*
|
|
5563
|
+
* const pnl = await getPositionMaxDrawdownPnlPercentage("BTCUSDT");
|
|
5564
|
+
* // e.g. -5.2 (deepest PnL percentage reached)
|
|
5565
|
+
* ```
|
|
5566
|
+
*/
|
|
5567
|
+
declare function getPositionMaxDrawdownPnlPercentage(symbol: string): Promise<number>;
|
|
5568
|
+
/**
|
|
5569
|
+
* Returns the PnL cost (in quote currency) at the moment the worst loss price was recorded during this position's life.
|
|
5570
|
+
*
|
|
5571
|
+
* Returns null if no pending signal exists.
|
|
5572
|
+
*
|
|
5573
|
+
* @param symbol - Trading pair symbol
|
|
5574
|
+
* @returns Promise resolving to PnL cost or null
|
|
5575
|
+
*
|
|
5576
|
+
* @example
|
|
5577
|
+
* ```typescript
|
|
5578
|
+
* import { getPositionMaxDrawdownPnlCost } from "backtest-kit";
|
|
5579
|
+
*
|
|
5580
|
+
* const cost = await getPositionMaxDrawdownPnlCost("BTCUSDT");
|
|
5581
|
+
* // e.g. -52 (deepest PnL in quote currency)
|
|
5582
|
+
* ```
|
|
5583
|
+
*/
|
|
5584
|
+
declare function getPositionMaxDrawdownPnlCost(symbol: string): Promise<number>;
|
|
5352
5585
|
/**
|
|
5353
5586
|
* Checks whether the current price falls within the tolerance zone of any existing DCA entry level.
|
|
5354
5587
|
* Use this to prevent duplicate DCA entries at the same price area.
|
|
@@ -5653,6 +5886,13 @@ declare const GLOBAL_CONFIG: {
|
|
|
5653
5886
|
* Default: 250 events
|
|
5654
5887
|
*/
|
|
5655
5888
|
CC_MAX_HIGHEST_PROFIT_MARKDOWN_ROWS: number;
|
|
5889
|
+
/**
|
|
5890
|
+
* Maximum number of events to keep in max drawdown markdown report storage.
|
|
5891
|
+
* Older events are removed (FIFO) when this limit is exceeded.
|
|
5892
|
+
*
|
|
5893
|
+
* Default: 250 events
|
|
5894
|
+
*/
|
|
5895
|
+
CC_MAX_MAX_DRAWDOWN_MARKDOWN_ROWS: number;
|
|
5656
5896
|
/**
|
|
5657
5897
|
* Maximum number of events to keep in live markdown report storage.
|
|
5658
5898
|
* Older events are removed (FIFO) when this limit is exceeded.
|
|
@@ -5807,6 +6047,8 @@ declare const COLUMN_CONFIG: {
|
|
|
5807
6047
|
sync_columns: ColumnModel<SyncEvent>[];
|
|
5808
6048
|
/** Columns for highest profit milestone tracking events */
|
|
5809
6049
|
highest_profit_columns: ColumnModel<HighestProfitEvent>[];
|
|
6050
|
+
/** Columns for max drawdown milestone tracking events */
|
|
6051
|
+
max_drawdown_columns: ColumnModel<MaxDrawdownEvent>[];
|
|
5810
6052
|
/** Walker: PnL summary columns */
|
|
5811
6053
|
walker_pnl_columns: ColumnModel<SignalData$1>[];
|
|
5812
6054
|
/** Walker: strategy-level summary columns */
|
|
@@ -5886,6 +6128,7 @@ declare function getConfig(): {
|
|
|
5886
6128
|
CC_MAX_BREAKEVEN_MARKDOWN_ROWS: number;
|
|
5887
6129
|
CC_MAX_HEATMAP_MARKDOWN_ROWS: number;
|
|
5888
6130
|
CC_MAX_HIGHEST_PROFIT_MARKDOWN_ROWS: number;
|
|
6131
|
+
CC_MAX_MAX_DRAWDOWN_MARKDOWN_ROWS: number;
|
|
5889
6132
|
CC_MAX_LIVE_MARKDOWN_ROWS: number;
|
|
5890
6133
|
CC_MAX_PARTIAL_MARKDOWN_ROWS: number;
|
|
5891
6134
|
CC_MAX_RISK_MARKDOWN_ROWS: number;
|
|
@@ -5941,6 +6184,7 @@ declare function getDefaultConfig(): Readonly<{
|
|
|
5941
6184
|
CC_MAX_BREAKEVEN_MARKDOWN_ROWS: number;
|
|
5942
6185
|
CC_MAX_HEATMAP_MARKDOWN_ROWS: number;
|
|
5943
6186
|
CC_MAX_HIGHEST_PROFIT_MARKDOWN_ROWS: number;
|
|
6187
|
+
CC_MAX_MAX_DRAWDOWN_MARKDOWN_ROWS: number;
|
|
5944
6188
|
CC_MAX_LIVE_MARKDOWN_ROWS: number;
|
|
5945
6189
|
CC_MAX_PARTIAL_MARKDOWN_ROWS: number;
|
|
5946
6190
|
CC_MAX_RISK_MARKDOWN_ROWS: number;
|
|
@@ -6010,6 +6254,7 @@ declare function getColumns(): {
|
|
|
6010
6254
|
strategy_columns: ColumnModel<StrategyEvent>[];
|
|
6011
6255
|
sync_columns: ColumnModel<SyncEvent>[];
|
|
6012
6256
|
highest_profit_columns: ColumnModel<HighestProfitEvent>[];
|
|
6257
|
+
max_drawdown_columns: ColumnModel<MaxDrawdownEvent>[];
|
|
6013
6258
|
walker_pnl_columns: ColumnModel<SignalData$1>[];
|
|
6014
6259
|
walker_strategy_columns: ColumnModel<IStrategyResult>[];
|
|
6015
6260
|
};
|
|
@@ -6039,6 +6284,7 @@ declare function getDefaultColumns(): Readonly<{
|
|
|
6039
6284
|
strategy_columns: ColumnModel<StrategyEvent>[];
|
|
6040
6285
|
sync_columns: ColumnModel<SyncEvent>[];
|
|
6041
6286
|
highest_profit_columns: ColumnModel<HighestProfitEvent>[];
|
|
6287
|
+
max_drawdown_columns: ColumnModel<MaxDrawdownEvent>[];
|
|
6042
6288
|
walker_pnl_columns: ColumnModel<SignalData$1>[];
|
|
6043
6289
|
walker_strategy_columns: ColumnModel<IStrategyResult>[];
|
|
6044
6290
|
}>;
|
|
@@ -7112,6 +7358,35 @@ interface HighestProfitContract {
|
|
|
7112
7358
|
backtest: boolean;
|
|
7113
7359
|
}
|
|
7114
7360
|
|
|
7361
|
+
/**
|
|
7362
|
+
* Contract for max drawdown updates emitted by the framework.
|
|
7363
|
+
* This contract defines the structure of the data emitted when a new maximum drawdown is reached for an open position.
|
|
7364
|
+
* It includes contextual information about the strategy, exchange, frame, and the associated signal.
|
|
7365
|
+
* Consumers can use this information to implement custom logic based on drawdown milestones (e.g. dynamic stop-loss adjustments, risk management).
|
|
7366
|
+
* The backtest flag allows consumers to differentiate between live and backtest updates for appropriate handling.
|
|
7367
|
+
* Max drawdown events are crucial for monitoring and managing risk, as they indicate the largest peak-to-trough decline in the position's value.
|
|
7368
|
+
* By tracking max drawdown, traders can make informed decisions to protect capital and optimize position management strategies.
|
|
7369
|
+
* The framework emits max drawdown updates whenever a new drawdown level is reached, allowing consumers to react in real-time to changing market conditions and position performance.
|
|
7370
|
+
*/
|
|
7371
|
+
interface MaxDrawdownContract {
|
|
7372
|
+
/** Trading symbol (e.g. "BTC/USDT") */
|
|
7373
|
+
symbol: string;
|
|
7374
|
+
/** Current price at the time of the max drawdown update */
|
|
7375
|
+
currentPrice: number;
|
|
7376
|
+
/** Timestamp of the max drawdown update (milliseconds since epoch) */
|
|
7377
|
+
timestamp: number;
|
|
7378
|
+
/** Strategy name for context */
|
|
7379
|
+
strategyName: StrategyName;
|
|
7380
|
+
/** Exchange name for context */
|
|
7381
|
+
exchangeName: ExchangeName;
|
|
7382
|
+
/** Frame name for context (e.g. "1m", "5m") */
|
|
7383
|
+
frameName: FrameName;
|
|
7384
|
+
/** Public signal data for the position associated with this max drawdown update */
|
|
7385
|
+
signal: IPublicSignalRow;
|
|
7386
|
+
/** Indicates if the update is from a backtest or live trading (true for backtest, false for live) */
|
|
7387
|
+
backtest: boolean;
|
|
7388
|
+
}
|
|
7389
|
+
|
|
7115
7390
|
/**
|
|
7116
7391
|
* Subscribes to all signal events with queued async processing.
|
|
7117
7392
|
*
|
|
@@ -8148,6 +8423,25 @@ declare function listenHighestProfit(fn: (event: HighestProfitContract) => void)
|
|
|
8148
8423
|
* @returns Unsubscribe function to cancel the listener before it fires
|
|
8149
8424
|
*/
|
|
8150
8425
|
declare function listenHighestProfitOnce(filterFn: (event: HighestProfitContract) => boolean, fn: (event: HighestProfitContract) => void): () => void;
|
|
8426
|
+
/**
|
|
8427
|
+
* Subscribes to max drawdown events with queued async processing.
|
|
8428
|
+
* Emits when a signal reaches a new maximum drawdown level during its lifecycle.
|
|
8429
|
+
* Events are processed sequentially in order received, even if callback is async.
|
|
8430
|
+
* Uses queued wrapper to prevent concurrent execution of the callback.
|
|
8431
|
+
* Useful for tracking drawdown milestones and implementing dynamic risk management logic.
|
|
8432
|
+
* @param fn - Callback function to handle max drawdown events
|
|
8433
|
+
* @return Unsubscribe function to stop listening to events
|
|
8434
|
+
*/
|
|
8435
|
+
declare function listenMaxDrawdown(fn: (event: MaxDrawdownContract) => void): () => void;
|
|
8436
|
+
/**
|
|
8437
|
+
* Subscribes to filtered max drawdown events with one-time execution.
|
|
8438
|
+
* Listens for events matching the filter predicate, then executes callback once
|
|
8439
|
+
* and automatically unsubscribes. Useful for waiting for specific drawdown conditions.
|
|
8440
|
+
* @param filterFn - Predicate to filter which events trigger the callback
|
|
8441
|
+
* @param fn - Callback function to handle the filtered event (called only once)
|
|
8442
|
+
* @return Unsubscribe function to cancel the listener before it fires
|
|
8443
|
+
*/
|
|
8444
|
+
declare function listenMaxDrawdownOnce(filterFn: (event: MaxDrawdownContract) => boolean, fn: (event: MaxDrawdownContract) => void): () => void;
|
|
8151
8445
|
|
|
8152
8446
|
/**
|
|
8153
8447
|
* Checks if trade context is active (execution and method contexts).
|
|
@@ -8826,6 +9120,10 @@ interface IHeatmapRow {
|
|
|
8826
9120
|
maxLossStreak: number;
|
|
8827
9121
|
/** Expectancy: (winRate * avgWin) - (lossRate * avgLoss) */
|
|
8828
9122
|
expectancy: number | null;
|
|
9123
|
+
/** Average peak PNL percentage across all trades (_peak.pnlPercentage). Higher is better. */
|
|
9124
|
+
avgPeakPnl: number | null;
|
|
9125
|
+
/** Average fall PNL percentage across all trades (_fall.pnlPercentage). Closer to 0 is better. */
|
|
9126
|
+
avgFallPnl: number | null;
|
|
8829
9127
|
}
|
|
8830
9128
|
|
|
8831
9129
|
/**
|
|
@@ -10111,6 +10409,10 @@ interface TickEvent {
|
|
|
10111
10409
|
pendingAt?: number;
|
|
10112
10410
|
/** Timestamp when signal was created/scheduled (only for scheduled/waiting/opened/active/closed/cancelled) */
|
|
10113
10411
|
scheduledAt?: number;
|
|
10412
|
+
/** Peak PNL percentage at best price during position (_peak.pnlPercentage, only for closed) */
|
|
10413
|
+
peakPnl?: number;
|
|
10414
|
+
/** Fall PNL percentage at worst price during position (_fall.pnlPercentage, only for closed) */
|
|
10415
|
+
fallPnl?: number;
|
|
10114
10416
|
}
|
|
10115
10417
|
/**
|
|
10116
10418
|
* Statistical data calculated from live trading results.
|
|
@@ -10162,6 +10464,10 @@ interface LiveStatisticsModel {
|
|
|
10162
10464
|
certaintyRatio: number | null;
|
|
10163
10465
|
/** Expected yearly returns based on average trade duration and PNL, null if unsafe. Higher is better. */
|
|
10164
10466
|
expectedYearlyReturns: number | null;
|
|
10467
|
+
/** Average peak PNL percentage across all closed signals (_peak.pnlPercentage), null if unsafe. Higher is better. */
|
|
10468
|
+
avgPeakPnl: number | null;
|
|
10469
|
+
/** Average fall PNL percentage across all closed signals (_fall.pnlPercentage), null if unsafe. Closer to 0 is better. */
|
|
10470
|
+
avgFallPnl: number | null;
|
|
10165
10471
|
}
|
|
10166
10472
|
|
|
10167
10473
|
/**
|
|
@@ -10179,6 +10485,10 @@ interface HeatmapStatisticsModel {
|
|
|
10179
10485
|
portfolioSharpeRatio: number | null;
|
|
10180
10486
|
/** Portfolio-wide total trades */
|
|
10181
10487
|
portfolioTotalTrades: number;
|
|
10488
|
+
/** Trade-count-weighted average peak PNL across all symbols. Higher is better. */
|
|
10489
|
+
portfolioAvgPeakPnl: number | null;
|
|
10490
|
+
/** Trade-count-weighted average fall PNL across all symbols. Closer to 0 is better. */
|
|
10491
|
+
portfolioAvgFallPnl: number | null;
|
|
10182
10492
|
}
|
|
10183
10493
|
|
|
10184
10494
|
/**
|
|
@@ -10485,6 +10795,43 @@ interface HighestProfitStatisticsModel {
|
|
|
10485
10795
|
totalEvents: number;
|
|
10486
10796
|
}
|
|
10487
10797
|
|
|
10798
|
+
/**
|
|
10799
|
+
* Single max drawdown event recorded for a position.
|
|
10800
|
+
*/
|
|
10801
|
+
interface MaxDrawdownEvent {
|
|
10802
|
+
/** Unix timestamp in milliseconds when the record was set */
|
|
10803
|
+
timestamp: number;
|
|
10804
|
+
/** Trading pair symbol */
|
|
10805
|
+
symbol: string;
|
|
10806
|
+
/** Strategy name */
|
|
10807
|
+
strategyName: string;
|
|
10808
|
+
/** Signal unique identifier */
|
|
10809
|
+
signalId: string;
|
|
10810
|
+
/** Position direction */
|
|
10811
|
+
position: IPublicSignalRow["position"];
|
|
10812
|
+
/** Unrealized PNL at the time the record was set */
|
|
10813
|
+
pnl: IStrategyPnL;
|
|
10814
|
+
/** Record price reached in the loss direction */
|
|
10815
|
+
currentPrice: number;
|
|
10816
|
+
/** Effective entry price at the time of the update */
|
|
10817
|
+
priceOpen: number;
|
|
10818
|
+
/** Take profit price */
|
|
10819
|
+
priceTakeProfit: number;
|
|
10820
|
+
/** Stop loss price */
|
|
10821
|
+
priceStopLoss: number;
|
|
10822
|
+
/** Whether the event occurred in backtest mode */
|
|
10823
|
+
backtest: boolean;
|
|
10824
|
+
}
|
|
10825
|
+
/**
|
|
10826
|
+
* Aggregated statistics model for max drawdown events.
|
|
10827
|
+
*/
|
|
10828
|
+
interface MaxDrawdownStatisticsModel {
|
|
10829
|
+
/** Full list of recorded events (newest first) */
|
|
10830
|
+
eventList: MaxDrawdownEvent[];
|
|
10831
|
+
/** Total number of recorded events */
|
|
10832
|
+
totalEvents: number;
|
|
10833
|
+
}
|
|
10834
|
+
|
|
10488
10835
|
/**
|
|
10489
10836
|
* Risk rejection event data for report generation.
|
|
10490
10837
|
* Contains all information about rejected signals due to risk limits.
|
|
@@ -11849,44 +12196,235 @@ declare class PersistMemoryUtils {
|
|
|
11849
12196
|
*/
|
|
11850
12197
|
declare const PersistMemoryAdapter: PersistMemoryUtils;
|
|
11851
12198
|
|
|
11852
|
-
/** Symbol key for the singleshot waitForInit function on ReportBase instances. */
|
|
11853
|
-
declare const WAIT_FOR_INIT_SYMBOL$1: unique symbol;
|
|
11854
|
-
/** Symbol key for the timeout-protected write function on ReportBase instances. */
|
|
11855
|
-
declare const WRITE_SAFE_SYMBOL$1: unique symbol;
|
|
11856
12199
|
/**
|
|
11857
|
-
* Configuration interface for selective
|
|
11858
|
-
* Controls which report services should be activated
|
|
12200
|
+
* Configuration interface for selective markdown service enablement.
|
|
12201
|
+
* Controls which markdown report services should be activated.
|
|
11859
12202
|
*/
|
|
11860
|
-
interface
|
|
11861
|
-
/** Enable strategy
|
|
12203
|
+
interface IMarkdownTarget {
|
|
12204
|
+
/** Enable strategy event tracking reports (entry/exit signals) */
|
|
11862
12205
|
strategy: boolean;
|
|
11863
|
-
/** Enable risk rejection
|
|
12206
|
+
/** Enable risk rejection tracking reports (signals blocked by risk limits) */
|
|
11864
12207
|
risk: boolean;
|
|
11865
|
-
/** Enable breakeven event
|
|
12208
|
+
/** Enable breakeven event tracking reports (when stop loss moves to entry) */
|
|
11866
12209
|
breakeven: boolean;
|
|
11867
|
-
/** Enable partial
|
|
12210
|
+
/** Enable partial profit/loss event tracking reports */
|
|
11868
12211
|
partial: boolean;
|
|
11869
|
-
/** Enable heatmap
|
|
12212
|
+
/** Enable portfolio heatmap analysis reports across all symbols */
|
|
11870
12213
|
heat: boolean;
|
|
11871
|
-
/** Enable walker
|
|
12214
|
+
/** Enable walker strategy comparison and optimization reports */
|
|
11872
12215
|
walker: boolean;
|
|
11873
|
-
/** Enable performance metrics
|
|
12216
|
+
/** Enable performance metrics and bottleneck analysis reports */
|
|
11874
12217
|
performance: boolean;
|
|
11875
|
-
/** Enable scheduled signal
|
|
12218
|
+
/** Enable scheduled signal tracking reports (signals waiting for trigger) */
|
|
11876
12219
|
schedule: boolean;
|
|
11877
|
-
/** Enable live trading event
|
|
12220
|
+
/** Enable live trading event reports (all tick events) */
|
|
11878
12221
|
live: boolean;
|
|
11879
|
-
/** Enable backtest
|
|
12222
|
+
/** Enable backtest markdown reports (main strategy results with full trade history) */
|
|
11880
12223
|
backtest: boolean;
|
|
11881
|
-
/** Enable signal
|
|
12224
|
+
/** Enable signal sync lifecycle reports (signal-open and signal-close events) */
|
|
11882
12225
|
sync: boolean;
|
|
11883
|
-
/** Enable highest profit milestone
|
|
12226
|
+
/** Enable highest profit milestone tracking reports */
|
|
11884
12227
|
highest_profit: boolean;
|
|
12228
|
+
/** Enable max drawdown milestone tracking reports */
|
|
12229
|
+
max_drawdown: boolean;
|
|
11885
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;
|
|
11886
12235
|
/**
|
|
11887
|
-
* Union type of all valid report names.
|
|
11888
|
-
* Used for type-safe identification of
|
|
11889
|
-
*/
|
|
12236
|
+
* Union type of all valid markdown report names.
|
|
12237
|
+
* Used for type-safe identification of markdown services.
|
|
12238
|
+
*/
|
|
12239
|
+
type MarkdownName = keyof IMarkdownTarget;
|
|
12240
|
+
/**
|
|
12241
|
+
* Options for markdown dump operations.
|
|
12242
|
+
* Contains path information and metadata for filtering.
|
|
12243
|
+
*/
|
|
12244
|
+
interface IMarkdownDumpOptions {
|
|
12245
|
+
/** Directory path relative to process.cwd() */
|
|
12246
|
+
path: string;
|
|
12247
|
+
/** File name including extension */
|
|
12248
|
+
file: string;
|
|
12249
|
+
/** Trading pair symbol (e.g., "BTCUSDT") */
|
|
12250
|
+
symbol: string;
|
|
12251
|
+
/** Strategy name */
|
|
12252
|
+
strategyName: string;
|
|
12253
|
+
/** Exchange name */
|
|
12254
|
+
exchangeName: string;
|
|
12255
|
+
/** Frame name (timeframe identifier) */
|
|
12256
|
+
frameName: string;
|
|
12257
|
+
/** Signal unique identifier */
|
|
12258
|
+
signalId: string;
|
|
12259
|
+
}
|
|
12260
|
+
/**
|
|
12261
|
+
* Base interface for markdown storage adapters.
|
|
12262
|
+
* All markdown adapters must implement this interface.
|
|
12263
|
+
*/
|
|
12264
|
+
type TMarkdownBase = {
|
|
12265
|
+
/**
|
|
12266
|
+
* Initialize markdown storage and prepare for writes.
|
|
12267
|
+
* Uses singleshot to ensure one-time execution.
|
|
12268
|
+
*
|
|
12269
|
+
* @param initial - Whether this is the first initialization
|
|
12270
|
+
* @returns Promise that resolves when initialization is complete
|
|
12271
|
+
*/
|
|
12272
|
+
waitForInit(initial: boolean): Promise<void>;
|
|
12273
|
+
/**
|
|
12274
|
+
* Dump markdown content to storage.
|
|
12275
|
+
*
|
|
12276
|
+
* @param content - Markdown content to write
|
|
12277
|
+
* @param options - Metadata and path options for the dump
|
|
12278
|
+
* @returns Promise that resolves when write is complete
|
|
12279
|
+
* @throws Error if write fails or stream is not initialized
|
|
12280
|
+
*/
|
|
12281
|
+
dump(content: string, options: IMarkdownDumpOptions): Promise<void>;
|
|
12282
|
+
};
|
|
12283
|
+
/**
|
|
12284
|
+
* Constructor type for markdown storage adapters.
|
|
12285
|
+
* Used for custom markdown storage implementations.
|
|
12286
|
+
*/
|
|
12287
|
+
type TMarkdownBaseCtor = new (markdownName: MarkdownName) => TMarkdownBase;
|
|
12288
|
+
/**
|
|
12289
|
+
* JSONL-based markdown adapter with append-only writes.
|
|
12290
|
+
*
|
|
12291
|
+
* Features:
|
|
12292
|
+
* - Writes markdown reports as JSONL entries to a single file per markdown type
|
|
12293
|
+
* - Stream-based writes with backpressure handling
|
|
12294
|
+
* - 15-second timeout protection for write operations
|
|
12295
|
+
* - Automatic directory creation
|
|
12296
|
+
* - Error handling via exitEmitter
|
|
12297
|
+
* - Search metadata for filtering (symbol, strategy, exchange, frame, signalId)
|
|
12298
|
+
*
|
|
12299
|
+
* File format: ./dump/markdown/{markdownName}.jsonl
|
|
12300
|
+
* Each line contains: markdownName, data, symbol, strategyName, exchangeName, frameName, signalId, timestamp
|
|
12301
|
+
*
|
|
12302
|
+
* Use this adapter for centralized logging and post-processing with JSONL tools.
|
|
12303
|
+
*/
|
|
12304
|
+
declare class MarkdownFileBase implements TMarkdownBase {
|
|
12305
|
+
readonly markdownName: MarkdownName;
|
|
12306
|
+
/** Absolute path to the JSONL file for this markdown type */
|
|
12307
|
+
_filePath: string;
|
|
12308
|
+
/** WriteStream instance for append-only writes, null until initialized */
|
|
12309
|
+
_stream: WriteStream | null;
|
|
12310
|
+
/** Base directory for all JSONL markdown files */
|
|
12311
|
+
_baseDir: string;
|
|
12312
|
+
/**
|
|
12313
|
+
* Creates a new JSONL markdown adapter instance.
|
|
12314
|
+
*
|
|
12315
|
+
* @param markdownName - Type of markdown report (backtest, live, walker, etc.)
|
|
12316
|
+
*/
|
|
12317
|
+
constructor(markdownName: MarkdownName);
|
|
12318
|
+
/**
|
|
12319
|
+
* Singleshot initialization function that creates directory and stream.
|
|
12320
|
+
* Protected by singleshot to ensure one-time execution.
|
|
12321
|
+
* Sets up error handler that emits to exitEmitter.
|
|
12322
|
+
*/
|
|
12323
|
+
[WAIT_FOR_INIT_SYMBOL]: (() => Promise<void>) & functools_kit.ISingleshotClearable;
|
|
12324
|
+
/**
|
|
12325
|
+
* Timeout-protected write function with backpressure handling.
|
|
12326
|
+
* Waits for drain event if write buffer is full.
|
|
12327
|
+
* Times out after 15 seconds and returns TIMEOUT_SYMBOL.
|
|
12328
|
+
*/
|
|
12329
|
+
[WRITE_SAFE_SYMBOL]: (line: string) => Promise<symbol | void>;
|
|
12330
|
+
/**
|
|
12331
|
+
* Initializes the JSONL file and write stream.
|
|
12332
|
+
* Safe to call multiple times - singleshot ensures one-time execution.
|
|
12333
|
+
*
|
|
12334
|
+
* @returns Promise that resolves when initialization is complete
|
|
12335
|
+
*/
|
|
12336
|
+
waitForInit(): Promise<void>;
|
|
12337
|
+
/**
|
|
12338
|
+
* Writes markdown content to JSONL file with metadata.
|
|
12339
|
+
* Appends a single line with JSON object containing:
|
|
12340
|
+
* - markdownName: Type of report
|
|
12341
|
+
* - data: Markdown content
|
|
12342
|
+
* - Search flags: symbol, strategyName, exchangeName, frameName, signalId
|
|
12343
|
+
* - timestamp: Current timestamp in milliseconds
|
|
12344
|
+
*
|
|
12345
|
+
* @param data - Markdown content to write
|
|
12346
|
+
* @param options - Path and metadata options
|
|
12347
|
+
* @throws Error if stream not initialized or write timeout exceeded
|
|
12348
|
+
*/
|
|
12349
|
+
dump(data: string, options: IMarkdownDumpOptions): Promise<void>;
|
|
12350
|
+
}
|
|
12351
|
+
/**
|
|
12352
|
+
* Folder-based markdown adapter with separate files per report.
|
|
12353
|
+
*
|
|
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
|
|
12360
|
+
*
|
|
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.
|
|
12365
|
+
*/
|
|
12366
|
+
declare class MarkdownFolderBase implements TMarkdownBase {
|
|
12367
|
+
readonly markdownName: MarkdownName;
|
|
12368
|
+
/**
|
|
12369
|
+
* Creates a new folder-based markdown adapter instance.
|
|
12370
|
+
*
|
|
12371
|
+
* @param markdownName - Type of markdown report (backtest, live, walker, etc.)
|
|
12372
|
+
*/
|
|
12373
|
+
constructor(markdownName: MarkdownName);
|
|
12374
|
+
/**
|
|
12375
|
+
* No-op initialization for folder adapter.
|
|
12376
|
+
* This adapter doesn't need initialization since it uses direct writeFile.
|
|
12377
|
+
*
|
|
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.
|
|
12385
|
+
*
|
|
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
|
|
12389
|
+
*/
|
|
12390
|
+
dump(content: string, options: IMarkdownDumpOptions): Promise<void>;
|
|
12391
|
+
}
|
|
12392
|
+
/**
|
|
12393
|
+
* Configuration interface for selective report service enablement.
|
|
12394
|
+
* Controls which report services should be activated for JSONL event logging.
|
|
12395
|
+
*/
|
|
12396
|
+
interface IReportTarget {
|
|
12397
|
+
/** Enable strategy commit actions */
|
|
12398
|
+
strategy: boolean;
|
|
12399
|
+
/** Enable risk rejection event logging */
|
|
12400
|
+
risk: boolean;
|
|
12401
|
+
/** Enable breakeven event logging */
|
|
12402
|
+
breakeven: boolean;
|
|
12403
|
+
/** Enable partial close event logging */
|
|
12404
|
+
partial: boolean;
|
|
12405
|
+
/** Enable heatmap data event logging */
|
|
12406
|
+
heat: boolean;
|
|
12407
|
+
/** Enable walker iteration event logging */
|
|
12408
|
+
walker: boolean;
|
|
12409
|
+
/** Enable performance metrics event logging */
|
|
12410
|
+
performance: boolean;
|
|
12411
|
+
/** Enable scheduled signal event logging */
|
|
12412
|
+
schedule: boolean;
|
|
12413
|
+
/** Enable live trading event logging (all tick states) */
|
|
12414
|
+
live: boolean;
|
|
12415
|
+
/** Enable backtest closed signal event logging */
|
|
12416
|
+
backtest: boolean;
|
|
12417
|
+
/** Enable signal synchronization event logging (signal-open, signal-close) */
|
|
12418
|
+
sync: boolean;
|
|
12419
|
+
/** Enable highest profit milestone event logging */
|
|
12420
|
+
highest_profit: boolean;
|
|
12421
|
+
/** Enable max drawdown milestone event logging */
|
|
12422
|
+
max_drawdown: boolean;
|
|
12423
|
+
}
|
|
12424
|
+
/**
|
|
12425
|
+
* Union type of all valid report names.
|
|
12426
|
+
* Used for type-safe identification of report services.
|
|
12427
|
+
*/
|
|
11890
12428
|
type ReportName = keyof IReportTarget;
|
|
11891
12429
|
/**
|
|
11892
12430
|
* Options for report data writes.
|
|
@@ -11969,13 +12507,13 @@ declare class ReportBase implements TReportBase {
|
|
|
11969
12507
|
* Protected by singleshot to ensure one-time execution.
|
|
11970
12508
|
* Sets up error handler that emits to exitEmitter.
|
|
11971
12509
|
*/
|
|
11972
|
-
[WAIT_FOR_INIT_SYMBOL
|
|
12510
|
+
[WAIT_FOR_INIT_SYMBOL]: (() => Promise<void>) & functools_kit.ISingleshotClearable;
|
|
11973
12511
|
/**
|
|
11974
12512
|
* Timeout-protected write function with backpressure handling.
|
|
11975
12513
|
* Waits for drain event if write buffer is full.
|
|
11976
12514
|
* Times out after 15 seconds and returns TIMEOUT_SYMBOL.
|
|
11977
12515
|
*/
|
|
11978
|
-
[WRITE_SAFE_SYMBOL
|
|
12516
|
+
[WRITE_SAFE_SYMBOL]: (line: string) => Promise<symbol | void>;
|
|
11979
12517
|
/**
|
|
11980
12518
|
* Initializes the JSONL file and write stream.
|
|
11981
12519
|
* Safe to call multiple times - singleshot ensures one-time execution.
|
|
@@ -11998,6 +12536,7 @@ declare class ReportBase implements TReportBase {
|
|
|
11998
12536
|
*/
|
|
11999
12537
|
write<T = any>(data: T, options: IReportDumpOptions): Promise<void>;
|
|
12000
12538
|
}
|
|
12539
|
+
|
|
12001
12540
|
/**
|
|
12002
12541
|
* Utility class for managing report services.
|
|
12003
12542
|
*
|
|
@@ -12033,7 +12572,7 @@ declare class ReportUtils {
|
|
|
12033
12572
|
*
|
|
12034
12573
|
* @returns Cleanup function that unsubscribes from all enabled services
|
|
12035
12574
|
*/
|
|
12036
|
-
enable: ({ backtest: bt, breakeven, heat, live, partial, performance, risk, schedule, walker, strategy, sync, highest_profit, }?: Partial<IReportTarget>) => (...args: any[]) => any;
|
|
12575
|
+
enable: ({ backtest: bt, breakeven, heat, live, partial, performance, risk, schedule, walker, strategy, sync, highest_profit, max_drawdown, }?: Partial<IReportTarget>) => (...args: any[]) => any;
|
|
12037
12576
|
/**
|
|
12038
12577
|
* Disables report services selectively.
|
|
12039
12578
|
*
|
|
@@ -12070,7 +12609,7 @@ declare class ReportUtils {
|
|
|
12070
12609
|
* Report.disable();
|
|
12071
12610
|
* ```
|
|
12072
12611
|
*/
|
|
12073
|
-
disable: ({ backtest: bt, breakeven, heat, live, partial, performance, risk, schedule, walker, strategy, sync, highest_profit, }?: Partial<IReportTarget>) => void;
|
|
12612
|
+
disable: ({ backtest: bt, breakeven, heat, live, partial, performance, risk, schedule, walker, strategy, sync, highest_profit, max_drawdown, }?: Partial<IReportTarget>) => void;
|
|
12074
12613
|
}
|
|
12075
12614
|
/**
|
|
12076
12615
|
* Report adapter with pluggable storage backend and instance memoization.
|
|
@@ -12085,19 +12624,6 @@ declare class ReportUtils {
|
|
|
12085
12624
|
* Used for structured event logging and analytics pipelines.
|
|
12086
12625
|
*/
|
|
12087
12626
|
declare class ReportAdapter extends ReportUtils {
|
|
12088
|
-
/**
|
|
12089
|
-
* Current report storage adapter constructor.
|
|
12090
|
-
* Defaults to ReportBase for JSONL storage.
|
|
12091
|
-
* Can be changed via useReportAdapter().
|
|
12092
|
-
*/
|
|
12093
|
-
private ReportFactory;
|
|
12094
|
-
/**
|
|
12095
|
-
* Memoized storage instances cache.
|
|
12096
|
-
* Key: reportName (backtest, live, walker, etc.)
|
|
12097
|
-
* Value: TReportBase instance created with current ReportFactory.
|
|
12098
|
-
* Ensures single instance per report type for the lifetime of the application.
|
|
12099
|
-
*/
|
|
12100
|
-
private getReportStorage;
|
|
12101
12627
|
/**
|
|
12102
12628
|
* Sets the report storage adapter constructor.
|
|
12103
12629
|
* All future report instances will use this adapter.
|
|
@@ -12105,19 +12631,6 @@ declare class ReportAdapter extends ReportUtils {
|
|
|
12105
12631
|
* @param Ctor - Constructor for report storage adapter
|
|
12106
12632
|
*/
|
|
12107
12633
|
useReportAdapter(Ctor: TReportBaseCtor): void;
|
|
12108
|
-
/**
|
|
12109
|
-
* Writes report data to storage using the configured adapter.
|
|
12110
|
-
* Automatically initializes storage on first write for each report type.
|
|
12111
|
-
*
|
|
12112
|
-
* @param reportName - Type of report (backtest, live, walker, etc.)
|
|
12113
|
-
* @param data - Event data object to write
|
|
12114
|
-
* @param options - Metadata options for filtering and search
|
|
12115
|
-
* @returns Promise that resolves when write is complete
|
|
12116
|
-
* @throws Error if write fails or storage initialization fails
|
|
12117
|
-
*
|
|
12118
|
-
* @internal - Automatically called by report services, not for direct use
|
|
12119
|
-
*/
|
|
12120
|
-
writeData: <T = any>(reportName: ReportName, data: T, options: IReportDumpOptions) => Promise<void>;
|
|
12121
12634
|
/**
|
|
12122
12635
|
* Clears the memoized storage cache.
|
|
12123
12636
|
* Call this when process.cwd() changes between strategy iterations
|
|
@@ -12141,197 +12654,6 @@ declare class ReportAdapter extends ReportUtils {
|
|
|
12141
12654
|
*/
|
|
12142
12655
|
declare const Report: ReportAdapter;
|
|
12143
12656
|
|
|
12144
|
-
/**
|
|
12145
|
-
* Configuration interface for selective markdown service enablement.
|
|
12146
|
-
* Controls which markdown report services should be activated.
|
|
12147
|
-
*/
|
|
12148
|
-
interface IMarkdownTarget {
|
|
12149
|
-
/** Enable strategy event tracking reports (entry/exit signals) */
|
|
12150
|
-
strategy: boolean;
|
|
12151
|
-
/** Enable risk rejection tracking reports (signals blocked by risk limits) */
|
|
12152
|
-
risk: boolean;
|
|
12153
|
-
/** Enable breakeven event tracking reports (when stop loss moves to entry) */
|
|
12154
|
-
breakeven: boolean;
|
|
12155
|
-
/** Enable partial profit/loss event tracking reports */
|
|
12156
|
-
partial: boolean;
|
|
12157
|
-
/** Enable portfolio heatmap analysis reports across all symbols */
|
|
12158
|
-
heat: boolean;
|
|
12159
|
-
/** Enable walker strategy comparison and optimization reports */
|
|
12160
|
-
walker: boolean;
|
|
12161
|
-
/** Enable performance metrics and bottleneck analysis reports */
|
|
12162
|
-
performance: boolean;
|
|
12163
|
-
/** Enable scheduled signal tracking reports (signals waiting for trigger) */
|
|
12164
|
-
schedule: boolean;
|
|
12165
|
-
/** Enable live trading event reports (all tick events) */
|
|
12166
|
-
live: boolean;
|
|
12167
|
-
/** Enable backtest markdown reports (main strategy results with full trade history) */
|
|
12168
|
-
backtest: boolean;
|
|
12169
|
-
/** Enable signal sync lifecycle reports (signal-open and signal-close events) */
|
|
12170
|
-
sync: boolean;
|
|
12171
|
-
/** Enable highest profit milestone tracking reports */
|
|
12172
|
-
highest_profit: boolean;
|
|
12173
|
-
}
|
|
12174
|
-
/** Symbol key for the singleshot waitForInit function on MarkdownFileBase instances. */
|
|
12175
|
-
declare const WAIT_FOR_INIT_SYMBOL: unique symbol;
|
|
12176
|
-
/** Symbol key for the timeout-protected write function on MarkdownFileBase instances. */
|
|
12177
|
-
declare const WRITE_SAFE_SYMBOL: unique symbol;
|
|
12178
|
-
/**
|
|
12179
|
-
* Union type of all valid markdown report names.
|
|
12180
|
-
* Used for type-safe identification of markdown services.
|
|
12181
|
-
*/
|
|
12182
|
-
type MarkdownName = keyof IMarkdownTarget;
|
|
12183
|
-
/**
|
|
12184
|
-
* Options for markdown dump operations.
|
|
12185
|
-
* Contains path information and metadata for filtering.
|
|
12186
|
-
*/
|
|
12187
|
-
interface IMarkdownDumpOptions {
|
|
12188
|
-
/** Directory path relative to process.cwd() */
|
|
12189
|
-
path: string;
|
|
12190
|
-
/** File name including extension */
|
|
12191
|
-
file: string;
|
|
12192
|
-
/** Trading pair symbol (e.g., "BTCUSDT") */
|
|
12193
|
-
symbol: string;
|
|
12194
|
-
/** Strategy name */
|
|
12195
|
-
strategyName: string;
|
|
12196
|
-
/** Exchange name */
|
|
12197
|
-
exchangeName: string;
|
|
12198
|
-
/** Frame name (timeframe identifier) */
|
|
12199
|
-
frameName: string;
|
|
12200
|
-
/** Signal unique identifier */
|
|
12201
|
-
signalId: string;
|
|
12202
|
-
}
|
|
12203
|
-
/**
|
|
12204
|
-
* Base interface for markdown storage adapters.
|
|
12205
|
-
* All markdown adapters must implement this interface.
|
|
12206
|
-
*/
|
|
12207
|
-
type TMarkdownBase = {
|
|
12208
|
-
/**
|
|
12209
|
-
* Initialize markdown storage and prepare for writes.
|
|
12210
|
-
* Uses singleshot to ensure one-time execution.
|
|
12211
|
-
*
|
|
12212
|
-
* @param initial - Whether this is the first initialization
|
|
12213
|
-
* @returns Promise that resolves when initialization is complete
|
|
12214
|
-
*/
|
|
12215
|
-
waitForInit(initial: boolean): Promise<void>;
|
|
12216
|
-
/**
|
|
12217
|
-
* Dump markdown content to storage.
|
|
12218
|
-
*
|
|
12219
|
-
* @param content - Markdown content to write
|
|
12220
|
-
* @param options - Metadata and path options for the dump
|
|
12221
|
-
* @returns Promise that resolves when write is complete
|
|
12222
|
-
* @throws Error if write fails or stream is not initialized
|
|
12223
|
-
*/
|
|
12224
|
-
dump(content: string, options: IMarkdownDumpOptions): Promise<void>;
|
|
12225
|
-
};
|
|
12226
|
-
/**
|
|
12227
|
-
* Constructor type for markdown storage adapters.
|
|
12228
|
-
* Used for custom markdown storage implementations.
|
|
12229
|
-
*/
|
|
12230
|
-
type TMarkdownBaseCtor = new (markdownName: MarkdownName) => TMarkdownBase;
|
|
12231
|
-
/**
|
|
12232
|
-
* JSONL-based markdown adapter with append-only writes.
|
|
12233
|
-
*
|
|
12234
|
-
* Features:
|
|
12235
|
-
* - Writes markdown reports as JSONL entries to a single file per markdown type
|
|
12236
|
-
* - Stream-based writes with backpressure handling
|
|
12237
|
-
* - 15-second timeout protection for write operations
|
|
12238
|
-
* - Automatic directory creation
|
|
12239
|
-
* - Error handling via exitEmitter
|
|
12240
|
-
* - Search metadata for filtering (symbol, strategy, exchange, frame, signalId)
|
|
12241
|
-
*
|
|
12242
|
-
* File format: ./dump/markdown/{markdownName}.jsonl
|
|
12243
|
-
* Each line contains: markdownName, data, symbol, strategyName, exchangeName, frameName, signalId, timestamp
|
|
12244
|
-
*
|
|
12245
|
-
* Use this adapter for centralized logging and post-processing with JSONL tools.
|
|
12246
|
-
*/
|
|
12247
|
-
declare class MarkdownFileBase implements TMarkdownBase {
|
|
12248
|
-
readonly markdownName: MarkdownName;
|
|
12249
|
-
/** Absolute path to the JSONL file for this markdown type */
|
|
12250
|
-
_filePath: string;
|
|
12251
|
-
/** WriteStream instance for append-only writes, null until initialized */
|
|
12252
|
-
_stream: WriteStream | null;
|
|
12253
|
-
/** Base directory for all JSONL markdown files */
|
|
12254
|
-
_baseDir: string;
|
|
12255
|
-
/**
|
|
12256
|
-
* Creates a new JSONL markdown adapter instance.
|
|
12257
|
-
*
|
|
12258
|
-
* @param markdownName - Type of markdown report (backtest, live, walker, etc.)
|
|
12259
|
-
*/
|
|
12260
|
-
constructor(markdownName: MarkdownName);
|
|
12261
|
-
/**
|
|
12262
|
-
* Singleshot initialization function that creates directory and stream.
|
|
12263
|
-
* Protected by singleshot to ensure one-time execution.
|
|
12264
|
-
* Sets up error handler that emits to exitEmitter.
|
|
12265
|
-
*/
|
|
12266
|
-
[WAIT_FOR_INIT_SYMBOL]: (() => Promise<void>) & functools_kit.ISingleshotClearable;
|
|
12267
|
-
/**
|
|
12268
|
-
* Timeout-protected write function with backpressure handling.
|
|
12269
|
-
* Waits for drain event if write buffer is full.
|
|
12270
|
-
* Times out after 15 seconds and returns TIMEOUT_SYMBOL.
|
|
12271
|
-
*/
|
|
12272
|
-
[WRITE_SAFE_SYMBOL]: (line: string) => Promise<symbol | void>;
|
|
12273
|
-
/**
|
|
12274
|
-
* Initializes the JSONL file and write stream.
|
|
12275
|
-
* Safe to call multiple times - singleshot ensures one-time execution.
|
|
12276
|
-
*
|
|
12277
|
-
* @returns Promise that resolves when initialization is complete
|
|
12278
|
-
*/
|
|
12279
|
-
waitForInit(): Promise<void>;
|
|
12280
|
-
/**
|
|
12281
|
-
* Writes markdown content to JSONL file with metadata.
|
|
12282
|
-
* Appends a single line with JSON object containing:
|
|
12283
|
-
* - markdownName: Type of report
|
|
12284
|
-
* - data: Markdown content
|
|
12285
|
-
* - Search flags: symbol, strategyName, exchangeName, frameName, signalId
|
|
12286
|
-
* - timestamp: Current timestamp in milliseconds
|
|
12287
|
-
*
|
|
12288
|
-
* @param data - Markdown content to write
|
|
12289
|
-
* @param options - Path and metadata options
|
|
12290
|
-
* @throws Error if stream not initialized or write timeout exceeded
|
|
12291
|
-
*/
|
|
12292
|
-
dump(data: string, options: IMarkdownDumpOptions): Promise<void>;
|
|
12293
|
-
}
|
|
12294
|
-
/**
|
|
12295
|
-
* Folder-based markdown adapter with separate files per report.
|
|
12296
|
-
*
|
|
12297
|
-
* Features:
|
|
12298
|
-
* - Writes each markdown report as a separate .md file
|
|
12299
|
-
* - File path based on options.path and options.file
|
|
12300
|
-
* - Automatic directory creation
|
|
12301
|
-
* - No stream management (direct writeFile)
|
|
12302
|
-
* - Suitable for human-readable report directories
|
|
12303
|
-
*
|
|
12304
|
-
* File format: {options.path}/{options.file}
|
|
12305
|
-
* Example: ./dump/backtest/BTCUSDT_my-strategy_binance_2024-Q1_backtest-1736601234567.md
|
|
12306
|
-
*
|
|
12307
|
-
* Use this adapter (default) for organized report directories and manual review.
|
|
12308
|
-
*/
|
|
12309
|
-
declare class MarkdownFolderBase implements TMarkdownBase {
|
|
12310
|
-
readonly markdownName: MarkdownName;
|
|
12311
|
-
/**
|
|
12312
|
-
* Creates a new folder-based markdown adapter instance.
|
|
12313
|
-
*
|
|
12314
|
-
* @param markdownName - Type of markdown report (backtest, live, walker, etc.)
|
|
12315
|
-
*/
|
|
12316
|
-
constructor(markdownName: MarkdownName);
|
|
12317
|
-
/**
|
|
12318
|
-
* No-op initialization for folder adapter.
|
|
12319
|
-
* This adapter doesn't need initialization since it uses direct writeFile.
|
|
12320
|
-
*
|
|
12321
|
-
* @returns Promise that resolves immediately
|
|
12322
|
-
*/
|
|
12323
|
-
waitForInit(): Promise<void>;
|
|
12324
|
-
/**
|
|
12325
|
-
* Writes markdown content to a separate file.
|
|
12326
|
-
* Creates directory structure automatically.
|
|
12327
|
-
* File path is determined by options.path and options.file.
|
|
12328
|
-
*
|
|
12329
|
-
* @param content - Markdown content to write
|
|
12330
|
-
* @param options - Path and file options for the dump
|
|
12331
|
-
* @throws Error if directory creation or file write fails
|
|
12332
|
-
*/
|
|
12333
|
-
dump(content: string, options: IMarkdownDumpOptions): Promise<void>;
|
|
12334
|
-
}
|
|
12335
12657
|
/**
|
|
12336
12658
|
* Utility class for managing markdown report services.
|
|
12337
12659
|
*
|
|
@@ -12367,7 +12689,7 @@ declare class MarkdownUtils {
|
|
|
12367
12689
|
*
|
|
12368
12690
|
* @returns Cleanup function that unsubscribes from all enabled services
|
|
12369
12691
|
*/
|
|
12370
|
-
enable: ({ backtest: bt, breakeven, heat, live, partial, performance, strategy, risk, schedule, walker, sync, highest_profit, }?: Partial<IMarkdownTarget>) => (...args: any[]) => any;
|
|
12692
|
+
enable: ({ backtest: bt, breakeven, heat, live, partial, performance, strategy, risk, schedule, walker, sync, highest_profit, max_drawdown, }?: Partial<IMarkdownTarget>) => (...args: any[]) => any;
|
|
12371
12693
|
/**
|
|
12372
12694
|
* Disables markdown report services selectively.
|
|
12373
12695
|
*
|
|
@@ -12405,7 +12727,7 @@ declare class MarkdownUtils {
|
|
|
12405
12727
|
* Markdown.disable();
|
|
12406
12728
|
* ```
|
|
12407
12729
|
*/
|
|
12408
|
-
disable: ({ backtest: bt, breakeven, heat, live, partial, performance, risk, strategy, schedule, walker, sync, highest_profit, }?: Partial<IMarkdownTarget>) => void;
|
|
12730
|
+
disable: ({ backtest: bt, breakeven, heat, live, partial, performance, risk, strategy, schedule, walker, sync, highest_profit, max_drawdown, }?: Partial<IMarkdownTarget>) => void;
|
|
12409
12731
|
}
|
|
12410
12732
|
/**
|
|
12411
12733
|
* Markdown adapter with pluggable storage backend and instance memoization.
|
|
@@ -12419,19 +12741,6 @@ declare class MarkdownUtils {
|
|
|
12419
12741
|
* - Convenience methods: useMd(), useJsonl()
|
|
12420
12742
|
*/
|
|
12421
12743
|
declare class MarkdownAdapter extends MarkdownUtils {
|
|
12422
|
-
/**
|
|
12423
|
-
* Current markdown storage adapter constructor.
|
|
12424
|
-
* Defaults to MarkdownFolderBase for separate file storage.
|
|
12425
|
-
* Can be changed via useMarkdownAdapter().
|
|
12426
|
-
*/
|
|
12427
|
-
private MarkdownFactory;
|
|
12428
|
-
/**
|
|
12429
|
-
* Memoized storage instances cache.
|
|
12430
|
-
* Key: markdownName (backtest, live, walker, etc.)
|
|
12431
|
-
* Value: TMarkdownBase instance created with current MarkdownFactory.
|
|
12432
|
-
* Ensures single instance per markdown type for the lifetime of the application.
|
|
12433
|
-
*/
|
|
12434
|
-
private getMarkdownStorage;
|
|
12435
12744
|
/**
|
|
12436
12745
|
* Sets the markdown storage adapter constructor.
|
|
12437
12746
|
* All future markdown instances will use this adapter.
|
|
@@ -12439,19 +12748,6 @@ declare class MarkdownAdapter extends MarkdownUtils {
|
|
|
12439
12748
|
* @param Ctor - Constructor for markdown storage adapter
|
|
12440
12749
|
*/
|
|
12441
12750
|
useMarkdownAdapter(Ctor: TMarkdownBaseCtor): void;
|
|
12442
|
-
/**
|
|
12443
|
-
* Writes markdown data to storage using the configured adapter.
|
|
12444
|
-
* Automatically initializes storage on first write for each markdown type.
|
|
12445
|
-
*
|
|
12446
|
-
* @param markdownName - Type of markdown report (backtest, live, walker, etc.)
|
|
12447
|
-
* @param content - Markdown content to write
|
|
12448
|
-
* @param options - Path, file, and metadata options
|
|
12449
|
-
* @returns Promise that resolves when write is complete
|
|
12450
|
-
* @throws Error if write fails or storage initialization fails
|
|
12451
|
-
*
|
|
12452
|
-
* @internal - Use service-specific dump methods instead (e.g., Backtest.dump)
|
|
12453
|
-
*/
|
|
12454
|
-
writeData(markdownName: MarkdownName, content: string, options: IMarkdownDumpOptions): Promise<void>;
|
|
12455
12751
|
/**
|
|
12456
12752
|
* Switches to folder-based markdown storage (default).
|
|
12457
12753
|
* Shorthand for useMarkdownAdapter(MarkdownFolderBase).
|
|
@@ -12617,7 +12913,7 @@ declare const Log: LogAdapter;
|
|
|
12617
12913
|
* @see ColumnModel for the base interface
|
|
12618
12914
|
* @see IStrategyTickResultClosed for the signal data structure
|
|
12619
12915
|
*/
|
|
12620
|
-
type Columns$
|
|
12916
|
+
type Columns$b = ColumnModel<IStrategyTickResultClosed>;
|
|
12621
12917
|
/**
|
|
12622
12918
|
* Service for generating and saving backtest markdown reports.
|
|
12623
12919
|
*
|
|
@@ -12711,7 +13007,7 @@ declare class BacktestMarkdownService {
|
|
|
12711
13007
|
* console.log(markdown);
|
|
12712
13008
|
* ```
|
|
12713
13009
|
*/
|
|
12714
|
-
getReport: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, columns?: Columns$
|
|
13010
|
+
getReport: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, columns?: Columns$b[]) => Promise<string>;
|
|
12715
13011
|
/**
|
|
12716
13012
|
* Saves symbol-strategy report to disk.
|
|
12717
13013
|
* Creates directory if it doesn't exist.
|
|
@@ -12736,7 +13032,7 @@ declare class BacktestMarkdownService {
|
|
|
12736
13032
|
* await service.dump("BTCUSDT", "my-strategy", "binance", "1h", true, "./custom/path");
|
|
12737
13033
|
* ```
|
|
12738
13034
|
*/
|
|
12739
|
-
dump: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, path?: string, columns?: Columns$
|
|
13035
|
+
dump: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, path?: string, columns?: Columns$b[]) => Promise<void>;
|
|
12740
13036
|
/**
|
|
12741
13037
|
* Clears accumulated signal data from storage.
|
|
12742
13038
|
* If payload is provided, clears only that specific symbol-strategy-exchange-frame-backtest combination's data.
|
|
@@ -13191,87 +13487,178 @@ declare class BacktestUtils {
|
|
|
13191
13487
|
frameName: FrameName;
|
|
13192
13488
|
}) => Promise<number>;
|
|
13193
13489
|
/**
|
|
13194
|
-
* Returns the best price reached in the profit direction during this position's life.
|
|
13490
|
+
* Returns the best price reached in the profit direction during this position's life.
|
|
13491
|
+
*
|
|
13492
|
+
* Returns null if no pending signal exists.
|
|
13493
|
+
*
|
|
13494
|
+
* @param symbol - Trading pair symbol
|
|
13495
|
+
* @param context - Execution context with strategyName, exchangeName, and frameName
|
|
13496
|
+
* @returns price or null if no active position
|
|
13497
|
+
*/
|
|
13498
|
+
getPositionHighestProfitPrice: (symbol: string, context: {
|
|
13499
|
+
strategyName: StrategyName;
|
|
13500
|
+
exchangeName: ExchangeName;
|
|
13501
|
+
frameName: FrameName;
|
|
13502
|
+
}) => Promise<number>;
|
|
13503
|
+
/**
|
|
13504
|
+
* Returns the timestamp when the best profit price was recorded during this position's life.
|
|
13505
|
+
*
|
|
13506
|
+
* Returns null if no pending signal exists.
|
|
13507
|
+
*
|
|
13508
|
+
* @param symbol - Trading pair symbol
|
|
13509
|
+
* @param context - Execution context with strategyName, exchangeName, and frameName
|
|
13510
|
+
* @returns timestamp in milliseconds or null if no active position
|
|
13511
|
+
*/
|
|
13512
|
+
getPositionHighestProfitTimestamp: (symbol: string, context: {
|
|
13513
|
+
strategyName: StrategyName;
|
|
13514
|
+
exchangeName: ExchangeName;
|
|
13515
|
+
frameName: FrameName;
|
|
13516
|
+
}) => Promise<number>;
|
|
13517
|
+
/**
|
|
13518
|
+
* Returns the PnL percentage at the moment the best profit price was recorded during this position's life.
|
|
13519
|
+
*
|
|
13520
|
+
* Returns null if no pending signal exists.
|
|
13521
|
+
*
|
|
13522
|
+
* @param symbol - Trading pair symbol
|
|
13523
|
+
* @param context - Execution context with strategyName, exchangeName, and frameName
|
|
13524
|
+
* @returns PnL percentage or null if no active position
|
|
13525
|
+
*/
|
|
13526
|
+
getPositionHighestPnlPercentage: (symbol: string, context: {
|
|
13527
|
+
strategyName: StrategyName;
|
|
13528
|
+
exchangeName: ExchangeName;
|
|
13529
|
+
frameName: FrameName;
|
|
13530
|
+
}) => Promise<number>;
|
|
13531
|
+
/**
|
|
13532
|
+
* Returns the PnL cost (in quote currency) at the moment the best profit price was recorded during this position's life.
|
|
13533
|
+
*
|
|
13534
|
+
* Returns null if no pending signal exists.
|
|
13535
|
+
*
|
|
13536
|
+
* @param symbol - Trading pair symbol
|
|
13537
|
+
* @param context - Execution context with strategyName, exchangeName, and frameName
|
|
13538
|
+
* @returns PnL cost or null if no active position
|
|
13539
|
+
*/
|
|
13540
|
+
getPositionHighestPnlCost: (symbol: string, context: {
|
|
13541
|
+
strategyName: StrategyName;
|
|
13542
|
+
exchangeName: ExchangeName;
|
|
13543
|
+
frameName: FrameName;
|
|
13544
|
+
}) => Promise<number>;
|
|
13545
|
+
/**
|
|
13546
|
+
* Returns whether breakeven was mathematically reachable at the highest profit price.
|
|
13547
|
+
*
|
|
13548
|
+
* @param symbol - Trading pair symbol
|
|
13549
|
+
* @param context - Execution context with strategyName, exchangeName, and frameName
|
|
13550
|
+
* @returns true if breakeven was reachable at peak, false otherwise, or null if no active position
|
|
13551
|
+
*/
|
|
13552
|
+
getPositionHighestProfitBreakeven: (symbol: string, context: {
|
|
13553
|
+
strategyName: StrategyName;
|
|
13554
|
+
exchangeName: ExchangeName;
|
|
13555
|
+
frameName: FrameName;
|
|
13556
|
+
}) => Promise<boolean>;
|
|
13557
|
+
/**
|
|
13558
|
+
* Returns the number of minutes elapsed since the highest profit price was recorded.
|
|
13559
|
+
*
|
|
13560
|
+
* Measures how long the position has been pulling back from its peak profit level.
|
|
13561
|
+
* Zero when called at the exact moment the peak was set.
|
|
13562
|
+
* Grows continuously as price moves away from the peak without setting a new record.
|
|
13563
|
+
*
|
|
13564
|
+
* Returns null if no pending signal exists.
|
|
13565
|
+
*
|
|
13566
|
+
* @param symbol - Trading pair symbol
|
|
13567
|
+
* @param context - Execution context with strategyName, exchangeName, and frameName
|
|
13568
|
+
* @returns Drawdown duration in minutes, or null if no active position
|
|
13569
|
+
*/
|
|
13570
|
+
getPositionDrawdownMinutes: (symbol: string, context: {
|
|
13571
|
+
strategyName: StrategyName;
|
|
13572
|
+
exchangeName: ExchangeName;
|
|
13573
|
+
frameName: FrameName;
|
|
13574
|
+
}) => Promise<number>;
|
|
13575
|
+
/**
|
|
13576
|
+
* Returns the number of minutes elapsed since the highest profit price was recorded.
|
|
13577
|
+
*
|
|
13578
|
+
* Alias for getPositionDrawdownMinutes — measures how long the position has been
|
|
13579
|
+
* pulling back from its peak profit level.
|
|
13580
|
+
* Zero when called at the exact moment the peak was set.
|
|
13195
13581
|
*
|
|
13196
13582
|
* Returns null if no pending signal exists.
|
|
13197
13583
|
*
|
|
13198
13584
|
* @param symbol - Trading pair symbol
|
|
13199
13585
|
* @param context - Execution context with strategyName, exchangeName, and frameName
|
|
13200
|
-
* @returns
|
|
13586
|
+
* @returns Minutes since last profit peak, or null if no active position
|
|
13201
13587
|
*/
|
|
13202
|
-
|
|
13588
|
+
getPositionHighestProfitMinutes: (symbol: string, context: {
|
|
13203
13589
|
strategyName: StrategyName;
|
|
13204
13590
|
exchangeName: ExchangeName;
|
|
13205
13591
|
frameName: FrameName;
|
|
13206
13592
|
}) => Promise<number>;
|
|
13207
13593
|
/**
|
|
13208
|
-
* Returns the
|
|
13594
|
+
* Returns the number of minutes elapsed since the worst loss price was recorded.
|
|
13595
|
+
*
|
|
13596
|
+
* Measures how long ago the deepest drawdown point occurred.
|
|
13597
|
+
* Zero when called at the exact moment the trough was set.
|
|
13209
13598
|
*
|
|
13210
13599
|
* Returns null if no pending signal exists.
|
|
13211
13600
|
*
|
|
13212
13601
|
* @param symbol - Trading pair symbol
|
|
13213
13602
|
* @param context - Execution context with strategyName, exchangeName, and frameName
|
|
13214
|
-
* @returns
|
|
13603
|
+
* @returns Minutes since last drawdown trough, or null if no active position
|
|
13215
13604
|
*/
|
|
13216
|
-
|
|
13605
|
+
getPositionMaxDrawdownMinutes: (symbol: string, context: {
|
|
13217
13606
|
strategyName: StrategyName;
|
|
13218
13607
|
exchangeName: ExchangeName;
|
|
13219
13608
|
frameName: FrameName;
|
|
13220
13609
|
}) => Promise<number>;
|
|
13221
13610
|
/**
|
|
13222
|
-
* Returns the
|
|
13611
|
+
* Returns the worst price reached in the loss direction during this position's life.
|
|
13223
13612
|
*
|
|
13224
13613
|
* Returns null if no pending signal exists.
|
|
13225
13614
|
*
|
|
13226
13615
|
* @param symbol - Trading pair symbol
|
|
13227
13616
|
* @param context - Execution context with strategyName, exchangeName, and frameName
|
|
13228
|
-
* @returns
|
|
13617
|
+
* @returns price or null if no active position
|
|
13229
13618
|
*/
|
|
13230
|
-
|
|
13619
|
+
getPositionMaxDrawdownPrice: (symbol: string, context: {
|
|
13231
13620
|
strategyName: StrategyName;
|
|
13232
13621
|
exchangeName: ExchangeName;
|
|
13233
13622
|
frameName: FrameName;
|
|
13234
13623
|
}) => Promise<number>;
|
|
13235
13624
|
/**
|
|
13236
|
-
* Returns the
|
|
13625
|
+
* Returns the timestamp when the worst loss price was recorded during this position's life.
|
|
13237
13626
|
*
|
|
13238
13627
|
* Returns null if no pending signal exists.
|
|
13239
13628
|
*
|
|
13240
13629
|
* @param symbol - Trading pair symbol
|
|
13241
13630
|
* @param context - Execution context with strategyName, exchangeName, and frameName
|
|
13242
|
-
* @returns
|
|
13631
|
+
* @returns timestamp in milliseconds or null if no active position
|
|
13243
13632
|
*/
|
|
13244
|
-
|
|
13633
|
+
getPositionMaxDrawdownTimestamp: (symbol: string, context: {
|
|
13245
13634
|
strategyName: StrategyName;
|
|
13246
13635
|
exchangeName: ExchangeName;
|
|
13247
13636
|
frameName: FrameName;
|
|
13248
13637
|
}) => Promise<number>;
|
|
13249
13638
|
/**
|
|
13250
|
-
* Returns
|
|
13639
|
+
* Returns the PnL percentage at the moment the worst loss price was recorded during this position's life.
|
|
13640
|
+
*
|
|
13641
|
+
* Returns null if no pending signal exists.
|
|
13251
13642
|
*
|
|
13252
13643
|
* @param symbol - Trading pair symbol
|
|
13253
13644
|
* @param context - Execution context with strategyName, exchangeName, and frameName
|
|
13254
|
-
* @returns
|
|
13645
|
+
* @returns PnL percentage or null if no active position
|
|
13255
13646
|
*/
|
|
13256
|
-
|
|
13647
|
+
getPositionMaxDrawdownPnlPercentage: (symbol: string, context: {
|
|
13257
13648
|
strategyName: StrategyName;
|
|
13258
13649
|
exchangeName: ExchangeName;
|
|
13259
13650
|
frameName: FrameName;
|
|
13260
|
-
}) => Promise<
|
|
13651
|
+
}) => Promise<number>;
|
|
13261
13652
|
/**
|
|
13262
|
-
* Returns the
|
|
13263
|
-
*
|
|
13264
|
-
* Measures how long the position has been pulling back from its peak profit level.
|
|
13265
|
-
* Zero when called at the exact moment the peak was set.
|
|
13266
|
-
* Grows continuously as price moves away from the peak without setting a new record.
|
|
13653
|
+
* Returns the PnL cost (in quote currency) at the moment the worst loss price was recorded during this position's life.
|
|
13267
13654
|
*
|
|
13268
13655
|
* Returns null if no pending signal exists.
|
|
13269
13656
|
*
|
|
13270
13657
|
* @param symbol - Trading pair symbol
|
|
13271
13658
|
* @param context - Execution context with strategyName, exchangeName, and frameName
|
|
13272
|
-
* @returns
|
|
13659
|
+
* @returns PnL cost or null if no active position
|
|
13273
13660
|
*/
|
|
13274
|
-
|
|
13661
|
+
getPositionMaxDrawdownPnlCost: (symbol: string, context: {
|
|
13275
13662
|
strategyName: StrategyName;
|
|
13276
13663
|
exchangeName: ExchangeName;
|
|
13277
13664
|
frameName: FrameName;
|
|
@@ -13793,7 +14180,7 @@ declare class BacktestUtils {
|
|
|
13793
14180
|
strategyName: StrategyName;
|
|
13794
14181
|
exchangeName: ExchangeName;
|
|
13795
14182
|
frameName: FrameName;
|
|
13796
|
-
}, columns?: Columns$
|
|
14183
|
+
}, columns?: Columns$b[]) => Promise<string>;
|
|
13797
14184
|
/**
|
|
13798
14185
|
* Saves strategy report to disk.
|
|
13799
14186
|
*
|
|
@@ -13824,7 +14211,7 @@ declare class BacktestUtils {
|
|
|
13824
14211
|
strategyName: StrategyName;
|
|
13825
14212
|
exchangeName: ExchangeName;
|
|
13826
14213
|
frameName: FrameName;
|
|
13827
|
-
}, path?: string, columns?: Columns$
|
|
14214
|
+
}, path?: string, columns?: Columns$b[]) => Promise<void>;
|
|
13828
14215
|
/**
|
|
13829
14216
|
* Lists all active backtest instances with their current status.
|
|
13830
14217
|
*
|
|
@@ -13898,7 +14285,7 @@ declare const Backtest: BacktestUtils;
|
|
|
13898
14285
|
* @see ColumnModel for the base interface
|
|
13899
14286
|
* @see TickEvent for the event data structure
|
|
13900
14287
|
*/
|
|
13901
|
-
type Columns$
|
|
14288
|
+
type Columns$a = ColumnModel<TickEvent>;
|
|
13902
14289
|
/**
|
|
13903
14290
|
* Service for generating and saving live trading markdown reports.
|
|
13904
14291
|
*
|
|
@@ -14025,7 +14412,7 @@ declare class LiveMarkdownService {
|
|
|
14025
14412
|
* console.log(markdown);
|
|
14026
14413
|
* ```
|
|
14027
14414
|
*/
|
|
14028
|
-
getReport: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, columns?: Columns$
|
|
14415
|
+
getReport: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, columns?: Columns$a[]) => Promise<string>;
|
|
14029
14416
|
/**
|
|
14030
14417
|
* Saves symbol-strategy report to disk.
|
|
14031
14418
|
* Creates directory if it doesn't exist.
|
|
@@ -14050,7 +14437,7 @@ declare class LiveMarkdownService {
|
|
|
14050
14437
|
* await service.dump("BTCUSDT", "my-strategy", "binance", "1h", false, "./custom/path");
|
|
14051
14438
|
* ```
|
|
14052
14439
|
*/
|
|
14053
|
-
dump: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, path?: string, columns?: Columns$
|
|
14440
|
+
dump: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, path?: string, columns?: Columns$a[]) => Promise<void>;
|
|
14054
14441
|
/**
|
|
14055
14442
|
* Clears accumulated event data from storage.
|
|
14056
14443
|
* If payload is provided, clears only that specific symbol-strategy-exchange-frame-backtest combination's data.
|
|
@@ -14549,6 +14936,91 @@ declare class LiveUtils {
|
|
|
14549
14936
|
strategyName: StrategyName;
|
|
14550
14937
|
exchangeName: ExchangeName;
|
|
14551
14938
|
}) => Promise<number>;
|
|
14939
|
+
/**
|
|
14940
|
+
* Returns the number of minutes elapsed since the highest profit price was recorded.
|
|
14941
|
+
*
|
|
14942
|
+
* Alias for getPositionDrawdownMinutes — measures how long the position has been
|
|
14943
|
+
* pulling back from its peak profit level.
|
|
14944
|
+
* Zero when called at the exact moment the peak was set.
|
|
14945
|
+
*
|
|
14946
|
+
* Returns null if no pending signal exists.
|
|
14947
|
+
*
|
|
14948
|
+
* @param symbol - Trading pair symbol
|
|
14949
|
+
* @param context - Execution context with strategyName and exchangeName
|
|
14950
|
+
* @returns Minutes since last profit peak, or null if no active position
|
|
14951
|
+
*/
|
|
14952
|
+
getPositionHighestProfitMinutes: (symbol: string, context: {
|
|
14953
|
+
strategyName: StrategyName;
|
|
14954
|
+
exchangeName: ExchangeName;
|
|
14955
|
+
}) => Promise<number>;
|
|
14956
|
+
/**
|
|
14957
|
+
* Returns the number of minutes elapsed since the worst loss price was recorded.
|
|
14958
|
+
*
|
|
14959
|
+
* Measures how long ago the deepest drawdown point occurred.
|
|
14960
|
+
* Zero when called at the exact moment the trough was set.
|
|
14961
|
+
*
|
|
14962
|
+
* Returns null if no pending signal exists.
|
|
14963
|
+
*
|
|
14964
|
+
* @param symbol - Trading pair symbol
|
|
14965
|
+
* @param context - Execution context with strategyName and exchangeName
|
|
14966
|
+
* @returns Minutes since last drawdown trough, or null if no active position
|
|
14967
|
+
*/
|
|
14968
|
+
getPositionMaxDrawdownMinutes: (symbol: string, context: {
|
|
14969
|
+
strategyName: StrategyName;
|
|
14970
|
+
exchangeName: ExchangeName;
|
|
14971
|
+
}) => Promise<number>;
|
|
14972
|
+
/**
|
|
14973
|
+
* Returns the worst price reached in the loss direction during this position's life.
|
|
14974
|
+
*
|
|
14975
|
+
* Returns null if no pending signal exists.
|
|
14976
|
+
*
|
|
14977
|
+
* @param symbol - Trading pair symbol
|
|
14978
|
+
* @param context - Execution context with strategyName and exchangeName
|
|
14979
|
+
* @returns price or null if no active position
|
|
14980
|
+
*/
|
|
14981
|
+
getPositionMaxDrawdownPrice: (symbol: string, context: {
|
|
14982
|
+
strategyName: StrategyName;
|
|
14983
|
+
exchangeName: ExchangeName;
|
|
14984
|
+
}) => Promise<number>;
|
|
14985
|
+
/**
|
|
14986
|
+
* Returns the timestamp when the worst loss price was recorded during this position's life.
|
|
14987
|
+
*
|
|
14988
|
+
* Returns null if no pending signal exists.
|
|
14989
|
+
*
|
|
14990
|
+
* @param symbol - Trading pair symbol
|
|
14991
|
+
* @param context - Execution context with strategyName and exchangeName
|
|
14992
|
+
* @returns timestamp in milliseconds or null if no active position
|
|
14993
|
+
*/
|
|
14994
|
+
getPositionMaxDrawdownTimestamp: (symbol: string, context: {
|
|
14995
|
+
strategyName: StrategyName;
|
|
14996
|
+
exchangeName: ExchangeName;
|
|
14997
|
+
}) => Promise<number>;
|
|
14998
|
+
/**
|
|
14999
|
+
* Returns the PnL percentage at the moment the worst loss price was recorded during this position's life.
|
|
15000
|
+
*
|
|
15001
|
+
* Returns null if no pending signal exists.
|
|
15002
|
+
*
|
|
15003
|
+
* @param symbol - Trading pair symbol
|
|
15004
|
+
* @param context - Execution context with strategyName and exchangeName
|
|
15005
|
+
* @returns PnL percentage or null if no active position
|
|
15006
|
+
*/
|
|
15007
|
+
getPositionMaxDrawdownPnlPercentage: (symbol: string, context: {
|
|
15008
|
+
strategyName: StrategyName;
|
|
15009
|
+
exchangeName: ExchangeName;
|
|
15010
|
+
}) => Promise<number>;
|
|
15011
|
+
/**
|
|
15012
|
+
* Returns the PnL cost (in quote currency) at the moment the worst loss price was recorded during this position's life.
|
|
15013
|
+
*
|
|
15014
|
+
* Returns null if no pending signal exists.
|
|
15015
|
+
*
|
|
15016
|
+
* @param symbol - Trading pair symbol
|
|
15017
|
+
* @param context - Execution context with strategyName and exchangeName
|
|
15018
|
+
* @returns PnL cost or null if no active position
|
|
15019
|
+
*/
|
|
15020
|
+
getPositionMaxDrawdownPnlCost: (symbol: string, context: {
|
|
15021
|
+
strategyName: StrategyName;
|
|
15022
|
+
exchangeName: ExchangeName;
|
|
15023
|
+
}) => Promise<number>;
|
|
14552
15024
|
/**
|
|
14553
15025
|
* Checks whether the current price falls within the tolerance zone of any existing DCA entry level.
|
|
14554
15026
|
* Use this to prevent duplicate DCA entries at the same price area.
|
|
@@ -15034,7 +15506,7 @@ declare class LiveUtils {
|
|
|
15034
15506
|
getReport: (symbol: string, context: {
|
|
15035
15507
|
strategyName: StrategyName;
|
|
15036
15508
|
exchangeName: ExchangeName;
|
|
15037
|
-
}, columns?: Columns$
|
|
15509
|
+
}, columns?: Columns$a[]) => Promise<string>;
|
|
15038
15510
|
/**
|
|
15039
15511
|
* Saves strategy report to disk.
|
|
15040
15512
|
*
|
|
@@ -15064,7 +15536,7 @@ declare class LiveUtils {
|
|
|
15064
15536
|
dump: (symbol: string, context: {
|
|
15065
15537
|
strategyName: StrategyName;
|
|
15066
15538
|
exchangeName: ExchangeName;
|
|
15067
|
-
}, path?: string, columns?: Columns$
|
|
15539
|
+
}, path?: string, columns?: Columns$a[]) => Promise<void>;
|
|
15068
15540
|
/**
|
|
15069
15541
|
* Lists all active live trading instances with their current status.
|
|
15070
15542
|
*
|
|
@@ -15134,7 +15606,7 @@ declare const Live: LiveUtils;
|
|
|
15134
15606
|
* @see ColumnModel for the base interface
|
|
15135
15607
|
* @see ScheduledEvent for the event data structure
|
|
15136
15608
|
*/
|
|
15137
|
-
type Columns$
|
|
15609
|
+
type Columns$9 = ColumnModel<ScheduledEvent>;
|
|
15138
15610
|
/**
|
|
15139
15611
|
* Service for generating and saving scheduled signals markdown reports.
|
|
15140
15612
|
*
|
|
@@ -15245,7 +15717,7 @@ declare class ScheduleMarkdownService {
|
|
|
15245
15717
|
* console.log(markdown);
|
|
15246
15718
|
* ```
|
|
15247
15719
|
*/
|
|
15248
|
-
getReport: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, columns?: Columns$
|
|
15720
|
+
getReport: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, columns?: Columns$9[]) => Promise<string>;
|
|
15249
15721
|
/**
|
|
15250
15722
|
* Saves symbol-strategy report to disk.
|
|
15251
15723
|
* Creates directory if it doesn't exist.
|
|
@@ -15270,7 +15742,7 @@ declare class ScheduleMarkdownService {
|
|
|
15270
15742
|
* await service.dump("BTCUSDT", "my-strategy", "binance", "1h", false, "./custom/path");
|
|
15271
15743
|
* ```
|
|
15272
15744
|
*/
|
|
15273
|
-
dump: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, path?: string, columns?: Columns$
|
|
15745
|
+
dump: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, path?: string, columns?: Columns$9[]) => Promise<void>;
|
|
15274
15746
|
/**
|
|
15275
15747
|
* Clears accumulated event data from storage.
|
|
15276
15748
|
* If payload is provided, clears only that specific symbol-strategy-exchange-frame-backtest combination's data.
|
|
@@ -15360,7 +15832,7 @@ declare class ScheduleUtils {
|
|
|
15360
15832
|
strategyName: StrategyName;
|
|
15361
15833
|
exchangeName: ExchangeName;
|
|
15362
15834
|
frameName: FrameName;
|
|
15363
|
-
}, backtest?: boolean, columns?: Columns$
|
|
15835
|
+
}, backtest?: boolean, columns?: Columns$9[]) => Promise<string>;
|
|
15364
15836
|
/**
|
|
15365
15837
|
* Saves strategy report to disk.
|
|
15366
15838
|
*
|
|
@@ -15382,7 +15854,7 @@ declare class ScheduleUtils {
|
|
|
15382
15854
|
strategyName: StrategyName;
|
|
15383
15855
|
exchangeName: ExchangeName;
|
|
15384
15856
|
frameName: FrameName;
|
|
15385
|
-
}, backtest?: boolean, path?: string, columns?: Columns$
|
|
15857
|
+
}, backtest?: boolean, path?: string, columns?: Columns$9[]) => Promise<void>;
|
|
15386
15858
|
}
|
|
15387
15859
|
/**
|
|
15388
15860
|
* Singleton instance of ScheduleUtils for convenient scheduled signals reporting.
|
|
@@ -15428,7 +15900,7 @@ declare const Schedule: ScheduleUtils;
|
|
|
15428
15900
|
* @see ColumnModel for the base interface
|
|
15429
15901
|
* @see MetricStats for the metric data structure
|
|
15430
15902
|
*/
|
|
15431
|
-
type Columns$
|
|
15903
|
+
type Columns$8 = ColumnModel<MetricStats>;
|
|
15432
15904
|
/**
|
|
15433
15905
|
* Service for collecting and analyzing performance metrics.
|
|
15434
15906
|
*
|
|
@@ -15535,7 +16007,7 @@ declare class PerformanceMarkdownService {
|
|
|
15535
16007
|
* console.log(markdown);
|
|
15536
16008
|
* ```
|
|
15537
16009
|
*/
|
|
15538
|
-
getReport: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, columns?: Columns$
|
|
16010
|
+
getReport: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, columns?: Columns$8[]) => Promise<string>;
|
|
15539
16011
|
/**
|
|
15540
16012
|
* Saves performance report to disk.
|
|
15541
16013
|
*
|
|
@@ -15556,7 +16028,7 @@ declare class PerformanceMarkdownService {
|
|
|
15556
16028
|
* await performanceService.dump("BTCUSDT", "my-strategy", "binance", "1h", false, "./custom/path");
|
|
15557
16029
|
* ```
|
|
15558
16030
|
*/
|
|
15559
|
-
dump: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, path?: string, columns?: Columns$
|
|
16031
|
+
dump: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, path?: string, columns?: Columns$8[]) => Promise<void>;
|
|
15560
16032
|
/**
|
|
15561
16033
|
* Clears accumulated performance data from storage.
|
|
15562
16034
|
*
|
|
@@ -15664,7 +16136,7 @@ declare class Performance {
|
|
|
15664
16136
|
strategyName: StrategyName;
|
|
15665
16137
|
exchangeName: ExchangeName;
|
|
15666
16138
|
frameName: FrameName;
|
|
15667
|
-
}, backtest?: boolean, columns?: Columns$
|
|
16139
|
+
}, backtest?: boolean, columns?: Columns$8[]): Promise<string>;
|
|
15668
16140
|
/**
|
|
15669
16141
|
* Saves performance report to disk.
|
|
15670
16142
|
*
|
|
@@ -15689,7 +16161,7 @@ declare class Performance {
|
|
|
15689
16161
|
strategyName: StrategyName;
|
|
15690
16162
|
exchangeName: ExchangeName;
|
|
15691
16163
|
frameName: FrameName;
|
|
15692
|
-
}, backtest?: boolean, path?: string, columns?: Columns$
|
|
16164
|
+
}, backtest?: boolean, path?: string, columns?: Columns$8[]): Promise<void>;
|
|
15693
16165
|
}
|
|
15694
16166
|
|
|
15695
16167
|
/**
|
|
@@ -16120,7 +16592,7 @@ declare const Walker: WalkerUtils;
|
|
|
16120
16592
|
* @see ColumnModel for the base interface
|
|
16121
16593
|
* @see IHeatmapRow for the row data structure
|
|
16122
16594
|
*/
|
|
16123
|
-
type Columns$
|
|
16595
|
+
type Columns$7 = ColumnModel<IHeatmapRow>;
|
|
16124
16596
|
/**
|
|
16125
16597
|
* Portfolio Heatmap Markdown Service.
|
|
16126
16598
|
*
|
|
@@ -16255,7 +16727,7 @@ declare class HeatMarkdownService {
|
|
|
16255
16727
|
* // | ETHUSDT | +12.3% | 1.85 | -3.1% | 38 |
|
|
16256
16728
|
* ```
|
|
16257
16729
|
*/
|
|
16258
|
-
getReport: (strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, columns?: Columns$
|
|
16730
|
+
getReport: (strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, columns?: Columns$7[]) => Promise<string>;
|
|
16259
16731
|
/**
|
|
16260
16732
|
* Generates the heatmap report and writes it to disk.
|
|
16261
16733
|
*
|
|
@@ -16283,7 +16755,7 @@ declare class HeatMarkdownService {
|
|
|
16283
16755
|
* await service.dump("my-strategy", "binance", "frame1", true, "./reports");
|
|
16284
16756
|
* ```
|
|
16285
16757
|
*/
|
|
16286
|
-
dump: (strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, path?: string, columns?: Columns$
|
|
16758
|
+
dump: (strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, path?: string, columns?: Columns$7[]) => Promise<void>;
|
|
16287
16759
|
/**
|
|
16288
16760
|
* Evicts memoized `HeatmapStorage` instances, releasing all accumulated signal data.
|
|
16289
16761
|
*
|
|
@@ -16419,7 +16891,7 @@ declare class HeatUtils {
|
|
|
16419
16891
|
strategyName: StrategyName;
|
|
16420
16892
|
exchangeName: ExchangeName;
|
|
16421
16893
|
frameName: FrameName;
|
|
16422
|
-
}, backtest?: boolean, columns?: Columns$
|
|
16894
|
+
}, backtest?: boolean, columns?: Columns$7[]) => Promise<string>;
|
|
16423
16895
|
/**
|
|
16424
16896
|
* Saves heatmap report to disk for a strategy.
|
|
16425
16897
|
*
|
|
@@ -16452,7 +16924,7 @@ declare class HeatUtils {
|
|
|
16452
16924
|
strategyName: StrategyName;
|
|
16453
16925
|
exchangeName: ExchangeName;
|
|
16454
16926
|
frameName: FrameName;
|
|
16455
|
-
}, backtest?: boolean, path?: string, columns?: Columns$
|
|
16927
|
+
}, backtest?: boolean, path?: string, columns?: Columns$7[]) => Promise<void>;
|
|
16456
16928
|
}
|
|
16457
16929
|
/**
|
|
16458
16930
|
* Singleton instance of HeatUtils for convenient heatmap operations.
|
|
@@ -16606,7 +17078,7 @@ declare const PositionSize: typeof PositionSizeUtils;
|
|
|
16606
17078
|
* @see ColumnModel for the base interface
|
|
16607
17079
|
* @see PartialEvent for the event data structure
|
|
16608
17080
|
*/
|
|
16609
|
-
type Columns$
|
|
17081
|
+
type Columns$6 = ColumnModel<PartialEvent>;
|
|
16610
17082
|
/**
|
|
16611
17083
|
* Service for generating and saving partial profit/loss markdown reports.
|
|
16612
17084
|
*
|
|
@@ -16728,7 +17200,7 @@ declare class PartialMarkdownService {
|
|
|
16728
17200
|
* console.log(markdown);
|
|
16729
17201
|
* ```
|
|
16730
17202
|
*/
|
|
16731
|
-
getReport: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, columns?: Columns$
|
|
17203
|
+
getReport: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, columns?: Columns$6[]) => Promise<string>;
|
|
16732
17204
|
/**
|
|
16733
17205
|
* Saves symbol-strategy report to disk.
|
|
16734
17206
|
* Creates directory if it doesn't exist.
|
|
@@ -16753,7 +17225,7 @@ declare class PartialMarkdownService {
|
|
|
16753
17225
|
* await service.dump("BTCUSDT", "my-strategy", "binance", "1h", false, "./custom/path");
|
|
16754
17226
|
* ```
|
|
16755
17227
|
*/
|
|
16756
|
-
dump: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, path?: string, columns?: Columns$
|
|
17228
|
+
dump: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, path?: string, columns?: Columns$6[]) => Promise<void>;
|
|
16757
17229
|
/**
|
|
16758
17230
|
* Clears accumulated event data from storage.
|
|
16759
17231
|
* If payload is provided, clears only that specific symbol-strategy-exchange-frame-backtest combination's data.
|
|
@@ -16889,7 +17361,7 @@ declare class PartialUtils {
|
|
|
16889
17361
|
strategyName: StrategyName;
|
|
16890
17362
|
exchangeName: ExchangeName;
|
|
16891
17363
|
frameName: FrameName;
|
|
16892
|
-
}, backtest?: boolean, columns?: Columns$
|
|
17364
|
+
}, backtest?: boolean, columns?: Columns$6[]) => Promise<string>;
|
|
16893
17365
|
/**
|
|
16894
17366
|
* Generates and saves markdown report to file.
|
|
16895
17367
|
*
|
|
@@ -16926,7 +17398,7 @@ declare class PartialUtils {
|
|
|
16926
17398
|
strategyName: StrategyName;
|
|
16927
17399
|
exchangeName: ExchangeName;
|
|
16928
17400
|
frameName: FrameName;
|
|
16929
|
-
}, backtest?: boolean, path?: string, columns?: Columns$
|
|
17401
|
+
}, backtest?: boolean, path?: string, columns?: Columns$6[]) => Promise<void>;
|
|
16930
17402
|
}
|
|
16931
17403
|
/**
|
|
16932
17404
|
* Global singleton instance of PartialUtils.
|
|
@@ -16947,7 +17419,7 @@ declare const Partial$1: PartialUtils;
|
|
|
16947
17419
|
/**
|
|
16948
17420
|
* Type alias for column configuration used in highest profit markdown reports.
|
|
16949
17421
|
*/
|
|
16950
|
-
type Columns$
|
|
17422
|
+
type Columns$5 = ColumnModel<HighestProfitEvent>;
|
|
16951
17423
|
/**
|
|
16952
17424
|
* Service for generating and saving highest profit markdown reports.
|
|
16953
17425
|
*
|
|
@@ -17040,7 +17512,7 @@ declare class HighestProfitMarkdownService {
|
|
|
17040
17512
|
* @returns Promise resolving to the full markdown string
|
|
17041
17513
|
* @throws {Error} If `subscribe()` has not been called before this method
|
|
17042
17514
|
*/
|
|
17043
|
-
getReport: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, columns?: Columns$
|
|
17515
|
+
getReport: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, columns?: Columns$5[]) => Promise<string>;
|
|
17044
17516
|
/**
|
|
17045
17517
|
* Generates the highest profit report and writes it to disk.
|
|
17046
17518
|
*
|
|
@@ -17058,7 +17530,7 @@ declare class HighestProfitMarkdownService {
|
|
|
17058
17530
|
* defaults to `COLUMN_CONFIG.highest_profit_columns`
|
|
17059
17531
|
* @throws {Error} If `subscribe()` has not been called before this method
|
|
17060
17532
|
*/
|
|
17061
|
-
dump: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, path?: string, columns?: Columns$
|
|
17533
|
+
dump: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, path?: string, columns?: Columns$5[]) => Promise<void>;
|
|
17062
17534
|
/**
|
|
17063
17535
|
* Evicts memoized `ReportStorage` instances, releasing all accumulated event data.
|
|
17064
17536
|
*
|
|
@@ -17132,7 +17604,7 @@ declare class HighestProfitUtils {
|
|
|
17132
17604
|
strategyName: StrategyName;
|
|
17133
17605
|
exchangeName: ExchangeName;
|
|
17134
17606
|
frameName: FrameName;
|
|
17135
|
-
}, backtest?: boolean, columns?: Columns$
|
|
17607
|
+
}, backtest?: boolean, columns?: Columns$5[]) => Promise<string>;
|
|
17136
17608
|
/**
|
|
17137
17609
|
* Generates and saves a markdown report to file.
|
|
17138
17610
|
*
|
|
@@ -17146,13 +17618,135 @@ declare class HighestProfitUtils {
|
|
|
17146
17618
|
strategyName: StrategyName;
|
|
17147
17619
|
exchangeName: ExchangeName;
|
|
17148
17620
|
frameName: FrameName;
|
|
17149
|
-
}, backtest?: boolean, path?: string, columns?: Columns$
|
|
17621
|
+
}, backtest?: boolean, path?: string, columns?: Columns$5[]) => Promise<void>;
|
|
17150
17622
|
}
|
|
17151
17623
|
/**
|
|
17152
17624
|
* Global singleton instance of HighestProfitUtils.
|
|
17153
17625
|
*/
|
|
17154
17626
|
declare const HighestProfit: HighestProfitUtils;
|
|
17155
17627
|
|
|
17628
|
+
/**
|
|
17629
|
+
* Type alias for column configuration used in max drawdown markdown reports.
|
|
17630
|
+
*/
|
|
17631
|
+
type Columns$4 = ColumnModel<MaxDrawdownEvent>;
|
|
17632
|
+
/**
|
|
17633
|
+
* Service for generating and saving max drawdown markdown reports.
|
|
17634
|
+
*
|
|
17635
|
+
* Listens to maxDrawdownSubject and accumulates events per
|
|
17636
|
+
* symbol-strategy-exchange-frame combination. Provides getData(),
|
|
17637
|
+
* getReport(), and dump() methods matching the HighestProfit pattern.
|
|
17638
|
+
*/
|
|
17639
|
+
declare class MaxDrawdownMarkdownService {
|
|
17640
|
+
private readonly loggerService;
|
|
17641
|
+
private getStorage;
|
|
17642
|
+
/**
|
|
17643
|
+
* Subscribes to `maxDrawdownSubject` to start receiving `MaxDrawdownContract`
|
|
17644
|
+
* events. Protected against multiple subscriptions via `singleshot`.
|
|
17645
|
+
*
|
|
17646
|
+
* @returns Unsubscribe function; calling it tears down the subscription and
|
|
17647
|
+
* clears all accumulated data
|
|
17648
|
+
*/
|
|
17649
|
+
subscribe: (() => () => void) & functools_kit.ISingleshotClearable;
|
|
17650
|
+
/**
|
|
17651
|
+
* Detaches from `maxDrawdownSubject` and clears all accumulated data.
|
|
17652
|
+
*
|
|
17653
|
+
* If `subscribe()` was never called, does nothing.
|
|
17654
|
+
*/
|
|
17655
|
+
unsubscribe: () => Promise<void>;
|
|
17656
|
+
/**
|
|
17657
|
+
* Handles a single `MaxDrawdownContract` event emitted by `maxDrawdownSubject`.
|
|
17658
|
+
*/
|
|
17659
|
+
private tick;
|
|
17660
|
+
/**
|
|
17661
|
+
* Returns accumulated max drawdown statistics for the given context.
|
|
17662
|
+
*/
|
|
17663
|
+
getData: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean) => Promise<MaxDrawdownStatisticsModel>;
|
|
17664
|
+
/**
|
|
17665
|
+
* Generates a markdown max drawdown report for the given context.
|
|
17666
|
+
*/
|
|
17667
|
+
getReport: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, columns?: Columns$4[]) => Promise<string>;
|
|
17668
|
+
/**
|
|
17669
|
+
* Generates the max drawdown report and writes it to disk.
|
|
17670
|
+
*/
|
|
17671
|
+
dump: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, path?: string, columns?: Columns$4[]) => Promise<void>;
|
|
17672
|
+
/**
|
|
17673
|
+
* Evicts memoized `ReportStorage` instances, releasing all accumulated event data.
|
|
17674
|
+
*
|
|
17675
|
+
* - With `payload` — clears only the storage bucket for that combination.
|
|
17676
|
+
* - Without `payload` — clears **all** storage buckets.
|
|
17677
|
+
*/
|
|
17678
|
+
clear: (payload?: {
|
|
17679
|
+
symbol: string;
|
|
17680
|
+
strategyName: StrategyName;
|
|
17681
|
+
exchangeName: ExchangeName;
|
|
17682
|
+
frameName: FrameName;
|
|
17683
|
+
backtest: boolean;
|
|
17684
|
+
}) => Promise<void>;
|
|
17685
|
+
}
|
|
17686
|
+
|
|
17687
|
+
/**
|
|
17688
|
+
* Utility class for accessing max drawdown reports and statistics.
|
|
17689
|
+
*
|
|
17690
|
+
* Provides static-like methods (via singleton instance) to retrieve data
|
|
17691
|
+
* accumulated by MaxDrawdownMarkdownService from maxDrawdownSubject events.
|
|
17692
|
+
*
|
|
17693
|
+
* @example
|
|
17694
|
+
* ```typescript
|
|
17695
|
+
* import { MaxDrawdown } from "backtest-kit";
|
|
17696
|
+
*
|
|
17697
|
+
* const stats = await MaxDrawdown.getData("BTCUSDT", { strategyName, exchangeName, frameName });
|
|
17698
|
+
* const report = await MaxDrawdown.getReport("BTCUSDT", { strategyName, exchangeName, frameName });
|
|
17699
|
+
* await MaxDrawdown.dump("BTCUSDT", { strategyName, exchangeName, frameName });
|
|
17700
|
+
* ```
|
|
17701
|
+
*/
|
|
17702
|
+
declare class MaxDrawdownUtils {
|
|
17703
|
+
/**
|
|
17704
|
+
* Retrieves statistical data from accumulated max drawdown events.
|
|
17705
|
+
*
|
|
17706
|
+
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
17707
|
+
* @param context - Execution context
|
|
17708
|
+
* @param backtest - Whether to query backtest data
|
|
17709
|
+
* @returns Promise resolving to MaxDrawdownStatisticsModel
|
|
17710
|
+
*/
|
|
17711
|
+
getData: (symbol: string, context: {
|
|
17712
|
+
strategyName: StrategyName;
|
|
17713
|
+
exchangeName: ExchangeName;
|
|
17714
|
+
frameName: FrameName;
|
|
17715
|
+
}, backtest?: boolean) => Promise<MaxDrawdownStatisticsModel>;
|
|
17716
|
+
/**
|
|
17717
|
+
* Generates a markdown report with all max drawdown events for a symbol-strategy pair.
|
|
17718
|
+
*
|
|
17719
|
+
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
17720
|
+
* @param context - Execution context
|
|
17721
|
+
* @param backtest - Whether to query backtest data
|
|
17722
|
+
* @param columns - Optional column configuration
|
|
17723
|
+
* @returns Promise resolving to markdown formatted report string
|
|
17724
|
+
*/
|
|
17725
|
+
getReport: (symbol: string, context: {
|
|
17726
|
+
strategyName: StrategyName;
|
|
17727
|
+
exchangeName: ExchangeName;
|
|
17728
|
+
frameName: FrameName;
|
|
17729
|
+
}, backtest?: boolean, columns?: Columns$4[]) => Promise<string>;
|
|
17730
|
+
/**
|
|
17731
|
+
* Generates and saves a markdown report to file.
|
|
17732
|
+
*
|
|
17733
|
+
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
17734
|
+
* @param context - Execution context
|
|
17735
|
+
* @param backtest - Whether to query backtest data
|
|
17736
|
+
* @param path - Output directory path (default: "./dump/max_drawdown")
|
|
17737
|
+
* @param columns - Optional column configuration
|
|
17738
|
+
*/
|
|
17739
|
+
dump: (symbol: string, context: {
|
|
17740
|
+
strategyName: StrategyName;
|
|
17741
|
+
exchangeName: ExchangeName;
|
|
17742
|
+
frameName: FrameName;
|
|
17743
|
+
}, backtest?: boolean, path?: string, columns?: Columns$4[]) => Promise<void>;
|
|
17744
|
+
}
|
|
17745
|
+
/**
|
|
17746
|
+
* Global singleton instance of MaxDrawdownUtils.
|
|
17747
|
+
*/
|
|
17748
|
+
declare const MaxDrawdown: MaxDrawdownUtils;
|
|
17749
|
+
|
|
17156
17750
|
/**
|
|
17157
17751
|
* Utility class containing predefined trading constants for take-profit and stop-loss levels.
|
|
17158
17752
|
*
|
|
@@ -17692,7 +18286,7 @@ type Columns$2 = ColumnModel<SyncEvent>;
|
|
|
17692
18286
|
* ```typescript
|
|
17693
18287
|
* import { Markdown } from "backtest-kit";
|
|
17694
18288
|
*
|
|
17695
|
-
* const unsubscribe =
|
|
18289
|
+
* const unsubscribe = MarkdownWriter.enable({ sync: true });
|
|
17696
18290
|
* // ... later
|
|
17697
18291
|
* unsubscribe();
|
|
17698
18292
|
* ```
|
|
@@ -19644,67 +20238,6 @@ declare class BreakevenUtils {
|
|
|
19644
20238
|
*/
|
|
19645
20239
|
declare const Breakeven: BreakevenUtils;
|
|
19646
20240
|
|
|
19647
|
-
/**
|
|
19648
|
-
* Logger service with automatic context injection.
|
|
19649
|
-
*
|
|
19650
|
-
* Features:
|
|
19651
|
-
* - Delegates to user-provided logger via setLogger()
|
|
19652
|
-
* - Automatically appends method context (strategyName, exchangeName, frameName)
|
|
19653
|
-
* - Automatically appends execution context (symbol, when, backtest)
|
|
19654
|
-
* - Defaults to NOOP_LOGGER if no logger configured
|
|
19655
|
-
*
|
|
19656
|
-
* Used throughout the framework for consistent logging with context.
|
|
19657
|
-
*/
|
|
19658
|
-
declare class LoggerService implements ILogger {
|
|
19659
|
-
private readonly methodContextService;
|
|
19660
|
-
private readonly executionContextService;
|
|
19661
|
-
private _commonLogger;
|
|
19662
|
-
/**
|
|
19663
|
-
* Gets current method context if available.
|
|
19664
|
-
* Contains strategyName, exchangeName, frameName from MethodContextService.
|
|
19665
|
-
*/
|
|
19666
|
-
private get methodContext();
|
|
19667
|
-
/**
|
|
19668
|
-
* Gets current execution context if available.
|
|
19669
|
-
* Contains symbol, when, backtest from ExecutionContextService.
|
|
19670
|
-
*/
|
|
19671
|
-
private get executionContext();
|
|
19672
|
-
/**
|
|
19673
|
-
* Logs general-purpose message with automatic context injection.
|
|
19674
|
-
*
|
|
19675
|
-
* @param topic - Log topic/category
|
|
19676
|
-
* @param args - Additional log arguments
|
|
19677
|
-
*/
|
|
19678
|
-
log: (topic: string, ...args: any[]) => Promise<void>;
|
|
19679
|
-
/**
|
|
19680
|
-
* Logs debug-level message with automatic context injection.
|
|
19681
|
-
*
|
|
19682
|
-
* @param topic - Log topic/category
|
|
19683
|
-
* @param args - Additional log arguments
|
|
19684
|
-
*/
|
|
19685
|
-
debug: (topic: string, ...args: any[]) => Promise<void>;
|
|
19686
|
-
/**
|
|
19687
|
-
* Logs info-level message with automatic context injection.
|
|
19688
|
-
*
|
|
19689
|
-
* @param topic - Log topic/category
|
|
19690
|
-
* @param args - Additional log arguments
|
|
19691
|
-
*/
|
|
19692
|
-
info: (topic: string, ...args: any[]) => Promise<void>;
|
|
19693
|
-
/**
|
|
19694
|
-
* Logs warning-level message with automatic context injection.
|
|
19695
|
-
*
|
|
19696
|
-
* @param topic - Log topic/category
|
|
19697
|
-
* @param args - Additional log arguments
|
|
19698
|
-
*/
|
|
19699
|
-
warn: (topic: string, ...args: any[]) => Promise<void>;
|
|
19700
|
-
/**
|
|
19701
|
-
* Sets custom logger implementation.
|
|
19702
|
-
*
|
|
19703
|
-
* @param logger - Custom logger implementing ILogger interface
|
|
19704
|
-
*/
|
|
19705
|
-
setLogger: (logger: ILogger) => void;
|
|
19706
|
-
}
|
|
19707
|
-
|
|
19708
20241
|
/**
|
|
19709
20242
|
* Type alias for column configuration used in strategy markdown reports.
|
|
19710
20243
|
*
|
|
@@ -19759,7 +20292,22 @@ type Columns = ColumnModel<StrategyEvent>;
|
|
|
19759
20292
|
* @see Strategy for the high-level utility class that wraps this service
|
|
19760
20293
|
*/
|
|
19761
20294
|
declare class StrategyMarkdownService {
|
|
19762
|
-
readonly loggerService:
|
|
20295
|
+
readonly loggerService: {
|
|
20296
|
+
readonly methodContextService: {
|
|
20297
|
+
readonly context: IMethodContext;
|
|
20298
|
+
};
|
|
20299
|
+
readonly executionContextService: {
|
|
20300
|
+
readonly context: IExecutionContext;
|
|
20301
|
+
};
|
|
20302
|
+
_commonLogger: ILogger;
|
|
20303
|
+
readonly _methodContext: {};
|
|
20304
|
+
readonly _executionContext: {};
|
|
20305
|
+
log: (topic: string, ...args: any[]) => Promise<void>;
|
|
20306
|
+
debug: (topic: string, ...args: any[]) => Promise<void>;
|
|
20307
|
+
info: (topic: string, ...args: any[]) => Promise<void>;
|
|
20308
|
+
warn: (topic: string, ...args: any[]) => Promise<void>;
|
|
20309
|
+
setLogger: (logger: ILogger) => void;
|
|
20310
|
+
};
|
|
19763
20311
|
/**
|
|
19764
20312
|
* Memoized factory for ReportStorage instances.
|
|
19765
20313
|
*
|
|
@@ -19995,7 +20543,7 @@ declare class StrategyMarkdownService {
|
|
|
19995
20543
|
* Generates and saves a markdown report to disk.
|
|
19996
20544
|
*
|
|
19997
20545
|
* Creates the output directory if it doesn't exist and writes
|
|
19998
|
-
* the report with a timestamped filename via
|
|
20546
|
+
* the report with a timestamped filename via MarkdownWriter.writeData().
|
|
19999
20547
|
*
|
|
20000
20548
|
* Filename format: `{symbol}_{strategyName}_{exchangeName}[_{frameName}_backtest|_live]-{timestamp}.md`
|
|
20001
20549
|
*
|
|
@@ -20127,294 +20675,93 @@ declare class StrategyUtils {
|
|
|
20127
20675
|
* - Timestamp (ISO 8601)
|
|
20128
20676
|
* - Mode (Backtest/Live)
|
|
20129
20677
|
*
|
|
20130
|
-
* Also includes summary statistics at the end with counts by action type.
|
|
20131
|
-
*
|
|
20132
|
-
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
20133
|
-
* @param context - Strategy context with strategyName, exchangeName, frameName
|
|
20134
|
-
* @param backtest - Whether to get backtest data (default: false)
|
|
20135
|
-
* @param columns - Optional columns configuration for the report
|
|
20136
|
-
* @returns Promise resolving to markdown formatted report string
|
|
20137
|
-
*
|
|
20138
|
-
* @example
|
|
20139
|
-
* ```typescript
|
|
20140
|
-
* const markdown = await Strategy.getReport("BTCUSDT", { strategyName: "my-strategy", exchangeName: "binance", frameName: "1h" });
|
|
20141
|
-
* console.log(markdown);
|
|
20142
|
-
*
|
|
20143
|
-
* // Output:
|
|
20144
|
-
* // # Strategy Report: BTCUSDT:my-strategy
|
|
20145
|
-
* //
|
|
20146
|
-
* // | Symbol | Strategy | Signal ID | Action | Price | ... |
|
|
20147
|
-
* // | --- | --- | --- | --- | --- | ... |
|
|
20148
|
-
* // | BTCUSDT | my-strategy | abc123 | partial-profit | 50100.00000000 USD | ... |
|
|
20149
|
-
* //
|
|
20150
|
-
* // **Total events:** 5
|
|
20151
|
-
* // - Cancel scheduled: 0
|
|
20152
|
-
* // - Close pending: 1
|
|
20153
|
-
* // - Partial profit: 2
|
|
20154
|
-
* // ...
|
|
20155
|
-
* ```
|
|
20156
|
-
*/
|
|
20157
|
-
getReport: (symbol: string, context: {
|
|
20158
|
-
strategyName: StrategyName;
|
|
20159
|
-
exchangeName: ExchangeName;
|
|
20160
|
-
frameName: FrameName;
|
|
20161
|
-
}, backtest?: boolean, columns?: Columns[]) => Promise<string>;
|
|
20162
|
-
/**
|
|
20163
|
-
* Generates and saves markdown report to file.
|
|
20164
|
-
*
|
|
20165
|
-
* Creates directory if it doesn't exist.
|
|
20166
|
-
* Filename format: {symbol}_{strategyName}_{exchangeName}_{frameName|live}-{timestamp}.md
|
|
20167
|
-
*
|
|
20168
|
-
* Delegates to StrategyMarkdownService.dump() which:
|
|
20169
|
-
* 1. Generates markdown report via getReport()
|
|
20170
|
-
* 2. Creates output directory (recursive mkdir)
|
|
20171
|
-
* 3. Writes file with UTF-8 encoding
|
|
20172
|
-
* 4. Logs success/failure to console
|
|
20173
|
-
*
|
|
20174
|
-
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
20175
|
-
* @param context - Strategy context with strategyName, exchangeName, frameName
|
|
20176
|
-
* @param backtest - Whether to dump backtest data (default: false)
|
|
20177
|
-
* @param path - Output directory path (default: "./dump/strategy")
|
|
20178
|
-
* @param columns - Optional columns configuration for the report
|
|
20179
|
-
* @returns Promise that resolves when file is written
|
|
20180
|
-
*
|
|
20181
|
-
* @example
|
|
20182
|
-
* ```typescript
|
|
20183
|
-
* // Save to default path: ./dump/strategy/BTCUSDT_my-strategy_binance_1h_backtest-{timestamp}.md
|
|
20184
|
-
* await Strategy.dump("BTCUSDT", { strategyName: "my-strategy", exchangeName: "binance", frameName: "1h" }, true);
|
|
20185
|
-
*
|
|
20186
|
-
* // Save to custom path
|
|
20187
|
-
* await Strategy.dump("BTCUSDT", { strategyName: "my-strategy", exchangeName: "binance", frameName: "1h" }, true, "./reports/strategy");
|
|
20188
|
-
*
|
|
20189
|
-
* // After multiple symbols backtested, export all reports
|
|
20190
|
-
* for (const symbol of ["BTCUSDT", "ETHUSDT", "BNBUSDT"]) {
|
|
20191
|
-
* await Strategy.dump(symbol, { strategyName: "my-strategy", exchangeName: "binance", frameName: "1h" }, true, "./backtest-results");
|
|
20192
|
-
* }
|
|
20193
|
-
* ```
|
|
20194
|
-
*/
|
|
20195
|
-
dump: (symbol: string, context: {
|
|
20196
|
-
strategyName: StrategyName;
|
|
20197
|
-
exchangeName: ExchangeName;
|
|
20198
|
-
frameName: FrameName;
|
|
20199
|
-
}, backtest?: boolean, path?: string, columns?: Columns[]) => Promise<void>;
|
|
20200
|
-
}
|
|
20201
|
-
/**
|
|
20202
|
-
* Global singleton instance of StrategyUtils.
|
|
20203
|
-
* Provides static-like access to strategy management reporting methods.
|
|
20204
|
-
*
|
|
20205
|
-
* @example
|
|
20206
|
-
* ```typescript
|
|
20207
|
-
* import { Strategy } from "backtest-kit";
|
|
20208
|
-
*
|
|
20209
|
-
* // Usage same as StrategyUtils methods
|
|
20210
|
-
* const stats = await Strategy.getData("BTCUSDT", { strategyName: "my-strategy", exchangeName: "binance", frameName: "1h" });
|
|
20211
|
-
* const report = await Strategy.getReport("BTCUSDT", { strategyName: "my-strategy", exchangeName: "binance", frameName: "1h" });
|
|
20212
|
-
* await Strategy.dump("BTCUSDT", { strategyName: "my-strategy", exchangeName: "binance", frameName: "1h" });
|
|
20213
|
-
* ```
|
|
20214
|
-
*/
|
|
20215
|
-
declare const Strategy: StrategyUtils;
|
|
20216
|
-
|
|
20217
|
-
/**
|
|
20218
|
-
* Proxy wrapper for user-defined action handlers with automatic error capture.
|
|
20219
|
-
*
|
|
20220
|
-
* Wraps all IPublicAction methods with trycatch to prevent user code errors from crashing the system.
|
|
20221
|
-
* All errors are logged, sent to errorEmitter, and returned as null (non-breaking).
|
|
20222
|
-
*
|
|
20223
|
-
* Key features:
|
|
20224
|
-
* - Automatic error catching and logging for all action methods
|
|
20225
|
-
* - Safe execution of partial user implementations (missing methods return null)
|
|
20226
|
-
* - Consistent error capture across all action lifecycle events
|
|
20227
|
-
* - Non-breaking failure mode (errors logged but execution continues)
|
|
20228
|
-
*
|
|
20229
|
-
* Architecture:
|
|
20230
|
-
* - Private constructor enforces factory pattern via fromInstance()
|
|
20231
|
-
* - Each method checks if target implements the method before calling
|
|
20232
|
-
* - Errors caught with fallback handler (warn log + errorEmitter)
|
|
20233
|
-
* - Returns null on error to prevent undefined behavior
|
|
20234
|
-
*
|
|
20235
|
-
* Used by:
|
|
20236
|
-
* - ClientAction to wrap user-provided action handlers
|
|
20237
|
-
* - ActionCoreService to safely invoke action callbacks
|
|
20238
|
-
*
|
|
20239
|
-
* @example
|
|
20240
|
-
* ```typescript
|
|
20241
|
-
* // Create proxy from user implementation
|
|
20242
|
-
* const userAction = {
|
|
20243
|
-
* signal: async (event) => {
|
|
20244
|
-
* // User code that might throw
|
|
20245
|
-
* throw new Error('User error');
|
|
20246
|
-
* }
|
|
20247
|
-
* };
|
|
20248
|
-
*
|
|
20249
|
-
* const proxy = ActionProxy.fromInstance(userAction);
|
|
20250
|
-
*
|
|
20251
|
-
* // Error is caught and logged, execution continues
|
|
20252
|
-
* await proxy.signal(event); // Logs error, returns null
|
|
20253
|
-
* await proxy.dispose(); // Safe call even though not implemented
|
|
20254
|
-
* ```
|
|
20255
|
-
*
|
|
20256
|
-
* @example
|
|
20257
|
-
* ```typescript
|
|
20258
|
-
* // Partial implementation is safe
|
|
20259
|
-
* const partialAction = {
|
|
20260
|
-
* init: async () => console.log('Initialized'),
|
|
20261
|
-
* // Other methods not implemented
|
|
20262
|
-
* };
|
|
20263
|
-
*
|
|
20264
|
-
* const proxy = ActionProxy.fromInstance(partialAction);
|
|
20265
|
-
* await proxy.init(); // Works
|
|
20266
|
-
* await proxy.signal(event); // Returns null (not implemented)
|
|
20267
|
-
* ```
|
|
20268
|
-
*/
|
|
20269
|
-
declare class ActionProxy implements IPublicAction {
|
|
20270
|
-
readonly _target: Partial<IPublicAction>;
|
|
20271
|
-
/**
|
|
20272
|
-
* Creates a new ActionProxy instance.
|
|
20273
|
-
*
|
|
20274
|
-
* @param _target - Partial action implementation to wrap with error capture
|
|
20275
|
-
* @private Use ActionProxy.fromInstance() instead
|
|
20276
|
-
*/
|
|
20277
|
-
private constructor();
|
|
20278
|
-
/**
|
|
20279
|
-
* Initializes the action handler with error capture.
|
|
20280
|
-
*
|
|
20281
|
-
* Wraps the user's init() method in trycatch to prevent initialization errors from crashing the system.
|
|
20282
|
-
* If the target doesn't implement init(), this method safely returns undefined.
|
|
20283
|
-
*
|
|
20284
|
-
* @returns Promise resolving to user's init() result or undefined if not implemented
|
|
20285
|
-
*/
|
|
20286
|
-
init(): Promise<any>;
|
|
20287
|
-
/**
|
|
20288
|
-
* Handles signal events from all modes with error capture.
|
|
20289
|
-
*
|
|
20290
|
-
* Wraps the user's signal() method to catch and log any errors.
|
|
20291
|
-
* Called on every tick/candle when strategy is evaluated.
|
|
20292
|
-
*
|
|
20293
|
-
* @param event - Signal state result with action, state, signal data, and context
|
|
20294
|
-
* @returns Promise resolving to user's signal() result or null on error
|
|
20295
|
-
*/
|
|
20296
|
-
signal(event: IStrategyTickResult): Promise<any>;
|
|
20297
|
-
/**
|
|
20298
|
-
* Handles signal events from live trading only with error capture.
|
|
20299
|
-
*
|
|
20300
|
-
* Wraps the user's signalLive() method to catch and log any errors.
|
|
20301
|
-
* Called every tick in live mode.
|
|
20302
|
-
*
|
|
20303
|
-
* @param event - Signal state result from live trading
|
|
20304
|
-
* @returns Promise resolving to user's signalLive() result or null on error
|
|
20305
|
-
*/
|
|
20306
|
-
signalLive(event: IStrategyTickResult): Promise<any>;
|
|
20307
|
-
/**
|
|
20308
|
-
* Handles signal events from backtest only with error capture.
|
|
20309
|
-
*
|
|
20310
|
-
* Wraps the user's signalBacktest() method to catch and log any errors.
|
|
20311
|
-
* Called every candle in backtest mode.
|
|
20312
|
-
*
|
|
20313
|
-
* @param event - Signal state result from backtest
|
|
20314
|
-
* @returns Promise resolving to user's signalBacktest() result or null on error
|
|
20315
|
-
*/
|
|
20316
|
-
signalBacktest(event: IStrategyTickResult): Promise<any>;
|
|
20317
|
-
/**
|
|
20318
|
-
* Handles breakeven events with error capture.
|
|
20319
|
-
*
|
|
20320
|
-
* Wraps the user's breakevenAvailable() method to catch and log any errors.
|
|
20321
|
-
* Called once per signal when stop-loss is moved to entry price.
|
|
20322
|
-
*
|
|
20323
|
-
* @param event - Breakeven milestone data with signal info, current price, timestamp
|
|
20324
|
-
* @returns Promise resolving to user's breakevenAvailable() result or null on error
|
|
20325
|
-
*/
|
|
20326
|
-
breakevenAvailable(event: BreakevenContract): Promise<any>;
|
|
20327
|
-
/**
|
|
20328
|
-
* Handles partial profit level events with error capture.
|
|
20329
|
-
*
|
|
20330
|
-
* Wraps the user's partialProfitAvailable() method to catch and log any errors.
|
|
20331
|
-
* Called once per profit level per signal (10%, 20%, 30%, etc).
|
|
20332
|
-
*
|
|
20333
|
-
* @param event - Profit milestone data with signal info, level, price, timestamp
|
|
20334
|
-
* @returns Promise resolving to user's partialProfitAvailable() result or null on error
|
|
20335
|
-
*/
|
|
20336
|
-
partialProfitAvailable(event: PartialProfitContract): Promise<any>;
|
|
20337
|
-
/**
|
|
20338
|
-
* Handles partial loss level events with error capture.
|
|
20339
|
-
*
|
|
20340
|
-
* Wraps the user's partialLossAvailable() method to catch and log any errors.
|
|
20341
|
-
* Called once per loss level per signal (-10%, -20%, -30%, etc).
|
|
20342
|
-
*
|
|
20343
|
-
* @param event - Loss milestone data with signal info, level, price, timestamp
|
|
20344
|
-
* @returns Promise resolving to user's partialLossAvailable() result or null on error
|
|
20345
|
-
*/
|
|
20346
|
-
partialLossAvailable(event: PartialLossContract): Promise<any>;
|
|
20347
|
-
/**
|
|
20348
|
-
* Handles scheduled ping events with error capture.
|
|
20349
|
-
*
|
|
20350
|
-
* Wraps the user's pingScheduled() method to catch and log any errors.
|
|
20351
|
-
* Called every minute while a scheduled signal is waiting for activation.
|
|
20352
|
-
*
|
|
20353
|
-
* @param event - Scheduled signal monitoring data with symbol, strategy info, signal data, timestamp
|
|
20354
|
-
* @returns Promise resolving to user's pingScheduled() result or null on error
|
|
20355
|
-
*/
|
|
20356
|
-
pingScheduled(event: SchedulePingContract): Promise<any>;
|
|
20357
|
-
/**
|
|
20358
|
-
* Handles active ping events with error capture.
|
|
20359
|
-
*
|
|
20360
|
-
* Wraps the user's pingActive() method to catch and log any errors.
|
|
20361
|
-
* Called every minute while a pending signal is active (position open).
|
|
20362
|
-
*
|
|
20363
|
-
* @param event - Active pending signal monitoring data with symbol, strategy info, signal data, timestamp
|
|
20364
|
-
* @returns Promise resolving to user's pingActive() result or null on error
|
|
20365
|
-
*/
|
|
20366
|
-
pingActive(event: ActivePingContract): Promise<any>;
|
|
20367
|
-
/**
|
|
20368
|
-
* Handles risk rejection events with error capture.
|
|
20369
|
-
*
|
|
20370
|
-
* Wraps the user's riskRejection() method to catch and log any errors.
|
|
20371
|
-
* Called only when signal is rejected by risk management validation.
|
|
20372
|
-
*
|
|
20373
|
-
* @param event - Risk rejection data with symbol, pending signal, rejection reason, timestamp
|
|
20374
|
-
* @returns Promise resolving to user's riskRejection() result or null on error
|
|
20375
|
-
*/
|
|
20376
|
-
riskRejection(event: RiskContract): Promise<any>;
|
|
20377
|
-
/**
|
|
20378
|
-
* Gate for position open/close via limit order.
|
|
20379
|
-
* NOT wrapped in trycatch — exceptions propagate to CREATE_SYNC_FN.
|
|
20380
|
-
*
|
|
20381
|
-
* @param event - Sync event with action "signal-open" or "signal-close"
|
|
20382
|
-
*/
|
|
20383
|
-
signalSync(event: SignalSyncContract): Promise<void>;
|
|
20384
|
-
/**
|
|
20385
|
-
* Cleans up resources with error capture.
|
|
20678
|
+
* Also includes summary statistics at the end with counts by action type.
|
|
20386
20679
|
*
|
|
20387
|
-
*
|
|
20388
|
-
*
|
|
20680
|
+
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
20681
|
+
* @param context - Strategy context with strategyName, exchangeName, frameName
|
|
20682
|
+
* @param backtest - Whether to get backtest data (default: false)
|
|
20683
|
+
* @param columns - Optional columns configuration for the report
|
|
20684
|
+
* @returns Promise resolving to markdown formatted report string
|
|
20389
20685
|
*
|
|
20390
|
-
* @
|
|
20686
|
+
* @example
|
|
20687
|
+
* ```typescript
|
|
20688
|
+
* const markdown = await Strategy.getReport("BTCUSDT", { strategyName: "my-strategy", exchangeName: "binance", frameName: "1h" });
|
|
20689
|
+
* console.log(markdown);
|
|
20690
|
+
*
|
|
20691
|
+
* // Output:
|
|
20692
|
+
* // # Strategy Report: BTCUSDT:my-strategy
|
|
20693
|
+
* //
|
|
20694
|
+
* // | Symbol | Strategy | Signal ID | Action | Price | ... |
|
|
20695
|
+
* // | --- | --- | --- | --- | --- | ... |
|
|
20696
|
+
* // | BTCUSDT | my-strategy | abc123 | partial-profit | 50100.00000000 USD | ... |
|
|
20697
|
+
* //
|
|
20698
|
+
* // **Total events:** 5
|
|
20699
|
+
* // - Cancel scheduled: 0
|
|
20700
|
+
* // - Close pending: 1
|
|
20701
|
+
* // - Partial profit: 2
|
|
20702
|
+
* // ...
|
|
20703
|
+
* ```
|
|
20391
20704
|
*/
|
|
20392
|
-
|
|
20705
|
+
getReport: (symbol: string, context: {
|
|
20706
|
+
strategyName: StrategyName;
|
|
20707
|
+
exchangeName: ExchangeName;
|
|
20708
|
+
frameName: FrameName;
|
|
20709
|
+
}, backtest?: boolean, columns?: Columns[]) => Promise<string>;
|
|
20393
20710
|
/**
|
|
20394
|
-
*
|
|
20711
|
+
* Generates and saves markdown report to file.
|
|
20395
20712
|
*
|
|
20396
|
-
*
|
|
20397
|
-
*
|
|
20713
|
+
* Creates directory if it doesn't exist.
|
|
20714
|
+
* Filename format: {symbol}_{strategyName}_{exchangeName}_{frameName|live}-{timestamp}.md
|
|
20398
20715
|
*
|
|
20399
|
-
*
|
|
20400
|
-
*
|
|
20716
|
+
* Delegates to StrategyMarkdownService.dump() which:
|
|
20717
|
+
* 1. Generates markdown report via getReport()
|
|
20718
|
+
* 2. Creates output directory (recursive mkdir)
|
|
20719
|
+
* 3. Writes file with UTF-8 encoding
|
|
20720
|
+
* 4. Logs success/failure to console
|
|
20721
|
+
*
|
|
20722
|
+
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
20723
|
+
* @param context - Strategy context with strategyName, exchangeName, frameName
|
|
20724
|
+
* @param backtest - Whether to dump backtest data (default: false)
|
|
20725
|
+
* @param path - Output directory path (default: "./dump/strategy")
|
|
20726
|
+
* @param columns - Optional columns configuration for the report
|
|
20727
|
+
* @returns Promise that resolves when file is written
|
|
20401
20728
|
*
|
|
20402
20729
|
* @example
|
|
20403
20730
|
* ```typescript
|
|
20404
|
-
*
|
|
20405
|
-
*
|
|
20406
|
-
* console.log('Signal received:', event);
|
|
20407
|
-
* },
|
|
20408
|
-
* dispose: async () => {
|
|
20409
|
-
* console.log('Cleanup complete');
|
|
20410
|
-
* }
|
|
20411
|
-
* };
|
|
20731
|
+
* // Save to default path: ./dump/strategy/BTCUSDT_my-strategy_binance_1h_backtest-{timestamp}.md
|
|
20732
|
+
* await Strategy.dump("BTCUSDT", { strategyName: "my-strategy", exchangeName: "binance", frameName: "1h" }, true);
|
|
20412
20733
|
*
|
|
20413
|
-
*
|
|
20734
|
+
* // Save to custom path
|
|
20735
|
+
* await Strategy.dump("BTCUSDT", { strategyName: "my-strategy", exchangeName: "binance", frameName: "1h" }, true, "./reports/strategy");
|
|
20736
|
+
*
|
|
20737
|
+
* // After multiple symbols backtested, export all reports
|
|
20738
|
+
* for (const symbol of ["BTCUSDT", "ETHUSDT", "BNBUSDT"]) {
|
|
20739
|
+
* await Strategy.dump(symbol, { strategyName: "my-strategy", exchangeName: "binance", frameName: "1h" }, true, "./backtest-results");
|
|
20740
|
+
* }
|
|
20414
20741
|
* ```
|
|
20415
20742
|
*/
|
|
20416
|
-
|
|
20743
|
+
dump: (symbol: string, context: {
|
|
20744
|
+
strategyName: StrategyName;
|
|
20745
|
+
exchangeName: ExchangeName;
|
|
20746
|
+
frameName: FrameName;
|
|
20747
|
+
}, backtest?: boolean, path?: string, columns?: Columns[]) => Promise<void>;
|
|
20417
20748
|
}
|
|
20749
|
+
/**
|
|
20750
|
+
* Global singleton instance of StrategyUtils.
|
|
20751
|
+
* Provides static-like access to strategy management reporting methods.
|
|
20752
|
+
*
|
|
20753
|
+
* @example
|
|
20754
|
+
* ```typescript
|
|
20755
|
+
* import { Strategy } from "backtest-kit";
|
|
20756
|
+
*
|
|
20757
|
+
* // Usage same as StrategyUtils methods
|
|
20758
|
+
* const stats = await Strategy.getData("BTCUSDT", { strategyName: "my-strategy", exchangeName: "binance", frameName: "1h" });
|
|
20759
|
+
* const report = await Strategy.getReport("BTCUSDT", { strategyName: "my-strategy", exchangeName: "binance", frameName: "1h" });
|
|
20760
|
+
* await Strategy.dump("BTCUSDT", { strategyName: "my-strategy", exchangeName: "binance", frameName: "1h" });
|
|
20761
|
+
* ```
|
|
20762
|
+
*/
|
|
20763
|
+
declare const Strategy: StrategyUtils;
|
|
20764
|
+
|
|
20418
20765
|
/**
|
|
20419
20766
|
* Base class for custom action handlers.
|
|
20420
20767
|
*
|
|
@@ -20428,7 +20775,7 @@ declare class ActionProxy implements IPublicAction {
|
|
|
20428
20775
|
*
|
|
20429
20776
|
* Key features:
|
|
20430
20777
|
* - All methods have default implementations (no need to implement unused methods)
|
|
20431
|
-
* - Automatic logging of all events via
|
|
20778
|
+
* - Automatic logging of all events via LOGGER_SERVICE
|
|
20432
20779
|
* - Access to strategy context (strategyName, frameName, actionName)
|
|
20433
20780
|
* - Implements full IPublicAction interface
|
|
20434
20781
|
*
|
|
@@ -21992,6 +22339,12 @@ declare const backtestScheduleOpenSubject: Subject<IStrategyTickResultOpened>;
|
|
|
21992
22339
|
* Allows users to track profit milestones and implement custom management logic based on profit levels.
|
|
21993
22340
|
*/
|
|
21994
22341
|
declare const highestProfitSubject: Subject<HighestProfitContract>;
|
|
22342
|
+
/**
|
|
22343
|
+
* Max drawdown emitter for real-time risk tracking.
|
|
22344
|
+
* Emits updates on the maximum drawdown experienced for an open position.
|
|
22345
|
+
* Allows users to track drawdown levels and implement custom risk management logic based on drawdown thresholds.
|
|
22346
|
+
*/
|
|
22347
|
+
declare const maxDrawdownSubject: Subject<MaxDrawdownContract>;
|
|
21995
22348
|
|
|
21996
22349
|
declare const emitters_activePingSubject: typeof activePingSubject;
|
|
21997
22350
|
declare const emitters_backtestScheduleOpenSubject: typeof backtestScheduleOpenSubject;
|
|
@@ -22002,6 +22355,7 @@ declare const emitters_doneWalkerSubject: typeof doneWalkerSubject;
|
|
|
22002
22355
|
declare const emitters_errorEmitter: typeof errorEmitter;
|
|
22003
22356
|
declare const emitters_exitEmitter: typeof exitEmitter;
|
|
22004
22357
|
declare const emitters_highestProfitSubject: typeof highestProfitSubject;
|
|
22358
|
+
declare const emitters_maxDrawdownSubject: typeof maxDrawdownSubject;
|
|
22005
22359
|
declare const emitters_partialLossSubject: typeof partialLossSubject;
|
|
22006
22360
|
declare const emitters_partialProfitSubject: typeof partialProfitSubject;
|
|
22007
22361
|
declare const emitters_performanceEmitter: typeof performanceEmitter;
|
|
@@ -22020,7 +22374,7 @@ declare const emitters_walkerCompleteSubject: typeof walkerCompleteSubject;
|
|
|
22020
22374
|
declare const emitters_walkerEmitter: typeof walkerEmitter;
|
|
22021
22375
|
declare const emitters_walkerStopSubject: typeof walkerStopSubject;
|
|
22022
22376
|
declare namespace emitters {
|
|
22023
|
-
export { emitters_activePingSubject as activePingSubject, emitters_backtestScheduleOpenSubject as backtestScheduleOpenSubject, emitters_breakevenSubject as breakevenSubject, emitters_doneBacktestSubject as doneBacktestSubject, emitters_doneLiveSubject as doneLiveSubject, emitters_doneWalkerSubject as doneWalkerSubject, emitters_errorEmitter as errorEmitter, emitters_exitEmitter as exitEmitter, emitters_highestProfitSubject as highestProfitSubject, emitters_partialLossSubject as partialLossSubject, emitters_partialProfitSubject as partialProfitSubject, emitters_performanceEmitter as performanceEmitter, emitters_progressBacktestEmitter as progressBacktestEmitter, emitters_progressWalkerEmitter as progressWalkerEmitter, emitters_riskSubject as riskSubject, emitters_schedulePingSubject as schedulePingSubject, emitters_shutdownEmitter as shutdownEmitter, emitters_signalBacktestEmitter as signalBacktestEmitter, emitters_signalEmitter as signalEmitter, emitters_signalLiveEmitter as signalLiveEmitter, emitters_strategyCommitSubject as strategyCommitSubject, emitters_syncSubject as syncSubject, emitters_validationSubject as validationSubject, emitters_walkerCompleteSubject as walkerCompleteSubject, emitters_walkerEmitter as walkerEmitter, emitters_walkerStopSubject as walkerStopSubject };
|
|
22377
|
+
export { emitters_activePingSubject as activePingSubject, emitters_backtestScheduleOpenSubject as backtestScheduleOpenSubject, emitters_breakevenSubject as breakevenSubject, emitters_doneBacktestSubject as doneBacktestSubject, emitters_doneLiveSubject as doneLiveSubject, emitters_doneWalkerSubject as doneWalkerSubject, emitters_errorEmitter as errorEmitter, emitters_exitEmitter as exitEmitter, emitters_highestProfitSubject as highestProfitSubject, emitters_maxDrawdownSubject as maxDrawdownSubject, emitters_partialLossSubject as partialLossSubject, emitters_partialProfitSubject as partialProfitSubject, emitters_performanceEmitter as performanceEmitter, emitters_progressBacktestEmitter as progressBacktestEmitter, emitters_progressWalkerEmitter as progressWalkerEmitter, emitters_riskSubject as riskSubject, emitters_schedulePingSubject as schedulePingSubject, emitters_shutdownEmitter as shutdownEmitter, emitters_signalBacktestEmitter as signalBacktestEmitter, emitters_signalEmitter as signalEmitter, emitters_signalLiveEmitter as signalLiveEmitter, emitters_strategyCommitSubject as strategyCommitSubject, emitters_syncSubject as syncSubject, emitters_validationSubject as validationSubject, emitters_walkerCompleteSubject as walkerCompleteSubject, emitters_walkerEmitter as walkerEmitter, emitters_walkerStopSubject as walkerStopSubject };
|
|
22024
22378
|
}
|
|
22025
22379
|
|
|
22026
22380
|
/**
|
|
@@ -22645,7 +22999,22 @@ declare class ExchangeConnectionService implements IExchange {
|
|
|
22645
22999
|
* Strategies are registered via addStrategy() and retrieved by name.
|
|
22646
23000
|
*/
|
|
22647
23001
|
declare class StrategySchemaService {
|
|
22648
|
-
readonly loggerService:
|
|
23002
|
+
readonly loggerService: {
|
|
23003
|
+
readonly methodContextService: {
|
|
23004
|
+
readonly context: IMethodContext;
|
|
23005
|
+
};
|
|
23006
|
+
readonly executionContextService: {
|
|
23007
|
+
readonly context: IExecutionContext;
|
|
23008
|
+
};
|
|
23009
|
+
_commonLogger: ILogger;
|
|
23010
|
+
readonly _methodContext: {};
|
|
23011
|
+
readonly _executionContext: {};
|
|
23012
|
+
log: (topic: string, ...args: any[]) => Promise<void>;
|
|
23013
|
+
debug: (topic: string, ...args: any[]) => Promise<void>;
|
|
23014
|
+
info: (topic: string, ...args: any[]) => Promise<void>;
|
|
23015
|
+
warn: (topic: string, ...args: any[]) => Promise<void>;
|
|
23016
|
+
setLogger: (logger: ILogger) => void;
|
|
23017
|
+
};
|
|
22649
23018
|
private _registry;
|
|
22650
23019
|
/**
|
|
22651
23020
|
* Registers a new strategy schema.
|
|
@@ -22771,6 +23140,67 @@ declare class ClientRisk implements IRisk {
|
|
|
22771
23140
|
checkSignal: (params: IRiskCheckArgs) => Promise<boolean>;
|
|
22772
23141
|
}
|
|
22773
23142
|
|
|
23143
|
+
/**
|
|
23144
|
+
* Service for managing risk schema registry.
|
|
23145
|
+
*
|
|
23146
|
+
* Uses ToolRegistry from functools-kit for type-safe schema storage.
|
|
23147
|
+
* Risk profiles are registered via addRisk() and retrieved by name.
|
|
23148
|
+
*/
|
|
23149
|
+
declare class RiskSchemaService {
|
|
23150
|
+
readonly loggerService: {
|
|
23151
|
+
readonly methodContextService: {
|
|
23152
|
+
readonly context: IMethodContext;
|
|
23153
|
+
};
|
|
23154
|
+
readonly executionContextService: {
|
|
23155
|
+
readonly context: IExecutionContext;
|
|
23156
|
+
};
|
|
23157
|
+
_commonLogger: ILogger;
|
|
23158
|
+
readonly _methodContext: {};
|
|
23159
|
+
readonly _executionContext: {};
|
|
23160
|
+
log: (topic: string, ...args: any[]) => Promise<void>;
|
|
23161
|
+
debug: (topic: string, ...args: any[]) => Promise<void>;
|
|
23162
|
+
info: (topic: string, ...args: any[]) => Promise<void>;
|
|
23163
|
+
warn: (topic: string, ...args: any[]) => Promise<void>;
|
|
23164
|
+
setLogger: (logger: ILogger) => void;
|
|
23165
|
+
};
|
|
23166
|
+
private _registry;
|
|
23167
|
+
/**
|
|
23168
|
+
* Registers a new risk schema.
|
|
23169
|
+
*
|
|
23170
|
+
* @param key - Unique risk profile name
|
|
23171
|
+
* @param value - Risk schema configuration
|
|
23172
|
+
* @throws Error if risk name already exists
|
|
23173
|
+
*/
|
|
23174
|
+
register: (key: RiskName, value: IRiskSchema) => void;
|
|
23175
|
+
/**
|
|
23176
|
+
* Validates risk schema structure for required properties.
|
|
23177
|
+
*
|
|
23178
|
+
* Performs shallow validation to ensure all required properties exist
|
|
23179
|
+
* and have correct types before registration in the registry.
|
|
23180
|
+
*
|
|
23181
|
+
* @param riskSchema - Risk schema to validate
|
|
23182
|
+
* @throws Error if riskName is missing or not a string
|
|
23183
|
+
*/
|
|
23184
|
+
private validateShallow;
|
|
23185
|
+
/**
|
|
23186
|
+
* Overrides an existing risk schema with partial updates.
|
|
23187
|
+
*
|
|
23188
|
+
* @param key - Risk name to override
|
|
23189
|
+
* @param value - Partial schema updates
|
|
23190
|
+
* @returns Updated risk schema
|
|
23191
|
+
* @throws Error if risk name doesn't exist
|
|
23192
|
+
*/
|
|
23193
|
+
override: (key: RiskName, value: Partial<IRiskSchema>) => IRiskSchema;
|
|
23194
|
+
/**
|
|
23195
|
+
* Retrieves a risk schema by name.
|
|
23196
|
+
*
|
|
23197
|
+
* @param key - Risk name
|
|
23198
|
+
* @returns Risk schema configuration
|
|
23199
|
+
* @throws Error if risk name doesn't exist
|
|
23200
|
+
*/
|
|
23201
|
+
get: (key: RiskName) => IRiskSchema;
|
|
23202
|
+
}
|
|
23203
|
+
|
|
22774
23204
|
/**
|
|
22775
23205
|
* Type definition for action methods.
|
|
22776
23206
|
* Maps all keys of IAction to any type.
|
|
@@ -23057,8 +23487,26 @@ type TRisk$1 = {
|
|
|
23057
23487
|
* ```
|
|
23058
23488
|
*/
|
|
23059
23489
|
declare class RiskConnectionService implements TRisk$1 {
|
|
23060
|
-
|
|
23061
|
-
|
|
23490
|
+
readonly loggerService: {
|
|
23491
|
+
readonly methodContextService: {
|
|
23492
|
+
readonly context: IMethodContext;
|
|
23493
|
+
};
|
|
23494
|
+
readonly executionContextService: {
|
|
23495
|
+
readonly context: IExecutionContext;
|
|
23496
|
+
};
|
|
23497
|
+
_commonLogger: ILogger;
|
|
23498
|
+
readonly _methodContext: {};
|
|
23499
|
+
readonly _executionContext: {};
|
|
23500
|
+
log: (topic: string, ...args: any[]) => Promise<void>;
|
|
23501
|
+
debug: (topic: string, ...args: any[]) => Promise<void>;
|
|
23502
|
+
info: (topic: string, ...args: any[]) => Promise<void>;
|
|
23503
|
+
warn: (topic: string, ...args: any[]) => Promise<void>;
|
|
23504
|
+
setLogger: (logger: ILogger) => void;
|
|
23505
|
+
};
|
|
23506
|
+
readonly riskSchemaService: RiskSchemaService;
|
|
23507
|
+
readonly executionContextService: {
|
|
23508
|
+
readonly context: IExecutionContext;
|
|
23509
|
+
};
|
|
23062
23510
|
/**
|
|
23063
23511
|
* Action core service injected from DI container.
|
|
23064
23512
|
*/
|
|
@@ -23178,7 +23626,22 @@ declare class PartialConnectionService implements IPartial {
|
|
|
23178
23626
|
/**
|
|
23179
23627
|
* Logger service injected from DI container.
|
|
23180
23628
|
*/
|
|
23181
|
-
|
|
23629
|
+
readonly loggerService: {
|
|
23630
|
+
readonly methodContextService: {
|
|
23631
|
+
readonly context: IMethodContext;
|
|
23632
|
+
};
|
|
23633
|
+
readonly executionContextService: {
|
|
23634
|
+
readonly context: IExecutionContext;
|
|
23635
|
+
};
|
|
23636
|
+
_commonLogger: ILogger;
|
|
23637
|
+
readonly _methodContext: {};
|
|
23638
|
+
readonly _executionContext: {};
|
|
23639
|
+
log: (topic: string, ...args: any[]) => Promise<void>;
|
|
23640
|
+
debug: (topic: string, ...args: any[]) => Promise<void>;
|
|
23641
|
+
info: (topic: string, ...args: any[]) => Promise<void>;
|
|
23642
|
+
warn: (topic: string, ...args: any[]) => Promise<void>;
|
|
23643
|
+
setLogger: (logger: ILogger) => void;
|
|
23644
|
+
};
|
|
23182
23645
|
/**
|
|
23183
23646
|
* Action core service injected from DI container.
|
|
23184
23647
|
*/
|
|
@@ -23279,7 +23742,22 @@ declare class BreakevenConnectionService implements IBreakeven {
|
|
|
23279
23742
|
/**
|
|
23280
23743
|
* Logger service injected from DI container.
|
|
23281
23744
|
*/
|
|
23282
|
-
|
|
23745
|
+
readonly loggerService: {
|
|
23746
|
+
readonly methodContextService: {
|
|
23747
|
+
readonly context: IMethodContext;
|
|
23748
|
+
};
|
|
23749
|
+
readonly executionContextService: {
|
|
23750
|
+
readonly context: IExecutionContext;
|
|
23751
|
+
};
|
|
23752
|
+
_commonLogger: ILogger;
|
|
23753
|
+
readonly _methodContext: {};
|
|
23754
|
+
readonly _executionContext: {};
|
|
23755
|
+
log: (topic: string, ...args: any[]) => Promise<void>;
|
|
23756
|
+
debug: (topic: string, ...args: any[]) => Promise<void>;
|
|
23757
|
+
info: (topic: string, ...args: any[]) => Promise<void>;
|
|
23758
|
+
warn: (topic: string, ...args: any[]) => Promise<void>;
|
|
23759
|
+
setLogger: (logger: ILogger) => void;
|
|
23760
|
+
};
|
|
23283
23761
|
/**
|
|
23284
23762
|
* Action core service injected from DI container.
|
|
23285
23763
|
*/
|
|
@@ -23536,7 +24014,22 @@ type TStrategy$1 = {
|
|
|
23536
24014
|
* ```
|
|
23537
24015
|
*/
|
|
23538
24016
|
declare class StrategyConnectionService implements TStrategy$1 {
|
|
23539
|
-
readonly loggerService:
|
|
24017
|
+
readonly loggerService: {
|
|
24018
|
+
readonly methodContextService: {
|
|
24019
|
+
readonly context: IMethodContext;
|
|
24020
|
+
};
|
|
24021
|
+
readonly executionContextService: {
|
|
24022
|
+
readonly context: IExecutionContext;
|
|
24023
|
+
};
|
|
24024
|
+
_commonLogger: ILogger;
|
|
24025
|
+
readonly _methodContext: {};
|
|
24026
|
+
readonly _executionContext: {};
|
|
24027
|
+
log: (topic: string, ...args: any[]) => Promise<void>;
|
|
24028
|
+
debug: (topic: string, ...args: any[]) => Promise<void>;
|
|
24029
|
+
info: (topic: string, ...args: any[]) => Promise<void>;
|
|
24030
|
+
warn: (topic: string, ...args: any[]) => Promise<void>;
|
|
24031
|
+
setLogger: (logger: ILogger) => void;
|
|
24032
|
+
};
|
|
23540
24033
|
readonly executionContextService: {
|
|
23541
24034
|
readonly context: IExecutionContext;
|
|
23542
24035
|
};
|
|
@@ -23919,139 +24412,243 @@ declare class StrategyConnectionService implements TStrategy$1 {
|
|
|
23919
24412
|
* @param backtest - Whether running in backtest mode
|
|
23920
24413
|
* @param symbol - Trading pair symbol
|
|
23921
24414
|
* @param context - Execution context with strategyName, exchangeName, frameName
|
|
23922
|
-
* @returns Promise resolving to true if there is a waiting scheduled signal, false otherwise
|
|
24415
|
+
* @returns Promise resolving to true if there is a waiting scheduled signal, false otherwise
|
|
24416
|
+
*/
|
|
24417
|
+
hasScheduledSignal: (backtest: boolean, symbol: string, context: {
|
|
24418
|
+
strategyName: StrategyName;
|
|
24419
|
+
exchangeName: ExchangeName;
|
|
24420
|
+
frameName: FrameName;
|
|
24421
|
+
}) => Promise<boolean>;
|
|
24422
|
+
/**
|
|
24423
|
+
* Returns the original estimated duration for the current pending signal.
|
|
24424
|
+
*
|
|
24425
|
+
* Delegates to ClientStrategy.getPositionEstimateMinutes().
|
|
24426
|
+
* Returns null if no pending signal exists.
|
|
24427
|
+
*
|
|
24428
|
+
* @param backtest - Whether running in backtest mode
|
|
24429
|
+
* @param symbol - Trading pair symbol
|
|
24430
|
+
* @param context - Execution context with strategyName, exchangeName, frameName
|
|
24431
|
+
* @returns Promise resolving to estimated duration in minutes or null
|
|
24432
|
+
*/
|
|
24433
|
+
getPositionEstimateMinutes: (backtest: boolean, symbol: string, context: {
|
|
24434
|
+
strategyName: StrategyName;
|
|
24435
|
+
exchangeName: ExchangeName;
|
|
24436
|
+
frameName: FrameName;
|
|
24437
|
+
}) => Promise<number | null>;
|
|
24438
|
+
/**
|
|
24439
|
+
* Returns the remaining time before the position expires, clamped to zero.
|
|
24440
|
+
*
|
|
24441
|
+
* Resolves current timestamp via timeMetaService and delegates to
|
|
24442
|
+
* ClientStrategy.getPositionCountdownMinutes().
|
|
24443
|
+
* Returns null if no pending signal exists.
|
|
24444
|
+
*
|
|
24445
|
+
* @param backtest - Whether running in backtest mode
|
|
24446
|
+
* @param symbol - Trading pair symbol
|
|
24447
|
+
* @param context - Execution context with strategyName, exchangeName, frameName
|
|
24448
|
+
* @returns Promise resolving to remaining minutes (≥ 0) or null
|
|
24449
|
+
*/
|
|
24450
|
+
getPositionCountdownMinutes: (backtest: boolean, symbol: string, context: {
|
|
24451
|
+
strategyName: StrategyName;
|
|
24452
|
+
exchangeName: ExchangeName;
|
|
24453
|
+
frameName: FrameName;
|
|
24454
|
+
}) => Promise<number | null>;
|
|
24455
|
+
/**
|
|
24456
|
+
* Returns the best price reached in the profit direction during this position's life.
|
|
24457
|
+
*
|
|
24458
|
+
* Delegates to ClientStrategy.getPositionHighestProfitPrice().
|
|
24459
|
+
* Returns null if no pending signal exists.
|
|
24460
|
+
*
|
|
24461
|
+
* @param backtest - Whether running in backtest mode
|
|
24462
|
+
* @param symbol - Trading pair symbol
|
|
24463
|
+
* @param context - Execution context with strategyName, exchangeName, frameName
|
|
24464
|
+
* @returns Promise resolving to price or null
|
|
24465
|
+
*/
|
|
24466
|
+
getPositionHighestProfitPrice: (backtest: boolean, symbol: string, context: {
|
|
24467
|
+
strategyName: StrategyName;
|
|
24468
|
+
exchangeName: ExchangeName;
|
|
24469
|
+
frameName: FrameName;
|
|
24470
|
+
}) => Promise<number | null>;
|
|
24471
|
+
/**
|
|
24472
|
+
* Returns the timestamp when the best profit price was recorded during this position's life.
|
|
24473
|
+
*
|
|
24474
|
+
* Delegates to ClientStrategy.getPositionHighestProfitTimestamp().
|
|
24475
|
+
* Returns null if no pending signal exists.
|
|
24476
|
+
*
|
|
24477
|
+
* @param backtest - Whether running in backtest mode
|
|
24478
|
+
* @param symbol - Trading pair symbol
|
|
24479
|
+
* @param context - Execution context with strategyName, exchangeName, frameName
|
|
24480
|
+
* @returns Promise resolving to timestamp in milliseconds or null
|
|
24481
|
+
*/
|
|
24482
|
+
getPositionHighestProfitTimestamp: (backtest: boolean, symbol: string, context: {
|
|
24483
|
+
strategyName: StrategyName;
|
|
24484
|
+
exchangeName: ExchangeName;
|
|
24485
|
+
frameName: FrameName;
|
|
24486
|
+
}) => Promise<number | null>;
|
|
24487
|
+
/**
|
|
24488
|
+
* Returns the PnL percentage at the moment the best profit price was recorded during this position's life.
|
|
24489
|
+
*
|
|
24490
|
+
* Delegates to ClientStrategy.getPositionHighestPnlPercentage().
|
|
24491
|
+
* Returns null if no pending signal exists.
|
|
24492
|
+
*
|
|
24493
|
+
* @param backtest - Whether running in backtest mode
|
|
24494
|
+
* @param symbol - Trading pair symbol
|
|
24495
|
+
* @param context - Execution context with strategyName, exchangeName, frameName
|
|
24496
|
+
* @returns Promise resolving to PnL percentage or null
|
|
24497
|
+
*/
|
|
24498
|
+
getPositionHighestPnlPercentage: (backtest: boolean, symbol: string, context: {
|
|
24499
|
+
strategyName: StrategyName;
|
|
24500
|
+
exchangeName: ExchangeName;
|
|
24501
|
+
frameName: FrameName;
|
|
24502
|
+
}) => Promise<number | null>;
|
|
24503
|
+
/**
|
|
24504
|
+
* Returns the PnL cost (in quote currency) at the moment the best profit price was recorded during this position's life.
|
|
24505
|
+
*
|
|
24506
|
+
* Delegates to ClientStrategy.getPositionHighestPnlCost().
|
|
24507
|
+
* Returns null if no pending signal exists.
|
|
24508
|
+
*
|
|
24509
|
+
* @param backtest - Whether running in backtest mode
|
|
24510
|
+
* @param symbol - Trading pair symbol
|
|
24511
|
+
* @param context - Execution context with strategyName, exchangeName, frameName
|
|
24512
|
+
* @returns Promise resolving to PnL cost or null
|
|
23923
24513
|
*/
|
|
23924
|
-
|
|
24514
|
+
getPositionHighestPnlCost: (backtest: boolean, symbol: string, context: {
|
|
23925
24515
|
strategyName: StrategyName;
|
|
23926
24516
|
exchangeName: ExchangeName;
|
|
23927
24517
|
frameName: FrameName;
|
|
23928
|
-
}) => Promise<
|
|
24518
|
+
}) => Promise<number | null>;
|
|
23929
24519
|
/**
|
|
23930
|
-
* Returns
|
|
24520
|
+
* Returns whether breakeven was mathematically reachable at the highest profit price.
|
|
23931
24521
|
*
|
|
23932
|
-
* Delegates to ClientStrategy.
|
|
24522
|
+
* Delegates to ClientStrategy.getPositionHighestProfitBreakeven().
|
|
23933
24523
|
* Returns null if no pending signal exists.
|
|
23934
24524
|
*
|
|
23935
24525
|
* @param backtest - Whether running in backtest mode
|
|
23936
24526
|
* @param symbol - Trading pair symbol
|
|
23937
24527
|
* @param context - Execution context with strategyName, exchangeName, frameName
|
|
23938
|
-
* @returns Promise resolving to
|
|
24528
|
+
* @returns Promise resolving to true if breakeven was reachable at peak, false otherwise, or null
|
|
23939
24529
|
*/
|
|
23940
|
-
|
|
24530
|
+
getPositionHighestProfitBreakeven: (backtest: boolean, symbol: string, context: {
|
|
23941
24531
|
strategyName: StrategyName;
|
|
23942
24532
|
exchangeName: ExchangeName;
|
|
23943
24533
|
frameName: FrameName;
|
|
23944
|
-
}) => Promise<
|
|
24534
|
+
}) => Promise<boolean | null>;
|
|
23945
24535
|
/**
|
|
23946
|
-
* Returns the
|
|
24536
|
+
* Returns the number of minutes elapsed since the highest profit price was recorded.
|
|
23947
24537
|
*
|
|
23948
24538
|
* Resolves current timestamp via timeMetaService and delegates to
|
|
23949
|
-
* ClientStrategy.
|
|
24539
|
+
* ClientStrategy.getPositionDrawdownMinutes().
|
|
23950
24540
|
* Returns null if no pending signal exists.
|
|
23951
24541
|
*
|
|
23952
24542
|
* @param backtest - Whether running in backtest mode
|
|
23953
24543
|
* @param symbol - Trading pair symbol
|
|
23954
24544
|
* @param context - Execution context with strategyName, exchangeName, frameName
|
|
23955
|
-
* @returns Promise resolving to
|
|
24545
|
+
* @returns Promise resolving to drawdown duration in minutes or null
|
|
23956
24546
|
*/
|
|
23957
|
-
|
|
24547
|
+
getPositionDrawdownMinutes: (backtest: boolean, symbol: string, context: {
|
|
23958
24548
|
strategyName: StrategyName;
|
|
23959
24549
|
exchangeName: ExchangeName;
|
|
23960
24550
|
frameName: FrameName;
|
|
23961
24551
|
}) => Promise<number | null>;
|
|
23962
24552
|
/**
|
|
23963
|
-
* Returns the
|
|
24553
|
+
* Returns the number of minutes elapsed since the highest profit price was recorded.
|
|
23964
24554
|
*
|
|
23965
|
-
*
|
|
24555
|
+
* Alias for getPositionDrawdownMinutes — measures how long the position has been
|
|
24556
|
+
* pulling back from its peak profit level.
|
|
24557
|
+
*
|
|
24558
|
+
* Resolves current timestamp via timeMetaService and delegates to
|
|
24559
|
+
* ClientStrategy.getPositionHighestProfitMinutes().
|
|
23966
24560
|
* Returns null if no pending signal exists.
|
|
23967
24561
|
*
|
|
23968
24562
|
* @param backtest - Whether running in backtest mode
|
|
23969
24563
|
* @param symbol - Trading pair symbol
|
|
23970
24564
|
* @param context - Execution context with strategyName, exchangeName, frameName
|
|
23971
|
-
* @returns Promise resolving to
|
|
24565
|
+
* @returns Promise resolving to minutes since last profit peak or null
|
|
23972
24566
|
*/
|
|
23973
|
-
|
|
24567
|
+
getPositionHighestProfitMinutes: (backtest: boolean, symbol: string, context: {
|
|
23974
24568
|
strategyName: StrategyName;
|
|
23975
24569
|
exchangeName: ExchangeName;
|
|
23976
24570
|
frameName: FrameName;
|
|
23977
24571
|
}) => Promise<number | null>;
|
|
23978
24572
|
/**
|
|
23979
|
-
* Returns the
|
|
24573
|
+
* Returns the number of minutes elapsed since the worst loss price was recorded.
|
|
23980
24574
|
*
|
|
23981
|
-
*
|
|
24575
|
+
* Measures how long ago the deepest drawdown point occurred.
|
|
24576
|
+
* Zero when called at the exact moment the trough was set.
|
|
24577
|
+
*
|
|
24578
|
+
* Resolves current timestamp via timeMetaService and delegates to
|
|
24579
|
+
* ClientStrategy.getPositionMaxDrawdownMinutes().
|
|
23982
24580
|
* Returns null if no pending signal exists.
|
|
23983
24581
|
*
|
|
23984
24582
|
* @param backtest - Whether running in backtest mode
|
|
23985
24583
|
* @param symbol - Trading pair symbol
|
|
23986
24584
|
* @param context - Execution context with strategyName, exchangeName, frameName
|
|
23987
|
-
* @returns Promise resolving to
|
|
24585
|
+
* @returns Promise resolving to minutes since last drawdown trough or null
|
|
23988
24586
|
*/
|
|
23989
|
-
|
|
24587
|
+
getPositionMaxDrawdownMinutes: (backtest: boolean, symbol: string, context: {
|
|
23990
24588
|
strategyName: StrategyName;
|
|
23991
24589
|
exchangeName: ExchangeName;
|
|
23992
24590
|
frameName: FrameName;
|
|
23993
24591
|
}) => Promise<number | null>;
|
|
23994
24592
|
/**
|
|
23995
|
-
* Returns the
|
|
24593
|
+
* Returns the worst price reached in the loss direction during this position's life.
|
|
23996
24594
|
*
|
|
23997
|
-
* Delegates to ClientStrategy.
|
|
24595
|
+
* Delegates to ClientStrategy.getPositionMaxDrawdownPrice().
|
|
23998
24596
|
* Returns null if no pending signal exists.
|
|
23999
24597
|
*
|
|
24000
24598
|
* @param backtest - Whether running in backtest mode
|
|
24001
24599
|
* @param symbol - Trading pair symbol
|
|
24002
24600
|
* @param context - Execution context with strategyName, exchangeName, frameName
|
|
24003
|
-
* @returns Promise resolving to
|
|
24601
|
+
* @returns Promise resolving to price or null
|
|
24004
24602
|
*/
|
|
24005
|
-
|
|
24603
|
+
getPositionMaxDrawdownPrice: (backtest: boolean, symbol: string, context: {
|
|
24006
24604
|
strategyName: StrategyName;
|
|
24007
24605
|
exchangeName: ExchangeName;
|
|
24008
24606
|
frameName: FrameName;
|
|
24009
24607
|
}) => Promise<number | null>;
|
|
24010
24608
|
/**
|
|
24011
|
-
* Returns the
|
|
24609
|
+
* Returns the timestamp when the worst loss price was recorded during this position's life.
|
|
24012
24610
|
*
|
|
24013
|
-
* Delegates to ClientStrategy.
|
|
24611
|
+
* Delegates to ClientStrategy.getPositionMaxDrawdownTimestamp().
|
|
24014
24612
|
* Returns null if no pending signal exists.
|
|
24015
24613
|
*
|
|
24016
24614
|
* @param backtest - Whether running in backtest mode
|
|
24017
24615
|
* @param symbol - Trading pair symbol
|
|
24018
24616
|
* @param context - Execution context with strategyName, exchangeName, frameName
|
|
24019
|
-
* @returns Promise resolving to
|
|
24617
|
+
* @returns Promise resolving to timestamp in milliseconds or null
|
|
24020
24618
|
*/
|
|
24021
|
-
|
|
24619
|
+
getPositionMaxDrawdownTimestamp: (backtest: boolean, symbol: string, context: {
|
|
24022
24620
|
strategyName: StrategyName;
|
|
24023
24621
|
exchangeName: ExchangeName;
|
|
24024
24622
|
frameName: FrameName;
|
|
24025
24623
|
}) => Promise<number | null>;
|
|
24026
24624
|
/**
|
|
24027
|
-
* Returns
|
|
24625
|
+
* Returns the PnL percentage at the moment the worst loss price was recorded during this position's life.
|
|
24028
24626
|
*
|
|
24029
|
-
* Delegates to ClientStrategy.
|
|
24627
|
+
* Delegates to ClientStrategy.getPositionMaxDrawdownPnlPercentage().
|
|
24030
24628
|
* Returns null if no pending signal exists.
|
|
24031
24629
|
*
|
|
24032
24630
|
* @param backtest - Whether running in backtest mode
|
|
24033
24631
|
* @param symbol - Trading pair symbol
|
|
24034
24632
|
* @param context - Execution context with strategyName, exchangeName, frameName
|
|
24035
|
-
* @returns Promise resolving to
|
|
24633
|
+
* @returns Promise resolving to PnL percentage or null
|
|
24036
24634
|
*/
|
|
24037
|
-
|
|
24635
|
+
getPositionMaxDrawdownPnlPercentage: (backtest: boolean, symbol: string, context: {
|
|
24038
24636
|
strategyName: StrategyName;
|
|
24039
24637
|
exchangeName: ExchangeName;
|
|
24040
24638
|
frameName: FrameName;
|
|
24041
|
-
}) => Promise<
|
|
24639
|
+
}) => Promise<number | null>;
|
|
24042
24640
|
/**
|
|
24043
|
-
* Returns the
|
|
24641
|
+
* Returns the PnL cost (in quote currency) at the moment the worst loss price was recorded during this position's life.
|
|
24044
24642
|
*
|
|
24045
|
-
*
|
|
24046
|
-
* ClientStrategy.getPositionDrawdownMinutes().
|
|
24643
|
+
* Delegates to ClientStrategy.getPositionMaxDrawdownPnlCost().
|
|
24047
24644
|
* Returns null if no pending signal exists.
|
|
24048
24645
|
*
|
|
24049
24646
|
* @param backtest - Whether running in backtest mode
|
|
24050
24647
|
* @param symbol - Trading pair symbol
|
|
24051
24648
|
* @param context - Execution context with strategyName, exchangeName, frameName
|
|
24052
|
-
* @returns Promise resolving to
|
|
24649
|
+
* @returns Promise resolving to PnL cost or null
|
|
24053
24650
|
*/
|
|
24054
|
-
|
|
24651
|
+
getPositionMaxDrawdownPnlCost: (backtest: boolean, symbol: string, context: {
|
|
24055
24652
|
strategyName: StrategyName;
|
|
24056
24653
|
exchangeName: ExchangeName;
|
|
24057
24654
|
frameName: FrameName;
|
|
@@ -24579,16 +25176,219 @@ declare class SizingConnectionService implements TSizing$1 {
|
|
|
24579
25176
|
/**
|
|
24580
25177
|
* Calculates position size based on risk parameters and configured method.
|
|
24581
25178
|
*
|
|
24582
|
-
* Routes to appropriate ClientSizing instance based on provided context.
|
|
24583
|
-
* Supports multiple sizing methods: fixed-percentage, kelly-criterion, atr-based.
|
|
25179
|
+
* Routes to appropriate ClientSizing instance based on provided context.
|
|
25180
|
+
* Supports multiple sizing methods: fixed-percentage, kelly-criterion, atr-based.
|
|
25181
|
+
*
|
|
25182
|
+
* @param params - Calculation parameters (symbol, balance, prices, method-specific data)
|
|
25183
|
+
* @param context - Execution context with sizing name
|
|
25184
|
+
* @returns Promise resolving to calculated position size
|
|
25185
|
+
*/
|
|
25186
|
+
calculate: (params: ISizingCalculateParams, context: {
|
|
25187
|
+
sizingName: SizingName;
|
|
25188
|
+
}) => Promise<number>;
|
|
25189
|
+
}
|
|
25190
|
+
|
|
25191
|
+
/**
|
|
25192
|
+
* Proxy wrapper for user-defined action handlers with automatic error capture.
|
|
25193
|
+
*
|
|
25194
|
+
* Wraps all IPublicAction methods with trycatch to prevent user code errors from crashing the system.
|
|
25195
|
+
* All errors are logged, sent to errorEmitter, and returned as null (non-breaking).
|
|
25196
|
+
*
|
|
25197
|
+
* Key features:
|
|
25198
|
+
* - Automatic error catching and logging for all action methods
|
|
25199
|
+
* - Safe execution of partial user implementations (missing methods return null)
|
|
25200
|
+
* - Consistent error capture across all action lifecycle events
|
|
25201
|
+
* - Non-breaking failure mode (errors logged but execution continues)
|
|
25202
|
+
*
|
|
25203
|
+
* Architecture:
|
|
25204
|
+
* - Private constructor enforces factory pattern via fromInstance()
|
|
25205
|
+
* - Each method checks if target implements the method before calling
|
|
25206
|
+
* - Errors caught with fallback handler (warn log + errorEmitter)
|
|
25207
|
+
* - Returns null on error to prevent undefined behavior
|
|
25208
|
+
*
|
|
25209
|
+
* Used by:
|
|
25210
|
+
* - ClientAction to wrap user-provided action handlers
|
|
25211
|
+
* - ActionCoreService to safely invoke action callbacks
|
|
25212
|
+
*
|
|
25213
|
+
* @example
|
|
25214
|
+
* ```typescript
|
|
25215
|
+
* // Create proxy from user implementation
|
|
25216
|
+
* const userAction = {
|
|
25217
|
+
* signal: async (event) => {
|
|
25218
|
+
* // User code that might throw
|
|
25219
|
+
* throw new Error('User error');
|
|
25220
|
+
* }
|
|
25221
|
+
* };
|
|
25222
|
+
*
|
|
25223
|
+
* const proxy = ActionProxy.fromInstance(userAction);
|
|
25224
|
+
*
|
|
25225
|
+
* // Error is caught and logged, execution continues
|
|
25226
|
+
* await proxy.signal(event); // Logs error, returns null
|
|
25227
|
+
* await proxy.dispose(); // Safe call even though not implemented
|
|
25228
|
+
* ```
|
|
25229
|
+
*
|
|
25230
|
+
* @example
|
|
25231
|
+
* ```typescript
|
|
25232
|
+
* // Partial implementation is safe
|
|
25233
|
+
* const partialAction = {
|
|
25234
|
+
* init: async () => console.log('Initialized'),
|
|
25235
|
+
* // Other methods not implemented
|
|
25236
|
+
* };
|
|
25237
|
+
*
|
|
25238
|
+
* const proxy = ActionProxy.fromInstance(partialAction);
|
|
25239
|
+
* await proxy.init(); // Works
|
|
25240
|
+
* await proxy.signal(event); // Returns null (not implemented)
|
|
25241
|
+
* ```
|
|
25242
|
+
*/
|
|
25243
|
+
declare class ActionProxy implements IPublicAction {
|
|
25244
|
+
readonly _target: Partial<IPublicAction>;
|
|
25245
|
+
readonly params: IActionParams;
|
|
25246
|
+
/**
|
|
25247
|
+
* Creates a new ActionProxy instance.
|
|
25248
|
+
*
|
|
25249
|
+
* @param _target - Partial action implementation to wrap with error capture
|
|
25250
|
+
* @private Use ActionProxy.fromInstance() instead
|
|
25251
|
+
*/
|
|
25252
|
+
private constructor();
|
|
25253
|
+
/**
|
|
25254
|
+
* Initializes the action handler with error capture.
|
|
25255
|
+
*
|
|
25256
|
+
* Wraps the user's init() method in trycatch to prevent initialization errors from crashing the system.
|
|
25257
|
+
* If the target doesn't implement init(), this method safely returns undefined.
|
|
25258
|
+
*
|
|
25259
|
+
* @returns Promise resolving to user's init() result or undefined if not implemented
|
|
25260
|
+
*/
|
|
25261
|
+
init(): Promise<any>;
|
|
25262
|
+
/**
|
|
25263
|
+
* Handles signal events from all modes with error capture.
|
|
25264
|
+
*
|
|
25265
|
+
* Wraps the user's signal() method to catch and log any errors.
|
|
25266
|
+
* Called on every tick/candle when strategy is evaluated.
|
|
25267
|
+
*
|
|
25268
|
+
* @param event - Signal state result with action, state, signal data, and context
|
|
25269
|
+
* @returns Promise resolving to user's signal() result or null on error
|
|
25270
|
+
*/
|
|
25271
|
+
signal(event: IStrategyTickResult): Promise<any>;
|
|
25272
|
+
/**
|
|
25273
|
+
* Handles signal events from live trading only with error capture.
|
|
25274
|
+
*
|
|
25275
|
+
* Wraps the user's signalLive() method to catch and log any errors.
|
|
25276
|
+
* Called every tick in live mode.
|
|
25277
|
+
*
|
|
25278
|
+
* @param event - Signal state result from live trading
|
|
25279
|
+
* @returns Promise resolving to user's signalLive() result or null on error
|
|
25280
|
+
*/
|
|
25281
|
+
signalLive(event: IStrategyTickResult): Promise<any>;
|
|
25282
|
+
/**
|
|
25283
|
+
* Handles signal events from backtest only with error capture.
|
|
25284
|
+
*
|
|
25285
|
+
* Wraps the user's signalBacktest() method to catch and log any errors.
|
|
25286
|
+
* Called every candle in backtest mode.
|
|
25287
|
+
*
|
|
25288
|
+
* @param event - Signal state result from backtest
|
|
25289
|
+
* @returns Promise resolving to user's signalBacktest() result or null on error
|
|
25290
|
+
*/
|
|
25291
|
+
signalBacktest(event: IStrategyTickResult): Promise<any>;
|
|
25292
|
+
/**
|
|
25293
|
+
* Handles breakeven events with error capture.
|
|
25294
|
+
*
|
|
25295
|
+
* Wraps the user's breakevenAvailable() method to catch and log any errors.
|
|
25296
|
+
* Called once per signal when stop-loss is moved to entry price.
|
|
25297
|
+
*
|
|
25298
|
+
* @param event - Breakeven milestone data with signal info, current price, timestamp
|
|
25299
|
+
* @returns Promise resolving to user's breakevenAvailable() result or null on error
|
|
25300
|
+
*/
|
|
25301
|
+
breakevenAvailable(event: BreakevenContract): Promise<any>;
|
|
25302
|
+
/**
|
|
25303
|
+
* Handles partial profit level events with error capture.
|
|
25304
|
+
*
|
|
25305
|
+
* Wraps the user's partialProfitAvailable() method to catch and log any errors.
|
|
25306
|
+
* Called once per profit level per signal (10%, 20%, 30%, etc).
|
|
25307
|
+
*
|
|
25308
|
+
* @param event - Profit milestone data with signal info, level, price, timestamp
|
|
25309
|
+
* @returns Promise resolving to user's partialProfitAvailable() result or null on error
|
|
25310
|
+
*/
|
|
25311
|
+
partialProfitAvailable(event: PartialProfitContract): Promise<any>;
|
|
25312
|
+
/**
|
|
25313
|
+
* Handles partial loss level events with error capture.
|
|
25314
|
+
*
|
|
25315
|
+
* Wraps the user's partialLossAvailable() method to catch and log any errors.
|
|
25316
|
+
* Called once per loss level per signal (-10%, -20%, -30%, etc).
|
|
25317
|
+
*
|
|
25318
|
+
* @param event - Loss milestone data with signal info, level, price, timestamp
|
|
25319
|
+
* @returns Promise resolving to user's partialLossAvailable() result or null on error
|
|
25320
|
+
*/
|
|
25321
|
+
partialLossAvailable(event: PartialLossContract): Promise<any>;
|
|
25322
|
+
/**
|
|
25323
|
+
* Handles scheduled ping events with error capture.
|
|
25324
|
+
*
|
|
25325
|
+
* Wraps the user's pingScheduled() method to catch and log any errors.
|
|
25326
|
+
* Called every minute while a scheduled signal is waiting for activation.
|
|
25327
|
+
*
|
|
25328
|
+
* @param event - Scheduled signal monitoring data with symbol, strategy info, signal data, timestamp
|
|
25329
|
+
* @returns Promise resolving to user's pingScheduled() result or null on error
|
|
25330
|
+
*/
|
|
25331
|
+
pingScheduled(event: SchedulePingContract): Promise<any>;
|
|
25332
|
+
/**
|
|
25333
|
+
* Handles active ping events with error capture.
|
|
25334
|
+
*
|
|
25335
|
+
* Wraps the user's pingActive() method to catch and log any errors.
|
|
25336
|
+
* Called every minute while a pending signal is active (position open).
|
|
25337
|
+
*
|
|
25338
|
+
* @param event - Active pending signal monitoring data with symbol, strategy info, signal data, timestamp
|
|
25339
|
+
* @returns Promise resolving to user's pingActive() result or null on error
|
|
25340
|
+
*/
|
|
25341
|
+
pingActive(event: ActivePingContract): Promise<any>;
|
|
25342
|
+
/**
|
|
25343
|
+
* Handles risk rejection events with error capture.
|
|
25344
|
+
*
|
|
25345
|
+
* Wraps the user's riskRejection() method to catch and log any errors.
|
|
25346
|
+
* Called only when signal is rejected by risk management validation.
|
|
25347
|
+
*
|
|
25348
|
+
* @param event - Risk rejection data with symbol, pending signal, rejection reason, timestamp
|
|
25349
|
+
* @returns Promise resolving to user's riskRejection() result or null on error
|
|
25350
|
+
*/
|
|
25351
|
+
riskRejection(event: RiskContract): Promise<any>;
|
|
25352
|
+
/**
|
|
25353
|
+
* Gate for position open/close via limit order.
|
|
25354
|
+
* NOT wrapped in trycatch — exceptions propagate to CREATE_SYNC_FN.
|
|
25355
|
+
*
|
|
25356
|
+
* @param event - Sync event with action "signal-open" or "signal-close"
|
|
25357
|
+
*/
|
|
25358
|
+
signalSync(event: SignalSyncContract): Promise<void>;
|
|
25359
|
+
/**
|
|
25360
|
+
* Cleans up resources with error capture.
|
|
25361
|
+
*
|
|
25362
|
+
* Wraps the user's dispose() method to catch and log any errors.
|
|
25363
|
+
* Called once when strategy execution ends.
|
|
25364
|
+
*
|
|
25365
|
+
* @returns Promise resolving to user's dispose() result or null on error
|
|
25366
|
+
*/
|
|
25367
|
+
dispose(): Promise<any>;
|
|
25368
|
+
/**
|
|
25369
|
+
* Creates a new ActionProxy instance wrapping a user-provided action handler.
|
|
25370
|
+
*
|
|
25371
|
+
* Factory method enforcing the private constructor pattern.
|
|
25372
|
+
* Wraps all methods of the provided instance with error capture.
|
|
24584
25373
|
*
|
|
24585
|
-
* @param
|
|
24586
|
-
* @
|
|
24587
|
-
*
|
|
25374
|
+
* @param instance - Partial action implementation to wrap
|
|
25375
|
+
* @returns New ActionProxy instance with error-safe method wrappers
|
|
25376
|
+
*
|
|
25377
|
+
* @example
|
|
25378
|
+
* ```typescript
|
|
25379
|
+
* const userAction = {
|
|
25380
|
+
* signal: async (event) => {
|
|
25381
|
+
* console.log('Signal received:', event);
|
|
25382
|
+
* },
|
|
25383
|
+
* dispose: async () => {
|
|
25384
|
+
* console.log('Cleanup complete');
|
|
25385
|
+
* }
|
|
25386
|
+
* };
|
|
25387
|
+
*
|
|
25388
|
+
* const proxy = ActionProxy.fromInstance(userAction);
|
|
25389
|
+
* ```
|
|
24588
25390
|
*/
|
|
24589
|
-
|
|
24590
|
-
sizingName: SizingName;
|
|
24591
|
-
}) => Promise<number>;
|
|
25391
|
+
static fromInstance(instance: Partial<IPublicAction>, params: IActionParams): ActionProxy;
|
|
24592
25392
|
}
|
|
24593
25393
|
|
|
24594
25394
|
/**
|
|
@@ -24748,6 +25548,7 @@ type TAction = {
|
|
|
24748
25548
|
declare class ActionConnectionService implements TAction {
|
|
24749
25549
|
private readonly loggerService;
|
|
24750
25550
|
private readonly actionSchemaService;
|
|
25551
|
+
private readonly strategyCoreService;
|
|
24751
25552
|
/**
|
|
24752
25553
|
* Retrieves memoized ClientAction instance for given action name, strategy, exchange, frame and backtest mode.
|
|
24753
25554
|
*
|
|
@@ -25933,6 +26734,96 @@ declare class StrategyCoreService implements TStrategy {
|
|
|
25933
26734
|
exchangeName: ExchangeName;
|
|
25934
26735
|
frameName: FrameName;
|
|
25935
26736
|
}) => Promise<number | null>;
|
|
26737
|
+
/**
|
|
26738
|
+
* Returns the number of minutes elapsed since the highest profit price was recorded.
|
|
26739
|
+
*
|
|
26740
|
+
* Alias for getPositionDrawdownMinutes — measures how long the position has been
|
|
26741
|
+
* pulling back from its peak profit level.
|
|
26742
|
+
*
|
|
26743
|
+
* Validates strategy existence and delegates to connection service.
|
|
26744
|
+
* Returns null if no pending signal exists.
|
|
26745
|
+
*
|
|
26746
|
+
* @param backtest - Whether running in backtest mode
|
|
26747
|
+
* @param symbol - Trading pair symbol
|
|
26748
|
+
* @param context - Execution context with strategyName, exchangeName, frameName
|
|
26749
|
+
* @returns Promise resolving to minutes since last profit peak or null
|
|
26750
|
+
*/
|
|
26751
|
+
getPositionHighestProfitMinutes: (backtest: boolean, symbol: string, context: {
|
|
26752
|
+
strategyName: StrategyName;
|
|
26753
|
+
exchangeName: ExchangeName;
|
|
26754
|
+
frameName: FrameName;
|
|
26755
|
+
}) => Promise<number | null>;
|
|
26756
|
+
/**
|
|
26757
|
+
* Returns the number of minutes elapsed since the worst loss price was recorded.
|
|
26758
|
+
*
|
|
26759
|
+
* Measures how long ago the deepest drawdown point occurred.
|
|
26760
|
+
* Zero when called at the exact moment the trough was set.
|
|
26761
|
+
*
|
|
26762
|
+
* Validates strategy existence and delegates to connection service.
|
|
26763
|
+
* Returns null if no pending signal exists.
|
|
26764
|
+
*
|
|
26765
|
+
* @param backtest - Whether running in backtest mode
|
|
26766
|
+
* @param symbol - Trading pair symbol
|
|
26767
|
+
* @param context - Execution context with strategyName, exchangeName, frameName
|
|
26768
|
+
* @returns Promise resolving to minutes since last drawdown trough or null
|
|
26769
|
+
*/
|
|
26770
|
+
getPositionMaxDrawdownMinutes: (backtest: boolean, symbol: string, context: {
|
|
26771
|
+
strategyName: StrategyName;
|
|
26772
|
+
exchangeName: ExchangeName;
|
|
26773
|
+
frameName: FrameName;
|
|
26774
|
+
}) => Promise<number | null>;
|
|
26775
|
+
/**
|
|
26776
|
+
* Returns the worst price reached in the loss direction during this position's life.
|
|
26777
|
+
*
|
|
26778
|
+
* @param backtest - Whether running in backtest mode
|
|
26779
|
+
* @param symbol - Trading pair symbol
|
|
26780
|
+
* @param context - Execution context with strategyName, exchangeName, frameName
|
|
26781
|
+
* @returns Promise resolving to price or null
|
|
26782
|
+
*/
|
|
26783
|
+
getPositionMaxDrawdownPrice: (backtest: boolean, symbol: string, context: {
|
|
26784
|
+
strategyName: StrategyName;
|
|
26785
|
+
exchangeName: ExchangeName;
|
|
26786
|
+
frameName: FrameName;
|
|
26787
|
+
}) => Promise<number | null>;
|
|
26788
|
+
/**
|
|
26789
|
+
* Returns the timestamp when the worst loss price was recorded during this position's life.
|
|
26790
|
+
*
|
|
26791
|
+
* @param backtest - Whether running in backtest mode
|
|
26792
|
+
* @param symbol - Trading pair symbol
|
|
26793
|
+
* @param context - Execution context with strategyName, exchangeName, frameName
|
|
26794
|
+
* @returns Promise resolving to timestamp in milliseconds or null
|
|
26795
|
+
*/
|
|
26796
|
+
getPositionMaxDrawdownTimestamp: (backtest: boolean, symbol: string, context: {
|
|
26797
|
+
strategyName: StrategyName;
|
|
26798
|
+
exchangeName: ExchangeName;
|
|
26799
|
+
frameName: FrameName;
|
|
26800
|
+
}) => Promise<number | null>;
|
|
26801
|
+
/**
|
|
26802
|
+
* Returns the PnL percentage at the moment the worst loss price was recorded during this position's life.
|
|
26803
|
+
*
|
|
26804
|
+
* @param backtest - Whether running in backtest mode
|
|
26805
|
+
* @param symbol - Trading pair symbol
|
|
26806
|
+
* @param context - Execution context with strategyName, exchangeName, frameName
|
|
26807
|
+
* @returns Promise resolving to PnL percentage or null
|
|
26808
|
+
*/
|
|
26809
|
+
getPositionMaxDrawdownPnlPercentage: (backtest: boolean, symbol: string, context: {
|
|
26810
|
+
strategyName: StrategyName;
|
|
26811
|
+
exchangeName: ExchangeName;
|
|
26812
|
+
frameName: FrameName;
|
|
26813
|
+
}) => Promise<number | null>;
|
|
26814
|
+
/**
|
|
26815
|
+
* Returns the PnL cost (in quote currency) at the moment the worst loss price was recorded during this position's life.
|
|
26816
|
+
*
|
|
26817
|
+
* @param backtest - Whether running in backtest mode
|
|
26818
|
+
* @param symbol - Trading pair symbol
|
|
26819
|
+
* @param context - Execution context with strategyName, exchangeName, frameName
|
|
26820
|
+
* @returns Promise resolving to PnL cost or null
|
|
26821
|
+
*/
|
|
26822
|
+
getPositionMaxDrawdownPnlCost: (backtest: boolean, symbol: string, context: {
|
|
26823
|
+
strategyName: StrategyName;
|
|
26824
|
+
exchangeName: ExchangeName;
|
|
26825
|
+
frameName: FrameName;
|
|
26826
|
+
}) => Promise<number | null>;
|
|
25936
26827
|
}
|
|
25937
26828
|
|
|
25938
26829
|
/**
|
|
@@ -26081,6 +26972,188 @@ declare class RiskGlobalService implements TRisk {
|
|
|
26081
26972
|
}) => Promise<void>;
|
|
26082
26973
|
}
|
|
26083
26974
|
|
|
26975
|
+
/**
|
|
26976
|
+
* Private service for backtest orchestration using async generators.
|
|
26977
|
+
*
|
|
26978
|
+
* Flow:
|
|
26979
|
+
* 1. Get timeframes from frame service
|
|
26980
|
+
* 2. Iterate through timeframes calling tick()
|
|
26981
|
+
* 3. When signal opens: fetch candles and call backtest()
|
|
26982
|
+
* 4. Skip timeframes until signal closes
|
|
26983
|
+
* 5. Yield closed result and continue
|
|
26984
|
+
*
|
|
26985
|
+
* Memory efficient: streams results without array accumulation.
|
|
26986
|
+
* Supports early termination via break in consumer.
|
|
26987
|
+
*/
|
|
26988
|
+
declare class BacktestLogicPrivateService {
|
|
26989
|
+
readonly loggerService: {
|
|
26990
|
+
readonly methodContextService: {
|
|
26991
|
+
readonly context: IMethodContext;
|
|
26992
|
+
};
|
|
26993
|
+
readonly executionContextService: {
|
|
26994
|
+
readonly context: IExecutionContext;
|
|
26995
|
+
};
|
|
26996
|
+
_commonLogger: ILogger;
|
|
26997
|
+
readonly _methodContext: {};
|
|
26998
|
+
readonly _executionContext: {};
|
|
26999
|
+
log: (topic: string, ...args: any[]) => Promise<void>;
|
|
27000
|
+
debug: (topic: string, ...args: any[]) => Promise<void>;
|
|
27001
|
+
info: (topic: string, ...args: any[]) => Promise<void>;
|
|
27002
|
+
warn: (topic: string, ...args: any[]) => Promise<void>;
|
|
27003
|
+
setLogger: (logger: ILogger) => void;
|
|
27004
|
+
};
|
|
27005
|
+
readonly strategyCoreService: StrategyCoreService;
|
|
27006
|
+
readonly exchangeCoreService: ExchangeCoreService;
|
|
27007
|
+
readonly frameCoreService: FrameCoreService;
|
|
27008
|
+
readonly methodContextService: {
|
|
27009
|
+
readonly context: IMethodContext;
|
|
27010
|
+
};
|
|
27011
|
+
readonly actionCoreService: ActionCoreService;
|
|
27012
|
+
/**
|
|
27013
|
+
* Runs backtest for a symbol, streaming closed signals as async generator.
|
|
27014
|
+
*
|
|
27015
|
+
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
27016
|
+
* @yields Closed signal results with PNL
|
|
27017
|
+
*
|
|
27018
|
+
* @example
|
|
27019
|
+
* ```typescript
|
|
27020
|
+
* for await (const result of backtestLogic.run("BTCUSDT")) {
|
|
27021
|
+
* console.log(result.closeReason, result.pnl.pnlPercentage);
|
|
27022
|
+
* if (result.pnl.pnlPercentage < -10) break; // Early termination
|
|
27023
|
+
* }
|
|
27024
|
+
* ```
|
|
27025
|
+
*/
|
|
27026
|
+
run(symbol: string): AsyncGenerator<IStrategyTickResultScheduled | IStrategyTickResultOpened | IStrategyTickResultClosed | IStrategyTickResultCancelled, void, any>;
|
|
27027
|
+
}
|
|
27028
|
+
|
|
27029
|
+
/**
|
|
27030
|
+
* Type definition for public BacktestLogic service.
|
|
27031
|
+
* Omits private dependencies from BacktestLogicPrivateService.
|
|
27032
|
+
*/
|
|
27033
|
+
type IBacktestLogicPrivateService = Omit<BacktestLogicPrivateService, keyof {
|
|
27034
|
+
loggerService: never;
|
|
27035
|
+
strategyCoreService: never;
|
|
27036
|
+
exchangeCoreService: never;
|
|
27037
|
+
frameCoreService: never;
|
|
27038
|
+
actionCoreService: never;
|
|
27039
|
+
methodContextService: never;
|
|
27040
|
+
}>;
|
|
27041
|
+
/**
|
|
27042
|
+
* Type definition for BacktestLogicPublicService.
|
|
27043
|
+
* Maps all keys of IBacktestLogicPrivateService to any type.
|
|
27044
|
+
*/
|
|
27045
|
+
type TBacktestLogicPrivateService = {
|
|
27046
|
+
[key in keyof IBacktestLogicPrivateService]: any;
|
|
27047
|
+
};
|
|
27048
|
+
/**
|
|
27049
|
+
* Public service for backtest orchestration with context management.
|
|
27050
|
+
*
|
|
27051
|
+
* Wraps BacktestLogicPrivateService with MethodContextService to provide
|
|
27052
|
+
* implicit context propagation for strategyName, exchangeName, and frameName.
|
|
27053
|
+
*
|
|
27054
|
+
* This allows getCandles(), getSignal(), and other functions to work without
|
|
27055
|
+
* explicit context parameters.
|
|
27056
|
+
*
|
|
27057
|
+
* @example
|
|
27058
|
+
* ```typescript
|
|
27059
|
+
* const backtestLogicPublicService = inject(TYPES.backtestLogicPublicService);
|
|
27060
|
+
*
|
|
27061
|
+
* for await (const result of backtestLogicPublicService.run("BTCUSDT", {
|
|
27062
|
+
* strategyName: "my-strategy",
|
|
27063
|
+
* exchangeName: "my-exchange",
|
|
27064
|
+
* frameName: "1d-backtest",
|
|
27065
|
+
* })) {
|
|
27066
|
+
* if (result.action === "closed") {
|
|
27067
|
+
* console.log("PNL:", result.pnl.profit);
|
|
27068
|
+
* }
|
|
27069
|
+
* }
|
|
27070
|
+
* ```
|
|
27071
|
+
*/
|
|
27072
|
+
declare class BacktestLogicPublicService implements TBacktestLogicPrivateService {
|
|
27073
|
+
private readonly loggerService;
|
|
27074
|
+
private readonly backtestLogicPrivateService;
|
|
27075
|
+
/**
|
|
27076
|
+
* Runs backtest for a symbol with context propagation.
|
|
27077
|
+
*
|
|
27078
|
+
* Streams closed signals as async generator. Context is automatically
|
|
27079
|
+
* injected into all framework functions called during iteration.
|
|
27080
|
+
*
|
|
27081
|
+
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
27082
|
+
* @param context - Execution context with strategy, exchange, and frame names
|
|
27083
|
+
* @returns Async generator yielding closed signals with PNL
|
|
27084
|
+
*/
|
|
27085
|
+
run: (symbol: string, context: {
|
|
27086
|
+
strategyName: StrategyName;
|
|
27087
|
+
exchangeName: ExchangeName;
|
|
27088
|
+
frameName: FrameName;
|
|
27089
|
+
}) => AsyncGenerator<IStrategyTickResultScheduled | IStrategyTickResultOpened | IStrategyTickResultClosed | IStrategyTickResultCancelled, void, any>;
|
|
27090
|
+
}
|
|
27091
|
+
|
|
27092
|
+
/**
|
|
27093
|
+
* Service for managing walker schema registry.
|
|
27094
|
+
*
|
|
27095
|
+
* Uses ToolRegistry from functools-kit for type-safe schema storage.
|
|
27096
|
+
* Walkers are registered via addWalker() and retrieved by name.
|
|
27097
|
+
*/
|
|
27098
|
+
declare class WalkerSchemaService {
|
|
27099
|
+
readonly loggerService: {
|
|
27100
|
+
readonly methodContextService: {
|
|
27101
|
+
readonly context: IMethodContext;
|
|
27102
|
+
};
|
|
27103
|
+
readonly executionContextService: {
|
|
27104
|
+
readonly context: IExecutionContext;
|
|
27105
|
+
};
|
|
27106
|
+
_commonLogger: ILogger;
|
|
27107
|
+
readonly _methodContext: {};
|
|
27108
|
+
readonly _executionContext: {};
|
|
27109
|
+
log: (topic: string, ...args: any[]) => Promise<void>;
|
|
27110
|
+
debug: (topic: string, ...args: any[]) => Promise<void>;
|
|
27111
|
+
info: (topic: string, ...args: any[]) => Promise<void>;
|
|
27112
|
+
warn: (topic: string, ...args: any[]) => Promise<void>;
|
|
27113
|
+
setLogger: (logger: ILogger) => void;
|
|
27114
|
+
};
|
|
27115
|
+
private _registry;
|
|
27116
|
+
/**
|
|
27117
|
+
* Registers a new walker schema.
|
|
27118
|
+
*
|
|
27119
|
+
* @param key - Unique walker name
|
|
27120
|
+
* @param value - Walker schema configuration
|
|
27121
|
+
* @throws Error if walker name already exists
|
|
27122
|
+
*/
|
|
27123
|
+
register: (key: WalkerName, value: IWalkerSchema) => void;
|
|
27124
|
+
/**
|
|
27125
|
+
* Validates walker schema structure for required properties.
|
|
27126
|
+
*
|
|
27127
|
+
* Performs shallow validation to ensure all required properties exist
|
|
27128
|
+
* and have correct types before registration in the registry.
|
|
27129
|
+
*
|
|
27130
|
+
* @param walkerSchema - Walker schema to validate
|
|
27131
|
+
* @throws Error if walkerName is missing or not a string
|
|
27132
|
+
* @throws Error if exchangeName is missing or not a string
|
|
27133
|
+
* @throws Error if frameName is missing or not a string
|
|
27134
|
+
* @throws Error if strategies is missing or not an array
|
|
27135
|
+
* @throws Error if strategies array is empty
|
|
27136
|
+
*/
|
|
27137
|
+
private validateShallow;
|
|
27138
|
+
/**
|
|
27139
|
+
* Overrides an existing walker schema with partial updates.
|
|
27140
|
+
*
|
|
27141
|
+
* @param key - Walker name to override
|
|
27142
|
+
* @param value - Partial schema updates
|
|
27143
|
+
* @returns Updated walker schema
|
|
27144
|
+
* @throws Error if walker name doesn't exist
|
|
27145
|
+
*/
|
|
27146
|
+
override: (key: WalkerName, value: Partial<IWalkerSchema>) => IWalkerSchema;
|
|
27147
|
+
/**
|
|
27148
|
+
* Retrieves a walker schema by name.
|
|
27149
|
+
*
|
|
27150
|
+
* @param key - Walker name
|
|
27151
|
+
* @returns Walker schema configuration
|
|
27152
|
+
* @throws Error if walker name doesn't exist
|
|
27153
|
+
*/
|
|
27154
|
+
get: (key: WalkerName) => IWalkerSchema;
|
|
27155
|
+
}
|
|
27156
|
+
|
|
26084
27157
|
/**
|
|
26085
27158
|
* Private service for walker orchestration (strategy comparison).
|
|
26086
27159
|
*
|
|
@@ -26092,10 +27165,25 @@ declare class RiskGlobalService implements TRisk {
|
|
|
26092
27165
|
* Uses BacktestLogicPublicService internally for each strategy.
|
|
26093
27166
|
*/
|
|
26094
27167
|
declare class WalkerLogicPrivateService {
|
|
26095
|
-
|
|
26096
|
-
|
|
26097
|
-
|
|
26098
|
-
|
|
27168
|
+
readonly loggerService: {
|
|
27169
|
+
readonly methodContextService: {
|
|
27170
|
+
readonly context: IMethodContext;
|
|
27171
|
+
};
|
|
27172
|
+
readonly executionContextService: {
|
|
27173
|
+
readonly context: IExecutionContext;
|
|
27174
|
+
};
|
|
27175
|
+
_commonLogger: ILogger;
|
|
27176
|
+
readonly _methodContext: {};
|
|
27177
|
+
readonly _executionContext: {};
|
|
27178
|
+
log: (topic: string, ...args: any[]) => Promise<void>;
|
|
27179
|
+
debug: (topic: string, ...args: any[]) => Promise<void>;
|
|
27180
|
+
info: (topic: string, ...args: any[]) => Promise<void>;
|
|
27181
|
+
warn: (topic: string, ...args: any[]) => Promise<void>;
|
|
27182
|
+
setLogger: (logger: ILogger) => void;
|
|
27183
|
+
};
|
|
27184
|
+
readonly backtestLogicPublicService: BacktestLogicPublicService;
|
|
27185
|
+
readonly backtestMarkdownService: BacktestMarkdownService;
|
|
27186
|
+
readonly walkerSchemaService: WalkerSchemaService;
|
|
26099
27187
|
/**
|
|
26100
27188
|
* Runs walker comparison for a symbol.
|
|
26101
27189
|
*
|
|
@@ -26232,7 +27320,22 @@ declare class WalkerCommandService implements TWalkerLogicPublicService {
|
|
|
26232
27320
|
* Exchanges are registered via addExchange() and retrieved by name.
|
|
26233
27321
|
*/
|
|
26234
27322
|
declare class ExchangeSchemaService {
|
|
26235
|
-
readonly loggerService:
|
|
27323
|
+
readonly loggerService: {
|
|
27324
|
+
readonly methodContextService: {
|
|
27325
|
+
readonly context: IMethodContext;
|
|
27326
|
+
};
|
|
27327
|
+
readonly executionContextService: {
|
|
27328
|
+
readonly context: IExecutionContext;
|
|
27329
|
+
};
|
|
27330
|
+
_commonLogger: ILogger;
|
|
27331
|
+
readonly _methodContext: {};
|
|
27332
|
+
readonly _executionContext: {};
|
|
27333
|
+
log: (topic: string, ...args: any[]) => Promise<void>;
|
|
27334
|
+
debug: (topic: string, ...args: any[]) => Promise<void>;
|
|
27335
|
+
info: (topic: string, ...args: any[]) => Promise<void>;
|
|
27336
|
+
warn: (topic: string, ...args: any[]) => Promise<void>;
|
|
27337
|
+
setLogger: (logger: ILogger) => void;
|
|
27338
|
+
};
|
|
26236
27339
|
private _registry;
|
|
26237
27340
|
/**
|
|
26238
27341
|
* Registers a new exchange schema.
|
|
@@ -26281,7 +27384,22 @@ declare class ExchangeSchemaService {
|
|
|
26281
27384
|
* Frames are registered via addFrame() and retrieved by name.
|
|
26282
27385
|
*/
|
|
26283
27386
|
declare class FrameSchemaService {
|
|
26284
|
-
readonly loggerService:
|
|
27387
|
+
readonly loggerService: {
|
|
27388
|
+
readonly methodContextService: {
|
|
27389
|
+
readonly context: IMethodContext;
|
|
27390
|
+
};
|
|
27391
|
+
readonly executionContextService: {
|
|
27392
|
+
readonly context: IExecutionContext;
|
|
27393
|
+
};
|
|
27394
|
+
_commonLogger: ILogger;
|
|
27395
|
+
readonly _methodContext: {};
|
|
27396
|
+
readonly _executionContext: {};
|
|
27397
|
+
log: (topic: string, ...args: any[]) => Promise<void>;
|
|
27398
|
+
debug: (topic: string, ...args: any[]) => Promise<void>;
|
|
27399
|
+
info: (topic: string, ...args: any[]) => Promise<void>;
|
|
27400
|
+
warn: (topic: string, ...args: any[]) => Promise<void>;
|
|
27401
|
+
setLogger: (logger: ILogger) => void;
|
|
27402
|
+
};
|
|
26285
27403
|
private _registry;
|
|
26286
27404
|
/**
|
|
26287
27405
|
* Registers a new frame schema.
|
|
@@ -26329,7 +27447,22 @@ declare class FrameSchemaService {
|
|
|
26329
27447
|
* Sizing schemas are registered via addSizing() and retrieved by name.
|
|
26330
27448
|
*/
|
|
26331
27449
|
declare class SizingSchemaService {
|
|
26332
|
-
readonly loggerService:
|
|
27450
|
+
readonly loggerService: {
|
|
27451
|
+
readonly methodContextService: {
|
|
27452
|
+
readonly context: IMethodContext;
|
|
27453
|
+
};
|
|
27454
|
+
readonly executionContextService: {
|
|
27455
|
+
readonly context: IExecutionContext;
|
|
27456
|
+
};
|
|
27457
|
+
_commonLogger: ILogger;
|
|
27458
|
+
readonly _methodContext: {};
|
|
27459
|
+
readonly _executionContext: {};
|
|
27460
|
+
log: (topic: string, ...args: any[]) => Promise<void>;
|
|
27461
|
+
debug: (topic: string, ...args: any[]) => Promise<void>;
|
|
27462
|
+
info: (topic: string, ...args: any[]) => Promise<void>;
|
|
27463
|
+
warn: (topic: string, ...args: any[]) => Promise<void>;
|
|
27464
|
+
setLogger: (logger: ILogger) => void;
|
|
27465
|
+
};
|
|
26333
27466
|
private _registry;
|
|
26334
27467
|
/**
|
|
26335
27468
|
* Registers a new sizing schema.
|
|
@@ -26369,52 +27502,6 @@ declare class SizingSchemaService {
|
|
|
26369
27502
|
get(key: SizingName): ISizingSchema;
|
|
26370
27503
|
}
|
|
26371
27504
|
|
|
26372
|
-
/**
|
|
26373
|
-
* Service for managing risk schema registry.
|
|
26374
|
-
*
|
|
26375
|
-
* Uses ToolRegistry from functools-kit for type-safe schema storage.
|
|
26376
|
-
* Risk profiles are registered via addRisk() and retrieved by name.
|
|
26377
|
-
*/
|
|
26378
|
-
declare class RiskSchemaService {
|
|
26379
|
-
readonly loggerService: LoggerService;
|
|
26380
|
-
private _registry;
|
|
26381
|
-
/**
|
|
26382
|
-
* Registers a new risk schema.
|
|
26383
|
-
*
|
|
26384
|
-
* @param key - Unique risk profile name
|
|
26385
|
-
* @param value - Risk schema configuration
|
|
26386
|
-
* @throws Error if risk name already exists
|
|
26387
|
-
*/
|
|
26388
|
-
register: (key: RiskName, value: IRiskSchema) => void;
|
|
26389
|
-
/**
|
|
26390
|
-
* Validates risk schema structure for required properties.
|
|
26391
|
-
*
|
|
26392
|
-
* Performs shallow validation to ensure all required properties exist
|
|
26393
|
-
* and have correct types before registration in the registry.
|
|
26394
|
-
*
|
|
26395
|
-
* @param riskSchema - Risk schema to validate
|
|
26396
|
-
* @throws Error if riskName is missing or not a string
|
|
26397
|
-
*/
|
|
26398
|
-
private validateShallow;
|
|
26399
|
-
/**
|
|
26400
|
-
* Overrides an existing risk schema with partial updates.
|
|
26401
|
-
*
|
|
26402
|
-
* @param key - Risk name to override
|
|
26403
|
-
* @param value - Partial schema updates
|
|
26404
|
-
* @returns Updated risk schema
|
|
26405
|
-
* @throws Error if risk name doesn't exist
|
|
26406
|
-
*/
|
|
26407
|
-
override: (key: RiskName, value: Partial<IRiskSchema>) => IRiskSchema;
|
|
26408
|
-
/**
|
|
26409
|
-
* Retrieves a risk schema by name.
|
|
26410
|
-
*
|
|
26411
|
-
* @param key - Risk name
|
|
26412
|
-
* @returns Risk schema configuration
|
|
26413
|
-
* @throws Error if risk name doesn't exist
|
|
26414
|
-
*/
|
|
26415
|
-
get: (key: RiskName) => IRiskSchema;
|
|
26416
|
-
}
|
|
26417
|
-
|
|
26418
27505
|
/**
|
|
26419
27506
|
* Service for managing action schema registry.
|
|
26420
27507
|
*
|
|
@@ -26449,7 +27536,22 @@ declare class RiskSchemaService {
|
|
|
26449
27536
|
* ```
|
|
26450
27537
|
*/
|
|
26451
27538
|
declare class ActionSchemaService {
|
|
26452
|
-
readonly loggerService:
|
|
27539
|
+
readonly loggerService: {
|
|
27540
|
+
readonly methodContextService: {
|
|
27541
|
+
readonly context: IMethodContext;
|
|
27542
|
+
};
|
|
27543
|
+
readonly executionContextService: {
|
|
27544
|
+
readonly context: IExecutionContext;
|
|
27545
|
+
};
|
|
27546
|
+
_commonLogger: ILogger;
|
|
27547
|
+
readonly _methodContext: {};
|
|
27548
|
+
readonly _executionContext: {};
|
|
27549
|
+
log: (topic: string, ...args: any[]) => Promise<void>;
|
|
27550
|
+
debug: (topic: string, ...args: any[]) => Promise<void>;
|
|
27551
|
+
info: (topic: string, ...args: any[]) => Promise<void>;
|
|
27552
|
+
warn: (topic: string, ...args: any[]) => Promise<void>;
|
|
27553
|
+
setLogger: (logger: ILogger) => void;
|
|
27554
|
+
};
|
|
26453
27555
|
private _registry;
|
|
26454
27556
|
/**
|
|
26455
27557
|
* Registers a new action schema.
|
|
@@ -26502,95 +27604,6 @@ declare class ActionSchemaService {
|
|
|
26502
27604
|
get: (key: ActionName) => IActionSchema;
|
|
26503
27605
|
}
|
|
26504
27606
|
|
|
26505
|
-
/**
|
|
26506
|
-
* Service for managing walker schema registry.
|
|
26507
|
-
*
|
|
26508
|
-
* Uses ToolRegistry from functools-kit for type-safe schema storage.
|
|
26509
|
-
* Walkers are registered via addWalker() and retrieved by name.
|
|
26510
|
-
*/
|
|
26511
|
-
declare class WalkerSchemaService {
|
|
26512
|
-
readonly loggerService: LoggerService;
|
|
26513
|
-
private _registry;
|
|
26514
|
-
/**
|
|
26515
|
-
* Registers a new walker schema.
|
|
26516
|
-
*
|
|
26517
|
-
* @param key - Unique walker name
|
|
26518
|
-
* @param value - Walker schema configuration
|
|
26519
|
-
* @throws Error if walker name already exists
|
|
26520
|
-
*/
|
|
26521
|
-
register: (key: WalkerName, value: IWalkerSchema) => void;
|
|
26522
|
-
/**
|
|
26523
|
-
* Validates walker schema structure for required properties.
|
|
26524
|
-
*
|
|
26525
|
-
* Performs shallow validation to ensure all required properties exist
|
|
26526
|
-
* and have correct types before registration in the registry.
|
|
26527
|
-
*
|
|
26528
|
-
* @param walkerSchema - Walker schema to validate
|
|
26529
|
-
* @throws Error if walkerName is missing or not a string
|
|
26530
|
-
* @throws Error if exchangeName is missing or not a string
|
|
26531
|
-
* @throws Error if frameName is missing or not a string
|
|
26532
|
-
* @throws Error if strategies is missing or not an array
|
|
26533
|
-
* @throws Error if strategies array is empty
|
|
26534
|
-
*/
|
|
26535
|
-
private validateShallow;
|
|
26536
|
-
/**
|
|
26537
|
-
* Overrides an existing walker schema with partial updates.
|
|
26538
|
-
*
|
|
26539
|
-
* @param key - Walker name to override
|
|
26540
|
-
* @param value - Partial schema updates
|
|
26541
|
-
* @returns Updated walker schema
|
|
26542
|
-
* @throws Error if walker name doesn't exist
|
|
26543
|
-
*/
|
|
26544
|
-
override: (key: WalkerName, value: Partial<IWalkerSchema>) => IWalkerSchema;
|
|
26545
|
-
/**
|
|
26546
|
-
* Retrieves a walker schema by name.
|
|
26547
|
-
*
|
|
26548
|
-
* @param key - Walker name
|
|
26549
|
-
* @returns Walker schema configuration
|
|
26550
|
-
* @throws Error if walker name doesn't exist
|
|
26551
|
-
*/
|
|
26552
|
-
get: (key: WalkerName) => IWalkerSchema;
|
|
26553
|
-
}
|
|
26554
|
-
|
|
26555
|
-
/**
|
|
26556
|
-
* Private service for backtest orchestration using async generators.
|
|
26557
|
-
*
|
|
26558
|
-
* Flow:
|
|
26559
|
-
* 1. Get timeframes from frame service
|
|
26560
|
-
* 2. Iterate through timeframes calling tick()
|
|
26561
|
-
* 3. When signal opens: fetch candles and call backtest()
|
|
26562
|
-
* 4. Skip timeframes until signal closes
|
|
26563
|
-
* 5. Yield closed result and continue
|
|
26564
|
-
*
|
|
26565
|
-
* Memory efficient: streams results without array accumulation.
|
|
26566
|
-
* Supports early termination via break in consumer.
|
|
26567
|
-
*/
|
|
26568
|
-
declare class BacktestLogicPrivateService {
|
|
26569
|
-
readonly loggerService: LoggerService;
|
|
26570
|
-
readonly strategyCoreService: StrategyCoreService;
|
|
26571
|
-
readonly exchangeCoreService: ExchangeCoreService;
|
|
26572
|
-
readonly frameCoreService: FrameCoreService;
|
|
26573
|
-
readonly methodContextService: {
|
|
26574
|
-
readonly context: IMethodContext;
|
|
26575
|
-
};
|
|
26576
|
-
readonly actionCoreService: ActionCoreService;
|
|
26577
|
-
/**
|
|
26578
|
-
* Runs backtest for a symbol, streaming closed signals as async generator.
|
|
26579
|
-
*
|
|
26580
|
-
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
26581
|
-
* @yields Closed signal results with PNL
|
|
26582
|
-
*
|
|
26583
|
-
* @example
|
|
26584
|
-
* ```typescript
|
|
26585
|
-
* for await (const result of backtestLogic.run("BTCUSDT")) {
|
|
26586
|
-
* console.log(result.closeReason, result.pnl.pnlPercentage);
|
|
26587
|
-
* if (result.pnl.pnlPercentage < -10) break; // Early termination
|
|
26588
|
-
* }
|
|
26589
|
-
* ```
|
|
26590
|
-
*/
|
|
26591
|
-
run(symbol: string): AsyncGenerator<IStrategyTickResultScheduled | IStrategyTickResultOpened | IStrategyTickResultClosed | IStrategyTickResultCancelled, void, any>;
|
|
26592
|
-
}
|
|
26593
|
-
|
|
26594
27607
|
/**
|
|
26595
27608
|
* Private service for live trading orchestration using async generators.
|
|
26596
27609
|
*
|
|
@@ -26636,69 +27649,6 @@ declare class LiveLogicPrivateService {
|
|
|
26636
27649
|
run(symbol: string): AsyncGenerator<IStrategyTickResultOpened | IStrategyTickResultClosed | IStrategyTickResultCancelled, void, unknown>;
|
|
26637
27650
|
}
|
|
26638
27651
|
|
|
26639
|
-
/**
|
|
26640
|
-
* Type definition for public BacktestLogic service.
|
|
26641
|
-
* Omits private dependencies from BacktestLogicPrivateService.
|
|
26642
|
-
*/
|
|
26643
|
-
type IBacktestLogicPrivateService = Omit<BacktestLogicPrivateService, keyof {
|
|
26644
|
-
loggerService: never;
|
|
26645
|
-
strategyCoreService: never;
|
|
26646
|
-
exchangeCoreService: never;
|
|
26647
|
-
frameCoreService: never;
|
|
26648
|
-
actionCoreService: never;
|
|
26649
|
-
methodContextService: never;
|
|
26650
|
-
}>;
|
|
26651
|
-
/**
|
|
26652
|
-
* Type definition for BacktestLogicPublicService.
|
|
26653
|
-
* Maps all keys of IBacktestLogicPrivateService to any type.
|
|
26654
|
-
*/
|
|
26655
|
-
type TBacktestLogicPrivateService = {
|
|
26656
|
-
[key in keyof IBacktestLogicPrivateService]: any;
|
|
26657
|
-
};
|
|
26658
|
-
/**
|
|
26659
|
-
* Public service for backtest orchestration with context management.
|
|
26660
|
-
*
|
|
26661
|
-
* Wraps BacktestLogicPrivateService with MethodContextService to provide
|
|
26662
|
-
* implicit context propagation for strategyName, exchangeName, and frameName.
|
|
26663
|
-
*
|
|
26664
|
-
* This allows getCandles(), getSignal(), and other functions to work without
|
|
26665
|
-
* explicit context parameters.
|
|
26666
|
-
*
|
|
26667
|
-
* @example
|
|
26668
|
-
* ```typescript
|
|
26669
|
-
* const backtestLogicPublicService = inject(TYPES.backtestLogicPublicService);
|
|
26670
|
-
*
|
|
26671
|
-
* for await (const result of backtestLogicPublicService.run("BTCUSDT", {
|
|
26672
|
-
* strategyName: "my-strategy",
|
|
26673
|
-
* exchangeName: "my-exchange",
|
|
26674
|
-
* frameName: "1d-backtest",
|
|
26675
|
-
* })) {
|
|
26676
|
-
* if (result.action === "closed") {
|
|
26677
|
-
* console.log("PNL:", result.pnl.profit);
|
|
26678
|
-
* }
|
|
26679
|
-
* }
|
|
26680
|
-
* ```
|
|
26681
|
-
*/
|
|
26682
|
-
declare class BacktestLogicPublicService implements TBacktestLogicPrivateService {
|
|
26683
|
-
private readonly loggerService;
|
|
26684
|
-
private readonly backtestLogicPrivateService;
|
|
26685
|
-
/**
|
|
26686
|
-
* Runs backtest for a symbol with context propagation.
|
|
26687
|
-
*
|
|
26688
|
-
* Streams closed signals as async generator. Context is automatically
|
|
26689
|
-
* injected into all framework functions called during iteration.
|
|
26690
|
-
*
|
|
26691
|
-
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
26692
|
-
* @param context - Execution context with strategy, exchange, and frame names
|
|
26693
|
-
* @returns Async generator yielding closed signals with PNL
|
|
26694
|
-
*/
|
|
26695
|
-
run: (symbol: string, context: {
|
|
26696
|
-
strategyName: StrategyName;
|
|
26697
|
-
exchangeName: ExchangeName;
|
|
26698
|
-
frameName: FrameName;
|
|
26699
|
-
}) => AsyncGenerator<IStrategyTickResultScheduled | IStrategyTickResultOpened | IStrategyTickResultClosed | IStrategyTickResultCancelled, void, any>;
|
|
26700
|
-
}
|
|
26701
|
-
|
|
26702
27652
|
/**
|
|
26703
27653
|
* Type definition for public LiveLogic service.
|
|
26704
27654
|
* Omits private dependencies from LiveLogicPrivateService.
|
|
@@ -27582,7 +28532,7 @@ declare class ColumnValidationService {
|
|
|
27582
28532
|
* Features:
|
|
27583
28533
|
* - Listens to backtest signal events via signalBacktestEmitter
|
|
27584
28534
|
* - Logs all tick event types with full signal details
|
|
27585
|
-
* - Stores events in
|
|
28535
|
+
* - Stores events in ReportWriter.writeData() for persistence
|
|
27586
28536
|
* - Protected against multiple subscriptions using singleshot
|
|
27587
28537
|
*
|
|
27588
28538
|
* @example
|
|
@@ -27654,7 +28604,7 @@ declare class BacktestReportService {
|
|
|
27654
28604
|
* Features:
|
|
27655
28605
|
* - Listens to live signal events via signalLiveEmitter
|
|
27656
28606
|
* - Logs all tick event types with full signal details
|
|
27657
|
-
* - Stores events in
|
|
28607
|
+
* - Stores events in ReportWriter.writeData() for persistence
|
|
27658
28608
|
* - Protected against multiple subscriptions using singleshot
|
|
27659
28609
|
*
|
|
27660
28610
|
* @example
|
|
@@ -27727,7 +28677,7 @@ declare class LiveReportService {
|
|
|
27727
28677
|
* - Listens to signal events via signalEmitter
|
|
27728
28678
|
* - Logs scheduled, opened (from scheduled), and cancelled events
|
|
27729
28679
|
* - Calculates duration between scheduling and execution/cancellation
|
|
27730
|
-
* - Stores events in
|
|
28680
|
+
* - Stores events in ReportWriter.writeData() for schedule tracking
|
|
27731
28681
|
* - Protected against multiple subscriptions using singleshot
|
|
27732
28682
|
*
|
|
27733
28683
|
* @example
|
|
@@ -27799,7 +28749,7 @@ declare class ScheduleReportService {
|
|
|
27799
28749
|
* Features:
|
|
27800
28750
|
* - Listens to performance events via performanceEmitter
|
|
27801
28751
|
* - Logs all timing metrics with duration and metadata
|
|
27802
|
-
* - Stores events in
|
|
28752
|
+
* - Stores events in ReportWriter.writeData() for performance analysis
|
|
27803
28753
|
* - Protected against multiple subscriptions using singleshot
|
|
27804
28754
|
*
|
|
27805
28755
|
* @example
|
|
@@ -27871,7 +28821,7 @@ declare class PerformanceReportService {
|
|
|
27871
28821
|
* - Listens to walker events via walkerEmitter
|
|
27872
28822
|
* - Logs each strategy test result with metrics and statistics
|
|
27873
28823
|
* - Tracks best strategy and optimization progress
|
|
27874
|
-
* - Stores events in
|
|
28824
|
+
* - Stores events in ReportWriter.writeData() for optimization analysis
|
|
27875
28825
|
* - Protected against multiple subscriptions using singleshot
|
|
27876
28826
|
*
|
|
27877
28827
|
* @example
|
|
@@ -27942,7 +28892,7 @@ declare class WalkerReportService {
|
|
|
27942
28892
|
* Features:
|
|
27943
28893
|
* - Listens to signal events via signalEmitter
|
|
27944
28894
|
* - Logs only closed signals with PNL data
|
|
27945
|
-
* - Stores events in
|
|
28895
|
+
* - Stores events in ReportWriter.writeData() for heatmap generation
|
|
27946
28896
|
* - Protected against multiple subscriptions using singleshot
|
|
27947
28897
|
*
|
|
27948
28898
|
* @example
|
|
@@ -28015,7 +28965,7 @@ declare class HeatReportService {
|
|
|
28015
28965
|
* - Listens to partial profit events via partialProfitSubject
|
|
28016
28966
|
* - Listens to partial loss events via partialLossSubject
|
|
28017
28967
|
* - Logs all partial exit events with level and price information
|
|
28018
|
-
* - Stores events in
|
|
28968
|
+
* - Stores events in ReportWriter.writeData() for persistence
|
|
28019
28969
|
* - Protected against multiple subscriptions using singleshot
|
|
28020
28970
|
*
|
|
28021
28971
|
* @example
|
|
@@ -28094,7 +29044,7 @@ declare class PartialReportService {
|
|
|
28094
29044
|
* Features:
|
|
28095
29045
|
* - Listens to breakeven events via breakevenSubject
|
|
28096
29046
|
* - Logs all breakeven achievements with full signal details
|
|
28097
|
-
* - Stores events in
|
|
29047
|
+
* - Stores events in ReportWriter.writeData() for persistence
|
|
28098
29048
|
* - Protected against multiple subscriptions using singleshot
|
|
28099
29049
|
*
|
|
28100
29050
|
* @example
|
|
@@ -28165,7 +29115,7 @@ declare class BreakevenReportService {
|
|
|
28165
29115
|
* Features:
|
|
28166
29116
|
* - Listens to risk rejection events via riskSubject
|
|
28167
29117
|
* - Logs all rejected signals with reason and pending signal details
|
|
28168
|
-
* - Stores events in
|
|
29118
|
+
* - Stores events in ReportWriter.writeData() for risk tracking
|
|
28169
29119
|
* - Protected against multiple subscriptions using singleshot
|
|
28170
29120
|
*
|
|
28171
29121
|
* @example
|
|
@@ -28239,14 +29189,29 @@ declare class RiskReportService {
|
|
|
28239
29189
|
*
|
|
28240
29190
|
* Lifecycle:
|
|
28241
29191
|
* - Call subscribe() to enable event logging
|
|
28242
|
-
* - Events are written via
|
|
29192
|
+
* - Events are written via ReportWriter.writeData() with "strategy" category
|
|
28243
29193
|
* - Call unsubscribe() to disable event logging
|
|
28244
29194
|
*
|
|
28245
29195
|
* @see StrategyMarkdownService for in-memory event accumulation and markdown report generation
|
|
28246
29196
|
* @see Report for the underlying persistence mechanism
|
|
28247
29197
|
*/
|
|
28248
29198
|
declare class StrategyReportService {
|
|
28249
|
-
readonly loggerService:
|
|
29199
|
+
readonly loggerService: {
|
|
29200
|
+
readonly methodContextService: {
|
|
29201
|
+
readonly context: IMethodContext;
|
|
29202
|
+
};
|
|
29203
|
+
readonly executionContextService: {
|
|
29204
|
+
readonly context: IExecutionContext;
|
|
29205
|
+
};
|
|
29206
|
+
_commonLogger: ILogger;
|
|
29207
|
+
readonly _methodContext: {};
|
|
29208
|
+
readonly _executionContext: {};
|
|
29209
|
+
log: (topic: string, ...args: any[]) => Promise<void>;
|
|
29210
|
+
debug: (topic: string, ...args: any[]) => Promise<void>;
|
|
29211
|
+
info: (topic: string, ...args: any[]) => Promise<void>;
|
|
29212
|
+
warn: (topic: string, ...args: any[]) => Promise<void>;
|
|
29213
|
+
setLogger: (logger: ILogger) => void;
|
|
29214
|
+
};
|
|
28250
29215
|
/**
|
|
28251
29216
|
* Logs a cancel-scheduled event when a scheduled signal is cancelled.
|
|
28252
29217
|
*/
|
|
@@ -28347,7 +29312,7 @@ declare class StrategyReportService {
|
|
|
28347
29312
|
* - Listens to sync events via syncSubject
|
|
28348
29313
|
* - Logs signal-open events (scheduled limit order filled) with full signal details
|
|
28349
29314
|
* - Logs signal-close events (position exited) with PNL and close reason
|
|
28350
|
-
* - Stores events in
|
|
29315
|
+
* - Stores events in ReportWriter.writeData() for persistence
|
|
28351
29316
|
* - Protected against multiple subscriptions using singleshot
|
|
28352
29317
|
*
|
|
28353
29318
|
* @example
|
|
@@ -28414,7 +29379,7 @@ declare class SyncReportService {
|
|
|
28414
29379
|
* Service for logging highest profit events to the JSONL report database.
|
|
28415
29380
|
*
|
|
28416
29381
|
* Listens to highestProfitSubject and writes each new price record to
|
|
28417
|
-
*
|
|
29382
|
+
* ReportWriter.writeData() for persistence and analytics.
|
|
28418
29383
|
*/
|
|
28419
29384
|
declare class HighestProfitReportService {
|
|
28420
29385
|
private readonly loggerService;
|
|
@@ -28422,7 +29387,7 @@ declare class HighestProfitReportService {
|
|
|
28422
29387
|
* Handles a single `HighestProfitContract` event emitted by `highestProfitSubject`.
|
|
28423
29388
|
*
|
|
28424
29389
|
* Writes a JSONL record to the `"highest_profit"` report database via
|
|
28425
|
-
* `
|
|
29390
|
+
* `ReportWriter.writeData`, capturing the full signal snapshot at the moment
|
|
28426
29391
|
* the new profit record was set:
|
|
28427
29392
|
* - `timestamp`, `symbol`, `strategyName`, `exchangeName`, `frameName`, `backtest`
|
|
28428
29393
|
* - `signalId`, `position`, `currentPrice`
|
|
@@ -28472,6 +29437,52 @@ declare class HighestProfitReportService {
|
|
|
28472
29437
|
unsubscribe: () => Promise<void>;
|
|
28473
29438
|
}
|
|
28474
29439
|
|
|
29440
|
+
/**
|
|
29441
|
+
* Service for logging max drawdown events to the JSONL report database.
|
|
29442
|
+
*
|
|
29443
|
+
* Listens to maxDrawdownSubject and writes each new drawdown record to
|
|
29444
|
+
* ReportWriter.writeData() for persistence and analytics.
|
|
29445
|
+
*/
|
|
29446
|
+
declare class MaxDrawdownReportService {
|
|
29447
|
+
private readonly loggerService;
|
|
29448
|
+
/**
|
|
29449
|
+
* Handles a single `MaxDrawdownContract` event emitted by `maxDrawdownSubject`.
|
|
29450
|
+
*
|
|
29451
|
+
* Writes a JSONL record to the `"max_drawdown"` report database via
|
|
29452
|
+
* `ReportWriter.writeData`, capturing the full signal snapshot at the moment
|
|
29453
|
+
* the new drawdown record was set:
|
|
29454
|
+
* - `timestamp`, `symbol`, `strategyName`, `exchangeName`, `frameName`, `backtest`
|
|
29455
|
+
* - `signalId`, `position`, `currentPrice`
|
|
29456
|
+
* - `priceOpen`, `priceTakeProfit`, `priceStopLoss` (effective values from the signal)
|
|
29457
|
+
*
|
|
29458
|
+
* `strategyName` and signal-level fields are sourced from `data.signal`
|
|
29459
|
+
* rather than the contract root.
|
|
29460
|
+
*
|
|
29461
|
+
* @param data - `MaxDrawdownContract` payload containing `symbol`,
|
|
29462
|
+
* `signal`, `currentPrice`, `backtest`, `timestamp`, `exchangeName`,
|
|
29463
|
+
* `frameName`
|
|
29464
|
+
*/
|
|
29465
|
+
private tick;
|
|
29466
|
+
/**
|
|
29467
|
+
* Subscribes to `maxDrawdownSubject` to start persisting drawdown records.
|
|
29468
|
+
* Protected against multiple subscriptions via `singleshot` — subsequent
|
|
29469
|
+
* calls return the same unsubscribe function without re-subscribing.
|
|
29470
|
+
*
|
|
29471
|
+
* The returned unsubscribe function clears the `singleshot` state and
|
|
29472
|
+
* detaches from `maxDrawdownSubject`.
|
|
29473
|
+
*
|
|
29474
|
+
* @returns Unsubscribe function; calling it tears down the subscription
|
|
29475
|
+
*/
|
|
29476
|
+
subscribe: (() => () => void) & functools_kit.ISingleshotClearable;
|
|
29477
|
+
/**
|
|
29478
|
+
* Detaches from `maxDrawdownSubject`, stopping further JSONL writes.
|
|
29479
|
+
*
|
|
29480
|
+
* Calls the unsubscribe closure returned by `subscribe()`.
|
|
29481
|
+
* If `subscribe()` was never called, does nothing.
|
|
29482
|
+
*/
|
|
29483
|
+
unsubscribe: () => Promise<void>;
|
|
29484
|
+
}
|
|
29485
|
+
|
|
28475
29486
|
declare const backtest: {
|
|
28476
29487
|
exchangeValidationService: ExchangeValidationService;
|
|
28477
29488
|
strategyValidationService: StrategyValidationService;
|
|
@@ -28494,6 +29505,7 @@ declare const backtest: {
|
|
|
28494
29505
|
strategyReportService: StrategyReportService;
|
|
28495
29506
|
syncReportService: SyncReportService;
|
|
28496
29507
|
highestProfitReportService: HighestProfitReportService;
|
|
29508
|
+
maxDrawdownReportService: MaxDrawdownReportService;
|
|
28497
29509
|
backtestMarkdownService: BacktestMarkdownService;
|
|
28498
29510
|
liveMarkdownService: LiveMarkdownService;
|
|
28499
29511
|
scheduleMarkdownService: ScheduleMarkdownService;
|
|
@@ -28506,6 +29518,7 @@ declare const backtest: {
|
|
|
28506
29518
|
strategyMarkdownService: StrategyMarkdownService;
|
|
28507
29519
|
syncMarkdownService: SyncMarkdownService;
|
|
28508
29520
|
highestProfitMarkdownService: HighestProfitMarkdownService;
|
|
29521
|
+
maxDrawdownMarkdownService: MaxDrawdownMarkdownService;
|
|
28509
29522
|
backtestLogicPublicService: BacktestLogicPublicService;
|
|
28510
29523
|
liveLogicPublicService: LiveLogicPublicService;
|
|
28511
29524
|
walkerLogicPublicService: WalkerLogicPublicService;
|
|
@@ -28521,6 +29534,28 @@ declare const backtest: {
|
|
|
28521
29534
|
breakevenGlobalService: BreakevenGlobalService;
|
|
28522
29535
|
timeMetaService: TimeMetaService;
|
|
28523
29536
|
priceMetaService: PriceMetaService;
|
|
29537
|
+
contextMetaService: {
|
|
29538
|
+
readonly loggerService: {
|
|
29539
|
+
readonly methodContextService: {
|
|
29540
|
+
readonly context: IMethodContext;
|
|
29541
|
+
};
|
|
29542
|
+
readonly executionContextService: {
|
|
29543
|
+
readonly context: IExecutionContext;
|
|
29544
|
+
};
|
|
29545
|
+
_commonLogger: ILogger;
|
|
29546
|
+
readonly _methodContext: {};
|
|
29547
|
+
readonly _executionContext: {};
|
|
29548
|
+
log: (topic: string, ...args: any[]) => Promise<void>;
|
|
29549
|
+
debug: (topic: string, ...args: any[]) => Promise<void>;
|
|
29550
|
+
info: (topic: string, ...args: any[]) => Promise<void>;
|
|
29551
|
+
warn: (topic: string, ...args: any[]) => Promise<void>;
|
|
29552
|
+
setLogger: (logger: ILogger) => void;
|
|
29553
|
+
};
|
|
29554
|
+
readonly executionContextService: {
|
|
29555
|
+
readonly context: IExecutionContext;
|
|
29556
|
+
};
|
|
29557
|
+
getContextTimestamp: () => number;
|
|
29558
|
+
};
|
|
28524
29559
|
exchangeCoreService: ExchangeCoreService;
|
|
28525
29560
|
strategyCoreService: StrategyCoreService;
|
|
28526
29561
|
actionCoreService: ActionCoreService;
|
|
@@ -28546,7 +29581,22 @@ declare const backtest: {
|
|
|
28546
29581
|
methodContextService: {
|
|
28547
29582
|
readonly context: IMethodContext;
|
|
28548
29583
|
};
|
|
28549
|
-
loggerService:
|
|
29584
|
+
loggerService: {
|
|
29585
|
+
readonly methodContextService: {
|
|
29586
|
+
readonly context: IMethodContext;
|
|
29587
|
+
};
|
|
29588
|
+
readonly executionContextService: {
|
|
29589
|
+
readonly context: IExecutionContext;
|
|
29590
|
+
};
|
|
29591
|
+
_commonLogger: ILogger;
|
|
29592
|
+
readonly _methodContext: {};
|
|
29593
|
+
readonly _executionContext: {};
|
|
29594
|
+
log: (topic: string, ...args: any[]) => Promise<void>;
|
|
29595
|
+
debug: (topic: string, ...args: any[]) => Promise<void>;
|
|
29596
|
+
info: (topic: string, ...args: any[]) => Promise<void>;
|
|
29597
|
+
warn: (topic: string, ...args: any[]) => Promise<void>;
|
|
29598
|
+
setLogger: (logger: ILogger) => void;
|
|
29599
|
+
};
|
|
28550
29600
|
};
|
|
28551
29601
|
|
|
28552
29602
|
interface Signal$2 extends ISignalDto {
|
|
@@ -28625,4 +29675,4 @@ declare const getTotalClosed: (signal: Signal) => {
|
|
|
28625
29675
|
remainingCostBasis: number;
|
|
28626
29676
|
};
|
|
28627
29677
|
|
|
28628
|
-
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, 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, getPositionHighestProfitPrice, getPositionHighestProfitTimestamp, getPositionInvestedCost, getPositionInvestedCount, getPositionLevels, 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, 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 };
|
|
29678
|
+
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 };
|