backtest-kit 2.2.1 → 2.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +32 -10
- package/build/index.cjs +1997 -178
- package/build/index.mjs +1996 -180
- package/package.json +2 -1
- package/types.d.ts +2039 -963
package/types.d.ts
CHANGED
|
@@ -1257,6 +1257,8 @@ interface IStrategyTickResultIdle {
|
|
|
1257
1257
|
currentPrice: number;
|
|
1258
1258
|
/** Whether this event is from backtest mode (true) or live mode (false) */
|
|
1259
1259
|
backtest: boolean;
|
|
1260
|
+
/** Unix timestamp in milliseconds when this tick result was created (from candle timestamp in backtest or execution context when in live) */
|
|
1261
|
+
createdAt: number;
|
|
1260
1262
|
}
|
|
1261
1263
|
/**
|
|
1262
1264
|
* Tick result: scheduled signal created, waiting for price to reach entry point.
|
|
@@ -1279,6 +1281,8 @@ interface IStrategyTickResultScheduled {
|
|
|
1279
1281
|
currentPrice: number;
|
|
1280
1282
|
/** Whether this event is from backtest mode (true) or live mode (false) */
|
|
1281
1283
|
backtest: boolean;
|
|
1284
|
+
/** Unix timestamp in milliseconds when this tick result was created (from candle timestamp in backtest or execution context when in live) */
|
|
1285
|
+
createdAt: number;
|
|
1282
1286
|
}
|
|
1283
1287
|
/**
|
|
1284
1288
|
* Tick result: scheduled signal is waiting for price to reach entry point.
|
|
@@ -1308,6 +1312,8 @@ interface IStrategyTickResultWaiting {
|
|
|
1308
1312
|
pnl: IStrategyPnL;
|
|
1309
1313
|
/** Whether this event is from backtest mode (true) or live mode (false) */
|
|
1310
1314
|
backtest: boolean;
|
|
1315
|
+
/** Unix timestamp in milliseconds when this tick result was created (from candle timestamp in backtest or execution context when in live) */
|
|
1316
|
+
createdAt: number;
|
|
1311
1317
|
}
|
|
1312
1318
|
/**
|
|
1313
1319
|
* Tick result: new signal just created.
|
|
@@ -1330,6 +1336,8 @@ interface IStrategyTickResultOpened {
|
|
|
1330
1336
|
currentPrice: number;
|
|
1331
1337
|
/** Whether this event is from backtest mode (true) or live mode (false) */
|
|
1332
1338
|
backtest: boolean;
|
|
1339
|
+
/** Unix timestamp in milliseconds when this tick result was created (from candle timestamp in backtest or execution context when in live) */
|
|
1340
|
+
createdAt: number;
|
|
1333
1341
|
}
|
|
1334
1342
|
/**
|
|
1335
1343
|
* Tick result: signal is being monitored.
|
|
@@ -1358,6 +1366,8 @@ interface IStrategyTickResultActive {
|
|
|
1358
1366
|
pnl: IStrategyPnL;
|
|
1359
1367
|
/** Whether this event is from backtest mode (true) or live mode (false) */
|
|
1360
1368
|
backtest: boolean;
|
|
1369
|
+
/** Unix timestamp in milliseconds when this tick result was created (from candle timestamp in backtest or execution context when in live) */
|
|
1370
|
+
createdAt: number;
|
|
1361
1371
|
}
|
|
1362
1372
|
/**
|
|
1363
1373
|
* Tick result: signal closed with PNL.
|
|
@@ -1388,6 +1398,8 @@ interface IStrategyTickResultClosed {
|
|
|
1388
1398
|
backtest: boolean;
|
|
1389
1399
|
/** Close ID (only for user-initiated closes with reason "closed") */
|
|
1390
1400
|
closeId?: string;
|
|
1401
|
+
/** Unix timestamp in milliseconds when this tick result was created (from candle timestamp in backtest or execution context when in live) */
|
|
1402
|
+
createdAt: number;
|
|
1391
1403
|
}
|
|
1392
1404
|
/**
|
|
1393
1405
|
* Tick result: scheduled signal cancelled without opening position.
|
|
@@ -1416,6 +1428,8 @@ interface IStrategyTickResultCancelled {
|
|
|
1416
1428
|
reason: StrategyCancelReason;
|
|
1417
1429
|
/** Optional cancellation ID (provided when user calls Backtest.cancel() or Live.cancel()) */
|
|
1418
1430
|
cancelId?: string;
|
|
1431
|
+
/** Unix timestamp in milliseconds when this tick result was created (from candle timestamp in backtest or execution context when in live) */
|
|
1432
|
+
createdAt: number;
|
|
1419
1433
|
}
|
|
1420
1434
|
/**
|
|
1421
1435
|
* Discriminated union of all tick results.
|
|
@@ -3839,6 +3853,8 @@ declare const COLUMN_CONFIG: {
|
|
|
3839
3853
|
risk_columns: ColumnModel<RiskEvent>[];
|
|
3840
3854
|
/** Columns for scheduled report output */
|
|
3841
3855
|
schedule_columns: ColumnModel<ScheduledEvent>[];
|
|
3856
|
+
/** Columns for strategy management events */
|
|
3857
|
+
strategy_columns: ColumnModel<StrategyEvent>[];
|
|
3842
3858
|
/** Walker: PnL summary columns */
|
|
3843
3859
|
walker_pnl_columns: ColumnModel<SignalData$1>[];
|
|
3844
3860
|
/** Walker: strategy-level summary columns */
|
|
@@ -3997,6 +4013,7 @@ declare function getColumns(): {
|
|
|
3997
4013
|
performance_columns: ColumnModel<MetricStats>[];
|
|
3998
4014
|
risk_columns: ColumnModel<RiskEvent>[];
|
|
3999
4015
|
schedule_columns: ColumnModel<ScheduledEvent>[];
|
|
4016
|
+
strategy_columns: ColumnModel<StrategyEvent>[];
|
|
4000
4017
|
walker_pnl_columns: ColumnModel<SignalData$1>[];
|
|
4001
4018
|
walker_strategy_columns: ColumnModel<IStrategyResult>[];
|
|
4002
4019
|
};
|
|
@@ -4023,6 +4040,7 @@ declare function getDefaultColumns(): Readonly<{
|
|
|
4023
4040
|
performance_columns: ColumnModel<MetricStats>[];
|
|
4024
4041
|
risk_columns: ColumnModel<RiskEvent>[];
|
|
4025
4042
|
schedule_columns: ColumnModel<ScheduledEvent>[];
|
|
4043
|
+
strategy_columns: ColumnModel<StrategyEvent>[];
|
|
4026
4044
|
walker_pnl_columns: ColumnModel<SignalData$1>[];
|
|
4027
4045
|
walker_strategy_columns: ColumnModel<IStrategyResult>[];
|
|
4028
4046
|
}>;
|
|
@@ -5071,6 +5089,84 @@ interface WalkerContract {
|
|
|
5071
5089
|
totalStrategies: number;
|
|
5072
5090
|
}
|
|
5073
5091
|
|
|
5092
|
+
/**
|
|
5093
|
+
* Base fields for all signal commit events.
|
|
5094
|
+
*/
|
|
5095
|
+
interface SignalCommitBase {
|
|
5096
|
+
symbol: string;
|
|
5097
|
+
strategyName: StrategyName;
|
|
5098
|
+
exchangeName: ExchangeName;
|
|
5099
|
+
frameName: FrameName;
|
|
5100
|
+
backtest: boolean;
|
|
5101
|
+
}
|
|
5102
|
+
/**
|
|
5103
|
+
* Cancel scheduled signal event.
|
|
5104
|
+
*/
|
|
5105
|
+
interface CancelScheduledCommit extends SignalCommitBase {
|
|
5106
|
+
action: "cancel-scheduled";
|
|
5107
|
+
cancelId?: string;
|
|
5108
|
+
}
|
|
5109
|
+
/**
|
|
5110
|
+
* Close pending signal event.
|
|
5111
|
+
*/
|
|
5112
|
+
interface ClosePendingCommit extends SignalCommitBase {
|
|
5113
|
+
action: "close-pending";
|
|
5114
|
+
closeId?: string;
|
|
5115
|
+
}
|
|
5116
|
+
/**
|
|
5117
|
+
* Partial profit event.
|
|
5118
|
+
*/
|
|
5119
|
+
interface PartialProfitCommit extends SignalCommitBase {
|
|
5120
|
+
action: "partial-profit";
|
|
5121
|
+
percentToClose: number;
|
|
5122
|
+
currentPrice: number;
|
|
5123
|
+
}
|
|
5124
|
+
/**
|
|
5125
|
+
* Partial loss event.
|
|
5126
|
+
*/
|
|
5127
|
+
interface PartialLossCommit extends SignalCommitBase {
|
|
5128
|
+
action: "partial-loss";
|
|
5129
|
+
percentToClose: number;
|
|
5130
|
+
currentPrice: number;
|
|
5131
|
+
}
|
|
5132
|
+
/**
|
|
5133
|
+
* Trailing stop event.
|
|
5134
|
+
*/
|
|
5135
|
+
interface TrailingStopCommit extends SignalCommitBase {
|
|
5136
|
+
action: "trailing-stop";
|
|
5137
|
+
percentShift: number;
|
|
5138
|
+
currentPrice: number;
|
|
5139
|
+
}
|
|
5140
|
+
/**
|
|
5141
|
+
* Trailing take event.
|
|
5142
|
+
*/
|
|
5143
|
+
interface TrailingTakeCommit extends SignalCommitBase {
|
|
5144
|
+
action: "trailing-take";
|
|
5145
|
+
percentShift: number;
|
|
5146
|
+
currentPrice: number;
|
|
5147
|
+
}
|
|
5148
|
+
/**
|
|
5149
|
+
* Breakeven event.
|
|
5150
|
+
*/
|
|
5151
|
+
interface BreakevenCommit extends SignalCommitBase {
|
|
5152
|
+
action: "breakeven";
|
|
5153
|
+
currentPrice: number;
|
|
5154
|
+
}
|
|
5155
|
+
/**
|
|
5156
|
+
* Discriminated union for strategy management signal events.
|
|
5157
|
+
*
|
|
5158
|
+
* Emitted by strategyCommitSubject when strategy management actions are executed.
|
|
5159
|
+
*
|
|
5160
|
+
* Consumers:
|
|
5161
|
+
* - StrategyReportService: Persists events to JSON files
|
|
5162
|
+
* - StrategyMarkdownService: Accumulates events for markdown reports
|
|
5163
|
+
*
|
|
5164
|
+
* Note: Signal data (IPublicSignalRow) is NOT included in this contract.
|
|
5165
|
+
* Consumers must retrieve signal data from StrategyCoreService using
|
|
5166
|
+
* getPendingSignal() or getScheduledSignal() methods.
|
|
5167
|
+
*/
|
|
5168
|
+
type StrategyCommitContract = CancelScheduledCommit | ClosePendingCommit | PartialProfitCommit | PartialLossCommit | TrailingStopCommit | TrailingTakeCommit | BreakevenCommit;
|
|
5169
|
+
|
|
5074
5170
|
/**
|
|
5075
5171
|
* Subscribes to all signal events with queued async processing.
|
|
5076
5172
|
*
|
|
@@ -6001,6 +6097,72 @@ declare function listenActivePing(fn: (event: ActivePingContract) => void): () =
|
|
|
6001
6097
|
* ```
|
|
6002
6098
|
*/
|
|
6003
6099
|
declare function listenActivePingOnce(filterFn: (event: ActivePingContract) => boolean, fn: (event: ActivePingContract) => void): () => void;
|
|
6100
|
+
/**
|
|
6101
|
+
* Subscribes to strategy management events with queued async processing.
|
|
6102
|
+
*
|
|
6103
|
+
* Emits when strategy management actions are executed:
|
|
6104
|
+
* - cancel-scheduled: Scheduled signal cancelled
|
|
6105
|
+
* - close-pending: Pending signal closed
|
|
6106
|
+
* - partial-profit: Partial close at profit level
|
|
6107
|
+
* - partial-loss: Partial close at loss level
|
|
6108
|
+
* - trailing-stop: Stop-loss adjusted
|
|
6109
|
+
* - trailing-take: Take-profit adjusted
|
|
6110
|
+
* - breakeven: Stop-loss moved to entry price
|
|
6111
|
+
*
|
|
6112
|
+
* Events are processed sequentially in order received, even if callback is async.
|
|
6113
|
+
* Uses queued wrapper to prevent concurrent execution of the callback.
|
|
6114
|
+
*
|
|
6115
|
+
* @param fn - Callback function to handle strategy commit events
|
|
6116
|
+
* @returns Unsubscribe function to stop listening
|
|
6117
|
+
*
|
|
6118
|
+
* @example
|
|
6119
|
+
* ```typescript
|
|
6120
|
+
* import { listenStrategyCommit } from "./function/event";
|
|
6121
|
+
*
|
|
6122
|
+
* const unsubscribe = listenStrategyCommit((event) => {
|
|
6123
|
+
* console.log(`[${event.action}] ${event.symbol}`);
|
|
6124
|
+
* console.log(`Strategy: ${event.strategyName}, Exchange: ${event.exchangeName}`);
|
|
6125
|
+
* if (event.action === "partial-profit") {
|
|
6126
|
+
* console.log(`Closed ${event.percentToClose}% at ${event.currentPrice}`);
|
|
6127
|
+
* }
|
|
6128
|
+
* });
|
|
6129
|
+
*
|
|
6130
|
+
* // Later: stop listening
|
|
6131
|
+
* unsubscribe();
|
|
6132
|
+
* ```
|
|
6133
|
+
*/
|
|
6134
|
+
declare function listenStrategyCommit(fn: (event: StrategyCommitContract) => void): () => void;
|
|
6135
|
+
/**
|
|
6136
|
+
* Subscribes to filtered strategy management events with one-time execution.
|
|
6137
|
+
*
|
|
6138
|
+
* Listens for events matching the filter predicate, then executes callback once
|
|
6139
|
+
* and automatically unsubscribes. Useful for waiting for specific strategy actions.
|
|
6140
|
+
*
|
|
6141
|
+
* @param filterFn - Predicate to filter which events trigger the callback
|
|
6142
|
+
* @param fn - Callback function to handle the filtered event (called only once)
|
|
6143
|
+
* @returns Unsubscribe function to cancel the listener before it fires
|
|
6144
|
+
*
|
|
6145
|
+
* @example
|
|
6146
|
+
* ```typescript
|
|
6147
|
+
* import { listenStrategyCommitOnce } from "./function/event";
|
|
6148
|
+
*
|
|
6149
|
+
* // Wait for first trailing stop adjustment
|
|
6150
|
+
* listenStrategyCommitOnce(
|
|
6151
|
+
* (event) => event.action === "trailing-stop",
|
|
6152
|
+
* (event) => console.log("Trailing stop adjusted:", event.symbol)
|
|
6153
|
+
* );
|
|
6154
|
+
*
|
|
6155
|
+
* // Wait for breakeven on BTCUSDT
|
|
6156
|
+
* const cancel = listenStrategyCommitOnce(
|
|
6157
|
+
* (event) => event.action === "breakeven" && event.symbol === "BTCUSDT",
|
|
6158
|
+
* (event) => console.log("BTCUSDT moved to breakeven at", event.currentPrice)
|
|
6159
|
+
* );
|
|
6160
|
+
*
|
|
6161
|
+
* // Cancel if needed before event fires
|
|
6162
|
+
* cancel();
|
|
6163
|
+
* ```
|
|
6164
|
+
*/
|
|
6165
|
+
declare function listenStrategyCommitOnce(filterFn: (event: StrategyCommitContract) => boolean, fn: (event: StrategyCommitContract) => void): () => void;
|
|
6004
6166
|
|
|
6005
6167
|
/**
|
|
6006
6168
|
* Checks if trade context is active (execution and method contexts).
|
|
@@ -6288,93 +6450,307 @@ interface ColumnModel<T extends object = any> {
|
|
|
6288
6450
|
* Emitted when a new trading position is opened.
|
|
6289
6451
|
*/
|
|
6290
6452
|
interface SignalOpenedNotification {
|
|
6453
|
+
/** Discriminator for type-safe union */
|
|
6291
6454
|
type: "signal.opened";
|
|
6455
|
+
/** Unique notification identifier */
|
|
6292
6456
|
id: string;
|
|
6457
|
+
/** Unix timestamp in milliseconds when signal was opened (pendingAt) */
|
|
6293
6458
|
timestamp: number;
|
|
6459
|
+
/** Whether this notification is from backtest mode (true) or live mode (false) */
|
|
6294
6460
|
backtest: boolean;
|
|
6461
|
+
/** Trading pair symbol (e.g., "BTCUSDT") */
|
|
6295
6462
|
symbol: string;
|
|
6463
|
+
/** Strategy name that generated this signal */
|
|
6296
6464
|
strategyName: StrategyName;
|
|
6465
|
+
/** Exchange name where signal was executed */
|
|
6297
6466
|
exchangeName: ExchangeName;
|
|
6467
|
+
/** Unique signal identifier (UUID v4) */
|
|
6298
6468
|
signalId: string;
|
|
6469
|
+
/** Trade direction: "long" (buy) or "short" (sell) */
|
|
6299
6470
|
position: "long" | "short";
|
|
6471
|
+
/** Entry price for the position */
|
|
6300
6472
|
priceOpen: number;
|
|
6473
|
+
/** Take profit target price */
|
|
6301
6474
|
priceTakeProfit: number;
|
|
6475
|
+
/** Stop loss exit price */
|
|
6302
6476
|
priceStopLoss: number;
|
|
6477
|
+
/** Optional human-readable description of signal reason */
|
|
6303
6478
|
note?: string;
|
|
6479
|
+
/** Unix timestamp in milliseconds when the tick result was created (from candle timestamp in backtest or execution context when in live) */
|
|
6480
|
+
createdAt: number;
|
|
6304
6481
|
}
|
|
6305
6482
|
/**
|
|
6306
6483
|
* Signal closed notification.
|
|
6307
6484
|
* Emitted when a trading position is closed (TP/SL hit).
|
|
6308
6485
|
*/
|
|
6309
6486
|
interface SignalClosedNotification {
|
|
6487
|
+
/** Discriminator for type-safe union */
|
|
6310
6488
|
type: "signal.closed";
|
|
6489
|
+
/** Unique notification identifier */
|
|
6311
6490
|
id: string;
|
|
6491
|
+
/** Unix timestamp in milliseconds when signal was closed (closeTimestamp) */
|
|
6312
6492
|
timestamp: number;
|
|
6493
|
+
/** Whether this notification is from backtest mode (true) or live mode (false) */
|
|
6313
6494
|
backtest: boolean;
|
|
6495
|
+
/** Trading pair symbol (e.g., "BTCUSDT") */
|
|
6314
6496
|
symbol: string;
|
|
6497
|
+
/** Strategy name that generated this signal */
|
|
6315
6498
|
strategyName: StrategyName;
|
|
6499
|
+
/** Exchange name where signal was executed */
|
|
6316
6500
|
exchangeName: ExchangeName;
|
|
6501
|
+
/** Unique signal identifier (UUID v4) */
|
|
6317
6502
|
signalId: string;
|
|
6503
|
+
/** Trade direction: "long" (buy) or "short" (sell) */
|
|
6318
6504
|
position: "long" | "short";
|
|
6505
|
+
/** Entry price for the position */
|
|
6319
6506
|
priceOpen: number;
|
|
6507
|
+
/** Exit price when position was closed */
|
|
6320
6508
|
priceClose: number;
|
|
6509
|
+
/** Profit/loss as percentage (e.g., 1.5 for +1.5%, -2.3 for -2.3%) */
|
|
6321
6510
|
pnlPercentage: number;
|
|
6511
|
+
/** Why signal closed (time_expired | take_profit | stop_loss | closed) */
|
|
6322
6512
|
closeReason: string;
|
|
6513
|
+
/** Duration of position in minutes (from pendingAt to closeTimestamp) */
|
|
6323
6514
|
duration: number;
|
|
6515
|
+
/** Optional human-readable description of signal reason */
|
|
6324
6516
|
note?: string;
|
|
6517
|
+
/** Unix timestamp in milliseconds when the tick result was created (from candle timestamp in backtest or execution context when in live) */
|
|
6518
|
+
createdAt: number;
|
|
6325
6519
|
}
|
|
6326
6520
|
/**
|
|
6327
6521
|
* Partial profit notification.
|
|
6328
6522
|
* Emitted when signal reaches profit level milestone (10%, 20%, etc).
|
|
6329
6523
|
*/
|
|
6330
|
-
interface
|
|
6331
|
-
type
|
|
6524
|
+
interface PartialProfitAvailableNotification {
|
|
6525
|
+
/** Discriminator for type-safe union */
|
|
6526
|
+
type: "partial_profit.available";
|
|
6527
|
+
/** Unique notification identifier */
|
|
6332
6528
|
id: string;
|
|
6529
|
+
/** Unix timestamp in milliseconds when partial profit level was reached */
|
|
6333
6530
|
timestamp: number;
|
|
6531
|
+
/** Whether this notification is from backtest mode (true) or live mode (false) */
|
|
6334
6532
|
backtest: boolean;
|
|
6533
|
+
/** Trading pair symbol (e.g., "BTCUSDT") */
|
|
6335
6534
|
symbol: string;
|
|
6535
|
+
/** Strategy name that generated this signal */
|
|
6336
6536
|
strategyName: StrategyName;
|
|
6537
|
+
/** Exchange name where signal was executed */
|
|
6337
6538
|
exchangeName: ExchangeName;
|
|
6539
|
+
/** Unique signal identifier (UUID v4) */
|
|
6338
6540
|
signalId: string;
|
|
6541
|
+
/** Profit level milestone reached (10, 20, 30, etc) */
|
|
6339
6542
|
level: PartialLevel;
|
|
6543
|
+
/** Current market price when milestone was reached */
|
|
6340
6544
|
currentPrice: number;
|
|
6545
|
+
/** Entry price for the position */
|
|
6341
6546
|
priceOpen: number;
|
|
6547
|
+
/** Trade direction: "long" (buy) or "short" (sell) */
|
|
6342
6548
|
position: "long" | "short";
|
|
6343
6549
|
}
|
|
6344
6550
|
/**
|
|
6345
6551
|
* Partial loss notification.
|
|
6346
6552
|
* Emitted when signal reaches loss level milestone (-10%, -20%, etc).
|
|
6347
6553
|
*/
|
|
6348
|
-
interface
|
|
6349
|
-
type
|
|
6554
|
+
interface PartialLossAvailableNotification {
|
|
6555
|
+
/** Discriminator for type-safe union */
|
|
6556
|
+
type: "partial_loss.available";
|
|
6557
|
+
/** Unique notification identifier */
|
|
6350
6558
|
id: string;
|
|
6559
|
+
/** Unix timestamp in milliseconds when partial loss level was reached */
|
|
6351
6560
|
timestamp: number;
|
|
6561
|
+
/** Whether this notification is from backtest mode (true) or live mode (false) */
|
|
6352
6562
|
backtest: boolean;
|
|
6563
|
+
/** Trading pair symbol (e.g., "BTCUSDT") */
|
|
6353
6564
|
symbol: string;
|
|
6565
|
+
/** Strategy name that generated this signal */
|
|
6354
6566
|
strategyName: StrategyName;
|
|
6567
|
+
/** Exchange name where signal was executed */
|
|
6355
6568
|
exchangeName: ExchangeName;
|
|
6569
|
+
/** Unique signal identifier (UUID v4) */
|
|
6356
6570
|
signalId: string;
|
|
6571
|
+
/** Loss level milestone reached (10, 20, 30, etc) */
|
|
6357
6572
|
level: PartialLevel;
|
|
6573
|
+
/** Current market price when milestone was reached */
|
|
6574
|
+
currentPrice: number;
|
|
6575
|
+
/** Entry price for the position */
|
|
6576
|
+
priceOpen: number;
|
|
6577
|
+
/** Trade direction: "long" (buy) or "short" (sell) */
|
|
6578
|
+
position: "long" | "short";
|
|
6579
|
+
}
|
|
6580
|
+
/**
|
|
6581
|
+
* Breakeven available notification.
|
|
6582
|
+
* Emitted when signal's stop-loss can be moved to breakeven (entry price).
|
|
6583
|
+
*/
|
|
6584
|
+
interface BreakevenAvailableNotification {
|
|
6585
|
+
/** Discriminator for type-safe union */
|
|
6586
|
+
type: "breakeven.available";
|
|
6587
|
+
/** Unique notification identifier */
|
|
6588
|
+
id: string;
|
|
6589
|
+
/** Unix timestamp in milliseconds when breakeven became available */
|
|
6590
|
+
timestamp: number;
|
|
6591
|
+
/** Whether this notification is from backtest mode (true) or live mode (false) */
|
|
6592
|
+
backtest: boolean;
|
|
6593
|
+
/** Trading pair symbol (e.g., "BTCUSDT") */
|
|
6594
|
+
symbol: string;
|
|
6595
|
+
/** Strategy name that generated this signal */
|
|
6596
|
+
strategyName: StrategyName;
|
|
6597
|
+
/** Exchange name where signal was executed */
|
|
6598
|
+
exchangeName: ExchangeName;
|
|
6599
|
+
/** Unique signal identifier (UUID v4) */
|
|
6600
|
+
signalId: string;
|
|
6601
|
+
/** Current market price when breakeven became available */
|
|
6358
6602
|
currentPrice: number;
|
|
6603
|
+
/** Entry price for the position (breakeven level) */
|
|
6359
6604
|
priceOpen: number;
|
|
6605
|
+
/** Trade direction: "long" (buy) or "short" (sell) */
|
|
6360
6606
|
position: "long" | "short";
|
|
6361
6607
|
}
|
|
6608
|
+
/**
|
|
6609
|
+
* Partial profit commit notification.
|
|
6610
|
+
* Emitted when partial profit action is executed.
|
|
6611
|
+
*/
|
|
6612
|
+
interface PartialProfitCommitNotification {
|
|
6613
|
+
/** Discriminator for type-safe union */
|
|
6614
|
+
type: "partial_profit.commit";
|
|
6615
|
+
/** Unique notification identifier */
|
|
6616
|
+
id: string;
|
|
6617
|
+
/** Unix timestamp in milliseconds when partial profit was committed */
|
|
6618
|
+
timestamp: number;
|
|
6619
|
+
/** Whether this notification is from backtest mode (true) or live mode (false) */
|
|
6620
|
+
backtest: boolean;
|
|
6621
|
+
/** Trading pair symbol (e.g., "BTCUSDT") */
|
|
6622
|
+
symbol: string;
|
|
6623
|
+
/** Strategy name that generated this signal */
|
|
6624
|
+
strategyName: StrategyName;
|
|
6625
|
+
/** Exchange name where signal was executed */
|
|
6626
|
+
exchangeName: ExchangeName;
|
|
6627
|
+
/** Percentage of position closed (0-100) */
|
|
6628
|
+
percentToClose: number;
|
|
6629
|
+
/** Current market price when partial was executed */
|
|
6630
|
+
currentPrice: number;
|
|
6631
|
+
}
|
|
6632
|
+
/**
|
|
6633
|
+
* Partial loss commit notification.
|
|
6634
|
+
* Emitted when partial loss action is executed.
|
|
6635
|
+
*/
|
|
6636
|
+
interface PartialLossCommitNotification {
|
|
6637
|
+
/** Discriminator for type-safe union */
|
|
6638
|
+
type: "partial_loss.commit";
|
|
6639
|
+
/** Unique notification identifier */
|
|
6640
|
+
id: string;
|
|
6641
|
+
/** Unix timestamp in milliseconds when partial loss was committed */
|
|
6642
|
+
timestamp: number;
|
|
6643
|
+
/** Whether this notification is from backtest mode (true) or live mode (false) */
|
|
6644
|
+
backtest: boolean;
|
|
6645
|
+
/** Trading pair symbol (e.g., "BTCUSDT") */
|
|
6646
|
+
symbol: string;
|
|
6647
|
+
/** Strategy name that generated this signal */
|
|
6648
|
+
strategyName: StrategyName;
|
|
6649
|
+
/** Exchange name where signal was executed */
|
|
6650
|
+
exchangeName: ExchangeName;
|
|
6651
|
+
/** Percentage of position closed (0-100) */
|
|
6652
|
+
percentToClose: number;
|
|
6653
|
+
/** Current market price when partial was executed */
|
|
6654
|
+
currentPrice: number;
|
|
6655
|
+
}
|
|
6656
|
+
/**
|
|
6657
|
+
* Breakeven commit notification.
|
|
6658
|
+
* Emitted when breakeven action is executed.
|
|
6659
|
+
*/
|
|
6660
|
+
interface BreakevenCommitNotification {
|
|
6661
|
+
/** Discriminator for type-safe union */
|
|
6662
|
+
type: "breakeven.commit";
|
|
6663
|
+
/** Unique notification identifier */
|
|
6664
|
+
id: string;
|
|
6665
|
+
/** Unix timestamp in milliseconds when breakeven was committed */
|
|
6666
|
+
timestamp: number;
|
|
6667
|
+
/** Whether this notification is from backtest mode (true) or live mode (false) */
|
|
6668
|
+
backtest: boolean;
|
|
6669
|
+
/** Trading pair symbol (e.g., "BTCUSDT") */
|
|
6670
|
+
symbol: string;
|
|
6671
|
+
/** Strategy name that generated this signal */
|
|
6672
|
+
strategyName: StrategyName;
|
|
6673
|
+
/** Exchange name where signal was executed */
|
|
6674
|
+
exchangeName: ExchangeName;
|
|
6675
|
+
/** Current market price when breakeven was executed */
|
|
6676
|
+
currentPrice: number;
|
|
6677
|
+
}
|
|
6678
|
+
/**
|
|
6679
|
+
* Trailing stop commit notification.
|
|
6680
|
+
* Emitted when trailing stop action is executed.
|
|
6681
|
+
*/
|
|
6682
|
+
interface TrailingStopCommitNotification {
|
|
6683
|
+
/** Discriminator for type-safe union */
|
|
6684
|
+
type: "trailing_stop.commit";
|
|
6685
|
+
/** Unique notification identifier */
|
|
6686
|
+
id: string;
|
|
6687
|
+
/** Unix timestamp in milliseconds when trailing stop was committed */
|
|
6688
|
+
timestamp: number;
|
|
6689
|
+
/** Whether this notification is from backtest mode (true) or live mode (false) */
|
|
6690
|
+
backtest: boolean;
|
|
6691
|
+
/** Trading pair symbol (e.g., "BTCUSDT") */
|
|
6692
|
+
symbol: string;
|
|
6693
|
+
/** Strategy name that generated this signal */
|
|
6694
|
+
strategyName: StrategyName;
|
|
6695
|
+
/** Exchange name where signal was executed */
|
|
6696
|
+
exchangeName: ExchangeName;
|
|
6697
|
+
/** Percentage shift of original SL distance (-100 to 100) */
|
|
6698
|
+
percentShift: number;
|
|
6699
|
+
/** Current market price when trailing stop was executed */
|
|
6700
|
+
currentPrice: number;
|
|
6701
|
+
}
|
|
6702
|
+
/**
|
|
6703
|
+
* Trailing take commit notification.
|
|
6704
|
+
* Emitted when trailing take action is executed.
|
|
6705
|
+
*/
|
|
6706
|
+
interface TrailingTakeCommitNotification {
|
|
6707
|
+
/** Discriminator for type-safe union */
|
|
6708
|
+
type: "trailing_take.commit";
|
|
6709
|
+
/** Unique notification identifier */
|
|
6710
|
+
id: string;
|
|
6711
|
+
/** Unix timestamp in milliseconds when trailing take was committed */
|
|
6712
|
+
timestamp: number;
|
|
6713
|
+
/** Whether this notification is from backtest mode (true) or live mode (false) */
|
|
6714
|
+
backtest: boolean;
|
|
6715
|
+
/** Trading pair symbol (e.g., "BTCUSDT") */
|
|
6716
|
+
symbol: string;
|
|
6717
|
+
/** Strategy name that generated this signal */
|
|
6718
|
+
strategyName: StrategyName;
|
|
6719
|
+
/** Exchange name where signal was executed */
|
|
6720
|
+
exchangeName: ExchangeName;
|
|
6721
|
+
/** Percentage shift of original TP distance (-100 to 100) */
|
|
6722
|
+
percentShift: number;
|
|
6723
|
+
/** Current market price when trailing take was executed */
|
|
6724
|
+
currentPrice: number;
|
|
6725
|
+
}
|
|
6362
6726
|
/**
|
|
6363
6727
|
* Risk rejection notification.
|
|
6364
6728
|
* Emitted when a signal is rejected due to risk management rules.
|
|
6365
6729
|
*/
|
|
6366
6730
|
interface RiskRejectionNotification {
|
|
6731
|
+
/** Discriminator for type-safe union */
|
|
6367
6732
|
type: "risk.rejection";
|
|
6733
|
+
/** Unique notification identifier */
|
|
6368
6734
|
id: string;
|
|
6735
|
+
/** Unix timestamp in milliseconds when signal was rejected */
|
|
6369
6736
|
timestamp: number;
|
|
6737
|
+
/** Whether this notification is from backtest mode (true) or live mode (false) */
|
|
6370
6738
|
backtest: boolean;
|
|
6739
|
+
/** Trading pair symbol (e.g., "BTCUSDT") */
|
|
6371
6740
|
symbol: string;
|
|
6741
|
+
/** Strategy name that attempted to create signal */
|
|
6372
6742
|
strategyName: StrategyName;
|
|
6743
|
+
/** Exchange name where signal was rejected */
|
|
6373
6744
|
exchangeName: ExchangeName;
|
|
6745
|
+
/** Human-readable reason for rejection */
|
|
6374
6746
|
rejectionNote: string;
|
|
6747
|
+
/** Optional unique rejection identifier for tracking */
|
|
6375
6748
|
rejectionId: string | null;
|
|
6749
|
+
/** Number of currently active positions at rejection time */
|
|
6376
6750
|
activePositionCount: number;
|
|
6751
|
+
/** Current market price when rejection occurred */
|
|
6377
6752
|
currentPrice: number;
|
|
6753
|
+
/** The signal that was rejected */
|
|
6378
6754
|
pendingSignal: ISignalDto;
|
|
6379
6755
|
}
|
|
6380
6756
|
/**
|
|
@@ -6382,73 +6758,81 @@ interface RiskRejectionNotification {
|
|
|
6382
6758
|
* Emitted when a signal is scheduled for future execution.
|
|
6383
6759
|
*/
|
|
6384
6760
|
interface SignalScheduledNotification {
|
|
6761
|
+
/** Discriminator for type-safe union */
|
|
6385
6762
|
type: "signal.scheduled";
|
|
6763
|
+
/** Unique notification identifier */
|
|
6386
6764
|
id: string;
|
|
6765
|
+
/** Unix timestamp in milliseconds when signal was scheduled (scheduledAt) */
|
|
6387
6766
|
timestamp: number;
|
|
6767
|
+
/** Whether this notification is from backtest mode (true) or live mode (false) */
|
|
6388
6768
|
backtest: boolean;
|
|
6769
|
+
/** Trading pair symbol (e.g., "BTCUSDT") */
|
|
6389
6770
|
symbol: string;
|
|
6771
|
+
/** Strategy name that generated this signal */
|
|
6390
6772
|
strategyName: StrategyName;
|
|
6773
|
+
/** Exchange name where signal will be executed */
|
|
6391
6774
|
exchangeName: ExchangeName;
|
|
6775
|
+
/** Unique signal identifier (UUID v4) */
|
|
6392
6776
|
signalId: string;
|
|
6777
|
+
/** Trade direction: "long" (buy) or "short" (sell) */
|
|
6393
6778
|
position: "long" | "short";
|
|
6779
|
+
/** Target entry price for activation */
|
|
6394
6780
|
priceOpen: number;
|
|
6781
|
+
/** Unix timestamp in milliseconds when signal was scheduled */
|
|
6395
6782
|
scheduledAt: number;
|
|
6783
|
+
/** Current market price when signal was scheduled */
|
|
6396
6784
|
currentPrice: number;
|
|
6785
|
+
/** Unix timestamp in milliseconds when the tick result was created (from candle timestamp in backtest or execution context when in live) */
|
|
6786
|
+
createdAt: number;
|
|
6397
6787
|
}
|
|
6398
6788
|
/**
|
|
6399
6789
|
* Signal cancelled notification.
|
|
6400
6790
|
* Emitted when a scheduled signal is cancelled before activation.
|
|
6401
6791
|
*/
|
|
6402
6792
|
interface SignalCancelledNotification {
|
|
6793
|
+
/** Discriminator for type-safe union */
|
|
6403
6794
|
type: "signal.cancelled";
|
|
6795
|
+
/** Unique notification identifier */
|
|
6404
6796
|
id: string;
|
|
6797
|
+
/** Unix timestamp in milliseconds when signal was cancelled (closeTimestamp) */
|
|
6405
6798
|
timestamp: number;
|
|
6799
|
+
/** Whether this notification is from backtest mode (true) or live mode (false) */
|
|
6406
6800
|
backtest: boolean;
|
|
6801
|
+
/** Trading pair symbol (e.g., "BTCUSDT") */
|
|
6407
6802
|
symbol: string;
|
|
6803
|
+
/** Strategy name that generated this signal */
|
|
6408
6804
|
strategyName: StrategyName;
|
|
6805
|
+
/** Exchange name where signal was scheduled */
|
|
6409
6806
|
exchangeName: ExchangeName;
|
|
6807
|
+
/** Unique signal identifier (UUID v4) */
|
|
6410
6808
|
signalId: string;
|
|
6809
|
+
/** Trade direction: "long" (buy) or "short" (sell) */
|
|
6411
6810
|
position: "long" | "short";
|
|
6811
|
+
/** Why signal was cancelled (timeout | price_reject | user) */
|
|
6412
6812
|
cancelReason: string;
|
|
6813
|
+
/** Optional cancellation identifier (provided when user calls cancel()) */
|
|
6413
6814
|
cancelId: string;
|
|
6815
|
+
/** Duration in minutes from scheduledAt to cancellation */
|
|
6414
6816
|
duration: number;
|
|
6415
|
-
|
|
6416
|
-
|
|
6417
|
-
* Backtest completed notification.
|
|
6418
|
-
* Emitted when backtest execution completes.
|
|
6419
|
-
*/
|
|
6420
|
-
interface BacktestDoneNotification {
|
|
6421
|
-
type: "backtest.done";
|
|
6422
|
-
id: string;
|
|
6423
|
-
timestamp: number;
|
|
6424
|
-
backtest: true;
|
|
6425
|
-
symbol: string;
|
|
6426
|
-
strategyName: StrategyName;
|
|
6427
|
-
exchangeName: ExchangeName;
|
|
6428
|
-
}
|
|
6429
|
-
/**
|
|
6430
|
-
* Live trading completed notification.
|
|
6431
|
-
* Emitted when live trading execution completes.
|
|
6432
|
-
*/
|
|
6433
|
-
interface LiveDoneNotification {
|
|
6434
|
-
type: "live.done";
|
|
6435
|
-
id: string;
|
|
6436
|
-
timestamp: number;
|
|
6437
|
-
backtest: false;
|
|
6438
|
-
symbol: string;
|
|
6439
|
-
strategyName: StrategyName;
|
|
6440
|
-
exchangeName: ExchangeName;
|
|
6817
|
+
/** Unix timestamp in milliseconds when the tick result was created (from candle timestamp in backtest or execution context when in live) */
|
|
6818
|
+
createdAt: number;
|
|
6441
6819
|
}
|
|
6442
6820
|
/**
|
|
6443
6821
|
* Error notification.
|
|
6444
6822
|
* Emitted for recoverable errors in background tasks.
|
|
6445
6823
|
*/
|
|
6446
6824
|
interface InfoErrorNotification {
|
|
6825
|
+
/** Discriminator for type-safe union */
|
|
6447
6826
|
type: "error.info";
|
|
6827
|
+
/** Unique notification identifier */
|
|
6448
6828
|
id: string;
|
|
6829
|
+
/** Serialized error object with stack trace and metadata */
|
|
6449
6830
|
error: object;
|
|
6831
|
+
/** Human-readable error message */
|
|
6450
6832
|
message: string;
|
|
6833
|
+
/** Unix timestamp in milliseconds when error occurred */
|
|
6451
6834
|
timestamp: number;
|
|
6835
|
+
/** Always false for error notifications (errors are from live context) */
|
|
6452
6836
|
backtest: boolean;
|
|
6453
6837
|
}
|
|
6454
6838
|
/**
|
|
@@ -6456,11 +6840,17 @@ interface InfoErrorNotification {
|
|
|
6456
6840
|
* Emitted for fatal errors requiring process termination.
|
|
6457
6841
|
*/
|
|
6458
6842
|
interface CriticalErrorNotification {
|
|
6843
|
+
/** Discriminator for type-safe union */
|
|
6459
6844
|
type: "error.critical";
|
|
6845
|
+
/** Unique notification identifier */
|
|
6460
6846
|
id: string;
|
|
6847
|
+
/** Serialized error object with stack trace and metadata */
|
|
6461
6848
|
error: object;
|
|
6849
|
+
/** Human-readable error message */
|
|
6462
6850
|
message: string;
|
|
6851
|
+
/** Unix timestamp in milliseconds when critical error occurred */
|
|
6463
6852
|
timestamp: number;
|
|
6853
|
+
/** Always false for error notifications (errors are from live context) */
|
|
6464
6854
|
backtest: boolean;
|
|
6465
6855
|
}
|
|
6466
6856
|
/**
|
|
@@ -6468,29 +6858,19 @@ interface CriticalErrorNotification {
|
|
|
6468
6858
|
* Emitted when risk validation functions throw errors.
|
|
6469
6859
|
*/
|
|
6470
6860
|
interface ValidationErrorNotification {
|
|
6861
|
+
/** Discriminator for type-safe union */
|
|
6471
6862
|
type: "error.validation";
|
|
6863
|
+
/** Unique notification identifier */
|
|
6472
6864
|
id: string;
|
|
6865
|
+
/** Serialized error object with stack trace and metadata */
|
|
6473
6866
|
error: object;
|
|
6867
|
+
/** Human-readable validation error message */
|
|
6474
6868
|
message: string;
|
|
6869
|
+
/** Unix timestamp in milliseconds when validation error occurred */
|
|
6475
6870
|
timestamp: number;
|
|
6871
|
+
/** Always false for error notifications (errors are from live context) */
|
|
6476
6872
|
backtest: boolean;
|
|
6477
6873
|
}
|
|
6478
|
-
/**
|
|
6479
|
-
* Progress update notification.
|
|
6480
|
-
* Emitted during backtest execution.
|
|
6481
|
-
*/
|
|
6482
|
-
interface ProgressBacktestNotification {
|
|
6483
|
-
type: "progress.backtest";
|
|
6484
|
-
id: string;
|
|
6485
|
-
timestamp: number;
|
|
6486
|
-
backtest: true;
|
|
6487
|
-
exchangeName: ExchangeName;
|
|
6488
|
-
strategyName: StrategyName;
|
|
6489
|
-
symbol: string;
|
|
6490
|
-
totalFrames: number;
|
|
6491
|
-
processedFrames: number;
|
|
6492
|
-
progress: number;
|
|
6493
|
-
}
|
|
6494
6874
|
/**
|
|
6495
6875
|
* Root discriminated union of all notification types.
|
|
6496
6876
|
* Type discrimination is done via the `type` field.
|
|
@@ -6517,7 +6897,7 @@ interface ProgressBacktestNotification {
|
|
|
6517
6897
|
* }
|
|
6518
6898
|
* ```
|
|
6519
6899
|
*/
|
|
6520
|
-
type NotificationModel = SignalOpenedNotification | SignalClosedNotification |
|
|
6900
|
+
type NotificationModel = SignalOpenedNotification | SignalClosedNotification | PartialProfitAvailableNotification | PartialLossAvailableNotification | BreakevenAvailableNotification | PartialProfitCommitNotification | PartialLossCommitNotification | BreakevenCommitNotification | TrailingStopCommitNotification | TrailingTakeCommitNotification | RiskRejectionNotification | SignalScheduledNotification | SignalCancelledNotification | InfoErrorNotification | CriticalErrorNotification | ValidationErrorNotification;
|
|
6521
6901
|
|
|
6522
6902
|
/**
|
|
6523
6903
|
* Unified tick event data for report generation.
|
|
@@ -6923,6 +7303,79 @@ interface RiskStatisticsModel {
|
|
|
6923
7303
|
byStrategy: Record<string, number>;
|
|
6924
7304
|
}
|
|
6925
7305
|
|
|
7306
|
+
/**
|
|
7307
|
+
* Action types for strategy events.
|
|
7308
|
+
* Represents all possible strategy management actions.
|
|
7309
|
+
*/
|
|
7310
|
+
type StrategyActionType = "cancel-scheduled" | "close-pending" | "partial-profit" | "partial-loss" | "trailing-stop" | "trailing-take" | "breakeven";
|
|
7311
|
+
/**
|
|
7312
|
+
* Unified strategy event data for markdown report generation.
|
|
7313
|
+
* Contains all information about strategy management actions.
|
|
7314
|
+
*/
|
|
7315
|
+
interface StrategyEvent {
|
|
7316
|
+
/** Event timestamp in milliseconds */
|
|
7317
|
+
timestamp: number;
|
|
7318
|
+
/** Trading pair symbol */
|
|
7319
|
+
symbol: string;
|
|
7320
|
+
/** Strategy name */
|
|
7321
|
+
strategyName: StrategyName;
|
|
7322
|
+
/** Exchange name */
|
|
7323
|
+
exchangeName: ExchangeName;
|
|
7324
|
+
/** Frame name (empty for live) */
|
|
7325
|
+
frameName: FrameName;
|
|
7326
|
+
/** Signal ID */
|
|
7327
|
+
signalId: string;
|
|
7328
|
+
/** Action type */
|
|
7329
|
+
action: StrategyActionType;
|
|
7330
|
+
/** Current market price when action was executed */
|
|
7331
|
+
currentPrice?: number;
|
|
7332
|
+
/** Percent to close for partial profit/loss */
|
|
7333
|
+
percentToClose?: number;
|
|
7334
|
+
/** Percent shift for trailing stop/take */
|
|
7335
|
+
percentShift?: number;
|
|
7336
|
+
/** Cancel ID for cancel-scheduled action */
|
|
7337
|
+
cancelId?: string;
|
|
7338
|
+
/** Close ID for close-pending action */
|
|
7339
|
+
closeId?: string;
|
|
7340
|
+
/** ISO timestamp string when action was created */
|
|
7341
|
+
createdAt: string;
|
|
7342
|
+
/** True if backtest mode, false if live mode */
|
|
7343
|
+
backtest: boolean;
|
|
7344
|
+
}
|
|
7345
|
+
/**
|
|
7346
|
+
* Statistical data calculated from strategy events.
|
|
7347
|
+
*
|
|
7348
|
+
* Provides metrics for strategy action tracking.
|
|
7349
|
+
*
|
|
7350
|
+
* @example
|
|
7351
|
+
* ```typescript
|
|
7352
|
+
* const stats = await Strategy.getData("BTCUSDT", "my-strategy");
|
|
7353
|
+
*
|
|
7354
|
+
* console.log(`Total events: ${stats.totalEvents}`);
|
|
7355
|
+
* console.log(`Cancel scheduled: ${stats.cancelScheduledCount}`);
|
|
7356
|
+
* ```
|
|
7357
|
+
*/
|
|
7358
|
+
interface StrategyStatisticsModel {
|
|
7359
|
+
/** Array of all strategy events with full details */
|
|
7360
|
+
eventList: StrategyEvent[];
|
|
7361
|
+
/** Total number of strategy events */
|
|
7362
|
+
totalEvents: number;
|
|
7363
|
+
/** Count of cancel-scheduled events */
|
|
7364
|
+
cancelScheduledCount: number;
|
|
7365
|
+
/** Count of close-pending events */
|
|
7366
|
+
closePendingCount: number;
|
|
7367
|
+
/** Count of partial-profit events */
|
|
7368
|
+
partialProfitCount: number;
|
|
7369
|
+
/** Count of partial-loss events */
|
|
7370
|
+
partialLossCount: number;
|
|
7371
|
+
/** Count of trailing-stop events */
|
|
7372
|
+
trailingStopCount: number;
|
|
7373
|
+
/** Count of trailing-take events */
|
|
7374
|
+
trailingTakeCount: number;
|
|
7375
|
+
/** Count of breakeven events */
|
|
7376
|
+
breakevenCount: number;
|
|
7377
|
+
}
|
|
7378
|
+
|
|
6926
7379
|
declare const BASE_WAIT_FOR_INIT_SYMBOL: unique symbol;
|
|
6927
7380
|
/**
|
|
6928
7381
|
* Signal data stored in persistence layer.
|
|
@@ -7602,6 +8055,8 @@ declare const WRITE_SAFE_SYMBOL$1: unique symbol;
|
|
|
7602
8055
|
* Controls which report services should be activated for JSONL event logging.
|
|
7603
8056
|
*/
|
|
7604
8057
|
interface IReportTarget {
|
|
8058
|
+
/** Enable strategy commit actions */
|
|
8059
|
+
strategy: boolean;
|
|
7605
8060
|
/** Enable risk rejection event logging */
|
|
7606
8061
|
risk: boolean;
|
|
7607
8062
|
/** Enable breakeven event logging */
|
|
@@ -7771,7 +8226,7 @@ declare class ReportUtils {
|
|
|
7771
8226
|
*
|
|
7772
8227
|
* @returns Cleanup function that unsubscribes from all enabled services
|
|
7773
8228
|
*/
|
|
7774
|
-
enable: ({ backtest: bt, breakeven, heat, live, partial, performance, risk, schedule, walker, }?: Partial<IReportTarget>) => (...args: any[]) => any;
|
|
8229
|
+
enable: ({ backtest: bt, breakeven, heat, live, partial, performance, risk, schedule, walker, strategy, }?: Partial<IReportTarget>) => (...args: any[]) => any;
|
|
7775
8230
|
/**
|
|
7776
8231
|
* Disables report services selectively.
|
|
7777
8232
|
*
|
|
@@ -7808,7 +8263,7 @@ declare class ReportUtils {
|
|
|
7808
8263
|
* Report.disable();
|
|
7809
8264
|
* ```
|
|
7810
8265
|
*/
|
|
7811
|
-
disable: ({ backtest: bt, breakeven, heat, live, partial, performance, risk, schedule, walker, }?: Partial<IReportTarget>) => void;
|
|
8266
|
+
disable: ({ backtest: bt, breakeven, heat, live, partial, performance, risk, schedule, walker, strategy, }?: Partial<IReportTarget>) => void;
|
|
7812
8267
|
}
|
|
7813
8268
|
/**
|
|
7814
8269
|
* Report adapter with pluggable storage backend and instance memoization.
|
|
@@ -7878,6 +8333,8 @@ declare const Report: ReportAdapter;
|
|
|
7878
8333
|
* Controls which markdown report services should be activated.
|
|
7879
8334
|
*/
|
|
7880
8335
|
interface IMarkdownTarget {
|
|
8336
|
+
/** Enable strategy event tracking reports (entry/exit signals) */
|
|
8337
|
+
strategy: boolean;
|
|
7881
8338
|
/** Enable risk rejection tracking reports (signals blocked by risk limits) */
|
|
7882
8339
|
risk: boolean;
|
|
7883
8340
|
/** Enable breakeven event tracking reports (when stop loss moves to entry) */
|
|
@@ -8091,7 +8548,7 @@ declare class MarkdownUtils {
|
|
|
8091
8548
|
*
|
|
8092
8549
|
* @returns Cleanup function that unsubscribes from all enabled services
|
|
8093
8550
|
*/
|
|
8094
|
-
enable: ({ backtest: bt, breakeven, heat, live, partial, performance, risk, schedule, walker, }?: Partial<IMarkdownTarget>) => (...args: any[]) => any;
|
|
8551
|
+
enable: ({ backtest: bt, breakeven, heat, live, partial, performance, strategy, risk, schedule, walker, }?: Partial<IMarkdownTarget>) => (...args: any[]) => any;
|
|
8095
8552
|
/**
|
|
8096
8553
|
* Disables markdown report services selectively.
|
|
8097
8554
|
*
|
|
@@ -8129,7 +8586,7 @@ declare class MarkdownUtils {
|
|
|
8129
8586
|
* Markdown.disable();
|
|
8130
8587
|
* ```
|
|
8131
8588
|
*/
|
|
8132
|
-
disable: ({ backtest: bt, breakeven, heat, live, partial, performance, risk, schedule, walker, }?: Partial<IMarkdownTarget>) => void;
|
|
8589
|
+
disable: ({ backtest: bt, breakeven, heat, live, partial, performance, risk, strategy, schedule, walker, }?: Partial<IMarkdownTarget>) => void;
|
|
8133
8590
|
}
|
|
8134
8591
|
/**
|
|
8135
8592
|
* Markdown adapter with pluggable storage backend and instance memoization.
|
|
@@ -8231,7 +8688,7 @@ declare const Markdown: MarkdownAdapter;
|
|
|
8231
8688
|
* @see ColumnModel for the base interface
|
|
8232
8689
|
* @see IStrategyTickResultClosed for the signal data structure
|
|
8233
8690
|
*/
|
|
8234
|
-
type Columns$
|
|
8691
|
+
type Columns$8 = ColumnModel<IStrategyTickResultClosed>;
|
|
8235
8692
|
/**
|
|
8236
8693
|
* Service for generating and saving backtest markdown reports.
|
|
8237
8694
|
*
|
|
@@ -8325,7 +8782,7 @@ declare class BacktestMarkdownService {
|
|
|
8325
8782
|
* console.log(markdown);
|
|
8326
8783
|
* ```
|
|
8327
8784
|
*/
|
|
8328
|
-
getReport: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, columns?: Columns$
|
|
8785
|
+
getReport: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, columns?: Columns$8[]) => Promise<string>;
|
|
8329
8786
|
/**
|
|
8330
8787
|
* Saves symbol-strategy report to disk.
|
|
8331
8788
|
* Creates directory if it doesn't exist.
|
|
@@ -8350,7 +8807,7 @@ declare class BacktestMarkdownService {
|
|
|
8350
8807
|
* await service.dump("BTCUSDT", "my-strategy", "binance", "1h", true, "./custom/path");
|
|
8351
8808
|
* ```
|
|
8352
8809
|
*/
|
|
8353
|
-
dump: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, path?: string, columns?: Columns$
|
|
8810
|
+
dump: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, path?: string, columns?: Columns$8[]) => Promise<void>;
|
|
8354
8811
|
/**
|
|
8355
8812
|
* Clears accumulated signal data from storage.
|
|
8356
8813
|
* If payload is provided, clears only that specific symbol-strategy-exchange-frame-backtest combination's data.
|
|
@@ -8860,7 +9317,7 @@ declare class BacktestUtils {
|
|
|
8860
9317
|
strategyName: StrategyName;
|
|
8861
9318
|
exchangeName: ExchangeName;
|
|
8862
9319
|
frameName: FrameName;
|
|
8863
|
-
}, columns?: Columns$
|
|
9320
|
+
}, columns?: Columns$8[]) => Promise<string>;
|
|
8864
9321
|
/**
|
|
8865
9322
|
* Saves strategy report to disk.
|
|
8866
9323
|
*
|
|
@@ -8891,7 +9348,7 @@ declare class BacktestUtils {
|
|
|
8891
9348
|
strategyName: StrategyName;
|
|
8892
9349
|
exchangeName: ExchangeName;
|
|
8893
9350
|
frameName: FrameName;
|
|
8894
|
-
}, path?: string, columns?: Columns$
|
|
9351
|
+
}, path?: string, columns?: Columns$8[]) => Promise<void>;
|
|
8895
9352
|
/**
|
|
8896
9353
|
* Lists all active backtest instances with their current status.
|
|
8897
9354
|
*
|
|
@@ -8965,7 +9422,7 @@ declare const Backtest: BacktestUtils;
|
|
|
8965
9422
|
* @see ColumnModel for the base interface
|
|
8966
9423
|
* @see TickEvent for the event data structure
|
|
8967
9424
|
*/
|
|
8968
|
-
type Columns$
|
|
9425
|
+
type Columns$7 = ColumnModel<TickEvent>;
|
|
8969
9426
|
/**
|
|
8970
9427
|
* Service for generating and saving live trading markdown reports.
|
|
8971
9428
|
*
|
|
@@ -9092,7 +9549,7 @@ declare class LiveMarkdownService {
|
|
|
9092
9549
|
* console.log(markdown);
|
|
9093
9550
|
* ```
|
|
9094
9551
|
*/
|
|
9095
|
-
getReport: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, columns?: Columns$
|
|
9552
|
+
getReport: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, columns?: Columns$7[]) => Promise<string>;
|
|
9096
9553
|
/**
|
|
9097
9554
|
* Saves symbol-strategy report to disk.
|
|
9098
9555
|
* Creates directory if it doesn't exist.
|
|
@@ -9117,7 +9574,7 @@ declare class LiveMarkdownService {
|
|
|
9117
9574
|
* await service.dump("BTCUSDT", "my-strategy", "binance", "1h", false, "./custom/path");
|
|
9118
9575
|
* ```
|
|
9119
9576
|
*/
|
|
9120
|
-
dump: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, path?: string, columns?: Columns$
|
|
9577
|
+
dump: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, path?: string, columns?: Columns$7[]) => Promise<void>;
|
|
9121
9578
|
/**
|
|
9122
9579
|
* Clears accumulated event data from storage.
|
|
9123
9580
|
* If payload is provided, clears only that specific symbol-strategy-exchange-frame-backtest combination's data.
|
|
@@ -9586,7 +10043,7 @@ declare class LiveUtils {
|
|
|
9586
10043
|
getReport: (symbol: string, context: {
|
|
9587
10044
|
strategyName: StrategyName;
|
|
9588
10045
|
exchangeName: ExchangeName;
|
|
9589
|
-
}, columns?: Columns$
|
|
10046
|
+
}, columns?: Columns$7[]) => Promise<string>;
|
|
9590
10047
|
/**
|
|
9591
10048
|
* Saves strategy report to disk.
|
|
9592
10049
|
*
|
|
@@ -9616,7 +10073,7 @@ declare class LiveUtils {
|
|
|
9616
10073
|
dump: (symbol: string, context: {
|
|
9617
10074
|
strategyName: StrategyName;
|
|
9618
10075
|
exchangeName: ExchangeName;
|
|
9619
|
-
}, path?: string, columns?: Columns$
|
|
10076
|
+
}, path?: string, columns?: Columns$7[]) => Promise<void>;
|
|
9620
10077
|
/**
|
|
9621
10078
|
* Lists all active live trading instances with their current status.
|
|
9622
10079
|
*
|
|
@@ -9686,7 +10143,7 @@ declare const Live: LiveUtils;
|
|
|
9686
10143
|
* @see ColumnModel for the base interface
|
|
9687
10144
|
* @see ScheduledEvent for the event data structure
|
|
9688
10145
|
*/
|
|
9689
|
-
type Columns$
|
|
10146
|
+
type Columns$6 = ColumnModel<ScheduledEvent>;
|
|
9690
10147
|
/**
|
|
9691
10148
|
* Service for generating and saving scheduled signals markdown reports.
|
|
9692
10149
|
*
|
|
@@ -9797,7 +10254,7 @@ declare class ScheduleMarkdownService {
|
|
|
9797
10254
|
* console.log(markdown);
|
|
9798
10255
|
* ```
|
|
9799
10256
|
*/
|
|
9800
|
-
getReport: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, columns?: Columns$
|
|
10257
|
+
getReport: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, columns?: Columns$6[]) => Promise<string>;
|
|
9801
10258
|
/**
|
|
9802
10259
|
* Saves symbol-strategy report to disk.
|
|
9803
10260
|
* Creates directory if it doesn't exist.
|
|
@@ -9822,7 +10279,7 @@ declare class ScheduleMarkdownService {
|
|
|
9822
10279
|
* await service.dump("BTCUSDT", "my-strategy", "binance", "1h", false, "./custom/path");
|
|
9823
10280
|
* ```
|
|
9824
10281
|
*/
|
|
9825
|
-
dump: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, path?: string, columns?: Columns$
|
|
10282
|
+
dump: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, path?: string, columns?: Columns$6[]) => Promise<void>;
|
|
9826
10283
|
/**
|
|
9827
10284
|
* Clears accumulated event data from storage.
|
|
9828
10285
|
* If payload is provided, clears only that specific symbol-strategy-exchange-frame-backtest combination's data.
|
|
@@ -9912,7 +10369,7 @@ declare class ScheduleUtils {
|
|
|
9912
10369
|
strategyName: StrategyName;
|
|
9913
10370
|
exchangeName: ExchangeName;
|
|
9914
10371
|
frameName: FrameName;
|
|
9915
|
-
}, backtest?: boolean, columns?: Columns$
|
|
10372
|
+
}, backtest?: boolean, columns?: Columns$6[]) => Promise<string>;
|
|
9916
10373
|
/**
|
|
9917
10374
|
* Saves strategy report to disk.
|
|
9918
10375
|
*
|
|
@@ -9934,7 +10391,7 @@ declare class ScheduleUtils {
|
|
|
9934
10391
|
strategyName: StrategyName;
|
|
9935
10392
|
exchangeName: ExchangeName;
|
|
9936
10393
|
frameName: FrameName;
|
|
9937
|
-
}, backtest?: boolean, path?: string, columns?: Columns$
|
|
10394
|
+
}, backtest?: boolean, path?: string, columns?: Columns$6[]) => Promise<void>;
|
|
9938
10395
|
}
|
|
9939
10396
|
/**
|
|
9940
10397
|
* Singleton instance of ScheduleUtils for convenient scheduled signals reporting.
|
|
@@ -9980,7 +10437,7 @@ declare const Schedule: ScheduleUtils;
|
|
|
9980
10437
|
* @see ColumnModel for the base interface
|
|
9981
10438
|
* @see MetricStats for the metric data structure
|
|
9982
10439
|
*/
|
|
9983
|
-
type Columns$
|
|
10440
|
+
type Columns$5 = ColumnModel<MetricStats>;
|
|
9984
10441
|
/**
|
|
9985
10442
|
* Service for collecting and analyzing performance metrics.
|
|
9986
10443
|
*
|
|
@@ -10087,7 +10544,7 @@ declare class PerformanceMarkdownService {
|
|
|
10087
10544
|
* console.log(markdown);
|
|
10088
10545
|
* ```
|
|
10089
10546
|
*/
|
|
10090
|
-
getReport: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, columns?: Columns$
|
|
10547
|
+
getReport: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, columns?: Columns$5[]) => Promise<string>;
|
|
10091
10548
|
/**
|
|
10092
10549
|
* Saves performance report to disk.
|
|
10093
10550
|
*
|
|
@@ -10108,7 +10565,7 @@ declare class PerformanceMarkdownService {
|
|
|
10108
10565
|
* await performanceService.dump("BTCUSDT", "my-strategy", "binance", "1h", false, "./custom/path");
|
|
10109
10566
|
* ```
|
|
10110
10567
|
*/
|
|
10111
|
-
dump: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, path?: string, columns?: Columns$
|
|
10568
|
+
dump: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, path?: string, columns?: Columns$5[]) => Promise<void>;
|
|
10112
10569
|
/**
|
|
10113
10570
|
* Clears accumulated performance data from storage.
|
|
10114
10571
|
*
|
|
@@ -10216,7 +10673,7 @@ declare class Performance {
|
|
|
10216
10673
|
strategyName: StrategyName;
|
|
10217
10674
|
exchangeName: ExchangeName;
|
|
10218
10675
|
frameName: FrameName;
|
|
10219
|
-
}, backtest?: boolean, columns?: Columns$
|
|
10676
|
+
}, backtest?: boolean, columns?: Columns$5[]): Promise<string>;
|
|
10220
10677
|
/**
|
|
10221
10678
|
* Saves performance report to disk.
|
|
10222
10679
|
*
|
|
@@ -10241,7 +10698,7 @@ declare class Performance {
|
|
|
10241
10698
|
strategyName: StrategyName;
|
|
10242
10699
|
exchangeName: ExchangeName;
|
|
10243
10700
|
frameName: FrameName;
|
|
10244
|
-
}, backtest?: boolean, path?: string, columns?: Columns$
|
|
10701
|
+
}, backtest?: boolean, path?: string, columns?: Columns$5[]): Promise<void>;
|
|
10245
10702
|
}
|
|
10246
10703
|
|
|
10247
10704
|
/**
|
|
@@ -10672,7 +11129,7 @@ declare const Walker: WalkerUtils;
|
|
|
10672
11129
|
* @see ColumnModel for the base interface
|
|
10673
11130
|
* @see IHeatmapRow for the row data structure
|
|
10674
11131
|
*/
|
|
10675
|
-
type Columns$
|
|
11132
|
+
type Columns$4 = ColumnModel<IHeatmapRow>;
|
|
10676
11133
|
/**
|
|
10677
11134
|
* Portfolio Heatmap Markdown Service.
|
|
10678
11135
|
*
|
|
@@ -10793,7 +11250,7 @@ declare class HeatMarkdownService {
|
|
|
10793
11250
|
* // ...
|
|
10794
11251
|
* ```
|
|
10795
11252
|
*/
|
|
10796
|
-
getReport: (strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, columns?: Columns$
|
|
11253
|
+
getReport: (strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, columns?: Columns$4[]) => Promise<string>;
|
|
10797
11254
|
/**
|
|
10798
11255
|
* Saves heatmap report to disk.
|
|
10799
11256
|
*
|
|
@@ -10818,7 +11275,7 @@ declare class HeatMarkdownService {
|
|
|
10818
11275
|
* await service.dump("my-strategy", "binance", "frame1", true, "./reports");
|
|
10819
11276
|
* ```
|
|
10820
11277
|
*/
|
|
10821
|
-
dump: (strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, path?: string, columns?: Columns$
|
|
11278
|
+
dump: (strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, path?: string, columns?: Columns$4[]) => Promise<void>;
|
|
10822
11279
|
/**
|
|
10823
11280
|
* Clears accumulated heatmap data from storage.
|
|
10824
11281
|
* If payload is provided, clears only that exchangeName+frameName+backtest combination's data.
|
|
@@ -10948,7 +11405,7 @@ declare class HeatUtils {
|
|
|
10948
11405
|
strategyName: StrategyName;
|
|
10949
11406
|
exchangeName: ExchangeName;
|
|
10950
11407
|
frameName: FrameName;
|
|
10951
|
-
}, backtest?: boolean, columns?: Columns$
|
|
11408
|
+
}, backtest?: boolean, columns?: Columns$4[]) => Promise<string>;
|
|
10952
11409
|
/**
|
|
10953
11410
|
* Saves heatmap report to disk for a strategy.
|
|
10954
11411
|
*
|
|
@@ -10981,7 +11438,7 @@ declare class HeatUtils {
|
|
|
10981
11438
|
strategyName: StrategyName;
|
|
10982
11439
|
exchangeName: ExchangeName;
|
|
10983
11440
|
frameName: FrameName;
|
|
10984
|
-
}, backtest?: boolean, path?: string, columns?: Columns$
|
|
11441
|
+
}, backtest?: boolean, path?: string, columns?: Columns$4[]) => Promise<void>;
|
|
10985
11442
|
}
|
|
10986
11443
|
/**
|
|
10987
11444
|
* Singleton instance of HeatUtils for convenient heatmap operations.
|
|
@@ -11135,7 +11592,7 @@ declare const PositionSize: typeof PositionSizeUtils;
|
|
|
11135
11592
|
* @see ColumnModel for the base interface
|
|
11136
11593
|
* @see PartialEvent for the event data structure
|
|
11137
11594
|
*/
|
|
11138
|
-
type Columns$
|
|
11595
|
+
type Columns$3 = ColumnModel<PartialEvent>;
|
|
11139
11596
|
/**
|
|
11140
11597
|
* Service for generating and saving partial profit/loss markdown reports.
|
|
11141
11598
|
*
|
|
@@ -11257,7 +11714,7 @@ declare class PartialMarkdownService {
|
|
|
11257
11714
|
* console.log(markdown);
|
|
11258
11715
|
* ```
|
|
11259
11716
|
*/
|
|
11260
|
-
getReport: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, columns?: Columns$
|
|
11717
|
+
getReport: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, columns?: Columns$3[]) => Promise<string>;
|
|
11261
11718
|
/**
|
|
11262
11719
|
* Saves symbol-strategy report to disk.
|
|
11263
11720
|
* Creates directory if it doesn't exist.
|
|
@@ -11282,7 +11739,7 @@ declare class PartialMarkdownService {
|
|
|
11282
11739
|
* await service.dump("BTCUSDT", "my-strategy", "binance", "1h", false, "./custom/path");
|
|
11283
11740
|
* ```
|
|
11284
11741
|
*/
|
|
11285
|
-
dump: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, path?: string, columns?: Columns$
|
|
11742
|
+
dump: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, path?: string, columns?: Columns$3[]) => Promise<void>;
|
|
11286
11743
|
/**
|
|
11287
11744
|
* Clears accumulated event data from storage.
|
|
11288
11745
|
* If payload is provided, clears only that specific symbol-strategy-exchange-frame-backtest combination's data.
|
|
@@ -11418,7 +11875,7 @@ declare class PartialUtils {
|
|
|
11418
11875
|
strategyName: StrategyName;
|
|
11419
11876
|
exchangeName: ExchangeName;
|
|
11420
11877
|
frameName: FrameName;
|
|
11421
|
-
}, backtest?: boolean, columns?: Columns$
|
|
11878
|
+
}, backtest?: boolean, columns?: Columns$3[]) => Promise<string>;
|
|
11422
11879
|
/**
|
|
11423
11880
|
* Generates and saves markdown report to file.
|
|
11424
11881
|
*
|
|
@@ -11455,7 +11912,7 @@ declare class PartialUtils {
|
|
|
11455
11912
|
strategyName: StrategyName;
|
|
11456
11913
|
exchangeName: ExchangeName;
|
|
11457
11914
|
frameName: FrameName;
|
|
11458
|
-
}, backtest?: boolean, path?: string, columns?: Columns$
|
|
11915
|
+
}, backtest?: boolean, path?: string, columns?: Columns$3[]) => Promise<void>;
|
|
11459
11916
|
}
|
|
11460
11917
|
/**
|
|
11461
11918
|
* Global singleton instance of PartialUtils.
|
|
@@ -11583,7 +12040,7 @@ declare const Constant: ConstantUtils;
|
|
|
11583
12040
|
* @see ColumnModel for the base interface
|
|
11584
12041
|
* @see RiskEvent for the event data structure
|
|
11585
12042
|
*/
|
|
11586
|
-
type Columns$
|
|
12043
|
+
type Columns$2 = ColumnModel<RiskEvent>;
|
|
11587
12044
|
/**
|
|
11588
12045
|
* Service for generating and saving risk rejection markdown reports.
|
|
11589
12046
|
*
|
|
@@ -11692,7 +12149,7 @@ declare class RiskMarkdownService {
|
|
|
11692
12149
|
* console.log(markdown);
|
|
11693
12150
|
* ```
|
|
11694
12151
|
*/
|
|
11695
|
-
getReport: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, columns?: Columns$
|
|
12152
|
+
getReport: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, columns?: Columns$2[]) => Promise<string>;
|
|
11696
12153
|
/**
|
|
11697
12154
|
* Saves symbol-strategy report to disk.
|
|
11698
12155
|
* Creates directory if it doesn't exist.
|
|
@@ -11717,7 +12174,7 @@ declare class RiskMarkdownService {
|
|
|
11717
12174
|
* await service.dump("BTCUSDT", "my-strategy", "binance", "1h", false, "./custom/path");
|
|
11718
12175
|
* ```
|
|
11719
12176
|
*/
|
|
11720
|
-
dump: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, path?: string, columns?: Columns$
|
|
12177
|
+
dump: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, path?: string, columns?: Columns$2[]) => Promise<void>;
|
|
11721
12178
|
/**
|
|
11722
12179
|
* Clears accumulated event data from storage.
|
|
11723
12180
|
* If payload is provided, clears only that specific symbol-strategy-exchange-frame-backtest combination's data.
|
|
@@ -11855,7 +12312,7 @@ declare class RiskUtils {
|
|
|
11855
12312
|
strategyName: StrategyName;
|
|
11856
12313
|
exchangeName: ExchangeName;
|
|
11857
12314
|
frameName: FrameName;
|
|
11858
|
-
}, backtest?: boolean, columns?: Columns$
|
|
12315
|
+
}, backtest?: boolean, columns?: Columns$2[]) => Promise<string>;
|
|
11859
12316
|
/**
|
|
11860
12317
|
* Generates and saves markdown report to file.
|
|
11861
12318
|
*
|
|
@@ -11892,7 +12349,7 @@ declare class RiskUtils {
|
|
|
11892
12349
|
strategyName: StrategyName;
|
|
11893
12350
|
exchangeName: ExchangeName;
|
|
11894
12351
|
frameName: FrameName;
|
|
11895
|
-
}, backtest?: boolean, path?: string, columns?: Columns$
|
|
12352
|
+
}, backtest?: boolean, path?: string, columns?: Columns$2[]) => Promise<void>;
|
|
11896
12353
|
}
|
|
11897
12354
|
/**
|
|
11898
12355
|
* Global singleton instance of RiskUtils.
|
|
@@ -12321,7 +12778,7 @@ declare const Notification: NotificationUtils;
|
|
|
12321
12778
|
* @see ColumnModel for the base interface
|
|
12322
12779
|
* @see BreakevenEvent for the event data structure
|
|
12323
12780
|
*/
|
|
12324
|
-
type Columns = ColumnModel<BreakevenEvent>;
|
|
12781
|
+
type Columns$1 = ColumnModel<BreakevenEvent>;
|
|
12325
12782
|
/**
|
|
12326
12783
|
* Service for generating and saving breakeven markdown reports.
|
|
12327
12784
|
*
|
|
@@ -12430,7 +12887,7 @@ declare class BreakevenMarkdownService {
|
|
|
12430
12887
|
* console.log(markdown);
|
|
12431
12888
|
* ```
|
|
12432
12889
|
*/
|
|
12433
|
-
getReport: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, columns?: Columns[]) => Promise<string>;
|
|
12890
|
+
getReport: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, columns?: Columns$1[]) => Promise<string>;
|
|
12434
12891
|
/**
|
|
12435
12892
|
* Saves symbol-strategy report to disk.
|
|
12436
12893
|
* Creates directory if it doesn't exist.
|
|
@@ -12455,7 +12912,7 @@ declare class BreakevenMarkdownService {
|
|
|
12455
12912
|
* await service.dump("BTCUSDT", "my-strategy", "binance", "1h", false, "./custom/path");
|
|
12456
12913
|
* ```
|
|
12457
12914
|
*/
|
|
12458
|
-
dump: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, path?: string, columns?: Columns[]) => Promise<void>;
|
|
12915
|
+
dump: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, path?: string, columns?: Columns$1[]) => Promise<void>;
|
|
12459
12916
|
/**
|
|
12460
12917
|
* Clears accumulated event data from storage.
|
|
12461
12918
|
* If payload is provided, clears only that specific symbol-strategy-exchange-frame-backtest combination's data.
|
|
@@ -12583,7 +13040,7 @@ declare class BreakevenUtils {
|
|
|
12583
13040
|
strategyName: StrategyName;
|
|
12584
13041
|
exchangeName: ExchangeName;
|
|
12585
13042
|
frameName: FrameName;
|
|
12586
|
-
}, backtest?: boolean, columns?: Columns[]) => Promise<string>;
|
|
13043
|
+
}, backtest?: boolean, columns?: Columns$1[]) => Promise<string>;
|
|
12587
13044
|
/**
|
|
12588
13045
|
* Generates and saves markdown report to file.
|
|
12589
13046
|
*
|
|
@@ -12620,7 +13077,7 @@ declare class BreakevenUtils {
|
|
|
12620
13077
|
strategyName: StrategyName;
|
|
12621
13078
|
exchangeName: ExchangeName;
|
|
12622
13079
|
frameName: FrameName;
|
|
12623
|
-
}, backtest?: boolean, path?: string, columns?: Columns[]) => Promise<void>;
|
|
13080
|
+
}, backtest?: boolean, path?: string, columns?: Columns$1[]) => Promise<void>;
|
|
12624
13081
|
}
|
|
12625
13082
|
/**
|
|
12626
13083
|
* Global singleton instance of BreakevenUtils.
|
|
@@ -12639,169 +13096,1060 @@ declare class BreakevenUtils {
|
|
|
12639
13096
|
declare const Breakeven: BreakevenUtils;
|
|
12640
13097
|
|
|
12641
13098
|
/**
|
|
12642
|
-
*
|
|
12643
|
-
*
|
|
12644
|
-
* Wraps all IPublicAction methods with trycatch to prevent user code errors from crashing the system.
|
|
12645
|
-
* All errors are logged, sent to errorEmitter, and returned as null (non-breaking).
|
|
12646
|
-
*
|
|
12647
|
-
* Key features:
|
|
12648
|
-
* - Automatic error catching and logging for all action methods
|
|
12649
|
-
* - Safe execution of partial user implementations (missing methods return null)
|
|
12650
|
-
* - Consistent error capture across all action lifecycle events
|
|
12651
|
-
* - Non-breaking failure mode (errors logged but execution continues)
|
|
12652
|
-
*
|
|
12653
|
-
* Architecture:
|
|
12654
|
-
* - Private constructor enforces factory pattern via fromInstance()
|
|
12655
|
-
* - Each method checks if target implements the method before calling
|
|
12656
|
-
* - Errors caught with fallback handler (warn log + errorEmitter)
|
|
12657
|
-
* - Returns null on error to prevent undefined behavior
|
|
12658
|
-
*
|
|
12659
|
-
* Used by:
|
|
12660
|
-
* - ClientAction to wrap user-provided action handlers
|
|
12661
|
-
* - ActionCoreService to safely invoke action callbacks
|
|
12662
|
-
*
|
|
12663
|
-
* @example
|
|
12664
|
-
* ```typescript
|
|
12665
|
-
* // Create proxy from user implementation
|
|
12666
|
-
* const userAction = {
|
|
12667
|
-
* signal: async (event) => {
|
|
12668
|
-
* // User code that might throw
|
|
12669
|
-
* throw new Error('User error');
|
|
12670
|
-
* }
|
|
12671
|
-
* };
|
|
12672
|
-
*
|
|
12673
|
-
* const proxy = ActionProxy.fromInstance(userAction);
|
|
12674
|
-
*
|
|
12675
|
-
* // Error is caught and logged, execution continues
|
|
12676
|
-
* await proxy.signal(event); // Logs error, returns null
|
|
12677
|
-
* await proxy.dispose(); // Safe call even though not implemented
|
|
12678
|
-
* ```
|
|
13099
|
+
* Logger service with automatic context injection.
|
|
12679
13100
|
*
|
|
12680
|
-
*
|
|
12681
|
-
*
|
|
12682
|
-
*
|
|
12683
|
-
*
|
|
12684
|
-
*
|
|
12685
|
-
* // Other methods not implemented
|
|
12686
|
-
* };
|
|
13101
|
+
* Features:
|
|
13102
|
+
* - Delegates to user-provided logger via setLogger()
|
|
13103
|
+
* - Automatically appends method context (strategyName, exchangeName, frameName)
|
|
13104
|
+
* - Automatically appends execution context (symbol, when, backtest)
|
|
13105
|
+
* - Defaults to NOOP_LOGGER if no logger configured
|
|
12687
13106
|
*
|
|
12688
|
-
*
|
|
12689
|
-
* await proxy.init(); // Works
|
|
12690
|
-
* await proxy.signal(event); // Returns null (not implemented)
|
|
12691
|
-
* ```
|
|
13107
|
+
* Used throughout the framework for consistent logging with context.
|
|
12692
13108
|
*/
|
|
12693
|
-
declare class
|
|
12694
|
-
readonly
|
|
13109
|
+
declare class LoggerService implements ILogger {
|
|
13110
|
+
private readonly methodContextService;
|
|
13111
|
+
private readonly executionContextService;
|
|
13112
|
+
private _commonLogger;
|
|
12695
13113
|
/**
|
|
12696
|
-
*
|
|
12697
|
-
*
|
|
12698
|
-
* @param _target - Partial action implementation to wrap with error capture
|
|
12699
|
-
* @private Use ActionProxy.fromInstance() instead
|
|
13114
|
+
* Gets current method context if available.
|
|
13115
|
+
* Contains strategyName, exchangeName, frameName from MethodContextService.
|
|
12700
13116
|
*/
|
|
12701
|
-
private
|
|
13117
|
+
private get methodContext();
|
|
12702
13118
|
/**
|
|
12703
|
-
*
|
|
12704
|
-
*
|
|
12705
|
-
* Wraps the user's init() method in trycatch to prevent initialization errors from crashing the system.
|
|
12706
|
-
* If the target doesn't implement init(), this method safely returns undefined.
|
|
12707
|
-
*
|
|
12708
|
-
* @returns Promise resolving to user's init() result or undefined if not implemented
|
|
13119
|
+
* Gets current execution context if available.
|
|
13120
|
+
* Contains symbol, when, backtest from ExecutionContextService.
|
|
12709
13121
|
*/
|
|
12710
|
-
|
|
13122
|
+
private get executionContext();
|
|
12711
13123
|
/**
|
|
12712
|
-
*
|
|
12713
|
-
*
|
|
12714
|
-
* Wraps the user's signal() method to catch and log any errors.
|
|
12715
|
-
* Called on every tick/candle when strategy is evaluated.
|
|
13124
|
+
* Logs general-purpose message with automatic context injection.
|
|
12716
13125
|
*
|
|
12717
|
-
* @param
|
|
12718
|
-
* @
|
|
13126
|
+
* @param topic - Log topic/category
|
|
13127
|
+
* @param args - Additional log arguments
|
|
12719
13128
|
*/
|
|
12720
|
-
|
|
13129
|
+
log: (topic: string, ...args: any[]) => Promise<void>;
|
|
12721
13130
|
/**
|
|
12722
|
-
*
|
|
12723
|
-
*
|
|
12724
|
-
* Wraps the user's signalLive() method to catch and log any errors.
|
|
12725
|
-
* Called every tick in live mode.
|
|
13131
|
+
* Logs debug-level message with automatic context injection.
|
|
12726
13132
|
*
|
|
12727
|
-
* @param
|
|
12728
|
-
* @
|
|
13133
|
+
* @param topic - Log topic/category
|
|
13134
|
+
* @param args - Additional log arguments
|
|
12729
13135
|
*/
|
|
12730
|
-
|
|
13136
|
+
debug: (topic: string, ...args: any[]) => Promise<void>;
|
|
12731
13137
|
/**
|
|
12732
|
-
*
|
|
12733
|
-
*
|
|
12734
|
-
* Wraps the user's signalBacktest() method to catch and log any errors.
|
|
12735
|
-
* Called every candle in backtest mode.
|
|
13138
|
+
* Logs info-level message with automatic context injection.
|
|
12736
13139
|
*
|
|
12737
|
-
* @param
|
|
12738
|
-
* @
|
|
13140
|
+
* @param topic - Log topic/category
|
|
13141
|
+
* @param args - Additional log arguments
|
|
12739
13142
|
*/
|
|
12740
|
-
|
|
13143
|
+
info: (topic: string, ...args: any[]) => Promise<void>;
|
|
12741
13144
|
/**
|
|
12742
|
-
*
|
|
12743
|
-
*
|
|
12744
|
-
* Wraps the user's breakevenAvailable() method to catch and log any errors.
|
|
12745
|
-
* Called once per signal when stop-loss is moved to entry price.
|
|
13145
|
+
* Logs warning-level message with automatic context injection.
|
|
12746
13146
|
*
|
|
12747
|
-
* @param
|
|
12748
|
-
* @
|
|
13147
|
+
* @param topic - Log topic/category
|
|
13148
|
+
* @param args - Additional log arguments
|
|
12749
13149
|
*/
|
|
12750
|
-
|
|
13150
|
+
warn: (topic: string, ...args: any[]) => Promise<void>;
|
|
12751
13151
|
/**
|
|
12752
|
-
*
|
|
12753
|
-
*
|
|
12754
|
-
* Wraps the user's partialProfitAvailable() method to catch and log any errors.
|
|
12755
|
-
* Called once per profit level per signal (10%, 20%, 30%, etc).
|
|
13152
|
+
* Sets custom logger implementation.
|
|
12756
13153
|
*
|
|
12757
|
-
* @param
|
|
12758
|
-
* @returns Promise resolving to user's partialProfitAvailable() result or null on error
|
|
13154
|
+
* @param logger - Custom logger implementing ILogger interface
|
|
12759
13155
|
*/
|
|
12760
|
-
|
|
13156
|
+
setLogger: (logger: ILogger) => void;
|
|
13157
|
+
}
|
|
13158
|
+
|
|
13159
|
+
/**
|
|
13160
|
+
* Type definition for strategy methods.
|
|
13161
|
+
* Maps all keys of IStrategy to any type.
|
|
13162
|
+
* Used for dynamic method routing in StrategyCoreService.
|
|
13163
|
+
*/
|
|
13164
|
+
type TStrategy$1 = {
|
|
13165
|
+
[key in keyof IStrategy]: any;
|
|
13166
|
+
};
|
|
13167
|
+
/**
|
|
13168
|
+
* Global service for strategy operations with execution context injection.
|
|
13169
|
+
*
|
|
13170
|
+
* Wraps StrategyConnectionService with ExecutionContextService to inject
|
|
13171
|
+
* symbol, when, and backtest parameters into the execution context.
|
|
13172
|
+
*
|
|
13173
|
+
* Used internally by BacktestLogicPrivateService and LiveLogicPrivateService.
|
|
13174
|
+
*/
|
|
13175
|
+
declare class StrategyCoreService implements TStrategy$1 {
|
|
13176
|
+
private readonly loggerService;
|
|
13177
|
+
private readonly strategyConnectionService;
|
|
13178
|
+
private readonly strategySchemaService;
|
|
13179
|
+
private readonly riskValidationService;
|
|
13180
|
+
private readonly strategyValidationService;
|
|
13181
|
+
private readonly exchangeValidationService;
|
|
13182
|
+
private readonly frameValidationService;
|
|
12761
13183
|
/**
|
|
12762
|
-
*
|
|
12763
|
-
*
|
|
12764
|
-
* Wraps the user's partialLossAvailable() method to catch and log any errors.
|
|
12765
|
-
* Called once per loss level per signal (-10%, -20%, -30%, etc).
|
|
13184
|
+
* Validates strategy and associated risk configuration.
|
|
12766
13185
|
*
|
|
12767
|
-
*
|
|
12768
|
-
*
|
|
13186
|
+
* Memoized to avoid redundant validations for the same symbol-strategy-exchange-frame combination.
|
|
13187
|
+
* Logs validation activity.
|
|
13188
|
+
* @param symbol - Trading pair symbol
|
|
13189
|
+
* @param context - Execution context with strategyName, exchangeName, frameName
|
|
13190
|
+
* @returns Promise that resolves when validation is complete
|
|
12769
13191
|
*/
|
|
12770
|
-
|
|
13192
|
+
private validate;
|
|
12771
13193
|
/**
|
|
12772
|
-
*
|
|
12773
|
-
*
|
|
12774
|
-
*
|
|
12775
|
-
* Called every minute while a scheduled signal is waiting for activation.
|
|
13194
|
+
* Retrieves the currently active pending signal for the symbol.
|
|
13195
|
+
* If no active signal exists, returns null.
|
|
13196
|
+
* Used internally for monitoring TP/SL and time expiration.
|
|
12776
13197
|
*
|
|
12777
|
-
* @param
|
|
12778
|
-
* @
|
|
13198
|
+
* @param backtest - Whether running in backtest mode
|
|
13199
|
+
* @param symbol - Trading pair symbol
|
|
13200
|
+
* @param context - Execution context with strategyName, exchangeName, frameName
|
|
13201
|
+
* @returns Promise resolving to pending signal or null
|
|
12779
13202
|
*/
|
|
12780
|
-
|
|
13203
|
+
getPendingSignal: (backtest: boolean, symbol: string, context: {
|
|
13204
|
+
strategyName: StrategyName;
|
|
13205
|
+
exchangeName: ExchangeName;
|
|
13206
|
+
frameName: FrameName;
|
|
13207
|
+
}) => Promise<ISignalRow | null>;
|
|
12781
13208
|
/**
|
|
12782
|
-
*
|
|
12783
|
-
*
|
|
12784
|
-
*
|
|
12785
|
-
* Called every minute while a pending signal is active (position open).
|
|
13209
|
+
* Retrieves the currently active scheduled signal for the symbol.
|
|
13210
|
+
* If no scheduled signal exists, returns null.
|
|
13211
|
+
* Used internally for monitoring scheduled signal activation.
|
|
12786
13212
|
*
|
|
12787
|
-
* @param
|
|
12788
|
-
* @
|
|
13213
|
+
* @param backtest - Whether running in backtest mode
|
|
13214
|
+
* @param symbol - Trading pair symbol
|
|
13215
|
+
* @param context - Execution context with strategyName, exchangeName, frameName
|
|
13216
|
+
* @returns Promise resolving to scheduled signal or null
|
|
12789
13217
|
*/
|
|
12790
|
-
|
|
13218
|
+
getScheduledSignal: (backtest: boolean, symbol: string, context: {
|
|
13219
|
+
strategyName: StrategyName;
|
|
13220
|
+
exchangeName: ExchangeName;
|
|
13221
|
+
frameName: FrameName;
|
|
13222
|
+
}) => Promise<IScheduledSignalRow | null>;
|
|
12791
13223
|
/**
|
|
12792
|
-
*
|
|
13224
|
+
* Checks if breakeven threshold has been reached for the current pending signal.
|
|
12793
13225
|
*
|
|
12794
|
-
*
|
|
12795
|
-
*
|
|
13226
|
+
* Validates strategy existence and delegates to connection service
|
|
13227
|
+
* to check if price has moved far enough to cover transaction costs.
|
|
12796
13228
|
*
|
|
12797
|
-
*
|
|
12798
|
-
* @returns Promise resolving to user's riskRejection() result or null on error
|
|
12799
|
-
*/
|
|
12800
|
-
riskRejection(event: RiskContract): Promise<any>;
|
|
12801
|
-
/**
|
|
12802
|
-
* Cleans up resources with error capture.
|
|
13229
|
+
* Does not require execution context as this is a state query operation.
|
|
12803
13230
|
*
|
|
12804
|
-
*
|
|
13231
|
+
* @param backtest - Whether running in backtest mode
|
|
13232
|
+
* @param symbol - Trading pair symbol
|
|
13233
|
+
* @param currentPrice - Current market price to check against threshold
|
|
13234
|
+
* @param context - Execution context with strategyName, exchangeName, frameName
|
|
13235
|
+
* @returns Promise<boolean> - true if breakeven threshold reached, false otherwise
|
|
13236
|
+
*
|
|
13237
|
+
* @example
|
|
13238
|
+
* ```typescript
|
|
13239
|
+
* // Check if breakeven is available for LONG position (entry=100, threshold=0.4%)
|
|
13240
|
+
* const canBreakeven = await strategyCoreService.getBreakeven(
|
|
13241
|
+
* false,
|
|
13242
|
+
* "BTCUSDT",
|
|
13243
|
+
* 100.5,
|
|
13244
|
+
* { strategyName: "my-strategy", exchangeName: "binance", frameName: "" }
|
|
13245
|
+
* );
|
|
13246
|
+
* // Returns true (price >= 100.4)
|
|
13247
|
+
*
|
|
13248
|
+
* if (canBreakeven) {
|
|
13249
|
+
* await strategyCoreService.breakeven(false, "BTCUSDT", 100.5, context);
|
|
13250
|
+
* }
|
|
13251
|
+
* ```
|
|
13252
|
+
*/
|
|
13253
|
+
getBreakeven: (backtest: boolean, symbol: string, currentPrice: number, context: {
|
|
13254
|
+
strategyName: StrategyName;
|
|
13255
|
+
exchangeName: ExchangeName;
|
|
13256
|
+
frameName: FrameName;
|
|
13257
|
+
}) => Promise<boolean>;
|
|
13258
|
+
/**
|
|
13259
|
+
* Checks if the strategy has been stopped.
|
|
13260
|
+
*
|
|
13261
|
+
* Validates strategy existence and delegates to connection service
|
|
13262
|
+
* to retrieve the stopped state from the strategy instance.
|
|
13263
|
+
*
|
|
13264
|
+
* @param backtest - Whether running in backtest mode
|
|
13265
|
+
* @param symbol - Trading pair symbol
|
|
13266
|
+
* @param context - Execution context with strategyName, exchangeName, frameName
|
|
13267
|
+
* @returns Promise resolving to true if strategy is stopped, false otherwise
|
|
13268
|
+
*/
|
|
13269
|
+
getStopped: (backtest: boolean, symbol: string, context: {
|
|
13270
|
+
strategyName: StrategyName;
|
|
13271
|
+
exchangeName: ExchangeName;
|
|
13272
|
+
frameName: FrameName;
|
|
13273
|
+
}) => Promise<boolean>;
|
|
13274
|
+
/**
|
|
13275
|
+
* Checks signal status at a specific timestamp.
|
|
13276
|
+
*
|
|
13277
|
+
* Wraps strategy tick() with execution context containing symbol, timestamp,
|
|
13278
|
+
* and backtest mode flag.
|
|
13279
|
+
*
|
|
13280
|
+
* @param symbol - Trading pair symbol
|
|
13281
|
+
* @param when - Timestamp for tick evaluation
|
|
13282
|
+
* @param backtest - Whether running in backtest mode
|
|
13283
|
+
* @param context - Execution context with strategyName, exchangeName, frameName
|
|
13284
|
+
* @returns Discriminated union of tick result (idle, opened, active, closed)
|
|
13285
|
+
*/
|
|
13286
|
+
tick: (symbol: string, when: Date, backtest: boolean, context: {
|
|
13287
|
+
strategyName: StrategyName;
|
|
13288
|
+
exchangeName: ExchangeName;
|
|
13289
|
+
frameName: FrameName;
|
|
13290
|
+
}) => Promise<IStrategyTickResult>;
|
|
13291
|
+
/**
|
|
13292
|
+
* Runs fast backtest against candle array.
|
|
13293
|
+
*
|
|
13294
|
+
* Wraps strategy backtest() with execution context containing symbol,
|
|
13295
|
+
* timestamp, and backtest mode flag.
|
|
13296
|
+
*
|
|
13297
|
+
* @param symbol - Trading pair symbol
|
|
13298
|
+
* @param candles - Array of historical candles to test against
|
|
13299
|
+
* @param when - Starting timestamp for backtest
|
|
13300
|
+
* @param backtest - Whether running in backtest mode (typically true)
|
|
13301
|
+
* @param context - Execution context with strategyName, exchangeName, frameName
|
|
13302
|
+
* @returns Closed signal result with PNL
|
|
13303
|
+
*/
|
|
13304
|
+
backtest: (symbol: string, candles: ICandleData[], when: Date, backtest: boolean, context: {
|
|
13305
|
+
strategyName: StrategyName;
|
|
13306
|
+
exchangeName: ExchangeName;
|
|
13307
|
+
frameName: FrameName;
|
|
13308
|
+
}) => Promise<IStrategyBacktestResult>;
|
|
13309
|
+
/**
|
|
13310
|
+
* Stops the strategy from generating new signals.
|
|
13311
|
+
*
|
|
13312
|
+
* Delegates to StrategyConnectionService.stop() to set internal flag.
|
|
13313
|
+
* Does not require execution context.
|
|
13314
|
+
*
|
|
13315
|
+
* @param backtest - Whether running in backtest mode
|
|
13316
|
+
* @param symbol - Trading pair symbol
|
|
13317
|
+
* @param ctx - Context with strategyName, exchangeName, frameName
|
|
13318
|
+
* @returns Promise that resolves when stop flag is set
|
|
13319
|
+
*/
|
|
13320
|
+
stopStrategy: (backtest: boolean, symbol: string, context: {
|
|
13321
|
+
strategyName: StrategyName;
|
|
13322
|
+
exchangeName: ExchangeName;
|
|
13323
|
+
frameName: FrameName;
|
|
13324
|
+
}) => Promise<void>;
|
|
13325
|
+
/**
|
|
13326
|
+
* Cancels the scheduled signal without stopping the strategy.
|
|
13327
|
+
*
|
|
13328
|
+
* Delegates to StrategyConnectionService.cancelScheduled() to clear scheduled signal
|
|
13329
|
+
* and emit cancelled event through emitters.
|
|
13330
|
+
* Does not require execution context.
|
|
13331
|
+
*
|
|
13332
|
+
* @param backtest - Whether running in backtest mode
|
|
13333
|
+
* @param symbol - Trading pair symbol
|
|
13334
|
+
* @param ctx - Context with strategyName, exchangeName, frameName
|
|
13335
|
+
* @param cancelId - Optional cancellation ID for user-initiated cancellations
|
|
13336
|
+
* @returns Promise that resolves when scheduled signal is cancelled
|
|
13337
|
+
*/
|
|
13338
|
+
cancelScheduled: (backtest: boolean, symbol: string, context: {
|
|
13339
|
+
strategyName: StrategyName;
|
|
13340
|
+
exchangeName: ExchangeName;
|
|
13341
|
+
frameName: FrameName;
|
|
13342
|
+
}, cancelId?: string) => Promise<void>;
|
|
13343
|
+
/**
|
|
13344
|
+
* Closes the pending signal without stopping the strategy.
|
|
13345
|
+
*
|
|
13346
|
+
* Clears the pending signal (active position).
|
|
13347
|
+
* Does NOT affect scheduled signals or strategy operation.
|
|
13348
|
+
* Does NOT set stop flag - strategy can continue generating new signals.
|
|
13349
|
+
*
|
|
13350
|
+
* Delegates to StrategyConnectionService.closePending() to clear pending signal
|
|
13351
|
+
* and emit closed event through emitters.
|
|
13352
|
+
* Does not require execution context.
|
|
13353
|
+
*
|
|
13354
|
+
* @param backtest - Whether running in backtest mode
|
|
13355
|
+
* @param symbol - Trading pair symbol
|
|
13356
|
+
* @param context - Context with strategyName, exchangeName, frameName
|
|
13357
|
+
* @param closeId - Optional close ID for user-initiated closes
|
|
13358
|
+
* @returns Promise that resolves when pending signal is closed
|
|
13359
|
+
*/
|
|
13360
|
+
closePending: (backtest: boolean, symbol: string, context: {
|
|
13361
|
+
strategyName: StrategyName;
|
|
13362
|
+
exchangeName: ExchangeName;
|
|
13363
|
+
frameName: FrameName;
|
|
13364
|
+
}, closeId?: string) => Promise<void>;
|
|
13365
|
+
/**
|
|
13366
|
+
* Disposes the ClientStrategy instance for the given context.
|
|
13367
|
+
*
|
|
13368
|
+
* Calls dispose on the strategy instance to clean up resources,
|
|
13369
|
+
* then removes it from cache.
|
|
13370
|
+
*
|
|
13371
|
+
* @param backtest - Whether running in backtest mode
|
|
13372
|
+
* @param symbol - Trading pair symbol
|
|
13373
|
+
* @param context - Execution context with strategyName, exchangeName, frameName
|
|
13374
|
+
*/
|
|
13375
|
+
dispose: (backtest: boolean, symbol: string, context: {
|
|
13376
|
+
strategyName: StrategyName;
|
|
13377
|
+
exchangeName: ExchangeName;
|
|
13378
|
+
frameName: FrameName;
|
|
13379
|
+
}) => Promise<void>;
|
|
13380
|
+
/**
|
|
13381
|
+
* Clears the memoized ClientStrategy instance from cache.
|
|
13382
|
+
*
|
|
13383
|
+
* Delegates to StrategyConnectionService.dispose() if payload provided,
|
|
13384
|
+
* otherwise clears all strategy instances.
|
|
13385
|
+
*
|
|
13386
|
+
* @param payload - Optional payload with symbol, context and backtest flag (clears all if not provided)
|
|
13387
|
+
*/
|
|
13388
|
+
clear: (payload?: {
|
|
13389
|
+
symbol: string;
|
|
13390
|
+
strategyName: StrategyName;
|
|
13391
|
+
exchangeName: ExchangeName;
|
|
13392
|
+
frameName: FrameName;
|
|
13393
|
+
backtest: boolean;
|
|
13394
|
+
}) => Promise<void>;
|
|
13395
|
+
/**
|
|
13396
|
+
* Executes partial close at profit level (moving toward TP).
|
|
13397
|
+
*
|
|
13398
|
+
* Validates strategy existence and delegates to connection service
|
|
13399
|
+
* to close a percentage of the pending position at profit.
|
|
13400
|
+
*
|
|
13401
|
+
* Does not require execution context as this is a direct state mutation.
|
|
13402
|
+
*
|
|
13403
|
+
* @param backtest - Whether running in backtest mode
|
|
13404
|
+
* @param symbol - Trading pair symbol
|
|
13405
|
+
* @param percentToClose - Percentage of position to close (0-100, absolute value)
|
|
13406
|
+
* @param currentPrice - Current market price for this partial close (must be in profit direction)
|
|
13407
|
+
* @param context - Execution context with strategyName, exchangeName, frameName
|
|
13408
|
+
* @returns Promise<boolean> - true if partial close executed, false if skipped
|
|
13409
|
+
*
|
|
13410
|
+
* @example
|
|
13411
|
+
* ```typescript
|
|
13412
|
+
* // Close 30% of position at profit
|
|
13413
|
+
* const success = await strategyCoreService.partialProfit(
|
|
13414
|
+
* false,
|
|
13415
|
+
* "BTCUSDT",
|
|
13416
|
+
* 30,
|
|
13417
|
+
* 45000,
|
|
13418
|
+
* { strategyName: "my-strategy", exchangeName: "binance", frameName: "" }
|
|
13419
|
+
* );
|
|
13420
|
+
* if (success) {
|
|
13421
|
+
* console.log('Partial profit executed');
|
|
13422
|
+
* }
|
|
13423
|
+
* ```
|
|
13424
|
+
*/
|
|
13425
|
+
partialProfit: (backtest: boolean, symbol: string, percentToClose: number, currentPrice: number, context: {
|
|
13426
|
+
strategyName: StrategyName;
|
|
13427
|
+
exchangeName: ExchangeName;
|
|
13428
|
+
frameName: FrameName;
|
|
13429
|
+
}) => Promise<boolean>;
|
|
13430
|
+
/**
|
|
13431
|
+
* Executes partial close at loss level (moving toward SL).
|
|
13432
|
+
*
|
|
13433
|
+
* Validates strategy existence and delegates to connection service
|
|
13434
|
+
* to close a percentage of the pending position at loss.
|
|
13435
|
+
*
|
|
13436
|
+
* Does not require execution context as this is a direct state mutation.
|
|
13437
|
+
*
|
|
13438
|
+
* @param backtest - Whether running in backtest mode
|
|
13439
|
+
* @param symbol - Trading pair symbol
|
|
13440
|
+
* @param percentToClose - Percentage of position to close (0-100, absolute value)
|
|
13441
|
+
* @param currentPrice - Current market price for this partial close (must be in loss direction)
|
|
13442
|
+
* @param context - Execution context with strategyName, exchangeName, frameName
|
|
13443
|
+
* @returns Promise<boolean> - true if partial close executed, false if skipped
|
|
13444
|
+
*
|
|
13445
|
+
* @example
|
|
13446
|
+
* ```typescript
|
|
13447
|
+
* // Close 40% of position at loss
|
|
13448
|
+
* const success = await strategyCoreService.partialLoss(
|
|
13449
|
+
* false,
|
|
13450
|
+
* "BTCUSDT",
|
|
13451
|
+
* 40,
|
|
13452
|
+
* 38000,
|
|
13453
|
+
* { strategyName: "my-strategy", exchangeName: "binance", frameName: "" }
|
|
13454
|
+
* );
|
|
13455
|
+
* if (success) {
|
|
13456
|
+
* console.log('Partial loss executed');
|
|
13457
|
+
* }
|
|
13458
|
+
* ```
|
|
13459
|
+
*/
|
|
13460
|
+
partialLoss: (backtest: boolean, symbol: string, percentToClose: number, currentPrice: number, context: {
|
|
13461
|
+
strategyName: StrategyName;
|
|
13462
|
+
exchangeName: ExchangeName;
|
|
13463
|
+
frameName: FrameName;
|
|
13464
|
+
}) => Promise<boolean>;
|
|
13465
|
+
/**
|
|
13466
|
+
* Adjusts the trailing stop-loss distance for an active pending signal.
|
|
13467
|
+
*
|
|
13468
|
+
* Validates strategy existence and delegates to connection service
|
|
13469
|
+
* to update the stop-loss distance by a percentage adjustment.
|
|
13470
|
+
*
|
|
13471
|
+
* Does not require execution context as this is a direct state mutation.
|
|
13472
|
+
*
|
|
13473
|
+
* @param backtest - Whether running in backtest mode
|
|
13474
|
+
* @param symbol - Trading pair symbol
|
|
13475
|
+
* @param percentShift - Percentage adjustment to SL distance (-100 to 100)
|
|
13476
|
+
* @param currentPrice - Current market price to check for intrusion
|
|
13477
|
+
* @param context - Execution context with strategyName, exchangeName, frameName
|
|
13478
|
+
* @returns Promise that resolves when trailing SL is updated
|
|
13479
|
+
*
|
|
13480
|
+
* @example
|
|
13481
|
+
* ```typescript
|
|
13482
|
+
* // LONG: entry=100, originalSL=90, distance=10%, currentPrice=102
|
|
13483
|
+
* // Tighten stop by 50%: newSL = 100 - 5% = 95
|
|
13484
|
+
* await strategyCoreService.trailingStop(
|
|
13485
|
+
* false,
|
|
13486
|
+
* "BTCUSDT",
|
|
13487
|
+
* -50,
|
|
13488
|
+
* 102,
|
|
13489
|
+
* { strategyName: "my-strategy", exchangeName: "binance", frameName: "" }
|
|
13490
|
+
* );
|
|
13491
|
+
* ```
|
|
13492
|
+
*/
|
|
13493
|
+
trailingStop: (backtest: boolean, symbol: string, percentShift: number, currentPrice: number, context: {
|
|
13494
|
+
strategyName: StrategyName;
|
|
13495
|
+
exchangeName: ExchangeName;
|
|
13496
|
+
frameName: FrameName;
|
|
13497
|
+
}) => Promise<boolean>;
|
|
13498
|
+
/**
|
|
13499
|
+
* Adjusts the trailing take-profit distance for an active pending signal.
|
|
13500
|
+
* Validates context and delegates to StrategyConnectionService.
|
|
13501
|
+
*
|
|
13502
|
+
* @param backtest - Whether running in backtest mode
|
|
13503
|
+
* @param symbol - Trading pair symbol
|
|
13504
|
+
* @param percentShift - Percentage adjustment to TP distance (-100 to 100)
|
|
13505
|
+
* @param currentPrice - Current market price to check for intrusion
|
|
13506
|
+
* @param context - Strategy context with strategyName, exchangeName, frameName
|
|
13507
|
+
* @returns Promise that resolves when trailing TP is updated
|
|
13508
|
+
*
|
|
13509
|
+
* @example
|
|
13510
|
+
* ```typescript
|
|
13511
|
+
* // LONG: entry=100, originalTP=110, distance=10%, currentPrice=102
|
|
13512
|
+
* // Move TP further by 50%: newTP = 100 + 15% = 115
|
|
13513
|
+
* await strategyCoreService.trailingTake(
|
|
13514
|
+
* false,
|
|
13515
|
+
* "BTCUSDT",
|
|
13516
|
+
* 50,
|
|
13517
|
+
* 102,
|
|
13518
|
+
* { strategyName: "my-strategy", exchangeName: "binance", frameName: "" }
|
|
13519
|
+
* );
|
|
13520
|
+
* ```
|
|
13521
|
+
*/
|
|
13522
|
+
trailingTake: (backtest: boolean, symbol: string, percentShift: number, currentPrice: number, context: {
|
|
13523
|
+
strategyName: StrategyName;
|
|
13524
|
+
exchangeName: ExchangeName;
|
|
13525
|
+
frameName: FrameName;
|
|
13526
|
+
}) => Promise<boolean>;
|
|
13527
|
+
/**
|
|
13528
|
+
* Moves stop-loss to breakeven when price reaches threshold.
|
|
13529
|
+
* Validates context and delegates to StrategyConnectionService.
|
|
13530
|
+
*
|
|
13531
|
+
* @param backtest - Whether running in backtest mode
|
|
13532
|
+
* @param symbol - Trading pair symbol
|
|
13533
|
+
* @param currentPrice - Current market price to check threshold
|
|
13534
|
+
* @param context - Strategy context with strategyName, exchangeName, frameName
|
|
13535
|
+
* @returns Promise<boolean> - true if breakeven was set, false otherwise
|
|
13536
|
+
*
|
|
13537
|
+
* @example
|
|
13538
|
+
* ```typescript
|
|
13539
|
+
* const moved = await strategyCoreService.breakeven(
|
|
13540
|
+
* false,
|
|
13541
|
+
* "BTCUSDT",
|
|
13542
|
+
* 112,
|
|
13543
|
+
* { strategyName: "my-strategy", exchangeName: "binance", frameName: "" }
|
|
13544
|
+
* );
|
|
13545
|
+
* ```
|
|
13546
|
+
*/
|
|
13547
|
+
breakeven: (backtest: boolean, symbol: string, currentPrice: number, context: {
|
|
13548
|
+
strategyName: StrategyName;
|
|
13549
|
+
exchangeName: ExchangeName;
|
|
13550
|
+
frameName: FrameName;
|
|
13551
|
+
}) => Promise<boolean>;
|
|
13552
|
+
}
|
|
13553
|
+
|
|
13554
|
+
/**
|
|
13555
|
+
* Type alias for column configuration used in strategy markdown reports.
|
|
13556
|
+
*
|
|
13557
|
+
* @see ColumnModel for the base interface
|
|
13558
|
+
* @see StrategyEvent for the event data structure
|
|
13559
|
+
*/
|
|
13560
|
+
type Columns = ColumnModel<StrategyEvent>;
|
|
13561
|
+
/**
|
|
13562
|
+
* Service for accumulating strategy management events and generating markdown reports.
|
|
13563
|
+
*
|
|
13564
|
+
* Collects strategy actions (cancel-scheduled, close-pending, partial-profit,
|
|
13565
|
+
* partial-loss, trailing-stop, trailing-take, breakeven) in memory and provides
|
|
13566
|
+
* methods to retrieve statistics, generate reports, and export to files.
|
|
13567
|
+
*
|
|
13568
|
+
* Unlike StrategyReportService which writes each event to disk immediately,
|
|
13569
|
+
* this service accumulates events in ReportStorage instances (max 250 per
|
|
13570
|
+
* symbol-strategy pair) for batch reporting.
|
|
13571
|
+
*
|
|
13572
|
+
* Features:
|
|
13573
|
+
* - In-memory event accumulation with memoized storage per symbol-strategy pair
|
|
13574
|
+
* - Statistical data extraction (event counts by action type)
|
|
13575
|
+
* - Markdown report generation with configurable columns
|
|
13576
|
+
* - File export with timestamped filenames
|
|
13577
|
+
* - Selective or full cache clearing
|
|
13578
|
+
*
|
|
13579
|
+
* Lifecycle:
|
|
13580
|
+
* - Call subscribe() to enable event collection
|
|
13581
|
+
* - Events are collected automatically via cancelScheduled, closePending, etc.
|
|
13582
|
+
* - Use getData(), getReport(), or dump() to retrieve accumulated data
|
|
13583
|
+
* - Call unsubscribe() to disable collection and clear all data
|
|
13584
|
+
*
|
|
13585
|
+
* @example
|
|
13586
|
+
* ```typescript
|
|
13587
|
+
* strategyMarkdownService.subscribe();
|
|
13588
|
+
*
|
|
13589
|
+
* // Events are collected automatically during strategy execution
|
|
13590
|
+
* // ...
|
|
13591
|
+
*
|
|
13592
|
+
* // Get statistics
|
|
13593
|
+
* const stats = await strategyMarkdownService.getData("BTCUSDT", "my-strategy", "binance", "1h", true);
|
|
13594
|
+
*
|
|
13595
|
+
* // Generate markdown report
|
|
13596
|
+
* const report = await strategyMarkdownService.getReport("BTCUSDT", "my-strategy", "binance", "1h", true);
|
|
13597
|
+
*
|
|
13598
|
+
* // Export to file
|
|
13599
|
+
* await strategyMarkdownService.dump("BTCUSDT", "my-strategy", "binance", "1h", true);
|
|
13600
|
+
*
|
|
13601
|
+
* strategyMarkdownService.unsubscribe();
|
|
13602
|
+
* ```
|
|
13603
|
+
*
|
|
13604
|
+
* @see StrategyReportService for immediate event persistence to JSON files
|
|
13605
|
+
* @see Strategy for the high-level utility class that wraps this service
|
|
13606
|
+
*/
|
|
13607
|
+
declare class StrategyMarkdownService {
|
|
13608
|
+
readonly loggerService: LoggerService;
|
|
13609
|
+
readonly executionContextService: {
|
|
13610
|
+
readonly context: IExecutionContext;
|
|
13611
|
+
};
|
|
13612
|
+
readonly strategyCoreService: StrategyCoreService;
|
|
13613
|
+
/**
|
|
13614
|
+
* Memoized factory for ReportStorage instances.
|
|
13615
|
+
*
|
|
13616
|
+
* Creates and caches ReportStorage per unique symbol-strategy-exchange-frame-backtest combination.
|
|
13617
|
+
* Uses CREATE_KEY_FN for cache key generation.
|
|
13618
|
+
*
|
|
13619
|
+
* @internal
|
|
13620
|
+
*/
|
|
13621
|
+
private getStorage;
|
|
13622
|
+
/**
|
|
13623
|
+
* Records a cancel-scheduled event when a scheduled signal is cancelled.
|
|
13624
|
+
*
|
|
13625
|
+
* Retrieves the scheduled signal from StrategyCoreService and stores
|
|
13626
|
+
* the cancellation event in the appropriate ReportStorage.
|
|
13627
|
+
*
|
|
13628
|
+
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
13629
|
+
* @param isBacktest - Whether this is a backtest or live trading event
|
|
13630
|
+
* @param context - Strategy context with strategyName, exchangeName, frameName
|
|
13631
|
+
* @param cancelId - Optional identifier for the cancellation reason
|
|
13632
|
+
*/
|
|
13633
|
+
cancelScheduled: (symbol: string, isBacktest: boolean, context: {
|
|
13634
|
+
strategyName: StrategyName;
|
|
13635
|
+
exchangeName: ExchangeName;
|
|
13636
|
+
frameName: FrameName;
|
|
13637
|
+
}, cancelId?: string) => Promise<void>;
|
|
13638
|
+
/**
|
|
13639
|
+
* Records a close-pending event when a pending signal is closed.
|
|
13640
|
+
*
|
|
13641
|
+
* Retrieves the pending signal from StrategyCoreService and stores
|
|
13642
|
+
* the close event in the appropriate ReportStorage.
|
|
13643
|
+
*
|
|
13644
|
+
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
13645
|
+
* @param isBacktest - Whether this is a backtest or live trading event
|
|
13646
|
+
* @param context - Strategy context with strategyName, exchangeName, frameName
|
|
13647
|
+
* @param closeId - Optional identifier for the close reason
|
|
13648
|
+
*/
|
|
13649
|
+
closePending: (symbol: string, isBacktest: boolean, context: {
|
|
13650
|
+
strategyName: StrategyName;
|
|
13651
|
+
exchangeName: ExchangeName;
|
|
13652
|
+
frameName: FrameName;
|
|
13653
|
+
}, closeId?: string) => Promise<void>;
|
|
13654
|
+
/**
|
|
13655
|
+
* Records a partial-profit event when a portion of the position is closed at profit.
|
|
13656
|
+
*
|
|
13657
|
+
* Stores the percentage closed and current price when partial profit-taking occurs.
|
|
13658
|
+
*
|
|
13659
|
+
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
13660
|
+
* @param percentToClose - Percentage of position to close (0-100)
|
|
13661
|
+
* @param currentPrice - Current market price at time of partial close
|
|
13662
|
+
* @param isBacktest - Whether this is a backtest or live trading event
|
|
13663
|
+
* @param context - Strategy context with strategyName, exchangeName, frameName
|
|
13664
|
+
*/
|
|
13665
|
+
partialProfit: (symbol: string, percentToClose: number, currentPrice: number, isBacktest: boolean, context: {
|
|
13666
|
+
strategyName: StrategyName;
|
|
13667
|
+
exchangeName: ExchangeName;
|
|
13668
|
+
frameName: FrameName;
|
|
13669
|
+
}) => Promise<void>;
|
|
13670
|
+
/**
|
|
13671
|
+
* Records a partial-loss event when a portion of the position is closed at loss.
|
|
13672
|
+
*
|
|
13673
|
+
* Stores the percentage closed and current price when partial loss-cutting occurs.
|
|
13674
|
+
*
|
|
13675
|
+
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
13676
|
+
* @param percentToClose - Percentage of position to close (0-100)
|
|
13677
|
+
* @param currentPrice - Current market price at time of partial close
|
|
13678
|
+
* @param isBacktest - Whether this is a backtest or live trading event
|
|
13679
|
+
* @param context - Strategy context with strategyName, exchangeName, frameName
|
|
13680
|
+
*/
|
|
13681
|
+
partialLoss: (symbol: string, percentToClose: number, currentPrice: number, isBacktest: boolean, context: {
|
|
13682
|
+
strategyName: StrategyName;
|
|
13683
|
+
exchangeName: ExchangeName;
|
|
13684
|
+
frameName: FrameName;
|
|
13685
|
+
}) => Promise<void>;
|
|
13686
|
+
/**
|
|
13687
|
+
* Records a trailing-stop event when the stop-loss is adjusted.
|
|
13688
|
+
*
|
|
13689
|
+
* Stores the percentage shift and current price when trailing stop moves.
|
|
13690
|
+
*
|
|
13691
|
+
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
13692
|
+
* @param percentShift - Percentage the stop-loss was shifted
|
|
13693
|
+
* @param currentPrice - Current market price at time of adjustment
|
|
13694
|
+
* @param isBacktest - Whether this is a backtest or live trading event
|
|
13695
|
+
* @param context - Strategy context with strategyName, exchangeName, frameName
|
|
13696
|
+
*/
|
|
13697
|
+
trailingStop: (symbol: string, percentShift: number, currentPrice: number, isBacktest: boolean, context: {
|
|
13698
|
+
strategyName: StrategyName;
|
|
13699
|
+
exchangeName: ExchangeName;
|
|
13700
|
+
frameName: FrameName;
|
|
13701
|
+
}) => Promise<void>;
|
|
13702
|
+
/**
|
|
13703
|
+
* Records a trailing-take event when the take-profit is adjusted.
|
|
13704
|
+
*
|
|
13705
|
+
* Stores the percentage shift and current price when trailing take-profit moves.
|
|
13706
|
+
*
|
|
13707
|
+
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
13708
|
+
* @param percentShift - Percentage the take-profit was shifted
|
|
13709
|
+
* @param currentPrice - Current market price at time of adjustment
|
|
13710
|
+
* @param isBacktest - Whether this is a backtest or live trading event
|
|
13711
|
+
* @param context - Strategy context with strategyName, exchangeName, frameName
|
|
13712
|
+
*/
|
|
13713
|
+
trailingTake: (symbol: string, percentShift: number, currentPrice: number, isBacktest: boolean, context: {
|
|
13714
|
+
strategyName: StrategyName;
|
|
13715
|
+
exchangeName: ExchangeName;
|
|
13716
|
+
frameName: FrameName;
|
|
13717
|
+
}) => Promise<void>;
|
|
13718
|
+
/**
|
|
13719
|
+
* Records a breakeven event when the stop-loss is moved to entry price.
|
|
13720
|
+
*
|
|
13721
|
+
* Stores the current price when breakeven protection is activated.
|
|
13722
|
+
*
|
|
13723
|
+
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
13724
|
+
* @param currentPrice - Current market price at time of breakeven activation
|
|
13725
|
+
* @param isBacktest - Whether this is a backtest or live trading event
|
|
13726
|
+
* @param context - Strategy context with strategyName, exchangeName, frameName
|
|
13727
|
+
*/
|
|
13728
|
+
breakeven: (symbol: string, currentPrice: number, isBacktest: boolean, context: {
|
|
13729
|
+
strategyName: StrategyName;
|
|
13730
|
+
exchangeName: ExchangeName;
|
|
13731
|
+
frameName: FrameName;
|
|
13732
|
+
}) => Promise<void>;
|
|
13733
|
+
/**
|
|
13734
|
+
* Retrieves aggregated statistics from accumulated strategy events.
|
|
13735
|
+
*
|
|
13736
|
+
* Returns counts for each action type and the full event list from the
|
|
13737
|
+
* ReportStorage for the specified symbol-strategy pair.
|
|
13738
|
+
*
|
|
13739
|
+
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
13740
|
+
* @param strategyName - Name of the trading strategy
|
|
13741
|
+
* @param exchangeName - Name of the exchange
|
|
13742
|
+
* @param frameName - Timeframe name for backtest identification
|
|
13743
|
+
* @param backtest - Whether to get backtest or live data
|
|
13744
|
+
* @returns Promise resolving to StrategyStatisticsModel with event list and counts
|
|
13745
|
+
* @throws Error if service not initialized (subscribe() not called)
|
|
13746
|
+
*/
|
|
13747
|
+
getData: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean) => Promise<StrategyStatisticsModel>;
|
|
13748
|
+
/**
|
|
13749
|
+
* Generates a markdown report from accumulated strategy events.
|
|
13750
|
+
*
|
|
13751
|
+
* Creates a formatted markdown document containing:
|
|
13752
|
+
* - Header with symbol and strategy name
|
|
13753
|
+
* - Table of all events with configurable columns
|
|
13754
|
+
* - Summary statistics with counts by action type
|
|
13755
|
+
*
|
|
13756
|
+
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
13757
|
+
* @param strategyName - Name of the trading strategy
|
|
13758
|
+
* @param exchangeName - Name of the exchange
|
|
13759
|
+
* @param frameName - Timeframe name for backtest identification
|
|
13760
|
+
* @param backtest - Whether to get backtest or live data
|
|
13761
|
+
* @param columns - Column configuration for the event table
|
|
13762
|
+
* @returns Promise resolving to formatted markdown string
|
|
13763
|
+
* @throws Error if service not initialized (subscribe() not called)
|
|
13764
|
+
*/
|
|
13765
|
+
getReport: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, columns?: Columns[]) => Promise<string>;
|
|
13766
|
+
/**
|
|
13767
|
+
* Generates and saves a markdown report to disk.
|
|
13768
|
+
*
|
|
13769
|
+
* Creates the output directory if it doesn't exist and writes
|
|
13770
|
+
* the report with a timestamped filename via Markdown.writeData().
|
|
13771
|
+
*
|
|
13772
|
+
* Filename format: `{symbol}_{strategyName}_{exchangeName}[_{frameName}_backtest|_live]-{timestamp}.md`
|
|
13773
|
+
*
|
|
13774
|
+
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
13775
|
+
* @param strategyName - Name of the trading strategy
|
|
13776
|
+
* @param exchangeName - Name of the exchange
|
|
13777
|
+
* @param frameName - Timeframe name for backtest identification
|
|
13778
|
+
* @param backtest - Whether to dump backtest or live data
|
|
13779
|
+
* @param path - Output directory path (default: "./dump/strategy")
|
|
13780
|
+
* @param columns - Column configuration for the event table
|
|
13781
|
+
* @returns Promise that resolves when file is written
|
|
13782
|
+
* @throws Error if service not initialized (subscribe() not called)
|
|
13783
|
+
*/
|
|
13784
|
+
dump: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, path?: string, columns?: Columns[]) => Promise<void>;
|
|
13785
|
+
/**
|
|
13786
|
+
* Clears accumulated events from storage.
|
|
13787
|
+
*
|
|
13788
|
+
* Can clear either a specific symbol-strategy pair or all stored data.
|
|
13789
|
+
*
|
|
13790
|
+
* @param payload - Optional filter to clear specific storage. If omitted, clears all.
|
|
13791
|
+
* @param payload.symbol - Trading pair symbol
|
|
13792
|
+
* @param payload.strategyName - Strategy name
|
|
13793
|
+
* @param payload.exchangeName - Exchange name
|
|
13794
|
+
* @param payload.frameName - Frame name
|
|
13795
|
+
* @param payload.backtest - Backtest mode flag
|
|
13796
|
+
*/
|
|
13797
|
+
clear: (payload?: {
|
|
13798
|
+
symbol: string;
|
|
13799
|
+
strategyName: StrategyName;
|
|
13800
|
+
exchangeName: ExchangeName;
|
|
13801
|
+
frameName: FrameName;
|
|
13802
|
+
backtest: boolean;
|
|
13803
|
+
}) => Promise<void>;
|
|
13804
|
+
/**
|
|
13805
|
+
* Initializes the service for event collection.
|
|
13806
|
+
*
|
|
13807
|
+
* Must be called before any events can be collected or reports generated.
|
|
13808
|
+
* Uses singleshot pattern to ensure only one subscription exists at a time.
|
|
13809
|
+
*
|
|
13810
|
+
* @returns Cleanup function that clears the subscription and all accumulated data
|
|
13811
|
+
*/
|
|
13812
|
+
subscribe: (() => () => void) & functools_kit.ISingleshotClearable;
|
|
13813
|
+
/**
|
|
13814
|
+
* Stops event collection and clears all accumulated data.
|
|
13815
|
+
*
|
|
13816
|
+
* Invokes the cleanup function returned by subscribe(), which clears
|
|
13817
|
+
* both the subscription and all ReportStorage instances.
|
|
13818
|
+
* Safe to call multiple times - only acts if subscription exists.
|
|
13819
|
+
*/
|
|
13820
|
+
unsubscribe: () => Promise<void>;
|
|
13821
|
+
}
|
|
13822
|
+
|
|
13823
|
+
/**
|
|
13824
|
+
* Utility class for accessing strategy management reports and statistics.
|
|
13825
|
+
*
|
|
13826
|
+
* Provides static-like methods (via singleton instance) to retrieve data
|
|
13827
|
+
* accumulated by StrategyMarkdownService from strategy management events.
|
|
13828
|
+
*
|
|
13829
|
+
* Features:
|
|
13830
|
+
* - Statistical data extraction (event counts by action type)
|
|
13831
|
+
* - Markdown report generation with event tables
|
|
13832
|
+
* - File export to disk
|
|
13833
|
+
*
|
|
13834
|
+
* Data source:
|
|
13835
|
+
* - StrategyMarkdownService receives events via direct method calls
|
|
13836
|
+
* - Accumulates events in ReportStorage (max 250 events per symbol-strategy pair)
|
|
13837
|
+
* - Events include: cancel-scheduled, close-pending, partial-profit, partial-loss,
|
|
13838
|
+
* trailing-stop, trailing-take, breakeven
|
|
13839
|
+
*
|
|
13840
|
+
* @example
|
|
13841
|
+
* ```typescript
|
|
13842
|
+
* import { Strategy } from "./classes/Strategy";
|
|
13843
|
+
*
|
|
13844
|
+
* // Get statistical data for BTCUSDT:my-strategy
|
|
13845
|
+
* const stats = await Strategy.getData("BTCUSDT", { strategyName: "my-strategy", exchangeName: "binance", frameName: "1h" });
|
|
13846
|
+
* console.log(`Total events: ${stats.totalEvents}`);
|
|
13847
|
+
* console.log(`Partial profit events: ${stats.partialProfitCount}`);
|
|
13848
|
+
*
|
|
13849
|
+
* // Generate markdown report
|
|
13850
|
+
* const markdown = await Strategy.getReport("BTCUSDT", { strategyName: "my-strategy", exchangeName: "binance", frameName: "1h" });
|
|
13851
|
+
* console.log(markdown); // Formatted table with all events
|
|
13852
|
+
*
|
|
13853
|
+
* // Export report to file
|
|
13854
|
+
* await Strategy.dump("BTCUSDT", { strategyName: "my-strategy", exchangeName: "binance", frameName: "1h" }); // Saves to ./dump/strategy/
|
|
13855
|
+
* ```
|
|
13856
|
+
*/
|
|
13857
|
+
declare class StrategyUtils {
|
|
13858
|
+
/**
|
|
13859
|
+
* Retrieves statistical data from accumulated strategy events.
|
|
13860
|
+
*
|
|
13861
|
+
* Delegates to StrategyMarkdownService.getData() which reads from ReportStorage.
|
|
13862
|
+
* Returns aggregated metrics calculated from all strategy events.
|
|
13863
|
+
*
|
|
13864
|
+
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
13865
|
+
* @param context - Strategy context with strategyName, exchangeName, frameName
|
|
13866
|
+
* @param backtest - Whether to get backtest data (default: false)
|
|
13867
|
+
* @returns Promise resolving to StrategyStatisticsModel object with counts and event list
|
|
13868
|
+
*
|
|
13869
|
+
* @example
|
|
13870
|
+
* ```typescript
|
|
13871
|
+
* const stats = await Strategy.getData("BTCUSDT", { strategyName: "my-strategy", exchangeName: "binance", frameName: "1h" });
|
|
13872
|
+
*
|
|
13873
|
+
* console.log(`Total events: ${stats.totalEvents}`);
|
|
13874
|
+
* console.log(`Partial profit: ${stats.partialProfitCount}`);
|
|
13875
|
+
* console.log(`Trailing stop: ${stats.trailingStopCount}`);
|
|
13876
|
+
*
|
|
13877
|
+
* // Iterate through all events
|
|
13878
|
+
* for (const event of stats.eventList) {
|
|
13879
|
+
* console.log(`Signal ${event.signalId}: ${event.action} at ${event.currentPrice}`);
|
|
13880
|
+
* }
|
|
13881
|
+
* ```
|
|
13882
|
+
*/
|
|
13883
|
+
getData: (symbol: string, context: {
|
|
13884
|
+
strategyName: StrategyName;
|
|
13885
|
+
exchangeName: ExchangeName;
|
|
13886
|
+
frameName: FrameName;
|
|
13887
|
+
}, backtest?: boolean) => Promise<StrategyStatisticsModel>;
|
|
13888
|
+
/**
|
|
13889
|
+
* Generates markdown report with all strategy events for a symbol-strategy pair.
|
|
13890
|
+
*
|
|
13891
|
+
* Creates formatted table containing:
|
|
13892
|
+
* - Symbol
|
|
13893
|
+
* - Strategy
|
|
13894
|
+
* - Signal ID
|
|
13895
|
+
* - Action (cancel-scheduled, close-pending, partial-profit, etc.)
|
|
13896
|
+
* - Price
|
|
13897
|
+
* - Percent values (% To Close, % Shift)
|
|
13898
|
+
* - Cancel/Close IDs
|
|
13899
|
+
* - Timestamp (ISO 8601)
|
|
13900
|
+
* - Mode (Backtest/Live)
|
|
13901
|
+
*
|
|
13902
|
+
* Also includes summary statistics at the end with counts by action type.
|
|
13903
|
+
*
|
|
13904
|
+
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
13905
|
+
* @param context - Strategy context with strategyName, exchangeName, frameName
|
|
13906
|
+
* @param backtest - Whether to get backtest data (default: false)
|
|
13907
|
+
* @param columns - Optional columns configuration for the report
|
|
13908
|
+
* @returns Promise resolving to markdown formatted report string
|
|
13909
|
+
*
|
|
13910
|
+
* @example
|
|
13911
|
+
* ```typescript
|
|
13912
|
+
* const markdown = await Strategy.getReport("BTCUSDT", { strategyName: "my-strategy", exchangeName: "binance", frameName: "1h" });
|
|
13913
|
+
* console.log(markdown);
|
|
13914
|
+
*
|
|
13915
|
+
* // Output:
|
|
13916
|
+
* // # Strategy Report: BTCUSDT:my-strategy
|
|
13917
|
+
* //
|
|
13918
|
+
* // | Symbol | Strategy | Signal ID | Action | Price | ... |
|
|
13919
|
+
* // | --- | --- | --- | --- | --- | ... |
|
|
13920
|
+
* // | BTCUSDT | my-strategy | abc123 | partial-profit | 50100.00000000 USD | ... |
|
|
13921
|
+
* //
|
|
13922
|
+
* // **Total events:** 5
|
|
13923
|
+
* // - Cancel scheduled: 0
|
|
13924
|
+
* // - Close pending: 1
|
|
13925
|
+
* // - Partial profit: 2
|
|
13926
|
+
* // ...
|
|
13927
|
+
* ```
|
|
13928
|
+
*/
|
|
13929
|
+
getReport: (symbol: string, context: {
|
|
13930
|
+
strategyName: StrategyName;
|
|
13931
|
+
exchangeName: ExchangeName;
|
|
13932
|
+
frameName: FrameName;
|
|
13933
|
+
}, backtest?: boolean, columns?: Columns[]) => Promise<string>;
|
|
13934
|
+
/**
|
|
13935
|
+
* Generates and saves markdown report to file.
|
|
13936
|
+
*
|
|
13937
|
+
* Creates directory if it doesn't exist.
|
|
13938
|
+
* Filename format: {symbol}_{strategyName}_{exchangeName}_{frameName|live}-{timestamp}.md
|
|
13939
|
+
*
|
|
13940
|
+
* Delegates to StrategyMarkdownService.dump() which:
|
|
13941
|
+
* 1. Generates markdown report via getReport()
|
|
13942
|
+
* 2. Creates output directory (recursive mkdir)
|
|
13943
|
+
* 3. Writes file with UTF-8 encoding
|
|
13944
|
+
* 4. Logs success/failure to console
|
|
13945
|
+
*
|
|
13946
|
+
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
13947
|
+
* @param context - Strategy context with strategyName, exchangeName, frameName
|
|
13948
|
+
* @param backtest - Whether to dump backtest data (default: false)
|
|
13949
|
+
* @param path - Output directory path (default: "./dump/strategy")
|
|
13950
|
+
* @param columns - Optional columns configuration for the report
|
|
13951
|
+
* @returns Promise that resolves when file is written
|
|
13952
|
+
*
|
|
13953
|
+
* @example
|
|
13954
|
+
* ```typescript
|
|
13955
|
+
* // Save to default path: ./dump/strategy/BTCUSDT_my-strategy_binance_1h_backtest-{timestamp}.md
|
|
13956
|
+
* await Strategy.dump("BTCUSDT", { strategyName: "my-strategy", exchangeName: "binance", frameName: "1h" }, true);
|
|
13957
|
+
*
|
|
13958
|
+
* // Save to custom path
|
|
13959
|
+
* await Strategy.dump("BTCUSDT", { strategyName: "my-strategy", exchangeName: "binance", frameName: "1h" }, true, "./reports/strategy");
|
|
13960
|
+
*
|
|
13961
|
+
* // After multiple symbols backtested, export all reports
|
|
13962
|
+
* for (const symbol of ["BTCUSDT", "ETHUSDT", "BNBUSDT"]) {
|
|
13963
|
+
* await Strategy.dump(symbol, { strategyName: "my-strategy", exchangeName: "binance", frameName: "1h" }, true, "./backtest-results");
|
|
13964
|
+
* }
|
|
13965
|
+
* ```
|
|
13966
|
+
*/
|
|
13967
|
+
dump: (symbol: string, context: {
|
|
13968
|
+
strategyName: StrategyName;
|
|
13969
|
+
exchangeName: ExchangeName;
|
|
13970
|
+
frameName: FrameName;
|
|
13971
|
+
}, backtest?: boolean, path?: string, columns?: Columns[]) => Promise<void>;
|
|
13972
|
+
}
|
|
13973
|
+
/**
|
|
13974
|
+
* Global singleton instance of StrategyUtils.
|
|
13975
|
+
* Provides static-like access to strategy management reporting methods.
|
|
13976
|
+
*
|
|
13977
|
+
* @example
|
|
13978
|
+
* ```typescript
|
|
13979
|
+
* import { Strategy } from "backtest-kit";
|
|
13980
|
+
*
|
|
13981
|
+
* // Usage same as StrategyUtils methods
|
|
13982
|
+
* const stats = await Strategy.getData("BTCUSDT", { strategyName: "my-strategy", exchangeName: "binance", frameName: "1h" });
|
|
13983
|
+
* const report = await Strategy.getReport("BTCUSDT", { strategyName: "my-strategy", exchangeName: "binance", frameName: "1h" });
|
|
13984
|
+
* await Strategy.dump("BTCUSDT", { strategyName: "my-strategy", exchangeName: "binance", frameName: "1h" });
|
|
13985
|
+
* ```
|
|
13986
|
+
*/
|
|
13987
|
+
declare const Strategy: StrategyUtils;
|
|
13988
|
+
|
|
13989
|
+
/**
|
|
13990
|
+
* Proxy wrapper for user-defined action handlers with automatic error capture.
|
|
13991
|
+
*
|
|
13992
|
+
* Wraps all IPublicAction methods with trycatch to prevent user code errors from crashing the system.
|
|
13993
|
+
* All errors are logged, sent to errorEmitter, and returned as null (non-breaking).
|
|
13994
|
+
*
|
|
13995
|
+
* Key features:
|
|
13996
|
+
* - Automatic error catching and logging for all action methods
|
|
13997
|
+
* - Safe execution of partial user implementations (missing methods return null)
|
|
13998
|
+
* - Consistent error capture across all action lifecycle events
|
|
13999
|
+
* - Non-breaking failure mode (errors logged but execution continues)
|
|
14000
|
+
*
|
|
14001
|
+
* Architecture:
|
|
14002
|
+
* - Private constructor enforces factory pattern via fromInstance()
|
|
14003
|
+
* - Each method checks if target implements the method before calling
|
|
14004
|
+
* - Errors caught with fallback handler (warn log + errorEmitter)
|
|
14005
|
+
* - Returns null on error to prevent undefined behavior
|
|
14006
|
+
*
|
|
14007
|
+
* Used by:
|
|
14008
|
+
* - ClientAction to wrap user-provided action handlers
|
|
14009
|
+
* - ActionCoreService to safely invoke action callbacks
|
|
14010
|
+
*
|
|
14011
|
+
* @example
|
|
14012
|
+
* ```typescript
|
|
14013
|
+
* // Create proxy from user implementation
|
|
14014
|
+
* const userAction = {
|
|
14015
|
+
* signal: async (event) => {
|
|
14016
|
+
* // User code that might throw
|
|
14017
|
+
* throw new Error('User error');
|
|
14018
|
+
* }
|
|
14019
|
+
* };
|
|
14020
|
+
*
|
|
14021
|
+
* const proxy = ActionProxy.fromInstance(userAction);
|
|
14022
|
+
*
|
|
14023
|
+
* // Error is caught and logged, execution continues
|
|
14024
|
+
* await proxy.signal(event); // Logs error, returns null
|
|
14025
|
+
* await proxy.dispose(); // Safe call even though not implemented
|
|
14026
|
+
* ```
|
|
14027
|
+
*
|
|
14028
|
+
* @example
|
|
14029
|
+
* ```typescript
|
|
14030
|
+
* // Partial implementation is safe
|
|
14031
|
+
* const partialAction = {
|
|
14032
|
+
* init: async () => console.log('Initialized'),
|
|
14033
|
+
* // Other methods not implemented
|
|
14034
|
+
* };
|
|
14035
|
+
*
|
|
14036
|
+
* const proxy = ActionProxy.fromInstance(partialAction);
|
|
14037
|
+
* await proxy.init(); // Works
|
|
14038
|
+
* await proxy.signal(event); // Returns null (not implemented)
|
|
14039
|
+
* ```
|
|
14040
|
+
*/
|
|
14041
|
+
declare class ActionProxy implements IPublicAction {
|
|
14042
|
+
readonly _target: Partial<IPublicAction>;
|
|
14043
|
+
/**
|
|
14044
|
+
* Creates a new ActionProxy instance.
|
|
14045
|
+
*
|
|
14046
|
+
* @param _target - Partial action implementation to wrap with error capture
|
|
14047
|
+
* @private Use ActionProxy.fromInstance() instead
|
|
14048
|
+
*/
|
|
14049
|
+
private constructor();
|
|
14050
|
+
/**
|
|
14051
|
+
* Initializes the action handler with error capture.
|
|
14052
|
+
*
|
|
14053
|
+
* Wraps the user's init() method in trycatch to prevent initialization errors from crashing the system.
|
|
14054
|
+
* If the target doesn't implement init(), this method safely returns undefined.
|
|
14055
|
+
*
|
|
14056
|
+
* @returns Promise resolving to user's init() result or undefined if not implemented
|
|
14057
|
+
*/
|
|
14058
|
+
init(): Promise<any>;
|
|
14059
|
+
/**
|
|
14060
|
+
* Handles signal events from all modes with error capture.
|
|
14061
|
+
*
|
|
14062
|
+
* Wraps the user's signal() method to catch and log any errors.
|
|
14063
|
+
* Called on every tick/candle when strategy is evaluated.
|
|
14064
|
+
*
|
|
14065
|
+
* @param event - Signal state result with action, state, signal data, and context
|
|
14066
|
+
* @returns Promise resolving to user's signal() result or null on error
|
|
14067
|
+
*/
|
|
14068
|
+
signal(event: IStrategyTickResult): Promise<any>;
|
|
14069
|
+
/**
|
|
14070
|
+
* Handles signal events from live trading only with error capture.
|
|
14071
|
+
*
|
|
14072
|
+
* Wraps the user's signalLive() method to catch and log any errors.
|
|
14073
|
+
* Called every tick in live mode.
|
|
14074
|
+
*
|
|
14075
|
+
* @param event - Signal state result from live trading
|
|
14076
|
+
* @returns Promise resolving to user's signalLive() result or null on error
|
|
14077
|
+
*/
|
|
14078
|
+
signalLive(event: IStrategyTickResult): Promise<any>;
|
|
14079
|
+
/**
|
|
14080
|
+
* Handles signal events from backtest only with error capture.
|
|
14081
|
+
*
|
|
14082
|
+
* Wraps the user's signalBacktest() method to catch and log any errors.
|
|
14083
|
+
* Called every candle in backtest mode.
|
|
14084
|
+
*
|
|
14085
|
+
* @param event - Signal state result from backtest
|
|
14086
|
+
* @returns Promise resolving to user's signalBacktest() result or null on error
|
|
14087
|
+
*/
|
|
14088
|
+
signalBacktest(event: IStrategyTickResult): Promise<any>;
|
|
14089
|
+
/**
|
|
14090
|
+
* Handles breakeven events with error capture.
|
|
14091
|
+
*
|
|
14092
|
+
* Wraps the user's breakevenAvailable() method to catch and log any errors.
|
|
14093
|
+
* Called once per signal when stop-loss is moved to entry price.
|
|
14094
|
+
*
|
|
14095
|
+
* @param event - Breakeven milestone data with signal info, current price, timestamp
|
|
14096
|
+
* @returns Promise resolving to user's breakevenAvailable() result or null on error
|
|
14097
|
+
*/
|
|
14098
|
+
breakevenAvailable(event: BreakevenContract): Promise<any>;
|
|
14099
|
+
/**
|
|
14100
|
+
* Handles partial profit level events with error capture.
|
|
14101
|
+
*
|
|
14102
|
+
* Wraps the user's partialProfitAvailable() method to catch and log any errors.
|
|
14103
|
+
* Called once per profit level per signal (10%, 20%, 30%, etc).
|
|
14104
|
+
*
|
|
14105
|
+
* @param event - Profit milestone data with signal info, level, price, timestamp
|
|
14106
|
+
* @returns Promise resolving to user's partialProfitAvailable() result or null on error
|
|
14107
|
+
*/
|
|
14108
|
+
partialProfitAvailable(event: PartialProfitContract): Promise<any>;
|
|
14109
|
+
/**
|
|
14110
|
+
* Handles partial loss level events with error capture.
|
|
14111
|
+
*
|
|
14112
|
+
* Wraps the user's partialLossAvailable() method to catch and log any errors.
|
|
14113
|
+
* Called once per loss level per signal (-10%, -20%, -30%, etc).
|
|
14114
|
+
*
|
|
14115
|
+
* @param event - Loss milestone data with signal info, level, price, timestamp
|
|
14116
|
+
* @returns Promise resolving to user's partialLossAvailable() result or null on error
|
|
14117
|
+
*/
|
|
14118
|
+
partialLossAvailable(event: PartialLossContract): Promise<any>;
|
|
14119
|
+
/**
|
|
14120
|
+
* Handles scheduled ping events with error capture.
|
|
14121
|
+
*
|
|
14122
|
+
* Wraps the user's pingScheduled() method to catch and log any errors.
|
|
14123
|
+
* Called every minute while a scheduled signal is waiting for activation.
|
|
14124
|
+
*
|
|
14125
|
+
* @param event - Scheduled signal monitoring data with symbol, strategy info, signal data, timestamp
|
|
14126
|
+
* @returns Promise resolving to user's pingScheduled() result or null on error
|
|
14127
|
+
*/
|
|
14128
|
+
pingScheduled(event: SchedulePingContract): Promise<any>;
|
|
14129
|
+
/**
|
|
14130
|
+
* Handles active ping events with error capture.
|
|
14131
|
+
*
|
|
14132
|
+
* Wraps the user's pingActive() method to catch and log any errors.
|
|
14133
|
+
* Called every minute while a pending signal is active (position open).
|
|
14134
|
+
*
|
|
14135
|
+
* @param event - Active pending signal monitoring data with symbol, strategy info, signal data, timestamp
|
|
14136
|
+
* @returns Promise resolving to user's pingActive() result or null on error
|
|
14137
|
+
*/
|
|
14138
|
+
pingActive(event: ActivePingContract): Promise<any>;
|
|
14139
|
+
/**
|
|
14140
|
+
* Handles risk rejection events with error capture.
|
|
14141
|
+
*
|
|
14142
|
+
* Wraps the user's riskRejection() method to catch and log any errors.
|
|
14143
|
+
* Called only when signal is rejected by risk management validation.
|
|
14144
|
+
*
|
|
14145
|
+
* @param event - Risk rejection data with symbol, pending signal, rejection reason, timestamp
|
|
14146
|
+
* @returns Promise resolving to user's riskRejection() result or null on error
|
|
14147
|
+
*/
|
|
14148
|
+
riskRejection(event: RiskContract): Promise<any>;
|
|
14149
|
+
/**
|
|
14150
|
+
* Cleans up resources with error capture.
|
|
14151
|
+
*
|
|
14152
|
+
* Wraps the user's dispose() method to catch and log any errors.
|
|
12805
14153
|
* Called once when strategy execution ends.
|
|
12806
14154
|
*
|
|
12807
14155
|
* @returns Promise resolving to user's dispose() result or null on error
|
|
@@ -13372,6 +14720,20 @@ declare const schedulePingSubject: Subject<SchedulePingContract>;
|
|
|
13372
14720
|
* Allows users to track active signal lifecycle and implement custom dynamic management logic.
|
|
13373
14721
|
*/
|
|
13374
14722
|
declare const activePingSubject: Subject<ActivePingContract>;
|
|
14723
|
+
/**
|
|
14724
|
+
* Strategy management signal emitter.
|
|
14725
|
+
* Emits when strategy management actions are executed:
|
|
14726
|
+
* - cancel-scheduled: Scheduled signal cancelled
|
|
14727
|
+
* - close-pending: Pending signal closed
|
|
14728
|
+
* - partial-profit: Partial close at profit level
|
|
14729
|
+
* - partial-loss: Partial close at loss level
|
|
14730
|
+
* - trailing-stop: Stop-loss adjusted
|
|
14731
|
+
* - trailing-take: Take-profit adjusted
|
|
14732
|
+
* - breakeven: Stop-loss moved to entry price
|
|
14733
|
+
*
|
|
14734
|
+
* Used by StrategyReportService and StrategyMarkdownService for event logging and reporting.
|
|
14735
|
+
*/
|
|
14736
|
+
declare const strategyCommitSubject: Subject<StrategyCommitContract>;
|
|
13375
14737
|
|
|
13376
14738
|
declare const emitters_activePingSubject: typeof activePingSubject;
|
|
13377
14739
|
declare const emitters_breakevenSubject: typeof breakevenSubject;
|
|
@@ -13390,12 +14752,13 @@ declare const emitters_schedulePingSubject: typeof schedulePingSubject;
|
|
|
13390
14752
|
declare const emitters_signalBacktestEmitter: typeof signalBacktestEmitter;
|
|
13391
14753
|
declare const emitters_signalEmitter: typeof signalEmitter;
|
|
13392
14754
|
declare const emitters_signalLiveEmitter: typeof signalLiveEmitter;
|
|
14755
|
+
declare const emitters_strategyCommitSubject: typeof strategyCommitSubject;
|
|
13393
14756
|
declare const emitters_validationSubject: typeof validationSubject;
|
|
13394
14757
|
declare const emitters_walkerCompleteSubject: typeof walkerCompleteSubject;
|
|
13395
14758
|
declare const emitters_walkerEmitter: typeof walkerEmitter;
|
|
13396
14759
|
declare const emitters_walkerStopSubject: typeof walkerStopSubject;
|
|
13397
14760
|
declare namespace emitters {
|
|
13398
|
-
export { emitters_activePingSubject as activePingSubject, 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_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_signalBacktestEmitter as signalBacktestEmitter, emitters_signalEmitter as signalEmitter, emitters_signalLiveEmitter as signalLiveEmitter, emitters_validationSubject as validationSubject, emitters_walkerCompleteSubject as walkerCompleteSubject, emitters_walkerEmitter as walkerEmitter, emitters_walkerStopSubject as walkerStopSubject };
|
|
14761
|
+
export { emitters_activePingSubject as activePingSubject, 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_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_signalBacktestEmitter as signalBacktestEmitter, emitters_signalEmitter as signalEmitter, emitters_signalLiveEmitter as signalLiveEmitter, emitters_strategyCommitSubject as strategyCommitSubject, emitters_validationSubject as validationSubject, emitters_walkerCompleteSubject as walkerCompleteSubject, emitters_walkerEmitter as walkerEmitter, emitters_walkerStopSubject as walkerStopSubject };
|
|
13399
14762
|
}
|
|
13400
14763
|
|
|
13401
14764
|
/**
|
|
@@ -13453,109 +14816,48 @@ interface IParseArgsResult extends IParseArgsParams {
|
|
|
13453
14816
|
* - --backtest: Enable backtest mode (boolean flag)
|
|
13454
14817
|
* - --paper: Enable paper trading mode (boolean flag)
|
|
13455
14818
|
* - --live: Enable live trading mode (boolean flag)
|
|
13456
|
-
*
|
|
13457
|
-
* @param params - Optional default values for parameters
|
|
13458
|
-
* @param params.symbol - Default trading pair symbol
|
|
13459
|
-
* @param params.strategyName - Default strategy name
|
|
13460
|
-
* @param params.exchangeName - Default exchange name
|
|
13461
|
-
* @param params.frameName - Default timeframe
|
|
13462
|
-
* @returns Parsed configuration with all parameters and mode flags
|
|
13463
|
-
*
|
|
13464
|
-
* @example
|
|
13465
|
-
* ```typescript
|
|
13466
|
-
* // Parse args with defaults
|
|
13467
|
-
* const config = parseArgs({
|
|
13468
|
-
* symbol: "BTCUSDT",
|
|
13469
|
-
* strategyName: "rsi_divergence",
|
|
13470
|
-
* exchangeName: "binance",
|
|
13471
|
-
* frameName: "1h"
|
|
13472
|
-
* });
|
|
13473
|
-
*
|
|
13474
|
-
* // Command: node app.js --backtest
|
|
13475
|
-
* // Result: { symbol: "BTCUSDT", ..., backtest: true, paper: false, live: false }
|
|
13476
|
-
* ```
|
|
13477
|
-
*/
|
|
13478
|
-
declare const parseArgs: ({ symbol, strategyName, exchangeName, frameName, }?: Partial<IParseArgsParams>) => IParseArgsResult;
|
|
13479
|
-
|
|
13480
|
-
/**
|
|
13481
|
-
* Retrieves a value from an object using a given path.
|
|
13482
|
-
*
|
|
13483
|
-
* @param object - The object from which to retrieve the value.
|
|
13484
|
-
* @param path - The path to the desired value, either as an array or dot-separated string.
|
|
13485
|
-
* @returns - The value at the specified path, or undefined if it does not exist.
|
|
13486
|
-
*/
|
|
13487
|
-
declare const get: (object: any, path: any) => any;
|
|
13488
|
-
|
|
13489
|
-
/**
|
|
13490
|
-
* Updates the value of a nested object property using a specific path.
|
|
13491
|
-
*
|
|
13492
|
-
* @param object - The object to update.
|
|
13493
|
-
* @param path - The path to the property. Can be either a dot-separated string or an array of strings.
|
|
13494
|
-
* @param value - The new value to set for the property.
|
|
13495
|
-
* @returns - Returns true if the property was successfully updated, false otherwise.
|
|
13496
|
-
*/
|
|
13497
|
-
declare const set: (object: any, path: any, value: any) => boolean;
|
|
13498
|
-
|
|
13499
|
-
/**
|
|
13500
|
-
* Logger service with automatic context injection.
|
|
13501
|
-
*
|
|
13502
|
-
* Features:
|
|
13503
|
-
* - Delegates to user-provided logger via setLogger()
|
|
13504
|
-
* - Automatically appends method context (strategyName, exchangeName, frameName)
|
|
13505
|
-
* - Automatically appends execution context (symbol, when, backtest)
|
|
13506
|
-
* - Defaults to NOOP_LOGGER if no logger configured
|
|
13507
|
-
*
|
|
13508
|
-
* Used throughout the framework for consistent logging with context.
|
|
13509
|
-
*/
|
|
13510
|
-
declare class LoggerService implements ILogger {
|
|
13511
|
-
private readonly methodContextService;
|
|
13512
|
-
private readonly executionContextService;
|
|
13513
|
-
private _commonLogger;
|
|
13514
|
-
/**
|
|
13515
|
-
* Gets current method context if available.
|
|
13516
|
-
* Contains strategyName, exchangeName, frameName from MethodContextService.
|
|
13517
|
-
*/
|
|
13518
|
-
private get methodContext();
|
|
13519
|
-
/**
|
|
13520
|
-
* Gets current execution context if available.
|
|
13521
|
-
* Contains symbol, when, backtest from ExecutionContextService.
|
|
13522
|
-
*/
|
|
13523
|
-
private get executionContext();
|
|
13524
|
-
/**
|
|
13525
|
-
* Logs general-purpose message with automatic context injection.
|
|
13526
|
-
*
|
|
13527
|
-
* @param topic - Log topic/category
|
|
13528
|
-
* @param args - Additional log arguments
|
|
13529
|
-
*/
|
|
13530
|
-
log: (topic: string, ...args: any[]) => Promise<void>;
|
|
13531
|
-
/**
|
|
13532
|
-
* Logs debug-level message with automatic context injection.
|
|
13533
|
-
*
|
|
13534
|
-
* @param topic - Log topic/category
|
|
13535
|
-
* @param args - Additional log arguments
|
|
13536
|
-
*/
|
|
13537
|
-
debug: (topic: string, ...args: any[]) => Promise<void>;
|
|
13538
|
-
/**
|
|
13539
|
-
* Logs info-level message with automatic context injection.
|
|
13540
|
-
*
|
|
13541
|
-
* @param topic - Log topic/category
|
|
13542
|
-
* @param args - Additional log arguments
|
|
13543
|
-
*/
|
|
13544
|
-
info: (topic: string, ...args: any[]) => Promise<void>;
|
|
13545
|
-
/**
|
|
13546
|
-
* Logs warning-level message with automatic context injection.
|
|
13547
|
-
*
|
|
13548
|
-
* @param topic - Log topic/category
|
|
13549
|
-
* @param args - Additional log arguments
|
|
13550
|
-
*/
|
|
13551
|
-
warn: (topic: string, ...args: any[]) => Promise<void>;
|
|
13552
|
-
/**
|
|
13553
|
-
* Sets custom logger implementation.
|
|
13554
|
-
*
|
|
13555
|
-
* @param logger - Custom logger implementing ILogger interface
|
|
13556
|
-
*/
|
|
13557
|
-
setLogger: (logger: ILogger) => void;
|
|
13558
|
-
}
|
|
14819
|
+
*
|
|
14820
|
+
* @param params - Optional default values for parameters
|
|
14821
|
+
* @param params.symbol - Default trading pair symbol
|
|
14822
|
+
* @param params.strategyName - Default strategy name
|
|
14823
|
+
* @param params.exchangeName - Default exchange name
|
|
14824
|
+
* @param params.frameName - Default timeframe
|
|
14825
|
+
* @returns Parsed configuration with all parameters and mode flags
|
|
14826
|
+
*
|
|
14827
|
+
* @example
|
|
14828
|
+
* ```typescript
|
|
14829
|
+
* // Parse args with defaults
|
|
14830
|
+
* const config = parseArgs({
|
|
14831
|
+
* symbol: "BTCUSDT",
|
|
14832
|
+
* strategyName: "rsi_divergence",
|
|
14833
|
+
* exchangeName: "binance",
|
|
14834
|
+
* frameName: "1h"
|
|
14835
|
+
* });
|
|
14836
|
+
*
|
|
14837
|
+
* // Command: node app.js --backtest
|
|
14838
|
+
* // Result: { symbol: "BTCUSDT", ..., backtest: true, paper: false, live: false }
|
|
14839
|
+
* ```
|
|
14840
|
+
*/
|
|
14841
|
+
declare const parseArgs: ({ symbol, strategyName, exchangeName, frameName, }?: Partial<IParseArgsParams>) => IParseArgsResult;
|
|
14842
|
+
|
|
14843
|
+
/**
|
|
14844
|
+
* Retrieves a value from an object using a given path.
|
|
14845
|
+
*
|
|
14846
|
+
* @param object - The object from which to retrieve the value.
|
|
14847
|
+
* @param path - The path to the desired value, either as an array or dot-separated string.
|
|
14848
|
+
* @returns - The value at the specified path, or undefined if it does not exist.
|
|
14849
|
+
*/
|
|
14850
|
+
declare const get: (object: any, path: any) => any;
|
|
14851
|
+
|
|
14852
|
+
/**
|
|
14853
|
+
* Updates the value of a nested object property using a specific path.
|
|
14854
|
+
*
|
|
14855
|
+
* @param object - The object to update.
|
|
14856
|
+
* @param path - The path to the property. Can be either a dot-separated string or an array of strings.
|
|
14857
|
+
* @param value - The new value to set for the property.
|
|
14858
|
+
* @returns - Returns true if the property was successfully updated, false otherwise.
|
|
14859
|
+
*/
|
|
14860
|
+
declare const set: (object: any, path: any, value: any) => boolean;
|
|
13559
14861
|
|
|
13560
14862
|
/**
|
|
13561
14863
|
* Client implementation for exchange data access.
|
|
@@ -14479,7 +15781,7 @@ declare class BreakevenConnectionService implements IBreakeven {
|
|
|
14479
15781
|
* Maps all keys of IStrategy to any type.
|
|
14480
15782
|
* Used for dynamic method routing in StrategyConnectionService.
|
|
14481
15783
|
*/
|
|
14482
|
-
type TStrategy
|
|
15784
|
+
type TStrategy = {
|
|
14483
15785
|
[key in keyof IStrategy]: any;
|
|
14484
15786
|
};
|
|
14485
15787
|
/**
|
|
@@ -14502,7 +15804,7 @@ type TStrategy$1 = {
|
|
|
14502
15804
|
* // Routes to correct strategy instance for symbol-strategy pair
|
|
14503
15805
|
* ```
|
|
14504
15806
|
*/
|
|
14505
|
-
declare class StrategyConnectionService implements TStrategy
|
|
15807
|
+
declare class StrategyConnectionService implements TStrategy {
|
|
14506
15808
|
readonly loggerService: LoggerService;
|
|
14507
15809
|
readonly executionContextService: {
|
|
14508
15810
|
readonly context: IExecutionContext;
|
|
@@ -15105,783 +16407,388 @@ declare class ClientAction implements IAction {
|
|
|
15105
16407
|
* onSignal: (event, actionName, strategyName, frameName, backtest) => {
|
|
15106
16408
|
* console.log(`Signal: ${event.action}`);
|
|
15107
16409
|
* }
|
|
15108
|
-
* },
|
|
15109
|
-
* logger: loggerService,
|
|
15110
|
-
* strategyName: "rsi_divergence",
|
|
15111
|
-
* exchangeName: "binance",
|
|
15112
|
-
* frameName: "1h",
|
|
15113
|
-
* backtest: false
|
|
15114
|
-
* });
|
|
15115
|
-
*
|
|
15116
|
-
* await actionClient.signal({
|
|
15117
|
-
* action: 'opened',
|
|
15118
|
-
* signal: { id: '123', side: 'long' },
|
|
15119
|
-
* backtest: false
|
|
15120
|
-
* });
|
|
15121
|
-
*
|
|
15122
|
-
* await actionClient.dispose();
|
|
15123
|
-
* ```
|
|
15124
|
-
*/
|
|
15125
|
-
constructor(params: IActionParams);
|
|
15126
|
-
/**
|
|
15127
|
-
* Initializes handler instance using singleshot pattern.
|
|
15128
|
-
* Ensures initialization happens exactly once.
|
|
15129
|
-
*/
|
|
15130
|
-
waitForInit: (() => Promise<void>) & functools_kit.ISingleshotClearable;
|
|
15131
|
-
/**
|
|
15132
|
-
* Handles signal events from all modes (live + backtest).
|
|
15133
|
-
*/
|
|
15134
|
-
signal(event: IStrategyTickResult): Promise<void>;
|
|
15135
|
-
/**
|
|
15136
|
-
* Handles signal events from live trading only.
|
|
15137
|
-
*/
|
|
15138
|
-
signalLive(event: IStrategyTickResult): Promise<void>;
|
|
15139
|
-
/**
|
|
15140
|
-
* Handles signal events from backtest only.
|
|
15141
|
-
*/
|
|
15142
|
-
signalBacktest(event: IStrategyTickResult): Promise<void>;
|
|
15143
|
-
/**
|
|
15144
|
-
* Handles breakeven events when stop-loss is moved to entry price.
|
|
15145
|
-
*/
|
|
15146
|
-
breakevenAvailable(event: BreakevenContract): Promise<void>;
|
|
15147
|
-
/**
|
|
15148
|
-
* Handles partial profit level events (10%, 20%, 30%, etc).
|
|
15149
|
-
*/
|
|
15150
|
-
partialProfitAvailable(event: PartialProfitContract): Promise<void>;
|
|
15151
|
-
/**
|
|
15152
|
-
* Handles partial loss level events (-10%, -20%, -30%, etc).
|
|
15153
|
-
*/
|
|
15154
|
-
partialLossAvailable(event: PartialLossContract): Promise<void>;
|
|
15155
|
-
/**
|
|
15156
|
-
* Handles scheduled ping events during scheduled signal monitoring.
|
|
15157
|
-
*/
|
|
15158
|
-
pingScheduled(event: SchedulePingContract): Promise<void>;
|
|
15159
|
-
/**
|
|
15160
|
-
* Handles active ping events during active pending signal monitoring.
|
|
15161
|
-
*/
|
|
15162
|
-
pingActive(event: ActivePingContract): Promise<void>;
|
|
15163
|
-
/**
|
|
15164
|
-
* Handles risk rejection events when signals fail risk validation.
|
|
15165
|
-
*/
|
|
15166
|
-
riskRejection(event: RiskContract): Promise<void>;
|
|
15167
|
-
/**
|
|
15168
|
-
* Cleans up resources and subscriptions when action handler is no longer needed.
|
|
15169
|
-
* Uses singleshot pattern to ensure cleanup happens exactly once.
|
|
15170
|
-
*/
|
|
15171
|
-
dispose: (() => Promise<void>) & functools_kit.ISingleshotClearable;
|
|
15172
|
-
}
|
|
15173
|
-
|
|
15174
|
-
/**
|
|
15175
|
-
* Type definition for action methods.
|
|
15176
|
-
* Maps all keys of IAction to any type.
|
|
15177
|
-
* Used for dynamic method routing in ActionConnectionService.
|
|
15178
|
-
*/
|
|
15179
|
-
type TAction = {
|
|
15180
|
-
[key in keyof IAction]: any;
|
|
15181
|
-
};
|
|
15182
|
-
/**
|
|
15183
|
-
* Connection service routing action operations to correct ClientAction instance.
|
|
15184
|
-
*
|
|
15185
|
-
* Routes action calls to the appropriate action implementation
|
|
15186
|
-
* based on the provided actionName parameter. Uses memoization to cache
|
|
15187
|
-
* ClientAction instances for performance.
|
|
15188
|
-
*
|
|
15189
|
-
* Key features:
|
|
15190
|
-
* - Explicit action routing via actionName parameter
|
|
15191
|
-
* - Memoized ClientAction instances by actionName, strategyName, frameName
|
|
15192
|
-
* - Event routing to action handlers
|
|
15193
|
-
*
|
|
15194
|
-
* @example
|
|
15195
|
-
* ```typescript
|
|
15196
|
-
* // Used internally by framework
|
|
15197
|
-
* await actionConnectionService.signal(
|
|
15198
|
-
* event,
|
|
15199
|
-
* {
|
|
15200
|
-
* actionName: "telegram-notifier",
|
|
15201
|
-
* strategyName: "rsi_divergence",
|
|
15202
|
-
* exchangeName: "binance",
|
|
15203
|
-
* frameName: "1h",
|
|
15204
|
-
* backtest: false
|
|
15205
|
-
* }
|
|
15206
|
-
* );
|
|
15207
|
-
* ```
|
|
15208
|
-
*/
|
|
15209
|
-
declare class ActionConnectionService implements TAction {
|
|
15210
|
-
private readonly loggerService;
|
|
15211
|
-
private readonly actionSchemaService;
|
|
15212
|
-
/**
|
|
15213
|
-
* Retrieves memoized ClientAction instance for given action name, strategy, exchange, frame and backtest mode.
|
|
15214
|
-
*
|
|
15215
|
-
* Creates ClientAction on first call, returns cached instance on subsequent calls.
|
|
15216
|
-
* Cache key includes strategyName, exchangeName and frameName to isolate action per strategy-frame pair.
|
|
15217
|
-
*
|
|
15218
|
-
* @param actionName - Name of registered action schema
|
|
15219
|
-
* @param strategyName - Strategy name
|
|
15220
|
-
* @param exchangeName - Exchange name
|
|
15221
|
-
* @param frameName - Frame name (empty string for live)
|
|
15222
|
-
* @param backtest - True if backtest mode, false if live mode
|
|
15223
|
-
* @returns Configured ClientAction instance
|
|
15224
|
-
*/
|
|
15225
|
-
getAction: ((actionName: ActionName, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean) => ClientAction) & functools_kit.IClearableMemoize<string> & functools_kit.IControlMemoize<string, ClientAction>;
|
|
15226
|
-
/**
|
|
15227
|
-
* Initializes the ClientAction instance for the given action name.
|
|
15228
|
-
*
|
|
15229
|
-
* Calls waitForInit() on the action instance to load persisted state.
|
|
15230
|
-
*
|
|
15231
|
-
* @param backtest - Whether running in backtest mode
|
|
15232
|
-
* @param context - Execution context with action name, strategy name, exchange name, frame name
|
|
15233
|
-
*/
|
|
15234
|
-
initFn: (backtest: boolean, context: {
|
|
15235
|
-
actionName: ActionName;
|
|
15236
|
-
strategyName: StrategyName;
|
|
15237
|
-
exchangeName: ExchangeName;
|
|
15238
|
-
frameName: FrameName;
|
|
15239
|
-
}) => Promise<void>;
|
|
15240
|
-
/**
|
|
15241
|
-
* Routes signal event to appropriate ClientAction instance.
|
|
15242
|
-
*
|
|
15243
|
-
* @param event - Signal event data
|
|
15244
|
-
* @param backtest - Whether running in backtest mode
|
|
15245
|
-
* @param context - Execution context with action name, strategy name, exchange name, frame name
|
|
15246
|
-
*/
|
|
15247
|
-
signal: (event: IStrategyTickResult, backtest: boolean, context: {
|
|
15248
|
-
actionName: ActionName;
|
|
15249
|
-
strategyName: StrategyName;
|
|
15250
|
-
exchangeName: ExchangeName;
|
|
15251
|
-
frameName: FrameName;
|
|
15252
|
-
}) => Promise<void>;
|
|
15253
|
-
/**
|
|
15254
|
-
* Routes signalLive event to appropriate ClientAction instance.
|
|
15255
|
-
*
|
|
15256
|
-
* @param event - Signal event data from live trading
|
|
15257
|
-
* @param backtest - Whether running in backtest mode
|
|
15258
|
-
* @param context - Execution context with action name, strategy name, exchange name, frame name
|
|
15259
|
-
*/
|
|
15260
|
-
signalLive: (event: IStrategyTickResult, backtest: boolean, context: {
|
|
15261
|
-
actionName: ActionName;
|
|
15262
|
-
strategyName: StrategyName;
|
|
15263
|
-
exchangeName: ExchangeName;
|
|
15264
|
-
frameName: FrameName;
|
|
15265
|
-
}) => Promise<void>;
|
|
15266
|
-
/**
|
|
15267
|
-
* Routes signalBacktest event to appropriate ClientAction instance.
|
|
15268
|
-
*
|
|
15269
|
-
* @param event - Signal event data from backtest
|
|
15270
|
-
* @param backtest - Whether running in backtest mode
|
|
15271
|
-
* @param context - Execution context with action name, strategy name, exchange name, frame name
|
|
15272
|
-
*/
|
|
15273
|
-
signalBacktest: (event: IStrategyTickResult, backtest: boolean, context: {
|
|
15274
|
-
actionName: ActionName;
|
|
15275
|
-
strategyName: StrategyName;
|
|
15276
|
-
exchangeName: ExchangeName;
|
|
15277
|
-
frameName: FrameName;
|
|
15278
|
-
}) => Promise<void>;
|
|
15279
|
-
/**
|
|
15280
|
-
* Routes breakeven event to appropriate ClientAction instance.
|
|
15281
|
-
*
|
|
15282
|
-
* @param event - Breakeven event data
|
|
15283
|
-
* @param backtest - Whether running in backtest mode
|
|
15284
|
-
* @param context - Execution context with action name, strategy name, exchange name, frame name
|
|
15285
|
-
*/
|
|
15286
|
-
breakevenAvailable: (event: BreakevenContract, backtest: boolean, context: {
|
|
15287
|
-
actionName: ActionName;
|
|
15288
|
-
strategyName: StrategyName;
|
|
15289
|
-
exchangeName: ExchangeName;
|
|
15290
|
-
frameName: FrameName;
|
|
15291
|
-
}) => Promise<void>;
|
|
15292
|
-
/**
|
|
15293
|
-
* Routes partialProfit event to appropriate ClientAction instance.
|
|
15294
|
-
*
|
|
15295
|
-
* @param event - Partial profit event data
|
|
15296
|
-
* @param backtest - Whether running in backtest mode
|
|
15297
|
-
* @param context - Execution context with action name, strategy name, exchange name, frame name
|
|
15298
|
-
*/
|
|
15299
|
-
partialProfitAvailable: (event: PartialProfitContract, backtest: boolean, context: {
|
|
15300
|
-
actionName: ActionName;
|
|
15301
|
-
strategyName: StrategyName;
|
|
15302
|
-
exchangeName: ExchangeName;
|
|
15303
|
-
frameName: FrameName;
|
|
15304
|
-
}) => Promise<void>;
|
|
15305
|
-
/**
|
|
15306
|
-
* Routes partialLoss event to appropriate ClientAction instance.
|
|
15307
|
-
*
|
|
15308
|
-
* @param event - Partial loss event data
|
|
15309
|
-
* @param backtest - Whether running in backtest mode
|
|
15310
|
-
* @param context - Execution context with action name, strategy name, exchange name, frame name
|
|
15311
|
-
*/
|
|
15312
|
-
partialLossAvailable: (event: PartialLossContract, backtest: boolean, context: {
|
|
15313
|
-
actionName: ActionName;
|
|
15314
|
-
strategyName: StrategyName;
|
|
15315
|
-
exchangeName: ExchangeName;
|
|
15316
|
-
frameName: FrameName;
|
|
15317
|
-
}) => Promise<void>;
|
|
15318
|
-
/**
|
|
15319
|
-
* Routes scheduled ping event to appropriate ClientAction instance.
|
|
16410
|
+
* },
|
|
16411
|
+
* logger: loggerService,
|
|
16412
|
+
* strategyName: "rsi_divergence",
|
|
16413
|
+
* exchangeName: "binance",
|
|
16414
|
+
* frameName: "1h",
|
|
16415
|
+
* backtest: false
|
|
16416
|
+
* });
|
|
15320
16417
|
*
|
|
15321
|
-
*
|
|
15322
|
-
*
|
|
15323
|
-
*
|
|
15324
|
-
|
|
15325
|
-
|
|
15326
|
-
actionName: ActionName;
|
|
15327
|
-
strategyName: StrategyName;
|
|
15328
|
-
exchangeName: ExchangeName;
|
|
15329
|
-
frameName: FrameName;
|
|
15330
|
-
}) => Promise<void>;
|
|
15331
|
-
/**
|
|
15332
|
-
* Routes active ping event to appropriate ClientAction instance.
|
|
16418
|
+
* await actionClient.signal({
|
|
16419
|
+
* action: 'opened',
|
|
16420
|
+
* signal: { id: '123', side: 'long' },
|
|
16421
|
+
* backtest: false
|
|
16422
|
+
* });
|
|
15333
16423
|
*
|
|
15334
|
-
*
|
|
15335
|
-
*
|
|
15336
|
-
* @param context - Execution context with action name, strategy name, exchange name, frame name
|
|
16424
|
+
* await actionClient.dispose();
|
|
16425
|
+
* ```
|
|
15337
16426
|
*/
|
|
15338
|
-
|
|
15339
|
-
actionName: ActionName;
|
|
15340
|
-
strategyName: StrategyName;
|
|
15341
|
-
exchangeName: ExchangeName;
|
|
15342
|
-
frameName: FrameName;
|
|
15343
|
-
}) => Promise<void>;
|
|
16427
|
+
constructor(params: IActionParams);
|
|
15344
16428
|
/**
|
|
15345
|
-
*
|
|
15346
|
-
*
|
|
15347
|
-
* @param event - Risk rejection event data
|
|
15348
|
-
* @param backtest - Whether running in backtest mode
|
|
15349
|
-
* @param context - Execution context with action name, strategy name, exchange name, frame name
|
|
16429
|
+
* Initializes handler instance using singleshot pattern.
|
|
16430
|
+
* Ensures initialization happens exactly once.
|
|
15350
16431
|
*/
|
|
15351
|
-
|
|
15352
|
-
actionName: ActionName;
|
|
15353
|
-
strategyName: StrategyName;
|
|
15354
|
-
exchangeName: ExchangeName;
|
|
15355
|
-
frameName: FrameName;
|
|
15356
|
-
}) => Promise<void>;
|
|
16432
|
+
waitForInit: (() => Promise<void>) & functools_kit.ISingleshotClearable;
|
|
15357
16433
|
/**
|
|
15358
|
-
*
|
|
15359
|
-
*
|
|
15360
|
-
* @param backtest - Whether running in backtest mode
|
|
15361
|
-
* @param context - Execution context with action name, strategy name, exchange name, frame name
|
|
16434
|
+
* Handles signal events from all modes (live + backtest).
|
|
15362
16435
|
*/
|
|
15363
|
-
|
|
15364
|
-
actionName: ActionName;
|
|
15365
|
-
strategyName: StrategyName;
|
|
15366
|
-
exchangeName: ExchangeName;
|
|
15367
|
-
frameName: FrameName;
|
|
15368
|
-
}) => Promise<void>;
|
|
16436
|
+
signal(event: IStrategyTickResult): Promise<void>;
|
|
15369
16437
|
/**
|
|
15370
|
-
*
|
|
15371
|
-
*
|
|
15372
|
-
* @param payload - Optional payload with actionName, strategyName, exchangeName, frameName, backtest (clears all if not provided)
|
|
16438
|
+
* Handles signal events from live trading only.
|
|
15373
16439
|
*/
|
|
15374
|
-
|
|
15375
|
-
actionName: ActionName;
|
|
15376
|
-
strategyName: StrategyName;
|
|
15377
|
-
exchangeName: ExchangeName;
|
|
15378
|
-
frameName: FrameName;
|
|
15379
|
-
backtest: boolean;
|
|
15380
|
-
}) => Promise<void>;
|
|
15381
|
-
}
|
|
15382
|
-
|
|
15383
|
-
/**
|
|
15384
|
-
* Type definition for exchange methods.
|
|
15385
|
-
* Maps all keys of IExchange to any type.
|
|
15386
|
-
* Used for dynamic method routing in ExchangeCoreService.
|
|
15387
|
-
*/
|
|
15388
|
-
type TExchange = {
|
|
15389
|
-
[key in keyof IExchange]: any;
|
|
15390
|
-
};
|
|
15391
|
-
/**
|
|
15392
|
-
* Global service for exchange operations with execution context injection.
|
|
15393
|
-
*
|
|
15394
|
-
* Wraps ExchangeConnectionService with ExecutionContextService to inject
|
|
15395
|
-
* symbol, when, and backtest parameters into the execution context.
|
|
15396
|
-
*
|
|
15397
|
-
* Used internally by BacktestLogicPrivateService and LiveLogicPrivateService.
|
|
15398
|
-
*/
|
|
15399
|
-
declare class ExchangeCoreService implements TExchange {
|
|
15400
|
-
private readonly loggerService;
|
|
15401
|
-
private readonly exchangeConnectionService;
|
|
15402
|
-
private readonly methodContextService;
|
|
15403
|
-
private readonly exchangeValidationService;
|
|
16440
|
+
signalLive(event: IStrategyTickResult): Promise<void>;
|
|
15404
16441
|
/**
|
|
15405
|
-
*
|
|
15406
|
-
* Memoized to avoid redundant validations for the same exchange.
|
|
15407
|
-
* Logs validation activity.
|
|
15408
|
-
* @param exchangeName - Name of the exchange to validate
|
|
15409
|
-
* @returns Promise that resolves when validation is complete
|
|
16442
|
+
* Handles signal events from backtest only.
|
|
15410
16443
|
*/
|
|
15411
|
-
|
|
16444
|
+
signalBacktest(event: IStrategyTickResult): Promise<void>;
|
|
15412
16445
|
/**
|
|
15413
|
-
*
|
|
15414
|
-
*
|
|
15415
|
-
* @param symbol - Trading pair symbol
|
|
15416
|
-
* @param interval - Candle interval (e.g., "1m", "1h")
|
|
15417
|
-
* @param limit - Maximum number of candles to fetch
|
|
15418
|
-
* @param when - Timestamp for context (used in backtest mode)
|
|
15419
|
-
* @param backtest - Whether running in backtest mode
|
|
15420
|
-
* @returns Promise resolving to array of candles
|
|
16446
|
+
* Handles breakeven events when stop-loss is moved to entry price.
|
|
15421
16447
|
*/
|
|
15422
|
-
|
|
16448
|
+
breakevenAvailable(event: BreakevenContract): Promise<void>;
|
|
15423
16449
|
/**
|
|
15424
|
-
*
|
|
15425
|
-
*
|
|
15426
|
-
* @param symbol - Trading pair symbol
|
|
15427
|
-
* @param interval - Candle interval
|
|
15428
|
-
* @param limit - Maximum number of candles to fetch
|
|
15429
|
-
* @param when - Timestamp for context
|
|
15430
|
-
* @param backtest - Whether running in backtest mode (must be true)
|
|
15431
|
-
* @returns Promise resolving to array of future candles
|
|
16450
|
+
* Handles partial profit level events (10%, 20%, 30%, etc).
|
|
15432
16451
|
*/
|
|
15433
|
-
|
|
16452
|
+
partialProfitAvailable(event: PartialProfitContract): Promise<void>;
|
|
15434
16453
|
/**
|
|
15435
|
-
*
|
|
15436
|
-
*
|
|
15437
|
-
* @param symbol - Trading pair symbol
|
|
15438
|
-
* @param when - Timestamp for context
|
|
15439
|
-
* @param backtest - Whether running in backtest mode
|
|
15440
|
-
* @returns Promise resolving to VWAP price
|
|
16454
|
+
* Handles partial loss level events (-10%, -20%, -30%, etc).
|
|
15441
16455
|
*/
|
|
15442
|
-
|
|
16456
|
+
partialLossAvailable(event: PartialLossContract): Promise<void>;
|
|
15443
16457
|
/**
|
|
15444
|
-
*
|
|
15445
|
-
*
|
|
15446
|
-
* @param symbol - Trading pair symbol
|
|
15447
|
-
* @param price - Price to format
|
|
15448
|
-
* @param when - Timestamp for context
|
|
15449
|
-
* @param backtest - Whether running in backtest mode
|
|
15450
|
-
* @returns Promise resolving to formatted price string
|
|
16458
|
+
* Handles scheduled ping events during scheduled signal monitoring.
|
|
15451
16459
|
*/
|
|
15452
|
-
|
|
16460
|
+
pingScheduled(event: SchedulePingContract): Promise<void>;
|
|
15453
16461
|
/**
|
|
15454
|
-
*
|
|
15455
|
-
*
|
|
15456
|
-
* @param symbol - Trading pair symbol
|
|
15457
|
-
* @param quantity - Quantity to format
|
|
15458
|
-
* @param when - Timestamp for context
|
|
15459
|
-
* @param backtest - Whether running in backtest mode
|
|
15460
|
-
* @returns Promise resolving to formatted quantity string
|
|
16462
|
+
* Handles active ping events during active pending signal monitoring.
|
|
15461
16463
|
*/
|
|
15462
|
-
|
|
16464
|
+
pingActive(event: ActivePingContract): Promise<void>;
|
|
15463
16465
|
/**
|
|
15464
|
-
*
|
|
15465
|
-
*
|
|
15466
|
-
* Sets up execution context with the provided when/backtest parameters.
|
|
15467
|
-
* The exchange implementation will receive time range parameters but may
|
|
15468
|
-
* choose to use them (backtest) or ignore them (live).
|
|
15469
|
-
*
|
|
15470
|
-
* @param symbol - Trading pair symbol
|
|
15471
|
-
* @param when - Timestamp for context
|
|
15472
|
-
* @param backtest - Whether running in backtest mode
|
|
15473
|
-
* @param depth - Maximum depth levels (default: CC_ORDER_BOOK_MAX_DEPTH_LEVELS)
|
|
15474
|
-
* @returns Promise resolving to order book data
|
|
16466
|
+
* Handles risk rejection events when signals fail risk validation.
|
|
15475
16467
|
*/
|
|
15476
|
-
|
|
16468
|
+
riskRejection(event: RiskContract): Promise<void>;
|
|
15477
16469
|
/**
|
|
15478
|
-
*
|
|
15479
|
-
*
|
|
15480
|
-
* @param symbol - Trading pair symbol
|
|
15481
|
-
* @param interval - Candle interval (e.g., "1m", "1h")
|
|
15482
|
-
* @param when - Timestamp for context (used in backtest mode)
|
|
15483
|
-
* @param backtest - Whether running in backtest mode
|
|
15484
|
-
* @param limit - Optional number of candles to fetch
|
|
15485
|
-
* @param sDate - Optional start date in milliseconds
|
|
15486
|
-
* @param eDate - Optional end date in milliseconds
|
|
15487
|
-
* @returns Promise resolving to array of candles
|
|
16470
|
+
* Cleans up resources and subscriptions when action handler is no longer needed.
|
|
16471
|
+
* Uses singleshot pattern to ensure cleanup happens exactly once.
|
|
15488
16472
|
*/
|
|
15489
|
-
|
|
16473
|
+
dispose: (() => Promise<void>) & functools_kit.ISingleshotClearable;
|
|
15490
16474
|
}
|
|
15491
16475
|
|
|
15492
16476
|
/**
|
|
15493
|
-
* Type definition for
|
|
15494
|
-
* Maps all keys of
|
|
15495
|
-
* Used for dynamic method routing in
|
|
16477
|
+
* Type definition for action methods.
|
|
16478
|
+
* Maps all keys of IAction to any type.
|
|
16479
|
+
* Used for dynamic method routing in ActionConnectionService.
|
|
15496
16480
|
*/
|
|
15497
|
-
type
|
|
15498
|
-
[key in keyof
|
|
16481
|
+
type TAction = {
|
|
16482
|
+
[key in keyof IAction]: any;
|
|
15499
16483
|
};
|
|
15500
16484
|
/**
|
|
15501
|
-
*
|
|
16485
|
+
* Connection service routing action operations to correct ClientAction instance.
|
|
15502
16486
|
*
|
|
15503
|
-
*
|
|
15504
|
-
*
|
|
16487
|
+
* Routes action calls to the appropriate action implementation
|
|
16488
|
+
* based on the provided actionName parameter. Uses memoization to cache
|
|
16489
|
+
* ClientAction instances for performance.
|
|
15505
16490
|
*
|
|
15506
|
-
*
|
|
16491
|
+
* Key features:
|
|
16492
|
+
* - Explicit action routing via actionName parameter
|
|
16493
|
+
* - Memoized ClientAction instances by actionName, strategyName, frameName
|
|
16494
|
+
* - Event routing to action handlers
|
|
16495
|
+
*
|
|
16496
|
+
* @example
|
|
16497
|
+
* ```typescript
|
|
16498
|
+
* // Used internally by framework
|
|
16499
|
+
* await actionConnectionService.signal(
|
|
16500
|
+
* event,
|
|
16501
|
+
* {
|
|
16502
|
+
* actionName: "telegram-notifier",
|
|
16503
|
+
* strategyName: "rsi_divergence",
|
|
16504
|
+
* exchangeName: "binance",
|
|
16505
|
+
* frameName: "1h",
|
|
16506
|
+
* backtest: false
|
|
16507
|
+
* }
|
|
16508
|
+
* );
|
|
16509
|
+
* ```
|
|
15507
16510
|
*/
|
|
15508
|
-
declare class
|
|
16511
|
+
declare class ActionConnectionService implements TAction {
|
|
15509
16512
|
private readonly loggerService;
|
|
15510
|
-
private readonly
|
|
15511
|
-
private readonly strategySchemaService;
|
|
15512
|
-
private readonly riskValidationService;
|
|
15513
|
-
private readonly strategyValidationService;
|
|
15514
|
-
private readonly exchangeValidationService;
|
|
15515
|
-
private readonly frameValidationService;
|
|
16513
|
+
private readonly actionSchemaService;
|
|
15516
16514
|
/**
|
|
15517
|
-
*
|
|
16515
|
+
* Retrieves memoized ClientAction instance for given action name, strategy, exchange, frame and backtest mode.
|
|
15518
16516
|
*
|
|
15519
|
-
*
|
|
15520
|
-
*
|
|
15521
|
-
*
|
|
15522
|
-
* @param
|
|
15523
|
-
* @
|
|
16517
|
+
* Creates ClientAction on first call, returns cached instance on subsequent calls.
|
|
16518
|
+
* Cache key includes strategyName, exchangeName and frameName to isolate action per strategy-frame pair.
|
|
16519
|
+
*
|
|
16520
|
+
* @param actionName - Name of registered action schema
|
|
16521
|
+
* @param strategyName - Strategy name
|
|
16522
|
+
* @param exchangeName - Exchange name
|
|
16523
|
+
* @param frameName - Frame name (empty string for live)
|
|
16524
|
+
* @param backtest - True if backtest mode, false if live mode
|
|
16525
|
+
* @returns Configured ClientAction instance
|
|
15524
16526
|
*/
|
|
15525
|
-
|
|
16527
|
+
getAction: ((actionName: ActionName, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean) => ClientAction) & functools_kit.IClearableMemoize<string> & functools_kit.IControlMemoize<string, ClientAction>;
|
|
16528
|
+
/**
|
|
16529
|
+
* Initializes the ClientAction instance for the given action name.
|
|
16530
|
+
*
|
|
16531
|
+
* Calls waitForInit() on the action instance to load persisted state.
|
|
16532
|
+
*
|
|
16533
|
+
* @param backtest - Whether running in backtest mode
|
|
16534
|
+
* @param context - Execution context with action name, strategy name, exchange name, frame name
|
|
16535
|
+
*/
|
|
16536
|
+
initFn: (backtest: boolean, context: {
|
|
16537
|
+
actionName: ActionName;
|
|
16538
|
+
strategyName: StrategyName;
|
|
16539
|
+
exchangeName: ExchangeName;
|
|
16540
|
+
frameName: FrameName;
|
|
16541
|
+
}) => Promise<void>;
|
|
15526
16542
|
/**
|
|
15527
|
-
*
|
|
15528
|
-
* If no active signal exists, returns null.
|
|
15529
|
-
* Used internally for monitoring TP/SL and time expiration.
|
|
16543
|
+
* Routes signal event to appropriate ClientAction instance.
|
|
15530
16544
|
*
|
|
16545
|
+
* @param event - Signal event data
|
|
15531
16546
|
* @param backtest - Whether running in backtest mode
|
|
15532
|
-
* @param
|
|
15533
|
-
* @param context - Execution context with strategyName, exchangeName, frameName
|
|
15534
|
-
* @returns Promise resolving to pending signal or null
|
|
16547
|
+
* @param context - Execution context with action name, strategy name, exchange name, frame name
|
|
15535
16548
|
*/
|
|
15536
|
-
|
|
16549
|
+
signal: (event: IStrategyTickResult, backtest: boolean, context: {
|
|
16550
|
+
actionName: ActionName;
|
|
15537
16551
|
strategyName: StrategyName;
|
|
15538
16552
|
exchangeName: ExchangeName;
|
|
15539
16553
|
frameName: FrameName;
|
|
15540
|
-
}) => Promise<
|
|
16554
|
+
}) => Promise<void>;
|
|
15541
16555
|
/**
|
|
15542
|
-
*
|
|
15543
|
-
* If no scheduled signal exists, returns null.
|
|
15544
|
-
* Used internally for monitoring scheduled signal activation.
|
|
16556
|
+
* Routes signalLive event to appropriate ClientAction instance.
|
|
15545
16557
|
*
|
|
16558
|
+
* @param event - Signal event data from live trading
|
|
15546
16559
|
* @param backtest - Whether running in backtest mode
|
|
15547
|
-
* @param
|
|
15548
|
-
* @param context - Execution context with strategyName, exchangeName, frameName
|
|
15549
|
-
* @returns Promise resolving to scheduled signal or null
|
|
16560
|
+
* @param context - Execution context with action name, strategy name, exchange name, frame name
|
|
15550
16561
|
*/
|
|
15551
|
-
|
|
16562
|
+
signalLive: (event: IStrategyTickResult, backtest: boolean, context: {
|
|
16563
|
+
actionName: ActionName;
|
|
15552
16564
|
strategyName: StrategyName;
|
|
15553
16565
|
exchangeName: ExchangeName;
|
|
15554
16566
|
frameName: FrameName;
|
|
15555
|
-
}) => Promise<
|
|
16567
|
+
}) => Promise<void>;
|
|
15556
16568
|
/**
|
|
15557
|
-
*
|
|
15558
|
-
*
|
|
15559
|
-
* Validates strategy existence and delegates to connection service
|
|
15560
|
-
* to check if price has moved far enough to cover transaction costs.
|
|
15561
|
-
*
|
|
15562
|
-
* Does not require execution context as this is a state query operation.
|
|
16569
|
+
* Routes signalBacktest event to appropriate ClientAction instance.
|
|
15563
16570
|
*
|
|
16571
|
+
* @param event - Signal event data from backtest
|
|
15564
16572
|
* @param backtest - Whether running in backtest mode
|
|
15565
|
-
* @param
|
|
15566
|
-
* @param currentPrice - Current market price to check against threshold
|
|
15567
|
-
* @param context - Execution context with strategyName, exchangeName, frameName
|
|
15568
|
-
* @returns Promise<boolean> - true if breakeven threshold reached, false otherwise
|
|
15569
|
-
*
|
|
15570
|
-
* @example
|
|
15571
|
-
* ```typescript
|
|
15572
|
-
* // Check if breakeven is available for LONG position (entry=100, threshold=0.4%)
|
|
15573
|
-
* const canBreakeven = await strategyCoreService.getBreakeven(
|
|
15574
|
-
* false,
|
|
15575
|
-
* "BTCUSDT",
|
|
15576
|
-
* 100.5,
|
|
15577
|
-
* { strategyName: "my-strategy", exchangeName: "binance", frameName: "" }
|
|
15578
|
-
* );
|
|
15579
|
-
* // Returns true (price >= 100.4)
|
|
15580
|
-
*
|
|
15581
|
-
* if (canBreakeven) {
|
|
15582
|
-
* await strategyCoreService.breakeven(false, "BTCUSDT", 100.5, context);
|
|
15583
|
-
* }
|
|
15584
|
-
* ```
|
|
16573
|
+
* @param context - Execution context with action name, strategy name, exchange name, frame name
|
|
15585
16574
|
*/
|
|
15586
|
-
|
|
16575
|
+
signalBacktest: (event: IStrategyTickResult, backtest: boolean, context: {
|
|
16576
|
+
actionName: ActionName;
|
|
15587
16577
|
strategyName: StrategyName;
|
|
15588
16578
|
exchangeName: ExchangeName;
|
|
15589
16579
|
frameName: FrameName;
|
|
15590
|
-
}) => Promise<
|
|
16580
|
+
}) => Promise<void>;
|
|
15591
16581
|
/**
|
|
15592
|
-
*
|
|
15593
|
-
*
|
|
15594
|
-
* Validates strategy existence and delegates to connection service
|
|
15595
|
-
* to retrieve the stopped state from the strategy instance.
|
|
16582
|
+
* Routes breakeven event to appropriate ClientAction instance.
|
|
15596
16583
|
*
|
|
16584
|
+
* @param event - Breakeven event data
|
|
15597
16585
|
* @param backtest - Whether running in backtest mode
|
|
15598
|
-
* @param
|
|
15599
|
-
* @param context - Execution context with strategyName, exchangeName, frameName
|
|
15600
|
-
* @returns Promise resolving to true if strategy is stopped, false otherwise
|
|
16586
|
+
* @param context - Execution context with action name, strategy name, exchange name, frame name
|
|
15601
16587
|
*/
|
|
15602
|
-
|
|
16588
|
+
breakevenAvailable: (event: BreakevenContract, backtest: boolean, context: {
|
|
16589
|
+
actionName: ActionName;
|
|
15603
16590
|
strategyName: StrategyName;
|
|
15604
16591
|
exchangeName: ExchangeName;
|
|
15605
16592
|
frameName: FrameName;
|
|
15606
|
-
}) => Promise<
|
|
16593
|
+
}) => Promise<void>;
|
|
15607
16594
|
/**
|
|
15608
|
-
*
|
|
15609
|
-
*
|
|
15610
|
-
* Wraps strategy tick() with execution context containing symbol, timestamp,
|
|
15611
|
-
* and backtest mode flag.
|
|
16595
|
+
* Routes partialProfit event to appropriate ClientAction instance.
|
|
15612
16596
|
*
|
|
15613
|
-
* @param
|
|
15614
|
-
* @param when - Timestamp for tick evaluation
|
|
16597
|
+
* @param event - Partial profit event data
|
|
15615
16598
|
* @param backtest - Whether running in backtest mode
|
|
15616
|
-
* @param context - Execution context with
|
|
15617
|
-
* @returns Discriminated union of tick result (idle, opened, active, closed)
|
|
16599
|
+
* @param context - Execution context with action name, strategy name, exchange name, frame name
|
|
15618
16600
|
*/
|
|
15619
|
-
|
|
16601
|
+
partialProfitAvailable: (event: PartialProfitContract, backtest: boolean, context: {
|
|
16602
|
+
actionName: ActionName;
|
|
15620
16603
|
strategyName: StrategyName;
|
|
15621
16604
|
exchangeName: ExchangeName;
|
|
15622
16605
|
frameName: FrameName;
|
|
15623
|
-
}) => Promise<
|
|
16606
|
+
}) => Promise<void>;
|
|
15624
16607
|
/**
|
|
15625
|
-
*
|
|
15626
|
-
*
|
|
15627
|
-
* Wraps strategy backtest() with execution context containing symbol,
|
|
15628
|
-
* timestamp, and backtest mode flag.
|
|
16608
|
+
* Routes partialLoss event to appropriate ClientAction instance.
|
|
15629
16609
|
*
|
|
15630
|
-
* @param
|
|
15631
|
-
* @param
|
|
15632
|
-
* @param
|
|
15633
|
-
* @param backtest - Whether running in backtest mode (typically true)
|
|
15634
|
-
* @param context - Execution context with strategyName, exchangeName, frameName
|
|
15635
|
-
* @returns Closed signal result with PNL
|
|
16610
|
+
* @param event - Partial loss event data
|
|
16611
|
+
* @param backtest - Whether running in backtest mode
|
|
16612
|
+
* @param context - Execution context with action name, strategy name, exchange name, frame name
|
|
15636
16613
|
*/
|
|
15637
|
-
|
|
16614
|
+
partialLossAvailable: (event: PartialLossContract, backtest: boolean, context: {
|
|
16615
|
+
actionName: ActionName;
|
|
15638
16616
|
strategyName: StrategyName;
|
|
15639
16617
|
exchangeName: ExchangeName;
|
|
15640
16618
|
frameName: FrameName;
|
|
15641
|
-
}) => Promise<
|
|
16619
|
+
}) => Promise<void>;
|
|
15642
16620
|
/**
|
|
15643
|
-
*
|
|
15644
|
-
*
|
|
15645
|
-
* Delegates to StrategyConnectionService.stop() to set internal flag.
|
|
15646
|
-
* Does not require execution context.
|
|
16621
|
+
* Routes scheduled ping event to appropriate ClientAction instance.
|
|
15647
16622
|
*
|
|
16623
|
+
* @param event - Scheduled ping event data
|
|
15648
16624
|
* @param backtest - Whether running in backtest mode
|
|
15649
|
-
* @param
|
|
15650
|
-
* @param ctx - Context with strategyName, exchangeName, frameName
|
|
15651
|
-
* @returns Promise that resolves when stop flag is set
|
|
16625
|
+
* @param context - Execution context with action name, strategy name, exchange name, frame name
|
|
15652
16626
|
*/
|
|
15653
|
-
|
|
16627
|
+
pingScheduled: (event: SchedulePingContract, backtest: boolean, context: {
|
|
16628
|
+
actionName: ActionName;
|
|
15654
16629
|
strategyName: StrategyName;
|
|
15655
16630
|
exchangeName: ExchangeName;
|
|
15656
16631
|
frameName: FrameName;
|
|
15657
16632
|
}) => Promise<void>;
|
|
15658
16633
|
/**
|
|
15659
|
-
*
|
|
15660
|
-
*
|
|
15661
|
-
* Delegates to StrategyConnectionService.cancelScheduled() to clear scheduled signal
|
|
15662
|
-
* and emit cancelled event through emitters.
|
|
15663
|
-
* Does not require execution context.
|
|
16634
|
+
* Routes active ping event to appropriate ClientAction instance.
|
|
15664
16635
|
*
|
|
16636
|
+
* @param event - Active ping event data
|
|
15665
16637
|
* @param backtest - Whether running in backtest mode
|
|
15666
|
-
* @param
|
|
15667
|
-
* @param ctx - Context with strategyName, exchangeName, frameName
|
|
15668
|
-
* @param cancelId - Optional cancellation ID for user-initiated cancellations
|
|
15669
|
-
* @returns Promise that resolves when scheduled signal is cancelled
|
|
16638
|
+
* @param context - Execution context with action name, strategy name, exchange name, frame name
|
|
15670
16639
|
*/
|
|
15671
|
-
|
|
16640
|
+
pingActive: (event: ActivePingContract, backtest: boolean, context: {
|
|
16641
|
+
actionName: ActionName;
|
|
15672
16642
|
strategyName: StrategyName;
|
|
15673
16643
|
exchangeName: ExchangeName;
|
|
15674
16644
|
frameName: FrameName;
|
|
15675
|
-
}
|
|
16645
|
+
}) => Promise<void>;
|
|
15676
16646
|
/**
|
|
15677
|
-
*
|
|
15678
|
-
*
|
|
15679
|
-
* Clears the pending signal (active position).
|
|
15680
|
-
* Does NOT affect scheduled signals or strategy operation.
|
|
15681
|
-
* Does NOT set stop flag - strategy can continue generating new signals.
|
|
15682
|
-
*
|
|
15683
|
-
* Delegates to StrategyConnectionService.closePending() to clear pending signal
|
|
15684
|
-
* and emit closed event through emitters.
|
|
15685
|
-
* Does not require execution context.
|
|
16647
|
+
* Routes riskRejection event to appropriate ClientAction instance.
|
|
15686
16648
|
*
|
|
16649
|
+
* @param event - Risk rejection event data
|
|
15687
16650
|
* @param backtest - Whether running in backtest mode
|
|
15688
|
-
* @param
|
|
15689
|
-
* @param context - Context with strategyName, exchangeName, frameName
|
|
15690
|
-
* @param closeId - Optional close ID for user-initiated closes
|
|
15691
|
-
* @returns Promise that resolves when pending signal is closed
|
|
16651
|
+
* @param context - Execution context with action name, strategy name, exchange name, frame name
|
|
15692
16652
|
*/
|
|
15693
|
-
|
|
16653
|
+
riskRejection: (event: RiskContract, backtest: boolean, context: {
|
|
16654
|
+
actionName: ActionName;
|
|
15694
16655
|
strategyName: StrategyName;
|
|
15695
16656
|
exchangeName: ExchangeName;
|
|
15696
16657
|
frameName: FrameName;
|
|
15697
|
-
}
|
|
16658
|
+
}) => Promise<void>;
|
|
15698
16659
|
/**
|
|
15699
|
-
* Disposes the
|
|
15700
|
-
*
|
|
15701
|
-
* Calls dispose on the strategy instance to clean up resources,
|
|
15702
|
-
* then removes it from cache.
|
|
16660
|
+
* Disposes the ClientAction instance for the given action name.
|
|
15703
16661
|
*
|
|
15704
16662
|
* @param backtest - Whether running in backtest mode
|
|
15705
|
-
* @param
|
|
15706
|
-
* @param context - Execution context with strategyName, exchangeName, frameName
|
|
16663
|
+
* @param context - Execution context with action name, strategy name, exchange name, frame name
|
|
15707
16664
|
*/
|
|
15708
|
-
dispose: (backtest: boolean,
|
|
16665
|
+
dispose: (backtest: boolean, context: {
|
|
16666
|
+
actionName: ActionName;
|
|
15709
16667
|
strategyName: StrategyName;
|
|
15710
16668
|
exchangeName: ExchangeName;
|
|
15711
16669
|
frameName: FrameName;
|
|
15712
16670
|
}) => Promise<void>;
|
|
15713
16671
|
/**
|
|
15714
|
-
* Clears the
|
|
15715
|
-
*
|
|
15716
|
-
* Delegates to StrategyConnectionService.dispose() if payload provided,
|
|
15717
|
-
* otherwise clears all strategy instances.
|
|
16672
|
+
* Clears the cached ClientAction instance for the given action name.
|
|
15718
16673
|
*
|
|
15719
|
-
* @param payload - Optional payload with
|
|
16674
|
+
* @param payload - Optional payload with actionName, strategyName, exchangeName, frameName, backtest (clears all if not provided)
|
|
15720
16675
|
*/
|
|
15721
16676
|
clear: (payload?: {
|
|
15722
|
-
|
|
16677
|
+
actionName: ActionName;
|
|
15723
16678
|
strategyName: StrategyName;
|
|
15724
16679
|
exchangeName: ExchangeName;
|
|
15725
16680
|
frameName: FrameName;
|
|
15726
16681
|
backtest: boolean;
|
|
15727
16682
|
}) => Promise<void>;
|
|
16683
|
+
}
|
|
16684
|
+
|
|
16685
|
+
/**
|
|
16686
|
+
* Type definition for exchange methods.
|
|
16687
|
+
* Maps all keys of IExchange to any type.
|
|
16688
|
+
* Used for dynamic method routing in ExchangeCoreService.
|
|
16689
|
+
*/
|
|
16690
|
+
type TExchange = {
|
|
16691
|
+
[key in keyof IExchange]: any;
|
|
16692
|
+
};
|
|
16693
|
+
/**
|
|
16694
|
+
* Global service for exchange operations with execution context injection.
|
|
16695
|
+
*
|
|
16696
|
+
* Wraps ExchangeConnectionService with ExecutionContextService to inject
|
|
16697
|
+
* symbol, when, and backtest parameters into the execution context.
|
|
16698
|
+
*
|
|
16699
|
+
* Used internally by BacktestLogicPrivateService and LiveLogicPrivateService.
|
|
16700
|
+
*/
|
|
16701
|
+
declare class ExchangeCoreService implements TExchange {
|
|
16702
|
+
private readonly loggerService;
|
|
16703
|
+
private readonly exchangeConnectionService;
|
|
16704
|
+
private readonly methodContextService;
|
|
16705
|
+
private readonly exchangeValidationService;
|
|
15728
16706
|
/**
|
|
15729
|
-
*
|
|
15730
|
-
*
|
|
15731
|
-
*
|
|
15732
|
-
*
|
|
15733
|
-
*
|
|
15734
|
-
|
|
16707
|
+
* Validates exchange configuration.
|
|
16708
|
+
* Memoized to avoid redundant validations for the same exchange.
|
|
16709
|
+
* Logs validation activity.
|
|
16710
|
+
* @param exchangeName - Name of the exchange to validate
|
|
16711
|
+
* @returns Promise that resolves when validation is complete
|
|
16712
|
+
*/
|
|
16713
|
+
private validate;
|
|
16714
|
+
/**
|
|
16715
|
+
* Fetches historical candles with execution context.
|
|
15735
16716
|
*
|
|
15736
|
-
* @param backtest - Whether running in backtest mode
|
|
15737
16717
|
* @param symbol - Trading pair symbol
|
|
15738
|
-
* @param
|
|
15739
|
-
* @param
|
|
15740
|
-
* @param
|
|
15741
|
-
* @
|
|
15742
|
-
*
|
|
15743
|
-
* @example
|
|
15744
|
-
* ```typescript
|
|
15745
|
-
* // Close 30% of position at profit
|
|
15746
|
-
* const success = await strategyCoreService.partialProfit(
|
|
15747
|
-
* false,
|
|
15748
|
-
* "BTCUSDT",
|
|
15749
|
-
* 30,
|
|
15750
|
-
* 45000,
|
|
15751
|
-
* { strategyName: "my-strategy", exchangeName: "binance", frameName: "" }
|
|
15752
|
-
* );
|
|
15753
|
-
* if (success) {
|
|
15754
|
-
* console.log('Partial profit executed');
|
|
15755
|
-
* }
|
|
15756
|
-
* ```
|
|
16718
|
+
* @param interval - Candle interval (e.g., "1m", "1h")
|
|
16719
|
+
* @param limit - Maximum number of candles to fetch
|
|
16720
|
+
* @param when - Timestamp for context (used in backtest mode)
|
|
16721
|
+
* @param backtest - Whether running in backtest mode
|
|
16722
|
+
* @returns Promise resolving to array of candles
|
|
15757
16723
|
*/
|
|
15758
|
-
|
|
15759
|
-
strategyName: StrategyName;
|
|
15760
|
-
exchangeName: ExchangeName;
|
|
15761
|
-
frameName: FrameName;
|
|
15762
|
-
}) => Promise<boolean>;
|
|
16724
|
+
getCandles: (symbol: string, interval: CandleInterval, limit: number, when: Date, backtest: boolean) => Promise<ICandleData[]>;
|
|
15763
16725
|
/**
|
|
15764
|
-
*
|
|
15765
|
-
*
|
|
15766
|
-
* Validates strategy existence and delegates to connection service
|
|
15767
|
-
* to close a percentage of the pending position at loss.
|
|
15768
|
-
*
|
|
15769
|
-
* Does not require execution context as this is a direct state mutation.
|
|
16726
|
+
* Fetches future candles (backtest mode only) with execution context.
|
|
15770
16727
|
*
|
|
15771
|
-
* @param backtest - Whether running in backtest mode
|
|
15772
16728
|
* @param symbol - Trading pair symbol
|
|
15773
|
-
* @param
|
|
15774
|
-
* @param
|
|
15775
|
-
* @param
|
|
15776
|
-
* @
|
|
15777
|
-
*
|
|
15778
|
-
* @example
|
|
15779
|
-
* ```typescript
|
|
15780
|
-
* // Close 40% of position at loss
|
|
15781
|
-
* const success = await strategyCoreService.partialLoss(
|
|
15782
|
-
* false,
|
|
15783
|
-
* "BTCUSDT",
|
|
15784
|
-
* 40,
|
|
15785
|
-
* 38000,
|
|
15786
|
-
* { strategyName: "my-strategy", exchangeName: "binance", frameName: "" }
|
|
15787
|
-
* );
|
|
15788
|
-
* if (success) {
|
|
15789
|
-
* console.log('Partial loss executed');
|
|
15790
|
-
* }
|
|
15791
|
-
* ```
|
|
16729
|
+
* @param interval - Candle interval
|
|
16730
|
+
* @param limit - Maximum number of candles to fetch
|
|
16731
|
+
* @param when - Timestamp for context
|
|
16732
|
+
* @param backtest - Whether running in backtest mode (must be true)
|
|
16733
|
+
* @returns Promise resolving to array of future candles
|
|
15792
16734
|
*/
|
|
15793
|
-
|
|
15794
|
-
strategyName: StrategyName;
|
|
15795
|
-
exchangeName: ExchangeName;
|
|
15796
|
-
frameName: FrameName;
|
|
15797
|
-
}) => Promise<boolean>;
|
|
16735
|
+
getNextCandles: (symbol: string, interval: CandleInterval, limit: number, when: Date, backtest: boolean) => Promise<ICandleData[]>;
|
|
15798
16736
|
/**
|
|
15799
|
-
*
|
|
15800
|
-
*
|
|
15801
|
-
* Validates strategy existence and delegates to connection service
|
|
15802
|
-
* to update the stop-loss distance by a percentage adjustment.
|
|
15803
|
-
*
|
|
15804
|
-
* Does not require execution context as this is a direct state mutation.
|
|
16737
|
+
* Calculates VWAP with execution context.
|
|
15805
16738
|
*
|
|
15806
|
-
* @param backtest - Whether running in backtest mode
|
|
15807
16739
|
* @param symbol - Trading pair symbol
|
|
15808
|
-
* @param
|
|
15809
|
-
* @param
|
|
15810
|
-
* @
|
|
15811
|
-
* @returns Promise that resolves when trailing SL is updated
|
|
15812
|
-
*
|
|
15813
|
-
* @example
|
|
15814
|
-
* ```typescript
|
|
15815
|
-
* // LONG: entry=100, originalSL=90, distance=10%, currentPrice=102
|
|
15816
|
-
* // Tighten stop by 50%: newSL = 100 - 5% = 95
|
|
15817
|
-
* await strategyCoreService.trailingStop(
|
|
15818
|
-
* false,
|
|
15819
|
-
* "BTCUSDT",
|
|
15820
|
-
* -50,
|
|
15821
|
-
* 102,
|
|
15822
|
-
* { strategyName: "my-strategy", exchangeName: "binance", frameName: "" }
|
|
15823
|
-
* );
|
|
15824
|
-
* ```
|
|
16740
|
+
* @param when - Timestamp for context
|
|
16741
|
+
* @param backtest - Whether running in backtest mode
|
|
16742
|
+
* @returns Promise resolving to VWAP price
|
|
15825
16743
|
*/
|
|
15826
|
-
|
|
15827
|
-
strategyName: StrategyName;
|
|
15828
|
-
exchangeName: ExchangeName;
|
|
15829
|
-
frameName: FrameName;
|
|
15830
|
-
}) => Promise<boolean>;
|
|
16744
|
+
getAveragePrice: (symbol: string, when: Date, backtest: boolean) => Promise<number>;
|
|
15831
16745
|
/**
|
|
15832
|
-
*
|
|
15833
|
-
* Validates context and delegates to StrategyConnectionService.
|
|
16746
|
+
* Formats price with execution context.
|
|
15834
16747
|
*
|
|
15835
|
-
* @param backtest - Whether running in backtest mode
|
|
15836
16748
|
* @param symbol - Trading pair symbol
|
|
15837
|
-
* @param
|
|
15838
|
-
* @param
|
|
15839
|
-
* @param
|
|
15840
|
-
* @returns Promise
|
|
15841
|
-
*
|
|
15842
|
-
* @example
|
|
15843
|
-
* ```typescript
|
|
15844
|
-
* // LONG: entry=100, originalTP=110, distance=10%, currentPrice=102
|
|
15845
|
-
* // Move TP further by 50%: newTP = 100 + 15% = 115
|
|
15846
|
-
* await strategyCoreService.trailingTake(
|
|
15847
|
-
* false,
|
|
15848
|
-
* "BTCUSDT",
|
|
15849
|
-
* 50,
|
|
15850
|
-
* 102,
|
|
15851
|
-
* { strategyName: "my-strategy", exchangeName: "binance", frameName: "" }
|
|
15852
|
-
* );
|
|
15853
|
-
* ```
|
|
16749
|
+
* @param price - Price to format
|
|
16750
|
+
* @param when - Timestamp for context
|
|
16751
|
+
* @param backtest - Whether running in backtest mode
|
|
16752
|
+
* @returns Promise resolving to formatted price string
|
|
15854
16753
|
*/
|
|
15855
|
-
|
|
15856
|
-
strategyName: StrategyName;
|
|
15857
|
-
exchangeName: ExchangeName;
|
|
15858
|
-
frameName: FrameName;
|
|
15859
|
-
}) => Promise<boolean>;
|
|
16754
|
+
formatPrice: (symbol: string, price: number, when: Date, backtest: boolean) => Promise<string>;
|
|
15860
16755
|
/**
|
|
15861
|
-
*
|
|
15862
|
-
* Validates context and delegates to StrategyConnectionService.
|
|
16756
|
+
* Formats quantity with execution context.
|
|
15863
16757
|
*
|
|
16758
|
+
* @param symbol - Trading pair symbol
|
|
16759
|
+
* @param quantity - Quantity to format
|
|
16760
|
+
* @param when - Timestamp for context
|
|
15864
16761
|
* @param backtest - Whether running in backtest mode
|
|
16762
|
+
* @returns Promise resolving to formatted quantity string
|
|
16763
|
+
*/
|
|
16764
|
+
formatQuantity: (symbol: string, quantity: number, when: Date, backtest: boolean) => Promise<string>;
|
|
16765
|
+
/**
|
|
16766
|
+
* Fetches order book with execution context.
|
|
16767
|
+
*
|
|
16768
|
+
* Sets up execution context with the provided when/backtest parameters.
|
|
16769
|
+
* The exchange implementation will receive time range parameters but may
|
|
16770
|
+
* choose to use them (backtest) or ignore them (live).
|
|
16771
|
+
*
|
|
15865
16772
|
* @param symbol - Trading pair symbol
|
|
15866
|
-
* @param
|
|
15867
|
-
* @param
|
|
15868
|
-
* @
|
|
16773
|
+
* @param when - Timestamp for context
|
|
16774
|
+
* @param backtest - Whether running in backtest mode
|
|
16775
|
+
* @param depth - Maximum depth levels (default: CC_ORDER_BOOK_MAX_DEPTH_LEVELS)
|
|
16776
|
+
* @returns Promise resolving to order book data
|
|
16777
|
+
*/
|
|
16778
|
+
getOrderBook: (symbol: string, when: Date, backtest: boolean, depth?: number) => Promise<IOrderBookData>;
|
|
16779
|
+
/**
|
|
16780
|
+
* Fetches raw candles with flexible date/limit parameters and execution context.
|
|
15869
16781
|
*
|
|
15870
|
-
* @
|
|
15871
|
-
*
|
|
15872
|
-
*
|
|
15873
|
-
*
|
|
15874
|
-
*
|
|
15875
|
-
*
|
|
15876
|
-
*
|
|
15877
|
-
*
|
|
15878
|
-
* ```
|
|
16782
|
+
* @param symbol - Trading pair symbol
|
|
16783
|
+
* @param interval - Candle interval (e.g., "1m", "1h")
|
|
16784
|
+
* @param when - Timestamp for context (used in backtest mode)
|
|
16785
|
+
* @param backtest - Whether running in backtest mode
|
|
16786
|
+
* @param limit - Optional number of candles to fetch
|
|
16787
|
+
* @param sDate - Optional start date in milliseconds
|
|
16788
|
+
* @param eDate - Optional end date in milliseconds
|
|
16789
|
+
* @returns Promise resolving to array of candles
|
|
15879
16790
|
*/
|
|
15880
|
-
|
|
15881
|
-
strategyName: StrategyName;
|
|
15882
|
-
exchangeName: ExchangeName;
|
|
15883
|
-
frameName: FrameName;
|
|
15884
|
-
}) => Promise<boolean>;
|
|
16791
|
+
getRawCandles: (symbol: string, interval: CandleInterval, when: Date, backtest: boolean, limit?: number, sDate?: number, eDate?: number) => Promise<ICandleData[]>;
|
|
15885
16792
|
}
|
|
15886
16793
|
|
|
15887
16794
|
/**
|
|
@@ -18172,6 +19079,173 @@ declare class RiskReportService {
|
|
|
18172
19079
|
unsubscribe: () => Promise<void>;
|
|
18173
19080
|
}
|
|
18174
19081
|
|
|
19082
|
+
/**
|
|
19083
|
+
* Service for persisting strategy management events to JSON report files.
|
|
19084
|
+
*
|
|
19085
|
+
* Handles logging of strategy actions (cancel-scheduled, close-pending, partial-profit,
|
|
19086
|
+
* partial-loss, trailing-stop, trailing-take, breakeven) to persistent storage via
|
|
19087
|
+
* the Report class. Each event is written as a separate JSON record.
|
|
19088
|
+
*
|
|
19089
|
+
* Unlike StrategyMarkdownService which accumulates events in memory for markdown reports,
|
|
19090
|
+
* this service writes each event immediately to disk for audit trail purposes.
|
|
19091
|
+
*
|
|
19092
|
+
* Lifecycle:
|
|
19093
|
+
* - Call subscribe() to enable event logging
|
|
19094
|
+
* - Events are written via Report.writeData() with "strategy" category
|
|
19095
|
+
* - Call unsubscribe() to disable event logging
|
|
19096
|
+
*
|
|
19097
|
+
* @example
|
|
19098
|
+
* ```typescript
|
|
19099
|
+
* // Service is typically used internally by strategy management classes
|
|
19100
|
+
* strategyReportService.subscribe();
|
|
19101
|
+
*
|
|
19102
|
+
* // Events are logged automatically when strategy actions occur
|
|
19103
|
+
* await strategyReportService.partialProfit("BTCUSDT", 50, 50100, false, {
|
|
19104
|
+
* strategyName: "my-strategy",
|
|
19105
|
+
* exchangeName: "binance",
|
|
19106
|
+
* frameName: "1h"
|
|
19107
|
+
* });
|
|
19108
|
+
*
|
|
19109
|
+
* strategyReportService.unsubscribe();
|
|
19110
|
+
* ```
|
|
19111
|
+
*
|
|
19112
|
+
* @see StrategyMarkdownService for in-memory event accumulation and markdown report generation
|
|
19113
|
+
* @see Report for the underlying persistence mechanism
|
|
19114
|
+
*/
|
|
19115
|
+
declare class StrategyReportService {
|
|
19116
|
+
readonly loggerService: LoggerService;
|
|
19117
|
+
readonly executionContextService: {
|
|
19118
|
+
readonly context: IExecutionContext;
|
|
19119
|
+
};
|
|
19120
|
+
readonly strategyCoreService: StrategyCoreService;
|
|
19121
|
+
/**
|
|
19122
|
+
* Logs a cancel-scheduled event when a scheduled signal is cancelled.
|
|
19123
|
+
*
|
|
19124
|
+
* Retrieves the scheduled signal from StrategyCoreService and writes
|
|
19125
|
+
* the cancellation event to the report file.
|
|
19126
|
+
*
|
|
19127
|
+
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
19128
|
+
* @param isBacktest - Whether this is a backtest or live trading event
|
|
19129
|
+
* @param context - Strategy context with strategyName, exchangeName, frameName
|
|
19130
|
+
* @param cancelId - Optional identifier for the cancellation reason
|
|
19131
|
+
*/
|
|
19132
|
+
cancelScheduled: (symbol: string, isBacktest: boolean, context: {
|
|
19133
|
+
strategyName: StrategyName;
|
|
19134
|
+
exchangeName: ExchangeName;
|
|
19135
|
+
frameName: FrameName;
|
|
19136
|
+
}, cancelId?: string) => Promise<void>;
|
|
19137
|
+
/**
|
|
19138
|
+
* Logs a close-pending event when a pending signal is closed.
|
|
19139
|
+
*
|
|
19140
|
+
* Retrieves the pending signal from StrategyCoreService and writes
|
|
19141
|
+
* the close event to the report file.
|
|
19142
|
+
*
|
|
19143
|
+
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
19144
|
+
* @param isBacktest - Whether this is a backtest or live trading event
|
|
19145
|
+
* @param context - Strategy context with strategyName, exchangeName, frameName
|
|
19146
|
+
* @param closeId - Optional identifier for the close reason
|
|
19147
|
+
*/
|
|
19148
|
+
closePending: (symbol: string, isBacktest: boolean, context: {
|
|
19149
|
+
strategyName: StrategyName;
|
|
19150
|
+
exchangeName: ExchangeName;
|
|
19151
|
+
frameName: FrameName;
|
|
19152
|
+
}, closeId?: string) => Promise<void>;
|
|
19153
|
+
/**
|
|
19154
|
+
* Logs a partial-profit event when a portion of the position is closed at profit.
|
|
19155
|
+
*
|
|
19156
|
+
* Records the percentage closed and current price when partial profit-taking occurs.
|
|
19157
|
+
*
|
|
19158
|
+
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
19159
|
+
* @param percentToClose - Percentage of position to close (0-100)
|
|
19160
|
+
* @param currentPrice - Current market price at time of partial close
|
|
19161
|
+
* @param isBacktest - Whether this is a backtest or live trading event
|
|
19162
|
+
* @param context - Strategy context with strategyName, exchangeName, frameName
|
|
19163
|
+
*/
|
|
19164
|
+
partialProfit: (symbol: string, percentToClose: number, currentPrice: number, isBacktest: boolean, context: {
|
|
19165
|
+
strategyName: StrategyName;
|
|
19166
|
+
exchangeName: ExchangeName;
|
|
19167
|
+
frameName: FrameName;
|
|
19168
|
+
}) => Promise<void>;
|
|
19169
|
+
/**
|
|
19170
|
+
* Logs a partial-loss event when a portion of the position is closed at loss.
|
|
19171
|
+
*
|
|
19172
|
+
* Records the percentage closed and current price when partial loss-cutting occurs.
|
|
19173
|
+
*
|
|
19174
|
+
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
19175
|
+
* @param percentToClose - Percentage of position to close (0-100)
|
|
19176
|
+
* @param currentPrice - Current market price at time of partial close
|
|
19177
|
+
* @param isBacktest - Whether this is a backtest or live trading event
|
|
19178
|
+
* @param context - Strategy context with strategyName, exchangeName, frameName
|
|
19179
|
+
*/
|
|
19180
|
+
partialLoss: (symbol: string, percentToClose: number, currentPrice: number, isBacktest: boolean, context: {
|
|
19181
|
+
strategyName: StrategyName;
|
|
19182
|
+
exchangeName: ExchangeName;
|
|
19183
|
+
frameName: FrameName;
|
|
19184
|
+
}) => Promise<void>;
|
|
19185
|
+
/**
|
|
19186
|
+
* Logs a trailing-stop event when the stop-loss is adjusted.
|
|
19187
|
+
*
|
|
19188
|
+
* Records the percentage shift and current price when trailing stop moves.
|
|
19189
|
+
*
|
|
19190
|
+
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
19191
|
+
* @param percentShift - Percentage the stop-loss was shifted
|
|
19192
|
+
* @param currentPrice - Current market price at time of adjustment
|
|
19193
|
+
* @param isBacktest - Whether this is a backtest or live trading event
|
|
19194
|
+
* @param context - Strategy context with strategyName, exchangeName, frameName
|
|
19195
|
+
*/
|
|
19196
|
+
trailingStop: (symbol: string, percentShift: number, currentPrice: number, isBacktest: boolean, context: {
|
|
19197
|
+
strategyName: StrategyName;
|
|
19198
|
+
exchangeName: ExchangeName;
|
|
19199
|
+
frameName: FrameName;
|
|
19200
|
+
}) => Promise<void>;
|
|
19201
|
+
/**
|
|
19202
|
+
* Logs a trailing-take event when the take-profit is adjusted.
|
|
19203
|
+
*
|
|
19204
|
+
* Records the percentage shift and current price when trailing take-profit moves.
|
|
19205
|
+
*
|
|
19206
|
+
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
19207
|
+
* @param percentShift - Percentage the take-profit was shifted
|
|
19208
|
+
* @param currentPrice - Current market price at time of adjustment
|
|
19209
|
+
* @param isBacktest - Whether this is a backtest or live trading event
|
|
19210
|
+
* @param context - Strategy context with strategyName, exchangeName, frameName
|
|
19211
|
+
*/
|
|
19212
|
+
trailingTake: (symbol: string, percentShift: number, currentPrice: number, isBacktest: boolean, context: {
|
|
19213
|
+
strategyName: StrategyName;
|
|
19214
|
+
exchangeName: ExchangeName;
|
|
19215
|
+
frameName: FrameName;
|
|
19216
|
+
}) => Promise<void>;
|
|
19217
|
+
/**
|
|
19218
|
+
* Logs a breakeven event when the stop-loss is moved to entry price.
|
|
19219
|
+
*
|
|
19220
|
+
* Records the current price when breakeven protection is activated.
|
|
19221
|
+
*
|
|
19222
|
+
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
19223
|
+
* @param currentPrice - Current market price at time of breakeven activation
|
|
19224
|
+
* @param isBacktest - Whether this is a backtest or live trading event
|
|
19225
|
+
* @param context - Strategy context with strategyName, exchangeName, frameName
|
|
19226
|
+
*/
|
|
19227
|
+
breakeven: (symbol: string, currentPrice: number, isBacktest: boolean, context: {
|
|
19228
|
+
strategyName: StrategyName;
|
|
19229
|
+
exchangeName: ExchangeName;
|
|
19230
|
+
frameName: FrameName;
|
|
19231
|
+
}) => Promise<void>;
|
|
19232
|
+
/**
|
|
19233
|
+
* Initializes the service for event logging.
|
|
19234
|
+
*
|
|
19235
|
+
* Must be called before any events can be logged. Uses singleshot pattern
|
|
19236
|
+
* to ensure only one subscription exists at a time.
|
|
19237
|
+
*
|
|
19238
|
+
* @returns Cleanup function that clears the subscription when called
|
|
19239
|
+
*/
|
|
19240
|
+
subscribe: (() => () => void) & functools_kit.ISingleshotClearable;
|
|
19241
|
+
/**
|
|
19242
|
+
* Stops event logging and cleans up the subscription.
|
|
19243
|
+
*
|
|
19244
|
+
* Safe to call multiple times - only clears if subscription exists.
|
|
19245
|
+
*/
|
|
19246
|
+
unsubscribe: () => Promise<void>;
|
|
19247
|
+
}
|
|
19248
|
+
|
|
18175
19249
|
declare const backtest: {
|
|
18176
19250
|
exchangeValidationService: ExchangeValidationService;
|
|
18177
19251
|
strategyValidationService: StrategyValidationService;
|
|
@@ -18191,6 +19265,7 @@ declare const backtest: {
|
|
|
18191
19265
|
partialReportService: PartialReportService;
|
|
18192
19266
|
breakevenReportService: BreakevenReportService;
|
|
18193
19267
|
riskReportService: RiskReportService;
|
|
19268
|
+
strategyReportService: StrategyReportService;
|
|
18194
19269
|
backtestMarkdownService: BacktestMarkdownService;
|
|
18195
19270
|
liveMarkdownService: LiveMarkdownService;
|
|
18196
19271
|
scheduleMarkdownService: ScheduleMarkdownService;
|
|
@@ -18200,6 +19275,7 @@ declare const backtest: {
|
|
|
18200
19275
|
partialMarkdownService: PartialMarkdownService;
|
|
18201
19276
|
breakevenMarkdownService: BreakevenMarkdownService;
|
|
18202
19277
|
riskMarkdownService: RiskMarkdownService;
|
|
19278
|
+
strategyMarkdownService: StrategyMarkdownService;
|
|
18203
19279
|
backtestLogicPublicService: BacktestLogicPublicService;
|
|
18204
19280
|
liveLogicPublicService: LiveLogicPublicService;
|
|
18205
19281
|
walkerLogicPublicService: WalkerLogicPublicService;
|
|
@@ -18241,4 +19317,4 @@ declare const backtest: {
|
|
|
18241
19317
|
loggerService: LoggerService;
|
|
18242
19318
|
};
|
|
18243
19319
|
|
|
18244
|
-
export { ActionBase, type ActivePingContract, Backtest, type
|
|
19320
|
+
export { ActionBase, type ActivePingContract, Backtest, type BacktestStatisticsModel, Breakeven, type BreakevenAvailableNotification, type BreakevenCommitNotification, type BreakevenContract, type BreakevenData, Cache, type CandleData, type CandleInterval, type ColumnConfig, type ColumnModel, Constant, type CriticalErrorNotification, type DoneContract, type EntityId, Exchange, ExecutionContextService, type FrameInterval, type GlobalConfig, Heat, type HeatmapStatisticsModel, type IBidData, type ICandleData, type IExchangeSchema, type IFrameSchema, type IHeatmapRow, type IMarkdownDumpOptions, type IOrderBookData, type IPersistBase, type IPositionSizeATRParams, type IPositionSizeFixedPercentageParams, type IPositionSizeKellyParams, type IPublicSignalRow, type IReportDumpOptions, type IRiskActivePosition, type IRiskCheckArgs, type IRiskSchema, type IRiskValidation, type IRiskValidationFn, type IRiskValidationPayload, type IScheduledSignalCancelRow, type IScheduledSignalRow, type ISignalDto, type ISignalRow, type ISizingCalculateParams, type ISizingCalculateParamsATR, type ISizingCalculateParamsFixedPercentage, type ISizingCalculateParamsKelly, type ISizingSchema, type ISizingSchemaATR, type ISizingSchemaFixedPercentage, type ISizingSchemaKelly, type IStrategyPnL, type IStrategyResult, type IStrategySchema, type IStrategyTickResult, type IStrategyTickResultActive, type IStrategyTickResultCancelled, type IStrategyTickResultClosed, type IStrategyTickResultIdle, type IStrategyTickResultOpened, type IStrategyTickResultScheduled, type IWalkerResults, type IWalkerSchema, type IWalkerStrategyResult, type InfoErrorNotification, Live, type LiveStatisticsModel, Markdown, MarkdownFileBase, MarkdownFolderBase, type MarkdownName, MethodContextService, type MetricStats, Notification, type NotificationModel, Partial$1 as Partial, type PartialData, type PartialEvent, type PartialLossAvailableNotification, type PartialLossCommitNotification, type PartialLossContract, type PartialProfitAvailableNotification, type PartialProfitCommitNotification, type PartialProfitContract, type PartialStatisticsModel, Performance, type PerformanceContract, type PerformanceMetricType, type PerformanceStatisticsModel, PersistBase, PersistBreakevenAdapter, PersistCandleAdapter, PersistPartialAdapter, PersistRiskAdapter, PersistScheduleAdapter, PersistSignalAdapter, PositionSize, type ProgressBacktestContract, type ProgressWalkerContract, Report, ReportBase, type ReportName, Risk, type RiskContract, type RiskData, type RiskEvent, type RiskRejectionNotification, type RiskStatisticsModel, Schedule, type ScheduleData, type SchedulePingContract, type ScheduleStatisticsModel, type ScheduledEvent, type SignalCancelledNotification, type SignalClosedNotification, type SignalData, type SignalInterval, type SignalOpenedNotification, type SignalScheduledNotification, Strategy, type StrategyActionType, type StrategyCommitContract, type StrategyEvent, type StrategyStatisticsModel, type TMarkdownBase, type TPersistBase, type TPersistBaseCtor, type TReportBase, type TickEvent, type TrailingStopCommitNotification, 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, commitBreakeven, commitCancelScheduled, commitClosePending, commitPartialLoss, commitPartialProfit, commitTrailingStop, commitTrailingTake, emitters, formatPrice, formatQuantity, get, getActionSchema, getAveragePrice, getBacktestTimeframe, getCandles, getColumns, getConfig, getContext, getDate, getDefaultColumns, getDefaultConfig, getExchangeSchema, getFrameSchema, getMode, getOrderBook, getRawCandles, getRiskSchema, getSizingSchema, getStrategySchema, getSymbol, getWalkerSchema, hasTradeContext, backtest as lib, listExchangeSchema, listFrameSchema, listRiskSchema, listSizingSchema, listStrategySchema, listWalkerSchema, listenActivePing, listenActivePingOnce, listenBacktestProgress, listenBreakevenAvailable, listenBreakevenAvailableOnce, listenDoneBacktest, listenDoneBacktestOnce, listenDoneLive, listenDoneLiveOnce, listenDoneWalker, listenDoneWalkerOnce, listenError, listenExit, listenPartialLossAvailable, listenPartialLossAvailableOnce, listenPartialProfitAvailable, listenPartialProfitAvailableOnce, listenPerformance, listenRisk, listenRiskOnce, listenSchedulePing, listenSchedulePingOnce, listenSignal, listenSignalBacktest, listenSignalBacktestOnce, listenSignalLive, listenSignalLiveOnce, listenSignalOnce, listenStrategyCommit, listenStrategyCommitOnce, listenValidation, listenWalker, listenWalkerComplete, listenWalkerOnce, listenWalkerProgress, overrideActionSchema, overrideExchangeSchema, overrideFrameSchema, overrideRiskSchema, overrideSizingSchema, overrideStrategySchema, overrideWalkerSchema, parseArgs, roundTicks, set, setColumns, setConfig, setLogger, stopStrategy, validate };
|