backtest-kit 1.7.1 → 1.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/index.cjs +1625 -542
- package/build/index.mjs +1624 -543
- package/package.json +2 -1
- package/types.d.ts +1061 -392
package/types.d.ts
CHANGED
|
@@ -155,6 +155,56 @@ declare function stop(symbol: string): Promise<void>;
|
|
|
155
155
|
* ```
|
|
156
156
|
*/
|
|
157
157
|
declare function cancel(symbol: string, cancelId?: string): Promise<void>;
|
|
158
|
+
/**
|
|
159
|
+
* Executes partial close at profit level (moving toward TP).
|
|
160
|
+
*
|
|
161
|
+
* Closes a percentage of the active pending position at profit.
|
|
162
|
+
* Price must be moving toward take profit (in profit direction).
|
|
163
|
+
*
|
|
164
|
+
* Automatically detects backtest/live mode from execution context.
|
|
165
|
+
*
|
|
166
|
+
* @param symbol - Trading pair symbol
|
|
167
|
+
* @param percentToClose - Percentage of position to close (0-100, absolute value)
|
|
168
|
+
* @returns Promise that resolves when state is updated
|
|
169
|
+
*
|
|
170
|
+
* @throws Error if currentPrice is not in profit direction:
|
|
171
|
+
* - LONG: currentPrice must be > priceOpen
|
|
172
|
+
* - SHORT: currentPrice must be < priceOpen
|
|
173
|
+
*
|
|
174
|
+
* @example
|
|
175
|
+
* ```typescript
|
|
176
|
+
* import { partialProfit } from "backtest-kit";
|
|
177
|
+
*
|
|
178
|
+
* // Close 30% of LONG position at profit
|
|
179
|
+
* await partialProfit("BTCUSDT", 30, 45000);
|
|
180
|
+
* ```
|
|
181
|
+
*/
|
|
182
|
+
declare function partialProfit(symbol: string, percentToClose: number): Promise<void>;
|
|
183
|
+
/**
|
|
184
|
+
* Executes partial close at loss level (moving toward SL).
|
|
185
|
+
*
|
|
186
|
+
* Closes a percentage of the active pending position at loss.
|
|
187
|
+
* Price must be moving toward stop loss (in loss direction).
|
|
188
|
+
*
|
|
189
|
+
* Automatically detects backtest/live mode from execution context.
|
|
190
|
+
*
|
|
191
|
+
* @param symbol - Trading pair symbol
|
|
192
|
+
* @param percentToClose - Percentage of position to close (0-100, absolute value)
|
|
193
|
+
* @returns Promise that resolves when state is updated
|
|
194
|
+
*
|
|
195
|
+
* @throws Error if currentPrice is not in loss direction:
|
|
196
|
+
* - LONG: currentPrice must be < priceOpen
|
|
197
|
+
* - SHORT: currentPrice must be > priceOpen
|
|
198
|
+
*
|
|
199
|
+
* @example
|
|
200
|
+
* ```typescript
|
|
201
|
+
* import { partialLoss } from "backtest-kit";
|
|
202
|
+
*
|
|
203
|
+
* // Close 40% of LONG position at loss
|
|
204
|
+
* await partialLoss("BTCUSDT", 40, 38000);
|
|
205
|
+
* ```
|
|
206
|
+
*/
|
|
207
|
+
declare function partialLoss(symbol: string, percentToClose: number): Promise<void>;
|
|
158
208
|
|
|
159
209
|
declare const GLOBAL_CONFIG: {
|
|
160
210
|
/**
|
|
@@ -825,7 +875,7 @@ interface IRiskCheckArgs {
|
|
|
825
875
|
/** Exchange name */
|
|
826
876
|
exchangeName: ExchangeName;
|
|
827
877
|
/** Frame name */
|
|
828
|
-
frameName:
|
|
878
|
+
frameName: FrameName;
|
|
829
879
|
/** Current VWAP price */
|
|
830
880
|
currentPrice: number;
|
|
831
881
|
/** Current timestamp */
|
|
@@ -836,9 +886,9 @@ interface IRiskCheckArgs {
|
|
|
836
886
|
*/
|
|
837
887
|
interface IRiskActivePosition {
|
|
838
888
|
/** Strategy name owning the position */
|
|
839
|
-
strategyName:
|
|
889
|
+
strategyName: StrategyName;
|
|
840
890
|
/** Exchange name */
|
|
841
|
-
exchangeName:
|
|
891
|
+
exchangeName: ExchangeName;
|
|
842
892
|
/** Timestamp when the position was opened */
|
|
843
893
|
openTimestamp: number;
|
|
844
894
|
}
|
|
@@ -952,10 +1002,10 @@ interface IRisk {
|
|
|
952
1002
|
* @param context - Context information (strategyName, riskName, exchangeName, frameName)
|
|
953
1003
|
*/
|
|
954
1004
|
addSignal: (symbol: string, context: {
|
|
955
|
-
strategyName:
|
|
956
|
-
riskName:
|
|
957
|
-
exchangeName:
|
|
958
|
-
frameName:
|
|
1005
|
+
strategyName: StrategyName;
|
|
1006
|
+
riskName: RiskName;
|
|
1007
|
+
exchangeName: ExchangeName;
|
|
1008
|
+
frameName: FrameName;
|
|
959
1009
|
}) => Promise<void>;
|
|
960
1010
|
/**
|
|
961
1011
|
* Remove a closed signal/position.
|
|
@@ -964,10 +1014,10 @@ interface IRisk {
|
|
|
964
1014
|
* @param context - Context information (strategyName, riskName, exchangeName, frameName)
|
|
965
1015
|
*/
|
|
966
1016
|
removeSignal: (symbol: string, context: {
|
|
967
|
-
strategyName:
|
|
968
|
-
riskName:
|
|
969
|
-
exchangeName:
|
|
970
|
-
frameName:
|
|
1017
|
+
strategyName: StrategyName;
|
|
1018
|
+
riskName: RiskName;
|
|
1019
|
+
exchangeName: ExchangeName;
|
|
1020
|
+
frameName: FrameName;
|
|
971
1021
|
}) => Promise<void>;
|
|
972
1022
|
}
|
|
973
1023
|
/**
|
|
@@ -1179,6 +1229,24 @@ interface ISignalRow extends ISignalDto {
|
|
|
1179
1229
|
symbol: string;
|
|
1180
1230
|
/** Internal runtime marker for scheduled signals */
|
|
1181
1231
|
_isScheduled: boolean;
|
|
1232
|
+
/**
|
|
1233
|
+
* History of partial closes for PNL calculation.
|
|
1234
|
+
* Each entry contains type (profit/loss), percent closed, and price.
|
|
1235
|
+
* Used to calculate weighted PNL: Σ(percent_i × pnl_i) for each partial + (remaining% × final_pnl)
|
|
1236
|
+
*
|
|
1237
|
+
* Computed values (derived from this array):
|
|
1238
|
+
* - _tpClosed: Sum of all "profit" type partial close percentages
|
|
1239
|
+
* - _slClosed: Sum of all "loss" type partial close percentages
|
|
1240
|
+
* - _totalClosed: Sum of all partial close percentages (profit + loss)
|
|
1241
|
+
*/
|
|
1242
|
+
_partial?: Array<{
|
|
1243
|
+
/** Type of partial close: profit (moving toward TP) or loss (moving toward SL) */
|
|
1244
|
+
type: "profit" | "loss";
|
|
1245
|
+
/** Percentage of position closed (0-100) */
|
|
1246
|
+
percent: number;
|
|
1247
|
+
/** Price at which this partial was executed */
|
|
1248
|
+
price: number;
|
|
1249
|
+
}>;
|
|
1182
1250
|
}
|
|
1183
1251
|
/**
|
|
1184
1252
|
* Scheduled signal row for delayed entry at specific price.
|
|
@@ -1428,6 +1496,170 @@ type IStrategyTickResult = IStrategyTickResultIdle | IStrategyTickResultSchedule
|
|
|
1428
1496
|
* Backtest returns closed result (TP/SL or time_expired) or cancelled result (scheduled signal never activated).
|
|
1429
1497
|
*/
|
|
1430
1498
|
type IStrategyBacktestResult = IStrategyTickResultClosed | IStrategyTickResultCancelled;
|
|
1499
|
+
/**
|
|
1500
|
+
* Strategy interface implemented by ClientStrategy.
|
|
1501
|
+
* Defines core strategy execution methods.
|
|
1502
|
+
*/
|
|
1503
|
+
interface IStrategy {
|
|
1504
|
+
/**
|
|
1505
|
+
* Single tick of strategy execution with VWAP monitoring.
|
|
1506
|
+
* Checks for signal generation (throttled) and TP/SL conditions.
|
|
1507
|
+
*
|
|
1508
|
+
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
1509
|
+
* @param strategyName - Name of the strategy
|
|
1510
|
+
* @returns Promise resolving to tick result (idle | opened | active | closed)
|
|
1511
|
+
*/
|
|
1512
|
+
tick: (symbol: string, strategyName: StrategyName) => Promise<IStrategyTickResult>;
|
|
1513
|
+
/**
|
|
1514
|
+
* Retrieves the currently active pending signal for the symbol.
|
|
1515
|
+
* If no active signal exists, returns null.
|
|
1516
|
+
* Used internally for monitoring TP/SL and time expiration.
|
|
1517
|
+
*
|
|
1518
|
+
* @param symbol - Trading pair symbol
|
|
1519
|
+
* @returns Promise resolving to pending signal or null
|
|
1520
|
+
*/
|
|
1521
|
+
getPendingSignal: (symbol: string) => Promise<ISignalRow | null>;
|
|
1522
|
+
/**
|
|
1523
|
+
* Retrieves the currently active scheduled signal for the symbol.
|
|
1524
|
+
* If no scheduled signal exists, returns null.
|
|
1525
|
+
* Used internally for monitoring scheduled signal activation.
|
|
1526
|
+
*
|
|
1527
|
+
* @param symbol - Trading pair symbol
|
|
1528
|
+
* @returns Promise resolving to scheduled signal or null
|
|
1529
|
+
*/
|
|
1530
|
+
getScheduledSignal: (symbol: string) => Promise<IScheduledSignalRow | null>;
|
|
1531
|
+
/**
|
|
1532
|
+
* Checks if the strategy has been stopped.
|
|
1533
|
+
*
|
|
1534
|
+
* Returns the stopped state indicating whether the strategy should
|
|
1535
|
+
* cease processing new ticks or signals.
|
|
1536
|
+
*
|
|
1537
|
+
* @param symbol - Trading pair symbol
|
|
1538
|
+
* @returns Promise resolving to true if strategy is stopped, false otherwise
|
|
1539
|
+
*/
|
|
1540
|
+
getStopped: (symbol: string) => Promise<boolean>;
|
|
1541
|
+
/**
|
|
1542
|
+
* Fast backtest using historical candles.
|
|
1543
|
+
* Iterates through candles, calculates VWAP, checks TP/SL on each candle.
|
|
1544
|
+
*
|
|
1545
|
+
* For scheduled signals: first monitors activation/cancellation,
|
|
1546
|
+
* then if activated continues with TP/SL monitoring.
|
|
1547
|
+
*
|
|
1548
|
+
* @param symbol - Trading pair symbol
|
|
1549
|
+
* @param strategyName - Name of the strategy
|
|
1550
|
+
* @param candles - Array of historical candle data
|
|
1551
|
+
* @returns Promise resolving to closed result (always completes signal)
|
|
1552
|
+
*/
|
|
1553
|
+
backtest: (symbol: string, strategyName: StrategyName, candles: ICandleData[]) => Promise<IStrategyBacktestResult>;
|
|
1554
|
+
/**
|
|
1555
|
+
* Stops the strategy from generating new signals.
|
|
1556
|
+
*
|
|
1557
|
+
* Sets internal flag to prevent getSignal from being called on subsequent ticks.
|
|
1558
|
+
* Does NOT force-close active pending signals - they continue monitoring until natural closure (TP/SL/time_expired).
|
|
1559
|
+
*
|
|
1560
|
+
* Use case: Graceful shutdown in live trading mode without abandoning open positions.
|
|
1561
|
+
*
|
|
1562
|
+
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
1563
|
+
* @returns Promise that resolves immediately when stop flag is set
|
|
1564
|
+
*
|
|
1565
|
+
* @example
|
|
1566
|
+
* ```typescript
|
|
1567
|
+
* // Graceful shutdown in Live.background() cancellation
|
|
1568
|
+
* const cancel = await Live.background("BTCUSDT", { ... });
|
|
1569
|
+
*
|
|
1570
|
+
* // Later: stop new signals, let existing ones close naturally
|
|
1571
|
+
* await cancel();
|
|
1572
|
+
* ```
|
|
1573
|
+
*/
|
|
1574
|
+
stop: (symbol: string, backtest: boolean) => Promise<void>;
|
|
1575
|
+
/**
|
|
1576
|
+
* Cancels the scheduled signal without stopping the strategy.
|
|
1577
|
+
*
|
|
1578
|
+
* Clears the scheduled signal (waiting for priceOpen activation).
|
|
1579
|
+
* Does NOT affect active pending signals or strategy operation.
|
|
1580
|
+
* Does NOT set stop flag - strategy can continue generating new signals.
|
|
1581
|
+
*
|
|
1582
|
+
* Use case: Cancel a scheduled entry that is no longer desired without stopping the entire strategy.
|
|
1583
|
+
*
|
|
1584
|
+
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
1585
|
+
* @param cancelId - Optional cancellation ID
|
|
1586
|
+
* @returns Promise that resolves when scheduled signal is cleared
|
|
1587
|
+
*
|
|
1588
|
+
* @example
|
|
1589
|
+
* ```typescript
|
|
1590
|
+
* // Cancel scheduled signal without stopping strategy
|
|
1591
|
+
* await strategy.cancel("BTCUSDT");
|
|
1592
|
+
* // Strategy continues, can generate new signals
|
|
1593
|
+
* ```
|
|
1594
|
+
*/
|
|
1595
|
+
cancel: (symbol: string, backtest: boolean, cancelId?: string) => Promise<void>;
|
|
1596
|
+
/**
|
|
1597
|
+
* Executes partial close at profit level (moving toward TP).
|
|
1598
|
+
*
|
|
1599
|
+
* Closes specified percentage of position at current price.
|
|
1600
|
+
* Updates _tpClosed, _totalClosed, and _partialHistory state.
|
|
1601
|
+
* Persists updated signal state for crash recovery.
|
|
1602
|
+
*
|
|
1603
|
+
* Validations:
|
|
1604
|
+
* - Throws if no pending signal exists
|
|
1605
|
+
* - Throws if called on scheduled signal (not yet activated)
|
|
1606
|
+
* - Throws if percentToClose <= 0 or > 100
|
|
1607
|
+
* - Does nothing if _totalClosed + percentToClose > 100 (prevents over-closing)
|
|
1608
|
+
*
|
|
1609
|
+
* Use case: User-controlled partial close triggered from onPartialProfit callback.
|
|
1610
|
+
*
|
|
1611
|
+
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
1612
|
+
* @param percentToClose - Absolute percentage of position to close (0-100)
|
|
1613
|
+
* @param currentPrice - Current market price for partial close
|
|
1614
|
+
* @param backtest - Whether running in backtest mode
|
|
1615
|
+
* @returns Promise that resolves when partial close is complete
|
|
1616
|
+
*
|
|
1617
|
+
* @example
|
|
1618
|
+
* ```typescript
|
|
1619
|
+
* callbacks: {
|
|
1620
|
+
* onPartialProfit: async (symbol, signal, currentPrice, percentTp, backtest) => {
|
|
1621
|
+
* if (percentTp >= 50) {
|
|
1622
|
+
* await strategy.partialProfit(symbol, 25, currentPrice, backtest);
|
|
1623
|
+
* }
|
|
1624
|
+
* }
|
|
1625
|
+
* }
|
|
1626
|
+
* ```
|
|
1627
|
+
*/
|
|
1628
|
+
partialProfit: (symbol: string, percentToClose: number, currentPrice: number, backtest: boolean) => Promise<void>;
|
|
1629
|
+
/**
|
|
1630
|
+
* Executes partial close at loss level (moving toward SL).
|
|
1631
|
+
*
|
|
1632
|
+
* Closes specified percentage of position at current price.
|
|
1633
|
+
* Updates _slClosed, _totalClosed, and _partialHistory state.
|
|
1634
|
+
* Persists updated signal state for crash recovery.
|
|
1635
|
+
*
|
|
1636
|
+
* Validations:
|
|
1637
|
+
* - Throws if no pending signal exists
|
|
1638
|
+
* - Throws if called on scheduled signal (not yet activated)
|
|
1639
|
+
* - Throws if percentToClose <= 0 or > 100
|
|
1640
|
+
* - Does nothing if _totalClosed + percentToClose > 100 (prevents over-closing)
|
|
1641
|
+
*
|
|
1642
|
+
* Use case: User-controlled partial close triggered from onPartialLoss callback.
|
|
1643
|
+
*
|
|
1644
|
+
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
1645
|
+
* @param percentToClose - Absolute percentage of position to close (0-100)
|
|
1646
|
+
* @param currentPrice - Current market price for partial close
|
|
1647
|
+
* @param backtest - Whether running in backtest mode
|
|
1648
|
+
* @returns Promise that resolves when partial close is complete
|
|
1649
|
+
*
|
|
1650
|
+
* @example
|
|
1651
|
+
* ```typescript
|
|
1652
|
+
* callbacks: {
|
|
1653
|
+
* onPartialLoss: async (symbol, signal, currentPrice, percentSl, backtest) => {
|
|
1654
|
+
* if (percentSl >= 80) {
|
|
1655
|
+
* await strategy.partialLoss(symbol, 50, currentPrice, backtest);
|
|
1656
|
+
* }
|
|
1657
|
+
* }
|
|
1658
|
+
* }
|
|
1659
|
+
* ```
|
|
1660
|
+
*/
|
|
1661
|
+
partialLoss: (symbol: string, percentToClose: number, currentPrice: number, backtest: boolean) => Promise<void>;
|
|
1662
|
+
}
|
|
1431
1663
|
/**
|
|
1432
1664
|
* Unique strategy identifier.
|
|
1433
1665
|
*/
|
|
@@ -2043,7 +2275,7 @@ interface IOptimizerTemplate {
|
|
|
2043
2275
|
* @param strategies - Array of strategy names to compare
|
|
2044
2276
|
* @returns Generated addWalker() call
|
|
2045
2277
|
*/
|
|
2046
|
-
getWalkerTemplate(walkerName:
|
|
2278
|
+
getWalkerTemplate(walkerName: WalkerName, exchangeName: ExchangeName, frameName: FrameName, strategies: string[]): string | Promise<string>;
|
|
2047
2279
|
/**
|
|
2048
2280
|
* Generates Exchange configuration code.
|
|
2049
2281
|
*
|
|
@@ -2051,7 +2283,7 @@ interface IOptimizerTemplate {
|
|
|
2051
2283
|
* @param exchangeName - Unique exchange identifier
|
|
2052
2284
|
* @returns Generated addExchange() call with CCXT integration
|
|
2053
2285
|
*/
|
|
2054
|
-
getExchangeTemplate(symbol: string, exchangeName:
|
|
2286
|
+
getExchangeTemplate(symbol: string, exchangeName: ExchangeName): string | Promise<string>;
|
|
2055
2287
|
/**
|
|
2056
2288
|
* Generates Frame (timeframe) configuration code.
|
|
2057
2289
|
*
|
|
@@ -2062,7 +2294,7 @@ interface IOptimizerTemplate {
|
|
|
2062
2294
|
* @param endDate - Frame end date
|
|
2063
2295
|
* @returns Generated addFrame() call
|
|
2064
2296
|
*/
|
|
2065
|
-
getFrameTemplate(symbol: string, frameName:
|
|
2297
|
+
getFrameTemplate(symbol: string, frameName: FrameName, interval: CandleInterval, startDate: Date, endDate: Date): string | Promise<string>;
|
|
2066
2298
|
/**
|
|
2067
2299
|
* Generates Strategy configuration code with LLM integration.
|
|
2068
2300
|
*
|
|
@@ -2071,7 +2303,7 @@ interface IOptimizerTemplate {
|
|
|
2071
2303
|
* @param prompt - Strategy logic prompt from getPrompt()
|
|
2072
2304
|
* @returns Generated addStrategy() call with getSignal() function
|
|
2073
2305
|
*/
|
|
2074
|
-
getStrategyTemplate(strategyName:
|
|
2306
|
+
getStrategyTemplate(strategyName: StrategyName, interval: CandleInterval, prompt: string): string | Promise<string>;
|
|
2075
2307
|
/**
|
|
2076
2308
|
* Generates launcher code to run Walker and listen to events.
|
|
2077
2309
|
*
|
|
@@ -2079,7 +2311,7 @@ interface IOptimizerTemplate {
|
|
|
2079
2311
|
* @param walkerName - Walker name to launch
|
|
2080
2312
|
* @returns Generated Walker.background() call with event listeners
|
|
2081
2313
|
*/
|
|
2082
|
-
getLauncherTemplate(symbol: string, walkerName:
|
|
2314
|
+
getLauncherTemplate(symbol: string, walkerName: WalkerName): string | Promise<string>;
|
|
2083
2315
|
/**
|
|
2084
2316
|
* Generates text() helper function for LLM text generation.
|
|
2085
2317
|
*
|
|
@@ -2783,9 +3015,11 @@ declare function listOptimizers(): Promise<IOptimizerSchema[]>;
|
|
|
2783
3015
|
*/
|
|
2784
3016
|
interface DoneContract {
|
|
2785
3017
|
/** exchangeName - Name of the exchange used in execution */
|
|
2786
|
-
exchangeName:
|
|
3018
|
+
exchangeName: ExchangeName;
|
|
2787
3019
|
/** strategyName - Name of the strategy that completed */
|
|
2788
|
-
strategyName:
|
|
3020
|
+
strategyName: StrategyName;
|
|
3021
|
+
/** frameName - Name of the frame (empty string for live mode) */
|
|
3022
|
+
frameName: FrameName;
|
|
2789
3023
|
/** backtest - True if backtest mode, false if live mode */
|
|
2790
3024
|
backtest: boolean;
|
|
2791
3025
|
/** symbol - Trading symbol (e.g., "BTCUSDT") */
|
|
@@ -2810,9 +3044,9 @@ interface DoneContract {
|
|
|
2810
3044
|
*/
|
|
2811
3045
|
interface ProgressBacktestContract {
|
|
2812
3046
|
/** exchangeName - Name of the exchange used in execution */
|
|
2813
|
-
exchangeName:
|
|
3047
|
+
exchangeName: ExchangeName;
|
|
2814
3048
|
/** strategyName - Name of the strategy being executed */
|
|
2815
|
-
strategyName:
|
|
3049
|
+
strategyName: StrategyName;
|
|
2816
3050
|
/** symbol - Trading symbol (e.g., "BTCUSDT") */
|
|
2817
3051
|
symbol: string;
|
|
2818
3052
|
/** totalFrames - Total number of frames to process */
|
|
@@ -2841,11 +3075,11 @@ interface ProgressBacktestContract {
|
|
|
2841
3075
|
*/
|
|
2842
3076
|
interface ProgressWalkerContract {
|
|
2843
3077
|
/** walkerName - Name of the walker being executed */
|
|
2844
|
-
walkerName:
|
|
3078
|
+
walkerName: WalkerName;
|
|
2845
3079
|
/** exchangeName - Name of the exchange used in execution */
|
|
2846
|
-
exchangeName:
|
|
3080
|
+
exchangeName: ExchangeName;
|
|
2847
3081
|
/** frameName - Name of the frame being used */
|
|
2848
|
-
frameName:
|
|
3082
|
+
frameName: FrameName;
|
|
2849
3083
|
/** symbol - Trading symbol (e.g., "BTCUSDT") */
|
|
2850
3084
|
symbol: string;
|
|
2851
3085
|
/** totalStrategies - Total number of strategies to process */
|
|
@@ -2923,11 +3157,11 @@ interface PerformanceContract {
|
|
|
2923
3157
|
/** Duration of the operation in milliseconds */
|
|
2924
3158
|
duration: number;
|
|
2925
3159
|
/** Strategy name associated with this metric */
|
|
2926
|
-
strategyName:
|
|
3160
|
+
strategyName: StrategyName;
|
|
2927
3161
|
/** Exchange name associated with this metric */
|
|
2928
|
-
exchangeName:
|
|
3162
|
+
exchangeName: ExchangeName;
|
|
2929
3163
|
/** Frame name associated with this metric (empty string for live mode) */
|
|
2930
|
-
frameName:
|
|
3164
|
+
frameName: FrameName;
|
|
2931
3165
|
/** Trading symbol associated with this metric */
|
|
2932
3166
|
symbol: string;
|
|
2933
3167
|
/** Whether this metric is from backtest mode (true) or live mode (false) */
|
|
@@ -2944,7 +3178,7 @@ interface WalkerContract {
|
|
|
2944
3178
|
/** Exchange name */
|
|
2945
3179
|
exchangeName: ExchangeName;
|
|
2946
3180
|
/** Frame name */
|
|
2947
|
-
frameName:
|
|
3181
|
+
frameName: FrameName;
|
|
2948
3182
|
/** Symbol being tested */
|
|
2949
3183
|
symbol: string;
|
|
2950
3184
|
/** Strategy that just completed */
|
|
@@ -3006,17 +3240,17 @@ interface PartialProfitContract {
|
|
|
3006
3240
|
* Strategy name that generated this signal.
|
|
3007
3241
|
* Identifies which strategy execution this profit event belongs to.
|
|
3008
3242
|
*/
|
|
3009
|
-
strategyName:
|
|
3243
|
+
strategyName: StrategyName;
|
|
3010
3244
|
/**
|
|
3011
3245
|
* Exchange name where this signal is being executed.
|
|
3012
3246
|
* Identifies which exchange this profit event belongs to.
|
|
3013
3247
|
*/
|
|
3014
|
-
exchangeName:
|
|
3248
|
+
exchangeName: ExchangeName;
|
|
3015
3249
|
/**
|
|
3016
3250
|
* Frame name where this signal is being executed.
|
|
3017
3251
|
* Identifies which frame this profit event belongs to (empty string for live mode).
|
|
3018
3252
|
*/
|
|
3019
|
-
frameName:
|
|
3253
|
+
frameName: FrameName;
|
|
3020
3254
|
/**
|
|
3021
3255
|
* Complete signal row data.
|
|
3022
3256
|
* Contains all signal information: id, position, priceOpen, priceTakeProfit, priceStopLoss, etc.
|
|
@@ -3106,17 +3340,17 @@ interface PartialLossContract {
|
|
|
3106
3340
|
* Strategy name that generated this signal.
|
|
3107
3341
|
* Identifies which strategy execution this loss event belongs to.
|
|
3108
3342
|
*/
|
|
3109
|
-
strategyName:
|
|
3343
|
+
strategyName: StrategyName;
|
|
3110
3344
|
/**
|
|
3111
3345
|
* Exchange name where this signal is being executed.
|
|
3112
3346
|
* Identifies which exchange this loss event belongs to.
|
|
3113
3347
|
*/
|
|
3114
|
-
exchangeName:
|
|
3348
|
+
exchangeName: ExchangeName;
|
|
3115
3349
|
/**
|
|
3116
3350
|
* Frame name where this signal is being executed.
|
|
3117
3351
|
* Identifies which frame this loss event belongs to (empty string for live mode).
|
|
3118
3352
|
*/
|
|
3119
|
-
frameName:
|
|
3353
|
+
frameName: FrameName;
|
|
3120
3354
|
/**
|
|
3121
3355
|
* Complete signal row data.
|
|
3122
3356
|
* Contains all signal information: id, position, priceOpen, priceTakeProfit, priceStopLoss, etc.
|
|
@@ -3315,12 +3549,12 @@ interface PingContract {
|
|
|
3315
3549
|
* Strategy name that is monitoring this scheduled signal.
|
|
3316
3550
|
* Identifies which strategy execution this ping event belongs to.
|
|
3317
3551
|
*/
|
|
3318
|
-
strategyName:
|
|
3552
|
+
strategyName: StrategyName;
|
|
3319
3553
|
/**
|
|
3320
3554
|
* Exchange name where this scheduled signal is being monitored.
|
|
3321
3555
|
* Identifies which exchange this ping event belongs to.
|
|
3322
3556
|
*/
|
|
3323
|
-
exchangeName:
|
|
3557
|
+
exchangeName: ExchangeName;
|
|
3324
3558
|
/**
|
|
3325
3559
|
* Complete scheduled signal row data.
|
|
3326
3560
|
* Contains all signal information: id, position, priceOpen, priceTakeProfit, priceStopLoss, etc.
|
|
@@ -4917,7 +5151,7 @@ interface MetricStats {
|
|
|
4917
5151
|
*/
|
|
4918
5152
|
interface PerformanceStatisticsModel {
|
|
4919
5153
|
/** Strategy name */
|
|
4920
|
-
strategyName:
|
|
5154
|
+
strategyName: StrategyName;
|
|
4921
5155
|
/** Total number of performance events recorded */
|
|
4922
5156
|
totalEvents: number;
|
|
4923
5157
|
/** Total execution time across all metrics (ms) */
|
|
@@ -4985,7 +5219,7 @@ interface PartialEvent {
|
|
|
4985
5219
|
/** Trading pair symbol */
|
|
4986
5220
|
symbol: string;
|
|
4987
5221
|
/** Strategy name */
|
|
4988
|
-
strategyName:
|
|
5222
|
+
strategyName: StrategyName;
|
|
4989
5223
|
/** Signal ID */
|
|
4990
5224
|
signalId: string;
|
|
4991
5225
|
/** Position type */
|
|
@@ -5034,11 +5268,11 @@ interface RiskEvent {
|
|
|
5034
5268
|
/** Pending signal details */
|
|
5035
5269
|
pendingSignal: ISignalDto;
|
|
5036
5270
|
/** Strategy name */
|
|
5037
|
-
strategyName:
|
|
5271
|
+
strategyName: StrategyName;
|
|
5038
5272
|
/** Exchange name */
|
|
5039
|
-
exchangeName:
|
|
5273
|
+
exchangeName: ExchangeName;
|
|
5040
5274
|
/** Time frame name */
|
|
5041
|
-
frameName:
|
|
5275
|
+
frameName: FrameName;
|
|
5042
5276
|
/** Current market price */
|
|
5043
5277
|
currentPrice: number;
|
|
5044
5278
|
/** Number of active positions at rejection time */
|
|
@@ -5631,7 +5865,7 @@ declare class BacktestMarkdownService {
|
|
|
5631
5865
|
* console.log(stats.sharpeRatio, stats.winRate);
|
|
5632
5866
|
* ```
|
|
5633
5867
|
*/
|
|
5634
|
-
getData: (symbol: string, strategyName: StrategyName, exchangeName:
|
|
5868
|
+
getData: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean) => Promise<BacktestStatisticsModel>;
|
|
5635
5869
|
/**
|
|
5636
5870
|
* Generates markdown report with all closed signals for a symbol-strategy pair.
|
|
5637
5871
|
* Delegates to ReportStorage.generateReport().
|
|
@@ -5651,7 +5885,7 @@ declare class BacktestMarkdownService {
|
|
|
5651
5885
|
* console.log(markdown);
|
|
5652
5886
|
* ```
|
|
5653
5887
|
*/
|
|
5654
|
-
getReport: (symbol: string, strategyName: StrategyName, exchangeName:
|
|
5888
|
+
getReport: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, columns?: Columns$6[]) => Promise<string>;
|
|
5655
5889
|
/**
|
|
5656
5890
|
* Saves symbol-strategy report to disk.
|
|
5657
5891
|
* Creates directory if it doesn't exist.
|
|
@@ -5676,7 +5910,7 @@ declare class BacktestMarkdownService {
|
|
|
5676
5910
|
* await service.dump("BTCUSDT", "my-strategy", "binance", "1h", true, "./custom/path");
|
|
5677
5911
|
* ```
|
|
5678
5912
|
*/
|
|
5679
|
-
dump: (symbol: string, strategyName: StrategyName, exchangeName:
|
|
5913
|
+
dump: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, path?: string, columns?: Columns$6[]) => Promise<void>;
|
|
5680
5914
|
/**
|
|
5681
5915
|
* Clears accumulated signal data from storage.
|
|
5682
5916
|
* If payload is provided, clears only that specific symbol-strategy-exchange-frame-backtest combination's data.
|
|
@@ -5698,8 +5932,8 @@ declare class BacktestMarkdownService {
|
|
|
5698
5932
|
clear: (payload?: {
|
|
5699
5933
|
symbol: string;
|
|
5700
5934
|
strategyName: StrategyName;
|
|
5701
|
-
exchangeName:
|
|
5702
|
-
frameName:
|
|
5935
|
+
exchangeName: ExchangeName;
|
|
5936
|
+
frameName: FrameName;
|
|
5703
5937
|
backtest: boolean;
|
|
5704
5938
|
}) => Promise<void>;
|
|
5705
5939
|
/**
|
|
@@ -5749,9 +5983,9 @@ declare class BacktestUtils {
|
|
|
5749
5983
|
* @returns Async generator yielding closed signals with PNL
|
|
5750
5984
|
*/
|
|
5751
5985
|
run: (symbol: string, context: {
|
|
5752
|
-
strategyName:
|
|
5753
|
-
exchangeName:
|
|
5754
|
-
frameName:
|
|
5986
|
+
strategyName: StrategyName;
|
|
5987
|
+
exchangeName: ExchangeName;
|
|
5988
|
+
frameName: FrameName;
|
|
5755
5989
|
}) => AsyncGenerator<IStrategyBacktestResult, void, unknown>;
|
|
5756
5990
|
/**
|
|
5757
5991
|
* Runs backtest in background without yielding results.
|
|
@@ -5775,9 +6009,9 @@ declare class BacktestUtils {
|
|
|
5775
6009
|
* ```
|
|
5776
6010
|
*/
|
|
5777
6011
|
background: (symbol: string, context: {
|
|
5778
|
-
strategyName:
|
|
5779
|
-
exchangeName:
|
|
5780
|
-
frameName:
|
|
6012
|
+
strategyName: StrategyName;
|
|
6013
|
+
exchangeName: ExchangeName;
|
|
6014
|
+
frameName: FrameName;
|
|
5781
6015
|
}) => () => void;
|
|
5782
6016
|
/**
|
|
5783
6017
|
* Retrieves the currently active pending signal for the strategy.
|
|
@@ -5796,9 +6030,9 @@ declare class BacktestUtils {
|
|
|
5796
6030
|
* ```
|
|
5797
6031
|
*/
|
|
5798
6032
|
getPendingSignal: (symbol: string, context: {
|
|
5799
|
-
strategyName:
|
|
5800
|
-
exchangeName:
|
|
5801
|
-
frameName:
|
|
6033
|
+
strategyName: StrategyName;
|
|
6034
|
+
exchangeName: ExchangeName;
|
|
6035
|
+
frameName: FrameName;
|
|
5802
6036
|
}) => Promise<ISignalRow>;
|
|
5803
6037
|
/**
|
|
5804
6038
|
* Retrieves the currently active scheduled signal for the strategy.
|
|
@@ -5817,9 +6051,9 @@ declare class BacktestUtils {
|
|
|
5817
6051
|
* ```
|
|
5818
6052
|
*/
|
|
5819
6053
|
getScheduledSignal: (symbol: string, context: {
|
|
5820
|
-
strategyName:
|
|
5821
|
-
exchangeName:
|
|
5822
|
-
frameName:
|
|
6054
|
+
strategyName: StrategyName;
|
|
6055
|
+
exchangeName: ExchangeName;
|
|
6056
|
+
frameName: FrameName;
|
|
5823
6057
|
}) => Promise<IScheduledSignalRow>;
|
|
5824
6058
|
/**
|
|
5825
6059
|
* Stops the strategy from generating new signals.
|
|
@@ -5844,9 +6078,9 @@ declare class BacktestUtils {
|
|
|
5844
6078
|
* ```
|
|
5845
6079
|
*/
|
|
5846
6080
|
stop: (symbol: string, context: {
|
|
5847
|
-
strategyName:
|
|
5848
|
-
exchangeName:
|
|
5849
|
-
frameName:
|
|
6081
|
+
strategyName: StrategyName;
|
|
6082
|
+
exchangeName: ExchangeName;
|
|
6083
|
+
frameName: FrameName;
|
|
5850
6084
|
}) => Promise<void>;
|
|
5851
6085
|
/**
|
|
5852
6086
|
* Cancels the scheduled signal without stopping the strategy.
|
|
@@ -5872,10 +6106,72 @@ declare class BacktestUtils {
|
|
|
5872
6106
|
* ```
|
|
5873
6107
|
*/
|
|
5874
6108
|
cancel: (symbol: string, context: {
|
|
5875
|
-
strategyName:
|
|
5876
|
-
exchangeName:
|
|
5877
|
-
frameName:
|
|
6109
|
+
strategyName: StrategyName;
|
|
6110
|
+
exchangeName: ExchangeName;
|
|
6111
|
+
frameName: FrameName;
|
|
5878
6112
|
}, cancelId?: string) => Promise<void>;
|
|
6113
|
+
/**
|
|
6114
|
+
* Executes partial close at profit level (moving toward TP).
|
|
6115
|
+
*
|
|
6116
|
+
* Closes a percentage of the active pending position at profit.
|
|
6117
|
+
* Price must be moving toward take profit (in profit direction).
|
|
6118
|
+
*
|
|
6119
|
+
* @param symbol - Trading pair symbol
|
|
6120
|
+
* @param percentToClose - Percentage of position to close (0-100, absolute value)
|
|
6121
|
+
* @param currentPrice - Current market price for this partial close
|
|
6122
|
+
* @param context - Execution context with strategyName, exchangeName, and frameName
|
|
6123
|
+
* @returns Promise that resolves when state is updated
|
|
6124
|
+
*
|
|
6125
|
+
* @throws Error if currentPrice is not in profit direction:
|
|
6126
|
+
* - LONG: currentPrice must be > priceOpen
|
|
6127
|
+
* - SHORT: currentPrice must be < priceOpen
|
|
6128
|
+
*
|
|
6129
|
+
* @example
|
|
6130
|
+
* ```typescript
|
|
6131
|
+
* // Close 30% of LONG position at profit
|
|
6132
|
+
* await Backtest.partialProfit("BTCUSDT", 30, 45000, {
|
|
6133
|
+
* exchangeName: "binance",
|
|
6134
|
+
* frameName: "frame1",
|
|
6135
|
+
* strategyName: "my-strategy"
|
|
6136
|
+
* });
|
|
6137
|
+
* ```
|
|
6138
|
+
*/
|
|
6139
|
+
partialProfit: (symbol: string, percentToClose: number, currentPrice: number, context: {
|
|
6140
|
+
strategyName: StrategyName;
|
|
6141
|
+
exchangeName: ExchangeName;
|
|
6142
|
+
frameName: FrameName;
|
|
6143
|
+
}) => Promise<void>;
|
|
6144
|
+
/**
|
|
6145
|
+
* Executes partial close at loss level (moving toward SL).
|
|
6146
|
+
*
|
|
6147
|
+
* Closes a percentage of the active pending position at loss.
|
|
6148
|
+
* Price must be moving toward stop loss (in loss direction).
|
|
6149
|
+
*
|
|
6150
|
+
* @param symbol - Trading pair symbol
|
|
6151
|
+
* @param percentToClose - Percentage of position to close (0-100, absolute value)
|
|
6152
|
+
* @param currentPrice - Current market price for this partial close
|
|
6153
|
+
* @param context - Execution context with strategyName, exchangeName, and frameName
|
|
6154
|
+
* @returns Promise that resolves when state is updated
|
|
6155
|
+
*
|
|
6156
|
+
* @throws Error if currentPrice is not in loss direction:
|
|
6157
|
+
* - LONG: currentPrice must be < priceOpen
|
|
6158
|
+
* - SHORT: currentPrice must be > priceOpen
|
|
6159
|
+
*
|
|
6160
|
+
* @example
|
|
6161
|
+
* ```typescript
|
|
6162
|
+
* // Close 40% of LONG position at loss
|
|
6163
|
+
* await Backtest.partialLoss("BTCUSDT", 40, 38000, {
|
|
6164
|
+
* exchangeName: "binance",
|
|
6165
|
+
* frameName: "frame1",
|
|
6166
|
+
* strategyName: "my-strategy"
|
|
6167
|
+
* });
|
|
6168
|
+
* ```
|
|
6169
|
+
*/
|
|
6170
|
+
partialLoss: (symbol: string, percentToClose: number, currentPrice: number, context: {
|
|
6171
|
+
strategyName: StrategyName;
|
|
6172
|
+
exchangeName: ExchangeName;
|
|
6173
|
+
frameName: FrameName;
|
|
6174
|
+
}) => Promise<void>;
|
|
5879
6175
|
/**
|
|
5880
6176
|
* Gets statistical data from all closed signals for a symbol-strategy pair.
|
|
5881
6177
|
*
|
|
@@ -5895,9 +6191,9 @@ declare class BacktestUtils {
|
|
|
5895
6191
|
* ```
|
|
5896
6192
|
*/
|
|
5897
6193
|
getData: (symbol: string, context: {
|
|
5898
|
-
strategyName:
|
|
5899
|
-
exchangeName:
|
|
5900
|
-
frameName:
|
|
6194
|
+
strategyName: StrategyName;
|
|
6195
|
+
exchangeName: ExchangeName;
|
|
6196
|
+
frameName: FrameName;
|
|
5901
6197
|
}) => Promise<BacktestStatisticsModel>;
|
|
5902
6198
|
/**
|
|
5903
6199
|
* Generates markdown report with all closed signals for a symbol-strategy pair.
|
|
@@ -5919,9 +6215,9 @@ declare class BacktestUtils {
|
|
|
5919
6215
|
* ```
|
|
5920
6216
|
*/
|
|
5921
6217
|
getReport: (symbol: string, context: {
|
|
5922
|
-
strategyName:
|
|
5923
|
-
exchangeName:
|
|
5924
|
-
frameName:
|
|
6218
|
+
strategyName: StrategyName;
|
|
6219
|
+
exchangeName: ExchangeName;
|
|
6220
|
+
frameName: FrameName;
|
|
5925
6221
|
}, columns?: Columns$6[]) => Promise<string>;
|
|
5926
6222
|
/**
|
|
5927
6223
|
* Saves strategy report to disk.
|
|
@@ -5950,9 +6246,9 @@ declare class BacktestUtils {
|
|
|
5950
6246
|
* ```
|
|
5951
6247
|
*/
|
|
5952
6248
|
dump: (symbol: string, context: {
|
|
5953
|
-
strategyName:
|
|
5954
|
-
exchangeName:
|
|
5955
|
-
frameName:
|
|
6249
|
+
strategyName: StrategyName;
|
|
6250
|
+
exchangeName: ExchangeName;
|
|
6251
|
+
frameName: FrameName;
|
|
5956
6252
|
}, path?: string, columns?: Columns$6[]) => Promise<void>;
|
|
5957
6253
|
/**
|
|
5958
6254
|
* Lists all active backtest instances with their current status.
|
|
@@ -6106,7 +6402,7 @@ declare class LiveMarkdownService {
|
|
|
6106
6402
|
* console.log(stats.sharpeRatio, stats.winRate);
|
|
6107
6403
|
* ```
|
|
6108
6404
|
*/
|
|
6109
|
-
getData: (symbol: string, strategyName: StrategyName, exchangeName:
|
|
6405
|
+
getData: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean) => Promise<LiveStatisticsModel>;
|
|
6110
6406
|
/**
|
|
6111
6407
|
* Generates markdown report with all events for a symbol-strategy pair.
|
|
6112
6408
|
* Delegates to ReportStorage.getReport().
|
|
@@ -6126,7 +6422,7 @@ declare class LiveMarkdownService {
|
|
|
6126
6422
|
* console.log(markdown);
|
|
6127
6423
|
* ```
|
|
6128
6424
|
*/
|
|
6129
|
-
getReport: (symbol: string, strategyName: StrategyName, exchangeName:
|
|
6425
|
+
getReport: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, columns?: Columns$5[]) => Promise<string>;
|
|
6130
6426
|
/**
|
|
6131
6427
|
* Saves symbol-strategy report to disk.
|
|
6132
6428
|
* Creates directory if it doesn't exist.
|
|
@@ -6151,7 +6447,7 @@ declare class LiveMarkdownService {
|
|
|
6151
6447
|
* await service.dump("BTCUSDT", "my-strategy", "binance", "1h", false, "./custom/path");
|
|
6152
6448
|
* ```
|
|
6153
6449
|
*/
|
|
6154
|
-
dump: (symbol: string, strategyName: StrategyName, exchangeName:
|
|
6450
|
+
dump: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, path?: string, columns?: Columns$5[]) => Promise<void>;
|
|
6155
6451
|
/**
|
|
6156
6452
|
* Clears accumulated event data from storage.
|
|
6157
6453
|
* If payload is provided, clears only that specific symbol-strategy-exchange-frame-backtest combination's data.
|
|
@@ -6173,8 +6469,8 @@ declare class LiveMarkdownService {
|
|
|
6173
6469
|
clear: (payload?: {
|
|
6174
6470
|
symbol: string;
|
|
6175
6471
|
strategyName: StrategyName;
|
|
6176
|
-
exchangeName:
|
|
6177
|
-
frameName:
|
|
6472
|
+
exchangeName: ExchangeName;
|
|
6473
|
+
frameName: FrameName;
|
|
6178
6474
|
backtest: boolean;
|
|
6179
6475
|
}) => Promise<void>;
|
|
6180
6476
|
/**
|
|
@@ -6237,8 +6533,8 @@ declare class LiveUtils {
|
|
|
6237
6533
|
* @returns Infinite async generator yielding opened and closed signals
|
|
6238
6534
|
*/
|
|
6239
6535
|
run: (symbol: string, context: {
|
|
6240
|
-
strategyName:
|
|
6241
|
-
exchangeName:
|
|
6536
|
+
strategyName: StrategyName;
|
|
6537
|
+
exchangeName: ExchangeName;
|
|
6242
6538
|
}) => AsyncGenerator<IStrategyTickResultOpened | IStrategyTickResultClosed, void, unknown>;
|
|
6243
6539
|
/**
|
|
6244
6540
|
* Runs live trading in background without yielding results.
|
|
@@ -6262,8 +6558,8 @@ declare class LiveUtils {
|
|
|
6262
6558
|
* ```
|
|
6263
6559
|
*/
|
|
6264
6560
|
background: (symbol: string, context: {
|
|
6265
|
-
strategyName:
|
|
6266
|
-
exchangeName:
|
|
6561
|
+
strategyName: StrategyName;
|
|
6562
|
+
exchangeName: ExchangeName;
|
|
6267
6563
|
}) => () => void;
|
|
6268
6564
|
/**
|
|
6269
6565
|
* Retrieves the currently active pending signal for the strategy.
|
|
@@ -6282,8 +6578,8 @@ declare class LiveUtils {
|
|
|
6282
6578
|
* ```
|
|
6283
6579
|
*/
|
|
6284
6580
|
getPendingSignal: (symbol: string, context: {
|
|
6285
|
-
strategyName:
|
|
6286
|
-
exchangeName:
|
|
6581
|
+
strategyName: StrategyName;
|
|
6582
|
+
exchangeName: ExchangeName;
|
|
6287
6583
|
}) => Promise<ISignalRow>;
|
|
6288
6584
|
/**
|
|
6289
6585
|
* Retrieves the currently active scheduled signal for the strategy.
|
|
@@ -6302,8 +6598,8 @@ declare class LiveUtils {
|
|
|
6302
6598
|
* ```
|
|
6303
6599
|
*/
|
|
6304
6600
|
getScheduledSignal: (symbol: string, context: {
|
|
6305
|
-
strategyName:
|
|
6306
|
-
exchangeName:
|
|
6601
|
+
strategyName: StrategyName;
|
|
6602
|
+
exchangeName: ExchangeName;
|
|
6307
6603
|
}) => Promise<IScheduledSignalRow>;
|
|
6308
6604
|
/**
|
|
6309
6605
|
* Stops the strategy from generating new signals.
|
|
@@ -6323,8 +6619,8 @@ declare class LiveUtils {
|
|
|
6323
6619
|
* ```
|
|
6324
6620
|
*/
|
|
6325
6621
|
stop: (symbol: string, context: {
|
|
6326
|
-
strategyName:
|
|
6327
|
-
exchangeName:
|
|
6622
|
+
strategyName: StrategyName;
|
|
6623
|
+
exchangeName: ExchangeName;
|
|
6328
6624
|
}) => Promise<void>;
|
|
6329
6625
|
/**
|
|
6330
6626
|
* Cancels the scheduled signal without stopping the strategy.
|
|
@@ -6350,9 +6646,67 @@ declare class LiveUtils {
|
|
|
6350
6646
|
* ```
|
|
6351
6647
|
*/
|
|
6352
6648
|
cancel: (symbol: string, context: {
|
|
6353
|
-
strategyName:
|
|
6354
|
-
exchangeName:
|
|
6649
|
+
strategyName: StrategyName;
|
|
6650
|
+
exchangeName: ExchangeName;
|
|
6355
6651
|
}, cancelId?: string) => Promise<void>;
|
|
6652
|
+
/**
|
|
6653
|
+
* Executes partial close at profit level (moving toward TP).
|
|
6654
|
+
*
|
|
6655
|
+
* Closes a percentage of the active pending position at profit.
|
|
6656
|
+
* Price must be moving toward take profit (in profit direction).
|
|
6657
|
+
*
|
|
6658
|
+
* @param symbol - Trading pair symbol
|
|
6659
|
+
* @param percentToClose - Percentage of position to close (0-100, absolute value)
|
|
6660
|
+
* @param currentPrice - Current market price for this partial close
|
|
6661
|
+
* @param context - Execution context with strategyName and exchangeName
|
|
6662
|
+
* @returns Promise that resolves when state is updated
|
|
6663
|
+
*
|
|
6664
|
+
* @throws Error if currentPrice is not in profit direction:
|
|
6665
|
+
* - LONG: currentPrice must be > priceOpen
|
|
6666
|
+
* - SHORT: currentPrice must be < priceOpen
|
|
6667
|
+
*
|
|
6668
|
+
* @example
|
|
6669
|
+
* ```typescript
|
|
6670
|
+
* // Close 30% of LONG position at profit
|
|
6671
|
+
* await Live.partialProfit("BTCUSDT", 30, 45000, {
|
|
6672
|
+
* exchangeName: "binance",
|
|
6673
|
+
* strategyName: "my-strategy"
|
|
6674
|
+
* });
|
|
6675
|
+
* ```
|
|
6676
|
+
*/
|
|
6677
|
+
partialProfit: (symbol: string, percentToClose: number, currentPrice: number, context: {
|
|
6678
|
+
strategyName: StrategyName;
|
|
6679
|
+
exchangeName: ExchangeName;
|
|
6680
|
+
}) => Promise<void>;
|
|
6681
|
+
/**
|
|
6682
|
+
* Executes partial close at loss level (moving toward SL).
|
|
6683
|
+
*
|
|
6684
|
+
* Closes a percentage of the active pending position at loss.
|
|
6685
|
+
* Price must be moving toward stop loss (in loss direction).
|
|
6686
|
+
*
|
|
6687
|
+
* @param symbol - Trading pair symbol
|
|
6688
|
+
* @param percentToClose - Percentage of position to close (0-100, absolute value)
|
|
6689
|
+
* @param currentPrice - Current market price for this partial close
|
|
6690
|
+
* @param context - Execution context with strategyName and exchangeName
|
|
6691
|
+
* @returns Promise that resolves when state is updated
|
|
6692
|
+
*
|
|
6693
|
+
* @throws Error if currentPrice is not in loss direction:
|
|
6694
|
+
* - LONG: currentPrice must be < priceOpen
|
|
6695
|
+
* - SHORT: currentPrice must be > priceOpen
|
|
6696
|
+
*
|
|
6697
|
+
* @example
|
|
6698
|
+
* ```typescript
|
|
6699
|
+
* // Close 40% of LONG position at loss
|
|
6700
|
+
* await Live.partialLoss("BTCUSDT", 40, 38000, {
|
|
6701
|
+
* exchangeName: "binance",
|
|
6702
|
+
* strategyName: "my-strategy"
|
|
6703
|
+
* });
|
|
6704
|
+
* ```
|
|
6705
|
+
*/
|
|
6706
|
+
partialLoss: (symbol: string, percentToClose: number, currentPrice: number, context: {
|
|
6707
|
+
strategyName: StrategyName;
|
|
6708
|
+
exchangeName: ExchangeName;
|
|
6709
|
+
}) => Promise<void>;
|
|
6356
6710
|
/**
|
|
6357
6711
|
* Gets statistical data from all live trading events for a symbol-strategy pair.
|
|
6358
6712
|
*
|
|
@@ -6372,8 +6726,8 @@ declare class LiveUtils {
|
|
|
6372
6726
|
* ```
|
|
6373
6727
|
*/
|
|
6374
6728
|
getData: (symbol: string, context: {
|
|
6375
|
-
strategyName:
|
|
6376
|
-
exchangeName:
|
|
6729
|
+
strategyName: StrategyName;
|
|
6730
|
+
exchangeName: ExchangeName;
|
|
6377
6731
|
}) => Promise<LiveStatisticsModel>;
|
|
6378
6732
|
/**
|
|
6379
6733
|
* Generates markdown report with all events for a symbol-strategy pair.
|
|
@@ -6395,8 +6749,8 @@ declare class LiveUtils {
|
|
|
6395
6749
|
* ```
|
|
6396
6750
|
*/
|
|
6397
6751
|
getReport: (symbol: string, context: {
|
|
6398
|
-
strategyName:
|
|
6399
|
-
exchangeName:
|
|
6752
|
+
strategyName: StrategyName;
|
|
6753
|
+
exchangeName: ExchangeName;
|
|
6400
6754
|
}, columns?: Columns$5[]) => Promise<string>;
|
|
6401
6755
|
/**
|
|
6402
6756
|
* Saves strategy report to disk.
|
|
@@ -6425,8 +6779,8 @@ declare class LiveUtils {
|
|
|
6425
6779
|
* ```
|
|
6426
6780
|
*/
|
|
6427
6781
|
dump: (symbol: string, context: {
|
|
6428
|
-
strategyName:
|
|
6429
|
-
exchangeName:
|
|
6782
|
+
strategyName: StrategyName;
|
|
6783
|
+
exchangeName: ExchangeName;
|
|
6430
6784
|
}, path?: string, columns?: Columns$5[]) => Promise<void>;
|
|
6431
6785
|
/**
|
|
6432
6786
|
* Lists all active live trading instances with their current status.
|
|
@@ -6560,7 +6914,7 @@ declare class ScheduleMarkdownService {
|
|
|
6560
6914
|
* console.log(stats.cancellationRate, stats.avgWaitTime);
|
|
6561
6915
|
* ```
|
|
6562
6916
|
*/
|
|
6563
|
-
getData: (symbol: string, strategyName: StrategyName, exchangeName:
|
|
6917
|
+
getData: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean) => Promise<ScheduleStatisticsModel>;
|
|
6564
6918
|
/**
|
|
6565
6919
|
* Generates markdown report with all scheduled events for a symbol-strategy pair.
|
|
6566
6920
|
* Delegates to ReportStorage.getReport().
|
|
@@ -6580,7 +6934,7 @@ declare class ScheduleMarkdownService {
|
|
|
6580
6934
|
* console.log(markdown);
|
|
6581
6935
|
* ```
|
|
6582
6936
|
*/
|
|
6583
|
-
getReport: (symbol: string, strategyName: StrategyName, exchangeName:
|
|
6937
|
+
getReport: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, columns?: Columns$4[]) => Promise<string>;
|
|
6584
6938
|
/**
|
|
6585
6939
|
* Saves symbol-strategy report to disk.
|
|
6586
6940
|
* Creates directory if it doesn't exist.
|
|
@@ -6605,7 +6959,7 @@ declare class ScheduleMarkdownService {
|
|
|
6605
6959
|
* await service.dump("BTCUSDT", "my-strategy", "binance", "1h", false, "./custom/path");
|
|
6606
6960
|
* ```
|
|
6607
6961
|
*/
|
|
6608
|
-
dump: (symbol: string, strategyName: StrategyName, exchangeName:
|
|
6962
|
+
dump: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, path?: string, columns?: Columns$4[]) => Promise<void>;
|
|
6609
6963
|
/**
|
|
6610
6964
|
* Clears accumulated event data from storage.
|
|
6611
6965
|
* If payload is provided, clears only that specific symbol-strategy-exchange-frame-backtest combination's data.
|
|
@@ -6627,8 +6981,8 @@ declare class ScheduleMarkdownService {
|
|
|
6627
6981
|
clear: (payload?: {
|
|
6628
6982
|
symbol: string;
|
|
6629
6983
|
strategyName: StrategyName;
|
|
6630
|
-
exchangeName:
|
|
6631
|
-
frameName:
|
|
6984
|
+
exchangeName: ExchangeName;
|
|
6985
|
+
frameName: FrameName;
|
|
6632
6986
|
backtest: boolean;
|
|
6633
6987
|
}) => Promise<void>;
|
|
6634
6988
|
/**
|
|
@@ -6685,9 +7039,9 @@ declare class ScheduleUtils {
|
|
|
6685
7039
|
* ```
|
|
6686
7040
|
*/
|
|
6687
7041
|
getData: (symbol: string, context: {
|
|
6688
|
-
strategyName:
|
|
6689
|
-
exchangeName:
|
|
6690
|
-
frameName:
|
|
7042
|
+
strategyName: StrategyName;
|
|
7043
|
+
exchangeName: ExchangeName;
|
|
7044
|
+
frameName: FrameName;
|
|
6691
7045
|
}, backtest?: boolean) => Promise<ScheduleStatisticsModel>;
|
|
6692
7046
|
/**
|
|
6693
7047
|
* Generates markdown report with all scheduled events for a symbol-strategy pair.
|
|
@@ -6704,9 +7058,9 @@ declare class ScheduleUtils {
|
|
|
6704
7058
|
* ```
|
|
6705
7059
|
*/
|
|
6706
7060
|
getReport: (symbol: string, context: {
|
|
6707
|
-
strategyName:
|
|
6708
|
-
exchangeName:
|
|
6709
|
-
frameName:
|
|
7061
|
+
strategyName: StrategyName;
|
|
7062
|
+
exchangeName: ExchangeName;
|
|
7063
|
+
frameName: FrameName;
|
|
6710
7064
|
}, backtest?: boolean, columns?: Columns$4[]) => Promise<string>;
|
|
6711
7065
|
/**
|
|
6712
7066
|
* Saves strategy report to disk.
|
|
@@ -6726,9 +7080,9 @@ declare class ScheduleUtils {
|
|
|
6726
7080
|
* ```
|
|
6727
7081
|
*/
|
|
6728
7082
|
dump: (symbol: string, context: {
|
|
6729
|
-
strategyName:
|
|
6730
|
-
exchangeName:
|
|
6731
|
-
frameName:
|
|
7083
|
+
strategyName: StrategyName;
|
|
7084
|
+
exchangeName: ExchangeName;
|
|
7085
|
+
frameName: FrameName;
|
|
6732
7086
|
}, backtest?: boolean, path?: string, columns?: Columns$4[]) => Promise<void>;
|
|
6733
7087
|
}
|
|
6734
7088
|
/**
|
|
@@ -6836,7 +7190,7 @@ declare class PerformanceMarkdownService {
|
|
|
6836
7190
|
* .sort((a, b) => b.avgDuration - a.avgDuration)[0]);
|
|
6837
7191
|
* ```
|
|
6838
7192
|
*/
|
|
6839
|
-
getData: (symbol: string, strategyName:
|
|
7193
|
+
getData: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean) => Promise<PerformanceStatisticsModel>;
|
|
6840
7194
|
/**
|
|
6841
7195
|
* Generates markdown report with performance analysis.
|
|
6842
7196
|
*
|
|
@@ -6854,7 +7208,7 @@ declare class PerformanceMarkdownService {
|
|
|
6854
7208
|
* console.log(markdown);
|
|
6855
7209
|
* ```
|
|
6856
7210
|
*/
|
|
6857
|
-
getReport: (symbol: string, strategyName:
|
|
7211
|
+
getReport: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, columns?: Columns$3[]) => Promise<string>;
|
|
6858
7212
|
/**
|
|
6859
7213
|
* Saves performance report to disk.
|
|
6860
7214
|
*
|
|
@@ -6875,7 +7229,7 @@ declare class PerformanceMarkdownService {
|
|
|
6875
7229
|
* await performanceService.dump("BTCUSDT", "my-strategy", "binance", "1h", false, "./custom/path");
|
|
6876
7230
|
* ```
|
|
6877
7231
|
*/
|
|
6878
|
-
dump: (symbol: string, strategyName:
|
|
7232
|
+
dump: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, path?: string, columns?: Columns$3[]) => Promise<void>;
|
|
6879
7233
|
/**
|
|
6880
7234
|
* Clears accumulated performance data from storage.
|
|
6881
7235
|
*
|
|
@@ -6883,9 +7237,9 @@ declare class PerformanceMarkdownService {
|
|
|
6883
7237
|
*/
|
|
6884
7238
|
clear: (payload?: {
|
|
6885
7239
|
symbol: string;
|
|
6886
|
-
strategyName:
|
|
6887
|
-
exchangeName:
|
|
6888
|
-
frameName:
|
|
7240
|
+
strategyName: StrategyName;
|
|
7241
|
+
exchangeName: ExchangeName;
|
|
7242
|
+
frameName: FrameName;
|
|
6889
7243
|
backtest: boolean;
|
|
6890
7244
|
}) => Promise<void>;
|
|
6891
7245
|
/**
|
|
@@ -6957,9 +7311,9 @@ declare class Performance {
|
|
|
6957
7311
|
* ```
|
|
6958
7312
|
*/
|
|
6959
7313
|
static getData(symbol: string, context: {
|
|
6960
|
-
strategyName:
|
|
6961
|
-
exchangeName:
|
|
6962
|
-
frameName:
|
|
7314
|
+
strategyName: StrategyName;
|
|
7315
|
+
exchangeName: ExchangeName;
|
|
7316
|
+
frameName: FrameName;
|
|
6963
7317
|
}, backtest?: boolean): Promise<PerformanceStatisticsModel>;
|
|
6964
7318
|
/**
|
|
6965
7319
|
* Generates markdown report with performance analysis.
|
|
@@ -6985,9 +7339,9 @@ declare class Performance {
|
|
|
6985
7339
|
* ```
|
|
6986
7340
|
*/
|
|
6987
7341
|
static getReport(symbol: string, context: {
|
|
6988
|
-
strategyName:
|
|
6989
|
-
exchangeName:
|
|
6990
|
-
frameName:
|
|
7342
|
+
strategyName: StrategyName;
|
|
7343
|
+
exchangeName: ExchangeName;
|
|
7344
|
+
frameName: FrameName;
|
|
6991
7345
|
}, backtest?: boolean, columns?: Columns$3[]): Promise<string>;
|
|
6992
7346
|
/**
|
|
6993
7347
|
* Saves performance report to disk.
|
|
@@ -7010,9 +7364,9 @@ declare class Performance {
|
|
|
7010
7364
|
* ```
|
|
7011
7365
|
*/
|
|
7012
7366
|
static dump(symbol: string, context: {
|
|
7013
|
-
strategyName:
|
|
7014
|
-
exchangeName:
|
|
7015
|
-
frameName:
|
|
7367
|
+
strategyName: StrategyName;
|
|
7368
|
+
exchangeName: ExchangeName;
|
|
7369
|
+
frameName: FrameName;
|
|
7016
7370
|
}, backtest?: boolean, path?: string, columns?: Columns$3[]): Promise<void>;
|
|
7017
7371
|
}
|
|
7018
7372
|
|
|
@@ -7135,8 +7489,8 @@ declare class WalkerMarkdownService {
|
|
|
7135
7489
|
* ```
|
|
7136
7490
|
*/
|
|
7137
7491
|
getData: (walkerName: WalkerName, symbol: string, metric: WalkerMetric, context: {
|
|
7138
|
-
exchangeName:
|
|
7139
|
-
frameName:
|
|
7492
|
+
exchangeName: ExchangeName;
|
|
7493
|
+
frameName: FrameName;
|
|
7140
7494
|
}) => Promise<WalkerCompleteContract>;
|
|
7141
7495
|
/**
|
|
7142
7496
|
* Generates markdown report with all strategy results for a walker.
|
|
@@ -7158,8 +7512,8 @@ declare class WalkerMarkdownService {
|
|
|
7158
7512
|
* ```
|
|
7159
7513
|
*/
|
|
7160
7514
|
getReport: (walkerName: WalkerName, symbol: string, metric: WalkerMetric, context: {
|
|
7161
|
-
exchangeName:
|
|
7162
|
-
frameName:
|
|
7515
|
+
exchangeName: ExchangeName;
|
|
7516
|
+
frameName: FrameName;
|
|
7163
7517
|
}, strategyColumns?: StrategyColumn[], pnlColumns?: PnlColumn[]) => Promise<string>;
|
|
7164
7518
|
/**
|
|
7165
7519
|
* Saves walker report to disk.
|
|
@@ -7186,8 +7540,8 @@ declare class WalkerMarkdownService {
|
|
|
7186
7540
|
* ```
|
|
7187
7541
|
*/
|
|
7188
7542
|
dump: (walkerName: WalkerName, symbol: string, metric: WalkerMetric, context: {
|
|
7189
|
-
exchangeName:
|
|
7190
|
-
frameName:
|
|
7543
|
+
exchangeName: ExchangeName;
|
|
7544
|
+
frameName: FrameName;
|
|
7191
7545
|
}, path?: string, strategyColumns?: StrategyColumn[], pnlColumns?: PnlColumn[]) => Promise<void>;
|
|
7192
7546
|
/**
|
|
7193
7547
|
* Clears accumulated result data from storage.
|
|
@@ -7255,7 +7609,7 @@ declare class WalkerUtils {
|
|
|
7255
7609
|
* @returns Async generator yielding progress updates after each strategy
|
|
7256
7610
|
*/
|
|
7257
7611
|
run: (symbol: string, context: {
|
|
7258
|
-
walkerName:
|
|
7612
|
+
walkerName: WalkerName;
|
|
7259
7613
|
}) => AsyncGenerator<WalkerContract, any, any>;
|
|
7260
7614
|
/**
|
|
7261
7615
|
* Runs walker comparison in background without yielding results.
|
|
@@ -7277,7 +7631,7 @@ declare class WalkerUtils {
|
|
|
7277
7631
|
* ```
|
|
7278
7632
|
*/
|
|
7279
7633
|
background: (symbol: string, context: {
|
|
7280
|
-
walkerName:
|
|
7634
|
+
walkerName: WalkerName;
|
|
7281
7635
|
}) => () => void;
|
|
7282
7636
|
/**
|
|
7283
7637
|
* Stops all strategies in the walker from generating new signals.
|
|
@@ -7293,51 +7647,57 @@ declare class WalkerUtils {
|
|
|
7293
7647
|
* Stop signal is filtered by walkerName to prevent interference.
|
|
7294
7648
|
*
|
|
7295
7649
|
* @param symbol - Trading pair symbol
|
|
7296
|
-
* @param
|
|
7650
|
+
* @param context - Execution context with walker name
|
|
7297
7651
|
* @returns Promise that resolves when all stop flags are set
|
|
7298
7652
|
*
|
|
7299
7653
|
* @example
|
|
7300
7654
|
* ```typescript
|
|
7301
7655
|
* // Stop walker and all its strategies
|
|
7302
|
-
* await Walker.stop("BTCUSDT", "my-walker");
|
|
7656
|
+
* await Walker.stop("BTCUSDT", { walkerName: "my-walker" });
|
|
7303
7657
|
* ```
|
|
7304
7658
|
*/
|
|
7305
|
-
stop: (symbol: string,
|
|
7659
|
+
stop: (symbol: string, context: {
|
|
7660
|
+
walkerName: WalkerName;
|
|
7661
|
+
}) => Promise<void>;
|
|
7306
7662
|
/**
|
|
7307
7663
|
* Gets walker results data from all strategy comparisons.
|
|
7308
7664
|
*
|
|
7309
7665
|
* @param symbol - Trading symbol
|
|
7310
|
-
* @param
|
|
7666
|
+
* @param context - Execution context with walker name
|
|
7311
7667
|
* @returns Promise resolving to walker results data object
|
|
7312
7668
|
*
|
|
7313
7669
|
* @example
|
|
7314
7670
|
* ```typescript
|
|
7315
|
-
* const results = await Walker.getData("BTCUSDT", "my-walker");
|
|
7671
|
+
* const results = await Walker.getData("BTCUSDT", { walkerName: "my-walker" });
|
|
7316
7672
|
* console.log(results.bestStrategy, results.bestMetric);
|
|
7317
7673
|
* ```
|
|
7318
7674
|
*/
|
|
7319
|
-
getData: (symbol: string,
|
|
7675
|
+
getData: (symbol: string, context: {
|
|
7676
|
+
walkerName: WalkerName;
|
|
7677
|
+
}) => Promise<WalkerCompleteContract>;
|
|
7320
7678
|
/**
|
|
7321
7679
|
* Generates markdown report with all strategy comparisons for a walker.
|
|
7322
7680
|
*
|
|
7323
7681
|
* @param symbol - Trading symbol
|
|
7324
|
-
* @param
|
|
7682
|
+
* @param context - Execution context with walker name
|
|
7325
7683
|
* @param strategyColumns - Optional strategy columns configuration
|
|
7326
7684
|
* @param pnlColumns - Optional PNL columns configuration
|
|
7327
7685
|
* @returns Promise resolving to markdown formatted report string
|
|
7328
7686
|
*
|
|
7329
7687
|
* @example
|
|
7330
7688
|
* ```typescript
|
|
7331
|
-
* const markdown = await Walker.getReport("BTCUSDT", "my-walker");
|
|
7689
|
+
* const markdown = await Walker.getReport("BTCUSDT", { walkerName: "my-walker" });
|
|
7332
7690
|
* console.log(markdown);
|
|
7333
7691
|
* ```
|
|
7334
7692
|
*/
|
|
7335
|
-
getReport: (symbol: string,
|
|
7693
|
+
getReport: (symbol: string, context: {
|
|
7694
|
+
walkerName: WalkerName;
|
|
7695
|
+
}, strategyColumns?: StrategyColumn[], pnlColumns?: PnlColumn[]) => Promise<string>;
|
|
7336
7696
|
/**
|
|
7337
7697
|
* Saves walker report to disk.
|
|
7338
7698
|
*
|
|
7339
7699
|
* @param symbol - Trading symbol
|
|
7340
|
-
* @param
|
|
7700
|
+
* @param context - Execution context with walker name
|
|
7341
7701
|
* @param path - Optional directory path to save report (default: "./dump/walker")
|
|
7342
7702
|
* @param strategyColumns - Optional strategy columns configuration
|
|
7343
7703
|
* @param pnlColumns - Optional PNL columns configuration
|
|
@@ -7345,13 +7705,15 @@ declare class WalkerUtils {
|
|
|
7345
7705
|
* @example
|
|
7346
7706
|
* ```typescript
|
|
7347
7707
|
* // Save to default path: ./dump/walker/my-walker.md
|
|
7348
|
-
* await Walker.dump("BTCUSDT", "my-walker");
|
|
7708
|
+
* await Walker.dump("BTCUSDT", { walkerName: "my-walker" });
|
|
7349
7709
|
*
|
|
7350
7710
|
* // Save to custom path: ./custom/path/my-walker.md
|
|
7351
|
-
* await Walker.dump("BTCUSDT", "my-walker", "./custom/path");
|
|
7711
|
+
* await Walker.dump("BTCUSDT", { walkerName: "my-walker" }, "./custom/path");
|
|
7352
7712
|
* ```
|
|
7353
7713
|
*/
|
|
7354
|
-
dump: (symbol: string,
|
|
7714
|
+
dump: (symbol: string, context: {
|
|
7715
|
+
walkerName: WalkerName;
|
|
7716
|
+
}, path?: string, strategyColumns?: StrategyColumn[], pnlColumns?: PnlColumn[]) => Promise<void>;
|
|
7355
7717
|
/**
|
|
7356
7718
|
* Lists all active walker instances with their current status.
|
|
7357
7719
|
*
|
|
@@ -7485,7 +7847,7 @@ declare class HeatMarkdownService {
|
|
|
7485
7847
|
* });
|
|
7486
7848
|
* ```
|
|
7487
7849
|
*/
|
|
7488
|
-
getData: (exchangeName:
|
|
7850
|
+
getData: (exchangeName: ExchangeName, frameName: FrameName, backtest: boolean) => Promise<HeatmapStatisticsModel>;
|
|
7489
7851
|
/**
|
|
7490
7852
|
* Generates markdown report with portfolio heatmap table.
|
|
7491
7853
|
*
|
|
@@ -7513,7 +7875,7 @@ declare class HeatMarkdownService {
|
|
|
7513
7875
|
* // ...
|
|
7514
7876
|
* ```
|
|
7515
7877
|
*/
|
|
7516
|
-
getReport: (strategyName: StrategyName, exchangeName:
|
|
7878
|
+
getReport: (strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, columns?: Columns$2[]) => Promise<string>;
|
|
7517
7879
|
/**
|
|
7518
7880
|
* Saves heatmap report to disk.
|
|
7519
7881
|
*
|
|
@@ -7538,7 +7900,7 @@ declare class HeatMarkdownService {
|
|
|
7538
7900
|
* await service.dump("my-strategy", "binance", "frame1", true, "./reports");
|
|
7539
7901
|
* ```
|
|
7540
7902
|
*/
|
|
7541
|
-
dump: (strategyName: StrategyName, exchangeName:
|
|
7903
|
+
dump: (strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, path?: string, columns?: Columns$2[]) => Promise<void>;
|
|
7542
7904
|
/**
|
|
7543
7905
|
* Clears accumulated heatmap data from storage.
|
|
7544
7906
|
* If payload is provided, clears only that exchangeName+frameName+backtest combination's data.
|
|
@@ -7558,8 +7920,8 @@ declare class HeatMarkdownService {
|
|
|
7558
7920
|
* ```
|
|
7559
7921
|
*/
|
|
7560
7922
|
clear: (payload?: {
|
|
7561
|
-
exchangeName:
|
|
7562
|
-
frameName:
|
|
7923
|
+
exchangeName: ExchangeName;
|
|
7924
|
+
frameName: FrameName;
|
|
7563
7925
|
backtest: boolean;
|
|
7564
7926
|
}) => Promise<void>;
|
|
7565
7927
|
/**
|
|
@@ -7588,15 +7950,27 @@ declare class HeatMarkdownService {
|
|
|
7588
7950
|
* import { Heat } from "backtest-kit";
|
|
7589
7951
|
*
|
|
7590
7952
|
* // Get raw heatmap data for a strategy
|
|
7591
|
-
* const stats = await Heat.getData(
|
|
7953
|
+
* const stats = await Heat.getData({
|
|
7954
|
+
* strategyName: "my-strategy",
|
|
7955
|
+
* exchangeName: "binance",
|
|
7956
|
+
* frameName: "frame1"
|
|
7957
|
+
* });
|
|
7592
7958
|
* console.log(`Portfolio PNL: ${stats.portfolioTotalPnl}%`);
|
|
7593
7959
|
*
|
|
7594
7960
|
* // Generate markdown report
|
|
7595
|
-
* const markdown = await Heat.getReport(
|
|
7961
|
+
* const markdown = await Heat.getReport({
|
|
7962
|
+
* strategyName: "my-strategy",
|
|
7963
|
+
* exchangeName: "binance",
|
|
7964
|
+
* frameName: "frame1"
|
|
7965
|
+
* });
|
|
7596
7966
|
* console.log(markdown);
|
|
7597
7967
|
*
|
|
7598
7968
|
* // Save to disk
|
|
7599
|
-
* await Heat.dump(
|
|
7969
|
+
* await Heat.dump({
|
|
7970
|
+
* strategyName: "my-strategy",
|
|
7971
|
+
* exchangeName: "binance",
|
|
7972
|
+
* frameName: "frame1"
|
|
7973
|
+
* }, false, "./reports");
|
|
7600
7974
|
* ```
|
|
7601
7975
|
*/
|
|
7602
7976
|
declare class HeatUtils {
|
|
@@ -7606,14 +7980,14 @@ declare class HeatUtils {
|
|
|
7606
7980
|
* Returns per-symbol breakdown and portfolio-wide metrics.
|
|
7607
7981
|
* Data is automatically collected from all closed signals for the strategy.
|
|
7608
7982
|
*
|
|
7609
|
-
* @param
|
|
7610
|
-
* @param context - Execution context with exchangeName and frameName
|
|
7983
|
+
* @param context - Execution context with strategyName, exchangeName and frameName
|
|
7611
7984
|
* @param backtest - True if backtest mode, false if live mode (default: false)
|
|
7612
7985
|
* @returns Promise resolving to heatmap statistics object
|
|
7613
7986
|
*
|
|
7614
7987
|
* @example
|
|
7615
7988
|
* ```typescript
|
|
7616
|
-
* const stats = await Heat.getData(
|
|
7989
|
+
* const stats = await Heat.getData({
|
|
7990
|
+
* strategyName: "my-strategy",
|
|
7617
7991
|
* exchangeName: "binance",
|
|
7618
7992
|
* frameName: "frame1"
|
|
7619
7993
|
* });
|
|
@@ -7628,9 +8002,10 @@ declare class HeatUtils {
|
|
|
7628
8002
|
* });
|
|
7629
8003
|
* ```
|
|
7630
8004
|
*/
|
|
7631
|
-
getData: (
|
|
7632
|
-
|
|
7633
|
-
|
|
8005
|
+
getData: (context: {
|
|
8006
|
+
strategyName: StrategyName;
|
|
8007
|
+
exchangeName: ExchangeName;
|
|
8008
|
+
frameName: FrameName;
|
|
7634
8009
|
}, backtest?: boolean) => Promise<HeatmapStatisticsModel>;
|
|
7635
8010
|
/**
|
|
7636
8011
|
* Generates markdown report with portfolio heatmap table for a strategy.
|
|
@@ -7638,15 +8013,15 @@ declare class HeatUtils {
|
|
|
7638
8013
|
* Table includes: Symbol, Total PNL, Sharpe Ratio, Max Drawdown, Trades.
|
|
7639
8014
|
* Symbols are sorted by Total PNL descending.
|
|
7640
8015
|
*
|
|
7641
|
-
* @param
|
|
7642
|
-
* @param context - Execution context with exchangeName and frameName
|
|
8016
|
+
* @param context - Execution context with strategyName, exchangeName and frameName
|
|
7643
8017
|
* @param backtest - True if backtest mode, false if live mode (default: false)
|
|
7644
8018
|
* @param columns - Optional columns configuration for the report
|
|
7645
8019
|
* @returns Promise resolving to markdown formatted report string
|
|
7646
8020
|
*
|
|
7647
8021
|
* @example
|
|
7648
8022
|
* ```typescript
|
|
7649
|
-
* const markdown = await Heat.getReport(
|
|
8023
|
+
* const markdown = await Heat.getReport({
|
|
8024
|
+
* strategyName: "my-strategy",
|
|
7650
8025
|
* exchangeName: "binance",
|
|
7651
8026
|
* frameName: "frame1"
|
|
7652
8027
|
* });
|
|
@@ -7663,9 +8038,10 @@ declare class HeatUtils {
|
|
|
7663
8038
|
* // ...
|
|
7664
8039
|
* ```
|
|
7665
8040
|
*/
|
|
7666
|
-
getReport: (
|
|
7667
|
-
|
|
7668
|
-
|
|
8041
|
+
getReport: (context: {
|
|
8042
|
+
strategyName: StrategyName;
|
|
8043
|
+
exchangeName: ExchangeName;
|
|
8044
|
+
frameName: FrameName;
|
|
7669
8045
|
}, backtest?: boolean, columns?: Columns$2[]) => Promise<string>;
|
|
7670
8046
|
/**
|
|
7671
8047
|
* Saves heatmap report to disk for a strategy.
|
|
@@ -7673,8 +8049,7 @@ declare class HeatUtils {
|
|
|
7673
8049
|
* Creates directory if it doesn't exist.
|
|
7674
8050
|
* Default filename: {strategyName}.md
|
|
7675
8051
|
*
|
|
7676
|
-
* @param
|
|
7677
|
-
* @param context - Execution context with exchangeName and frameName
|
|
8052
|
+
* @param context - Execution context with strategyName, exchangeName and frameName
|
|
7678
8053
|
* @param backtest - True if backtest mode, false if live mode (default: false)
|
|
7679
8054
|
* @param path - Optional directory path to save report (default: "./dump/heatmap")
|
|
7680
8055
|
* @param columns - Optional columns configuration for the report
|
|
@@ -7682,21 +8057,24 @@ declare class HeatUtils {
|
|
|
7682
8057
|
* @example
|
|
7683
8058
|
* ```typescript
|
|
7684
8059
|
* // Save to default path: ./dump/heatmap/my-strategy.md
|
|
7685
|
-
* await Heat.dump(
|
|
8060
|
+
* await Heat.dump({
|
|
8061
|
+
* strategyName: "my-strategy",
|
|
7686
8062
|
* exchangeName: "binance",
|
|
7687
8063
|
* frameName: "frame1"
|
|
7688
8064
|
* });
|
|
7689
8065
|
*
|
|
7690
8066
|
* // Save to custom path: ./reports/my-strategy.md
|
|
7691
|
-
* await Heat.dump(
|
|
8067
|
+
* await Heat.dump({
|
|
8068
|
+
* strategyName: "my-strategy",
|
|
7692
8069
|
* exchangeName: "binance",
|
|
7693
8070
|
* frameName: "frame1"
|
|
7694
8071
|
* }, false, "./reports");
|
|
7695
8072
|
* ```
|
|
7696
8073
|
*/
|
|
7697
|
-
dump: (
|
|
7698
|
-
|
|
7699
|
-
|
|
8074
|
+
dump: (context: {
|
|
8075
|
+
strategyName: StrategyName;
|
|
8076
|
+
exchangeName: ExchangeName;
|
|
8077
|
+
frameName: FrameName;
|
|
7700
8078
|
}, backtest?: boolean, path?: string, columns?: Columns$2[]) => Promise<void>;
|
|
7701
8079
|
}
|
|
7702
8080
|
/**
|
|
@@ -7707,7 +8085,11 @@ declare class HeatUtils {
|
|
|
7707
8085
|
* import { Heat } from "backtest-kit";
|
|
7708
8086
|
*
|
|
7709
8087
|
* // Strategy-specific heatmap
|
|
7710
|
-
* const stats = await Heat.getData(
|
|
8088
|
+
* const stats = await Heat.getData({
|
|
8089
|
+
* strategyName: "my-strategy",
|
|
8090
|
+
* exchangeName: "binance",
|
|
8091
|
+
* frameName: "frame1"
|
|
8092
|
+
* });
|
|
7711
8093
|
* console.log(`Portfolio PNL: ${stats.portfolioTotalPnl}%`);
|
|
7712
8094
|
* console.log(`Total Symbols: ${stats.totalSymbols}`);
|
|
7713
8095
|
*
|
|
@@ -7721,7 +8103,11 @@ declare class HeatUtils {
|
|
|
7721
8103
|
* });
|
|
7722
8104
|
*
|
|
7723
8105
|
* // Generate and save report
|
|
7724
|
-
* await Heat.dump(
|
|
8106
|
+
* await Heat.dump({
|
|
8107
|
+
* strategyName: "my-strategy",
|
|
8108
|
+
* exchangeName: "binance",
|
|
8109
|
+
* frameName: "frame1"
|
|
8110
|
+
* }, false, "./reports");
|
|
7725
8111
|
* ```
|
|
7726
8112
|
*/
|
|
7727
8113
|
declare const Heat: HeatUtils;
|
|
@@ -7994,7 +8380,7 @@ declare class PartialMarkdownService {
|
|
|
7994
8380
|
* console.log(stats.totalProfit, stats.totalLoss);
|
|
7995
8381
|
* ```
|
|
7996
8382
|
*/
|
|
7997
|
-
getData: (symbol: string, strategyName:
|
|
8383
|
+
getData: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean) => Promise<PartialStatisticsModel>;
|
|
7998
8384
|
/**
|
|
7999
8385
|
* Generates markdown report with all partial events for a symbol-strategy pair.
|
|
8000
8386
|
* Delegates to ReportStorage.getReport().
|
|
@@ -8014,7 +8400,7 @@ declare class PartialMarkdownService {
|
|
|
8014
8400
|
* console.log(markdown);
|
|
8015
8401
|
* ```
|
|
8016
8402
|
*/
|
|
8017
|
-
getReport: (symbol: string, strategyName:
|
|
8403
|
+
getReport: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, columns?: Columns$1[]) => Promise<string>;
|
|
8018
8404
|
/**
|
|
8019
8405
|
* Saves symbol-strategy report to disk.
|
|
8020
8406
|
* Creates directory if it doesn't exist.
|
|
@@ -8039,7 +8425,7 @@ declare class PartialMarkdownService {
|
|
|
8039
8425
|
* await service.dump("BTCUSDT", "my-strategy", "binance", "1h", false, "./custom/path");
|
|
8040
8426
|
* ```
|
|
8041
8427
|
*/
|
|
8042
|
-
dump: (symbol: string, strategyName:
|
|
8428
|
+
dump: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, path?: string, columns?: Columns$1[]) => Promise<void>;
|
|
8043
8429
|
/**
|
|
8044
8430
|
* Clears accumulated event data from storage.
|
|
8045
8431
|
* If payload is provided, clears only that specific symbol-strategy-exchange-frame-backtest combination's data.
|
|
@@ -8060,9 +8446,9 @@ declare class PartialMarkdownService {
|
|
|
8060
8446
|
*/
|
|
8061
8447
|
clear: (payload?: {
|
|
8062
8448
|
symbol: string;
|
|
8063
|
-
strategyName:
|
|
8064
|
-
exchangeName:
|
|
8065
|
-
frameName:
|
|
8449
|
+
strategyName: StrategyName;
|
|
8450
|
+
exchangeName: ExchangeName;
|
|
8451
|
+
frameName: FrameName;
|
|
8066
8452
|
backtest: boolean;
|
|
8067
8453
|
}) => Promise<void>;
|
|
8068
8454
|
/**
|
|
@@ -8140,9 +8526,9 @@ declare class PartialUtils {
|
|
|
8140
8526
|
* ```
|
|
8141
8527
|
*/
|
|
8142
8528
|
getData: (symbol: string, context: {
|
|
8143
|
-
strategyName:
|
|
8144
|
-
exchangeName:
|
|
8145
|
-
frameName:
|
|
8529
|
+
strategyName: StrategyName;
|
|
8530
|
+
exchangeName: ExchangeName;
|
|
8531
|
+
frameName: FrameName;
|
|
8146
8532
|
}, backtest?: boolean) => Promise<PartialStatisticsModel>;
|
|
8147
8533
|
/**
|
|
8148
8534
|
* Generates markdown report with all partial profit/loss events for a symbol-strategy pair.
|
|
@@ -8184,9 +8570,9 @@ declare class PartialUtils {
|
|
|
8184
8570
|
* ```
|
|
8185
8571
|
*/
|
|
8186
8572
|
getReport: (symbol: string, context: {
|
|
8187
|
-
strategyName:
|
|
8188
|
-
exchangeName:
|
|
8189
|
-
frameName:
|
|
8573
|
+
strategyName: StrategyName;
|
|
8574
|
+
exchangeName: ExchangeName;
|
|
8575
|
+
frameName: FrameName;
|
|
8190
8576
|
}, backtest?: boolean, columns?: Columns$1[]) => Promise<string>;
|
|
8191
8577
|
/**
|
|
8192
8578
|
* Generates and saves markdown report to file.
|
|
@@ -8221,9 +8607,9 @@ declare class PartialUtils {
|
|
|
8221
8607
|
* ```
|
|
8222
8608
|
*/
|
|
8223
8609
|
dump: (symbol: string, context: {
|
|
8224
|
-
strategyName:
|
|
8225
|
-
exchangeName:
|
|
8226
|
-
frameName:
|
|
8610
|
+
strategyName: StrategyName;
|
|
8611
|
+
exchangeName: ExchangeName;
|
|
8612
|
+
frameName: FrameName;
|
|
8227
8613
|
}, backtest?: boolean, path?: string, columns?: Columns$1[]) => Promise<void>;
|
|
8228
8614
|
}
|
|
8229
8615
|
/**
|
|
@@ -8413,7 +8799,7 @@ declare class RiskMarkdownService {
|
|
|
8413
8799
|
* console.log(stats.totalRejections, stats.bySymbol);
|
|
8414
8800
|
* ```
|
|
8415
8801
|
*/
|
|
8416
|
-
getData: (symbol: string, strategyName:
|
|
8802
|
+
getData: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean) => Promise<RiskStatisticsModel>;
|
|
8417
8803
|
/**
|
|
8418
8804
|
* Generates markdown report with all risk rejection events for a symbol-strategy pair.
|
|
8419
8805
|
* Delegates to ReportStorage.getReport().
|
|
@@ -8433,7 +8819,7 @@ declare class RiskMarkdownService {
|
|
|
8433
8819
|
* console.log(markdown);
|
|
8434
8820
|
* ```
|
|
8435
8821
|
*/
|
|
8436
|
-
getReport: (symbol: string, strategyName:
|
|
8822
|
+
getReport: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, columns?: Columns[]) => Promise<string>;
|
|
8437
8823
|
/**
|
|
8438
8824
|
* Saves symbol-strategy report to disk.
|
|
8439
8825
|
* Creates directory if it doesn't exist.
|
|
@@ -8458,7 +8844,7 @@ declare class RiskMarkdownService {
|
|
|
8458
8844
|
* await service.dump("BTCUSDT", "my-strategy", "binance", "1h", false, "./custom/path");
|
|
8459
8845
|
* ```
|
|
8460
8846
|
*/
|
|
8461
|
-
dump: (symbol: string, strategyName:
|
|
8847
|
+
dump: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean, path?: string, columns?: Columns[]) => Promise<void>;
|
|
8462
8848
|
/**
|
|
8463
8849
|
* Clears accumulated event data from storage.
|
|
8464
8850
|
* If payload is provided, clears only that specific symbol-strategy-exchange-frame-backtest combination's data.
|
|
@@ -8479,9 +8865,9 @@ declare class RiskMarkdownService {
|
|
|
8479
8865
|
*/
|
|
8480
8866
|
clear: (payload?: {
|
|
8481
8867
|
symbol: string;
|
|
8482
|
-
strategyName:
|
|
8483
|
-
exchangeName:
|
|
8484
|
-
frameName:
|
|
8868
|
+
strategyName: StrategyName;
|
|
8869
|
+
exchangeName: ExchangeName;
|
|
8870
|
+
frameName: FrameName;
|
|
8485
8871
|
backtest: boolean;
|
|
8486
8872
|
}) => Promise<void>;
|
|
8487
8873
|
/**
|
|
@@ -8559,9 +8945,9 @@ declare class RiskUtils {
|
|
|
8559
8945
|
* ```
|
|
8560
8946
|
*/
|
|
8561
8947
|
getData: (symbol: string, context: {
|
|
8562
|
-
strategyName:
|
|
8563
|
-
exchangeName:
|
|
8564
|
-
frameName:
|
|
8948
|
+
strategyName: StrategyName;
|
|
8949
|
+
exchangeName: ExchangeName;
|
|
8950
|
+
frameName: FrameName;
|
|
8565
8951
|
}, backtest?: boolean) => Promise<RiskStatisticsModel>;
|
|
8566
8952
|
/**
|
|
8567
8953
|
* Generates markdown report with all risk rejection events for a symbol-strategy pair.
|
|
@@ -8605,9 +8991,9 @@ declare class RiskUtils {
|
|
|
8605
8991
|
* ```
|
|
8606
8992
|
*/
|
|
8607
8993
|
getReport: (symbol: string, context: {
|
|
8608
|
-
strategyName:
|
|
8609
|
-
exchangeName:
|
|
8610
|
-
frameName:
|
|
8994
|
+
strategyName: StrategyName;
|
|
8995
|
+
exchangeName: ExchangeName;
|
|
8996
|
+
frameName: FrameName;
|
|
8611
8997
|
}, backtest?: boolean, columns?: Columns[]) => Promise<string>;
|
|
8612
8998
|
/**
|
|
8613
8999
|
* Generates and saves markdown report to file.
|
|
@@ -8642,9 +9028,9 @@ declare class RiskUtils {
|
|
|
8642
9028
|
* ```
|
|
8643
9029
|
*/
|
|
8644
9030
|
dump: (symbol: string, context: {
|
|
8645
|
-
strategyName:
|
|
8646
|
-
exchangeName:
|
|
8647
|
-
frameName:
|
|
9031
|
+
strategyName: StrategyName;
|
|
9032
|
+
exchangeName: ExchangeName;
|
|
9033
|
+
frameName: FrameName;
|
|
8648
9034
|
}, backtest?: boolean, path?: string, columns?: Columns[]) => Promise<void>;
|
|
8649
9035
|
}
|
|
8650
9036
|
/**
|
|
@@ -9475,18 +9861,18 @@ declare class ClientRisk implements IRisk {
|
|
|
9475
9861
|
* Called by StrategyConnectionService after signal is opened.
|
|
9476
9862
|
*/
|
|
9477
9863
|
addSignal(symbol: string, context: {
|
|
9478
|
-
strategyName:
|
|
9479
|
-
riskName:
|
|
9480
|
-
exchangeName:
|
|
9864
|
+
strategyName: StrategyName;
|
|
9865
|
+
riskName: RiskName;
|
|
9866
|
+
exchangeName: ExchangeName;
|
|
9481
9867
|
}): Promise<void>;
|
|
9482
9868
|
/**
|
|
9483
9869
|
* Removes a closed signal.
|
|
9484
9870
|
* Called by StrategyConnectionService when signal is closed.
|
|
9485
9871
|
*/
|
|
9486
9872
|
removeSignal(symbol: string, context: {
|
|
9487
|
-
strategyName:
|
|
9488
|
-
riskName:
|
|
9489
|
-
exchangeName:
|
|
9873
|
+
strategyName: StrategyName;
|
|
9874
|
+
riskName: RiskName;
|
|
9875
|
+
exchangeName: ExchangeName;
|
|
9490
9876
|
}): Promise<void>;
|
|
9491
9877
|
/**
|
|
9492
9878
|
* Checks if a signal should be allowed based on risk limits.
|
|
@@ -9504,6 +9890,14 @@ declare class ClientRisk implements IRisk {
|
|
|
9504
9890
|
checkSignal: (params: IRiskCheckArgs) => Promise<boolean>;
|
|
9505
9891
|
}
|
|
9506
9892
|
|
|
9893
|
+
/**
|
|
9894
|
+
* Type definition for risk methods.
|
|
9895
|
+
* Maps all keys of IRisk to any type.
|
|
9896
|
+
* Used for dynamic method routing in RiskConnectionService.
|
|
9897
|
+
*/
|
|
9898
|
+
type TRisk$1 = {
|
|
9899
|
+
[key in keyof IRisk]: any;
|
|
9900
|
+
};
|
|
9507
9901
|
/**
|
|
9508
9902
|
* Connection service routing risk operations to correct ClientRisk instance.
|
|
9509
9903
|
*
|
|
@@ -9536,7 +9930,7 @@ declare class ClientRisk implements IRisk {
|
|
|
9536
9930
|
* );
|
|
9537
9931
|
* ```
|
|
9538
9932
|
*/
|
|
9539
|
-
declare class RiskConnectionService {
|
|
9933
|
+
declare class RiskConnectionService implements TRisk$1 {
|
|
9540
9934
|
private readonly loggerService;
|
|
9541
9935
|
private readonly riskSchemaService;
|
|
9542
9936
|
/**
|
|
@@ -9551,7 +9945,7 @@ declare class RiskConnectionService {
|
|
|
9551
9945
|
* @param backtest - True if backtest mode, false if live mode
|
|
9552
9946
|
* @returns Configured ClientRisk instance
|
|
9553
9947
|
*/
|
|
9554
|
-
getRisk: ((riskName: RiskName, exchangeName:
|
|
9948
|
+
getRisk: ((riskName: RiskName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean) => ClientRisk) & functools_kit.IClearableMemoize<string> & functools_kit.IControlMemoize<string, ClientRisk>;
|
|
9555
9949
|
/**
|
|
9556
9950
|
* Checks if a signal should be allowed based on risk limits.
|
|
9557
9951
|
*
|
|
@@ -9565,8 +9959,8 @@ declare class RiskConnectionService {
|
|
|
9565
9959
|
*/
|
|
9566
9960
|
checkSignal: (params: IRiskCheckArgs, payload: {
|
|
9567
9961
|
riskName: RiskName;
|
|
9568
|
-
exchangeName:
|
|
9569
|
-
frameName:
|
|
9962
|
+
exchangeName: ExchangeName;
|
|
9963
|
+
frameName: FrameName;
|
|
9570
9964
|
backtest: boolean;
|
|
9571
9965
|
}) => Promise<boolean>;
|
|
9572
9966
|
/**
|
|
@@ -9577,10 +9971,10 @@ declare class RiskConnectionService {
|
|
|
9577
9971
|
* @param payload - Payload information (strategyName, riskName, exchangeName, frameName, backtest)
|
|
9578
9972
|
*/
|
|
9579
9973
|
addSignal: (symbol: string, payload: {
|
|
9580
|
-
strategyName:
|
|
9974
|
+
strategyName: StrategyName;
|
|
9581
9975
|
riskName: RiskName;
|
|
9582
|
-
exchangeName:
|
|
9583
|
-
frameName:
|
|
9976
|
+
exchangeName: ExchangeName;
|
|
9977
|
+
frameName: FrameName;
|
|
9584
9978
|
backtest: boolean;
|
|
9585
9979
|
}) => Promise<void>;
|
|
9586
9980
|
/**
|
|
@@ -9591,10 +9985,10 @@ declare class RiskConnectionService {
|
|
|
9591
9985
|
* @param payload - Payload information (strategyName, riskName, exchangeName, frameName, backtest)
|
|
9592
9986
|
*/
|
|
9593
9987
|
removeSignal: (symbol: string, payload: {
|
|
9594
|
-
strategyName:
|
|
9988
|
+
strategyName: StrategyName;
|
|
9595
9989
|
riskName: RiskName;
|
|
9596
|
-
exchangeName:
|
|
9597
|
-
frameName:
|
|
9990
|
+
exchangeName: ExchangeName;
|
|
9991
|
+
frameName: FrameName;
|
|
9598
9992
|
backtest: boolean;
|
|
9599
9993
|
}) => Promise<void>;
|
|
9600
9994
|
/**
|
|
@@ -9604,8 +9998,8 @@ declare class RiskConnectionService {
|
|
|
9604
9998
|
*/
|
|
9605
9999
|
clear: (payload?: {
|
|
9606
10000
|
riskName: RiskName;
|
|
9607
|
-
exchangeName:
|
|
9608
|
-
frameName:
|
|
10001
|
+
exchangeName: ExchangeName;
|
|
10002
|
+
frameName: FrameName;
|
|
9609
10003
|
backtest: boolean;
|
|
9610
10004
|
}) => Promise<void>;
|
|
9611
10005
|
}
|
|
@@ -9707,6 +10101,14 @@ declare class PartialConnectionService implements IPartial {
|
|
|
9707
10101
|
clear: (symbol: string, data: ISignalRow, priceClose: number, backtest: boolean) => Promise<void>;
|
|
9708
10102
|
}
|
|
9709
10103
|
|
|
10104
|
+
/**
|
|
10105
|
+
* Type definition for strategy methods.
|
|
10106
|
+
* Maps all keys of IStrategy to any type.
|
|
10107
|
+
* Used for dynamic method routing in StrategyConnectionService.
|
|
10108
|
+
*/
|
|
10109
|
+
type TStrategy$1 = {
|
|
10110
|
+
[key in keyof IStrategy]: any;
|
|
10111
|
+
};
|
|
9710
10112
|
/**
|
|
9711
10113
|
* Connection service routing strategy operations to correct ClientStrategy instance.
|
|
9712
10114
|
*
|
|
@@ -9727,11 +10129,14 @@ declare class PartialConnectionService implements IPartial {
|
|
|
9727
10129
|
* // Routes to correct strategy instance for symbol-strategy pair
|
|
9728
10130
|
* ```
|
|
9729
10131
|
*/
|
|
9730
|
-
declare class StrategyConnectionService {
|
|
10132
|
+
declare class StrategyConnectionService implements TStrategy$1 {
|
|
9731
10133
|
readonly loggerService: LoggerService;
|
|
9732
10134
|
readonly executionContextService: {
|
|
9733
10135
|
readonly context: IExecutionContext;
|
|
9734
10136
|
};
|
|
10137
|
+
readonly methodContextService: {
|
|
10138
|
+
readonly context: IMethodContext;
|
|
10139
|
+
};
|
|
9735
10140
|
readonly strategySchemaService: StrategySchemaService;
|
|
9736
10141
|
readonly riskConnectionService: RiskConnectionService;
|
|
9737
10142
|
readonly exchangeConnectionService: ExchangeConnectionService;
|
|
@@ -9763,8 +10168,8 @@ declare class StrategyConnectionService {
|
|
|
9763
10168
|
*/
|
|
9764
10169
|
getPendingSignal: (backtest: boolean, symbol: string, context: {
|
|
9765
10170
|
strategyName: StrategyName;
|
|
9766
|
-
exchangeName:
|
|
9767
|
-
frameName:
|
|
10171
|
+
exchangeName: ExchangeName;
|
|
10172
|
+
frameName: FrameName;
|
|
9768
10173
|
}) => Promise<ISignalRow | null>;
|
|
9769
10174
|
/**
|
|
9770
10175
|
* Retrieves the currently active scheduled signal for the strategy.
|
|
@@ -9779,8 +10184,8 @@ declare class StrategyConnectionService {
|
|
|
9779
10184
|
*/
|
|
9780
10185
|
getScheduledSignal: (backtest: boolean, symbol: string, context: {
|
|
9781
10186
|
strategyName: StrategyName;
|
|
9782
|
-
exchangeName:
|
|
9783
|
-
frameName:
|
|
10187
|
+
exchangeName: ExchangeName;
|
|
10188
|
+
frameName: FrameName;
|
|
9784
10189
|
}) => Promise<IScheduledSignalRow | null>;
|
|
9785
10190
|
/**
|
|
9786
10191
|
* Retrieves the stopped state of the strategy.
|
|
@@ -9795,8 +10200,8 @@ declare class StrategyConnectionService {
|
|
|
9795
10200
|
*/
|
|
9796
10201
|
getStopped: (backtest: boolean, symbol: string, context: {
|
|
9797
10202
|
strategyName: StrategyName;
|
|
9798
|
-
exchangeName:
|
|
9799
|
-
frameName:
|
|
10203
|
+
exchangeName: ExchangeName;
|
|
10204
|
+
frameName: FrameName;
|
|
9800
10205
|
}) => Promise<boolean>;
|
|
9801
10206
|
/**
|
|
9802
10207
|
* Executes live trading tick for current strategy.
|
|
@@ -9810,8 +10215,8 @@ declare class StrategyConnectionService {
|
|
|
9810
10215
|
*/
|
|
9811
10216
|
tick: (symbol: string, context: {
|
|
9812
10217
|
strategyName: StrategyName;
|
|
9813
|
-
exchangeName:
|
|
9814
|
-
frameName:
|
|
10218
|
+
exchangeName: ExchangeName;
|
|
10219
|
+
frameName: FrameName;
|
|
9815
10220
|
}) => Promise<IStrategyTickResult>;
|
|
9816
10221
|
/**
|
|
9817
10222
|
* Executes backtest for current strategy with provided candles.
|
|
@@ -9826,8 +10231,8 @@ declare class StrategyConnectionService {
|
|
|
9826
10231
|
*/
|
|
9827
10232
|
backtest: (symbol: string, context: {
|
|
9828
10233
|
strategyName: StrategyName;
|
|
9829
|
-
exchangeName:
|
|
9830
|
-
frameName:
|
|
10234
|
+
exchangeName: ExchangeName;
|
|
10235
|
+
frameName: FrameName;
|
|
9831
10236
|
}, candles: ICandleData[]) => Promise<IStrategyBacktestResult>;
|
|
9832
10237
|
/**
|
|
9833
10238
|
* Stops the specified strategy from generating new signals.
|
|
@@ -9842,8 +10247,8 @@ declare class StrategyConnectionService {
|
|
|
9842
10247
|
*/
|
|
9843
10248
|
stop: (backtest: boolean, symbol: string, context: {
|
|
9844
10249
|
strategyName: StrategyName;
|
|
9845
|
-
exchangeName:
|
|
9846
|
-
frameName:
|
|
10250
|
+
exchangeName: ExchangeName;
|
|
10251
|
+
frameName: FrameName;
|
|
9847
10252
|
}) => Promise<void>;
|
|
9848
10253
|
/**
|
|
9849
10254
|
* Clears the memoized ClientStrategy instance from cache.
|
|
@@ -9856,8 +10261,8 @@ declare class StrategyConnectionService {
|
|
|
9856
10261
|
clear: (payload?: {
|
|
9857
10262
|
symbol: string;
|
|
9858
10263
|
strategyName: StrategyName;
|
|
9859
|
-
exchangeName:
|
|
9860
|
-
frameName:
|
|
10264
|
+
exchangeName: ExchangeName;
|
|
10265
|
+
frameName: FrameName;
|
|
9861
10266
|
backtest: boolean;
|
|
9862
10267
|
}) => Promise<void>;
|
|
9863
10268
|
/**
|
|
@@ -9877,9 +10282,73 @@ declare class StrategyConnectionService {
|
|
|
9877
10282
|
*/
|
|
9878
10283
|
cancel: (backtest: boolean, symbol: string, context: {
|
|
9879
10284
|
strategyName: StrategyName;
|
|
9880
|
-
exchangeName:
|
|
9881
|
-
frameName:
|
|
10285
|
+
exchangeName: ExchangeName;
|
|
10286
|
+
frameName: FrameName;
|
|
9882
10287
|
}, cancelId?: string) => Promise<void>;
|
|
10288
|
+
/**
|
|
10289
|
+
* Executes partial close at profit level (moving toward TP).
|
|
10290
|
+
*
|
|
10291
|
+
* Closes a percentage of the pending position at the current price, recording it as a "profit" type partial.
|
|
10292
|
+
* The partial close is tracked in `_partial` array for weighted PNL calculation when position fully closes.
|
|
10293
|
+
*
|
|
10294
|
+
* Delegates to ClientStrategy.partialProfit() with current execution context.
|
|
10295
|
+
*
|
|
10296
|
+
* @param backtest - Whether running in backtest mode
|
|
10297
|
+
* @param symbol - Trading pair symbol
|
|
10298
|
+
* @param context - Execution context with strategyName, exchangeName, frameName
|
|
10299
|
+
* @param percentToClose - Percentage of position to close (0-100, absolute value)
|
|
10300
|
+
* @param currentPrice - Current market price for this partial close
|
|
10301
|
+
* @returns Promise that resolves when state is updated and persisted
|
|
10302
|
+
*
|
|
10303
|
+
* @example
|
|
10304
|
+
* ```typescript
|
|
10305
|
+
* // Close 30% of position at profit
|
|
10306
|
+
* await strategyConnectionService.partialProfit(
|
|
10307
|
+
* false,
|
|
10308
|
+
* "BTCUSDT",
|
|
10309
|
+
* { strategyName: "my-strategy", exchangeName: "binance", frameName: "" },
|
|
10310
|
+
* 30,
|
|
10311
|
+
* 45000
|
|
10312
|
+
* );
|
|
10313
|
+
* ```
|
|
10314
|
+
*/
|
|
10315
|
+
partialProfit: (backtest: boolean, symbol: string, percentToClose: number, currentPrice: number, context: {
|
|
10316
|
+
strategyName: StrategyName;
|
|
10317
|
+
exchangeName: ExchangeName;
|
|
10318
|
+
frameName: FrameName;
|
|
10319
|
+
}) => Promise<void>;
|
|
10320
|
+
/**
|
|
10321
|
+
* Executes partial close at loss level (moving toward SL).
|
|
10322
|
+
*
|
|
10323
|
+
* Closes a percentage of the pending position at the current price, recording it as a "loss" type partial.
|
|
10324
|
+
* The partial close is tracked in `_partial` array for weighted PNL calculation when position fully closes.
|
|
10325
|
+
*
|
|
10326
|
+
* Delegates to ClientStrategy.partialLoss() with current execution context.
|
|
10327
|
+
*
|
|
10328
|
+
* @param backtest - Whether running in backtest mode
|
|
10329
|
+
* @param symbol - Trading pair symbol
|
|
10330
|
+
* @param context - Execution context with strategyName, exchangeName, frameName
|
|
10331
|
+
* @param percentToClose - Percentage of position to close (0-100, absolute value)
|
|
10332
|
+
* @param currentPrice - Current market price for this partial close
|
|
10333
|
+
* @returns Promise that resolves when state is updated and persisted
|
|
10334
|
+
*
|
|
10335
|
+
* @example
|
|
10336
|
+
* ```typescript
|
|
10337
|
+
* // Close 40% of position at loss
|
|
10338
|
+
* await strategyConnectionService.partialLoss(
|
|
10339
|
+
* false,
|
|
10340
|
+
* "BTCUSDT",
|
|
10341
|
+
* { strategyName: "my-strategy", exchangeName: "binance", frameName: "" },
|
|
10342
|
+
* 40,
|
|
10343
|
+
* 38000
|
|
10344
|
+
* );
|
|
10345
|
+
* ```
|
|
10346
|
+
*/
|
|
10347
|
+
partialLoss: (backtest: boolean, symbol: string, percentToClose: number, currentPrice: number, context: {
|
|
10348
|
+
strategyName: StrategyName;
|
|
10349
|
+
exchangeName: ExchangeName;
|
|
10350
|
+
frameName: FrameName;
|
|
10351
|
+
}) => Promise<void>;
|
|
9883
10352
|
}
|
|
9884
10353
|
|
|
9885
10354
|
/**
|
|
@@ -9952,7 +10421,7 @@ declare class FrameConnectionService implements IFrame {
|
|
|
9952
10421
|
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
9953
10422
|
* @returns Promise resolving to { startDate: Date, endDate: Date }
|
|
9954
10423
|
*/
|
|
9955
|
-
getTimeframe: (symbol: string, frameName:
|
|
10424
|
+
getTimeframe: (symbol: string, frameName: FrameName) => Promise<Date[]>;
|
|
9956
10425
|
}
|
|
9957
10426
|
|
|
9958
10427
|
/**
|
|
@@ -9979,6 +10448,14 @@ declare class ClientSizing implements ISizing {
|
|
|
9979
10448
|
calculate(params: ISizingCalculateParams): Promise<number>;
|
|
9980
10449
|
}
|
|
9981
10450
|
|
|
10451
|
+
/**
|
|
10452
|
+
* Type definition for sizing methods.
|
|
10453
|
+
* Maps all keys of ISizing to any type.
|
|
10454
|
+
* Used for dynamic method routing in SizingConnectionService.
|
|
10455
|
+
*/
|
|
10456
|
+
type TSizing$1 = {
|
|
10457
|
+
[key in keyof ISizing]: any;
|
|
10458
|
+
};
|
|
9982
10459
|
/**
|
|
9983
10460
|
* Connection service routing sizing operations to correct ClientSizing instance.
|
|
9984
10461
|
*
|
|
@@ -10008,7 +10485,7 @@ declare class ClientSizing implements ISizing {
|
|
|
10008
10485
|
* );
|
|
10009
10486
|
* ```
|
|
10010
10487
|
*/
|
|
10011
|
-
declare class SizingConnectionService {
|
|
10488
|
+
declare class SizingConnectionService implements TSizing$1 {
|
|
10012
10489
|
private readonly loggerService;
|
|
10013
10490
|
private readonly sizingSchemaService;
|
|
10014
10491
|
/**
|
|
@@ -10036,6 +10513,14 @@ declare class SizingConnectionService {
|
|
|
10036
10513
|
}) => Promise<number>;
|
|
10037
10514
|
}
|
|
10038
10515
|
|
|
10516
|
+
/**
|
|
10517
|
+
* Type definition for exchange methods.
|
|
10518
|
+
* Maps all keys of IExchange to any type.
|
|
10519
|
+
* Used for dynamic method routing in ExchangeCoreService.
|
|
10520
|
+
*/
|
|
10521
|
+
type TExchange = {
|
|
10522
|
+
[key in keyof IExchange]: any;
|
|
10523
|
+
};
|
|
10039
10524
|
/**
|
|
10040
10525
|
* Global service for exchange operations with execution context injection.
|
|
10041
10526
|
*
|
|
@@ -10044,7 +10529,7 @@ declare class SizingConnectionService {
|
|
|
10044
10529
|
*
|
|
10045
10530
|
* Used internally by BacktestLogicPrivateService and LiveLogicPrivateService.
|
|
10046
10531
|
*/
|
|
10047
|
-
declare class ExchangeCoreService {
|
|
10532
|
+
declare class ExchangeCoreService implements TExchange {
|
|
10048
10533
|
private readonly loggerService;
|
|
10049
10534
|
private readonly exchangeConnectionService;
|
|
10050
10535
|
private readonly methodContextService;
|
|
@@ -10110,6 +10595,14 @@ declare class ExchangeCoreService {
|
|
|
10110
10595
|
formatQuantity: (symbol: string, quantity: number, when: Date, backtest: boolean) => Promise<string>;
|
|
10111
10596
|
}
|
|
10112
10597
|
|
|
10598
|
+
/**
|
|
10599
|
+
* Type definition for strategy methods.
|
|
10600
|
+
* Maps all keys of IStrategy to any type.
|
|
10601
|
+
* Used for dynamic method routing in StrategyCoreService.
|
|
10602
|
+
*/
|
|
10603
|
+
type TStrategy = {
|
|
10604
|
+
[key in keyof IStrategy]: any;
|
|
10605
|
+
};
|
|
10113
10606
|
/**
|
|
10114
10607
|
* Global service for strategy operations with execution context injection.
|
|
10115
10608
|
*
|
|
@@ -10118,7 +10611,7 @@ declare class ExchangeCoreService {
|
|
|
10118
10611
|
*
|
|
10119
10612
|
* Used internally by BacktestLogicPrivateService and LiveLogicPrivateService.
|
|
10120
10613
|
*/
|
|
10121
|
-
declare class StrategyCoreService {
|
|
10614
|
+
declare class StrategyCoreService implements TStrategy {
|
|
10122
10615
|
private readonly loggerService;
|
|
10123
10616
|
private readonly strategyConnectionService;
|
|
10124
10617
|
private readonly strategySchemaService;
|
|
@@ -10127,10 +10620,10 @@ declare class StrategyCoreService {
|
|
|
10127
10620
|
/**
|
|
10128
10621
|
* Validates strategy and associated risk configuration.
|
|
10129
10622
|
*
|
|
10130
|
-
* Memoized to avoid redundant validations for the same symbol-strategy
|
|
10623
|
+
* Memoized to avoid redundant validations for the same symbol-strategy-exchange-frame combination.
|
|
10131
10624
|
* Logs validation activity.
|
|
10132
10625
|
* @param symbol - Trading pair symbol
|
|
10133
|
-
* @param
|
|
10626
|
+
* @param context - Execution context with strategyName, exchangeName, frameName
|
|
10134
10627
|
* @returns Promise that resolves when validation is complete
|
|
10135
10628
|
*/
|
|
10136
10629
|
private validate;
|
|
@@ -10146,8 +10639,8 @@ declare class StrategyCoreService {
|
|
|
10146
10639
|
*/
|
|
10147
10640
|
getPendingSignal: (backtest: boolean, symbol: string, context: {
|
|
10148
10641
|
strategyName: StrategyName;
|
|
10149
|
-
exchangeName:
|
|
10150
|
-
frameName:
|
|
10642
|
+
exchangeName: ExchangeName;
|
|
10643
|
+
frameName: FrameName;
|
|
10151
10644
|
}) => Promise<ISignalRow | null>;
|
|
10152
10645
|
/**
|
|
10153
10646
|
* Retrieves the currently active scheduled signal for the symbol.
|
|
@@ -10161,8 +10654,8 @@ declare class StrategyCoreService {
|
|
|
10161
10654
|
*/
|
|
10162
10655
|
getScheduledSignal: (backtest: boolean, symbol: string, context: {
|
|
10163
10656
|
strategyName: StrategyName;
|
|
10164
|
-
exchangeName:
|
|
10165
|
-
frameName:
|
|
10657
|
+
exchangeName: ExchangeName;
|
|
10658
|
+
frameName: FrameName;
|
|
10166
10659
|
}) => Promise<IScheduledSignalRow | null>;
|
|
10167
10660
|
/**
|
|
10168
10661
|
* Checks if the strategy has been stopped.
|
|
@@ -10177,8 +10670,8 @@ declare class StrategyCoreService {
|
|
|
10177
10670
|
*/
|
|
10178
10671
|
getStopped: (backtest: boolean, symbol: string, context: {
|
|
10179
10672
|
strategyName: StrategyName;
|
|
10180
|
-
exchangeName:
|
|
10181
|
-
frameName:
|
|
10673
|
+
exchangeName: ExchangeName;
|
|
10674
|
+
frameName: FrameName;
|
|
10182
10675
|
}) => Promise<boolean>;
|
|
10183
10676
|
/**
|
|
10184
10677
|
* Checks signal status at a specific timestamp.
|
|
@@ -10194,8 +10687,8 @@ declare class StrategyCoreService {
|
|
|
10194
10687
|
*/
|
|
10195
10688
|
tick: (symbol: string, when: Date, backtest: boolean, context: {
|
|
10196
10689
|
strategyName: StrategyName;
|
|
10197
|
-
exchangeName:
|
|
10198
|
-
frameName:
|
|
10690
|
+
exchangeName: ExchangeName;
|
|
10691
|
+
frameName: FrameName;
|
|
10199
10692
|
}) => Promise<IStrategyTickResult>;
|
|
10200
10693
|
/**
|
|
10201
10694
|
* Runs fast backtest against candle array.
|
|
@@ -10212,8 +10705,8 @@ declare class StrategyCoreService {
|
|
|
10212
10705
|
*/
|
|
10213
10706
|
backtest: (symbol: string, candles: ICandleData[], when: Date, backtest: boolean, context: {
|
|
10214
10707
|
strategyName: StrategyName;
|
|
10215
|
-
exchangeName:
|
|
10216
|
-
frameName:
|
|
10708
|
+
exchangeName: ExchangeName;
|
|
10709
|
+
frameName: FrameName;
|
|
10217
10710
|
}) => Promise<IStrategyBacktestResult>;
|
|
10218
10711
|
/**
|
|
10219
10712
|
* Stops the strategy from generating new signals.
|
|
@@ -10228,8 +10721,8 @@ declare class StrategyCoreService {
|
|
|
10228
10721
|
*/
|
|
10229
10722
|
stop: (backtest: boolean, symbol: string, context: {
|
|
10230
10723
|
strategyName: StrategyName;
|
|
10231
|
-
exchangeName:
|
|
10232
|
-
frameName:
|
|
10724
|
+
exchangeName: ExchangeName;
|
|
10725
|
+
frameName: FrameName;
|
|
10233
10726
|
}) => Promise<void>;
|
|
10234
10727
|
/**
|
|
10235
10728
|
* Cancels the scheduled signal without stopping the strategy.
|
|
@@ -10246,8 +10739,8 @@ declare class StrategyCoreService {
|
|
|
10246
10739
|
*/
|
|
10247
10740
|
cancel: (backtest: boolean, symbol: string, context: {
|
|
10248
10741
|
strategyName: StrategyName;
|
|
10249
|
-
exchangeName:
|
|
10250
|
-
frameName:
|
|
10742
|
+
exchangeName: ExchangeName;
|
|
10743
|
+
frameName: FrameName;
|
|
10251
10744
|
}, cancelId?: string) => Promise<void>;
|
|
10252
10745
|
/**
|
|
10253
10746
|
* Clears the memoized ClientStrategy instance from cache.
|
|
@@ -10260,19 +10753,91 @@ declare class StrategyCoreService {
|
|
|
10260
10753
|
clear: (payload?: {
|
|
10261
10754
|
symbol: string;
|
|
10262
10755
|
strategyName: StrategyName;
|
|
10263
|
-
exchangeName:
|
|
10264
|
-
frameName:
|
|
10756
|
+
exchangeName: ExchangeName;
|
|
10757
|
+
frameName: FrameName;
|
|
10265
10758
|
backtest: boolean;
|
|
10266
10759
|
}) => Promise<void>;
|
|
10760
|
+
/**
|
|
10761
|
+
* Executes partial close at profit level (moving toward TP).
|
|
10762
|
+
*
|
|
10763
|
+
* Validates strategy existence and delegates to connection service
|
|
10764
|
+
* to close a percentage of the pending position at profit.
|
|
10765
|
+
*
|
|
10766
|
+
* Does not require execution context as this is a direct state mutation.
|
|
10767
|
+
*
|
|
10768
|
+
* @param backtest - Whether running in backtest mode
|
|
10769
|
+
* @param symbol - Trading pair symbol
|
|
10770
|
+
* @param percentToClose - Percentage of position to close (0-100, absolute value)
|
|
10771
|
+
* @param currentPrice - Current market price for this partial close (must be in profit direction)
|
|
10772
|
+
* @param context - Execution context with strategyName, exchangeName, frameName
|
|
10773
|
+
* @returns Promise that resolves when state is updated and persisted
|
|
10774
|
+
*
|
|
10775
|
+
* @example
|
|
10776
|
+
* ```typescript
|
|
10777
|
+
* // Close 30% of position at profit
|
|
10778
|
+
* await strategyCoreService.partialProfit(
|
|
10779
|
+
* false,
|
|
10780
|
+
* "BTCUSDT",
|
|
10781
|
+
* 30,
|
|
10782
|
+
* 45000,
|
|
10783
|
+
* { strategyName: "my-strategy", exchangeName: "binance", frameName: "" }
|
|
10784
|
+
* );
|
|
10785
|
+
* ```
|
|
10786
|
+
*/
|
|
10787
|
+
partialProfit: (backtest: boolean, symbol: string, percentToClose: number, currentPrice: number, context: {
|
|
10788
|
+
strategyName: StrategyName;
|
|
10789
|
+
exchangeName: ExchangeName;
|
|
10790
|
+
frameName: FrameName;
|
|
10791
|
+
}) => Promise<void>;
|
|
10792
|
+
/**
|
|
10793
|
+
* Executes partial close at loss level (moving toward SL).
|
|
10794
|
+
*
|
|
10795
|
+
* Validates strategy existence and delegates to connection service
|
|
10796
|
+
* to close a percentage of the pending position at loss.
|
|
10797
|
+
*
|
|
10798
|
+
* Does not require execution context as this is a direct state mutation.
|
|
10799
|
+
*
|
|
10800
|
+
* @param backtest - Whether running in backtest mode
|
|
10801
|
+
* @param symbol - Trading pair symbol
|
|
10802
|
+
* @param percentToClose - Percentage of position to close (0-100, absolute value)
|
|
10803
|
+
* @param currentPrice - Current market price for this partial close (must be in loss direction)
|
|
10804
|
+
* @param context - Execution context with strategyName, exchangeName, frameName
|
|
10805
|
+
* @returns Promise that resolves when state is updated and persisted
|
|
10806
|
+
*
|
|
10807
|
+
* @example
|
|
10808
|
+
* ```typescript
|
|
10809
|
+
* // Close 40% of position at loss
|
|
10810
|
+
* await strategyCoreService.partialLoss(
|
|
10811
|
+
* false,
|
|
10812
|
+
* "BTCUSDT",
|
|
10813
|
+
* 40,
|
|
10814
|
+
* 38000,
|
|
10815
|
+
* { strategyName: "my-strategy", exchangeName: "binance", frameName: "" }
|
|
10816
|
+
* );
|
|
10817
|
+
* ```
|
|
10818
|
+
*/
|
|
10819
|
+
partialLoss: (backtest: boolean, symbol: string, percentToClose: number, currentPrice: number, context: {
|
|
10820
|
+
strategyName: StrategyName;
|
|
10821
|
+
exchangeName: ExchangeName;
|
|
10822
|
+
frameName: FrameName;
|
|
10823
|
+
}) => Promise<void>;
|
|
10267
10824
|
}
|
|
10268
10825
|
|
|
10826
|
+
/**
|
|
10827
|
+
* Type definition for frame methods.
|
|
10828
|
+
* Maps all keys of IFrame to any type.
|
|
10829
|
+
* Used for dynamic method routing in FrameCoreService.
|
|
10830
|
+
*/
|
|
10831
|
+
type TFrame = {
|
|
10832
|
+
[key in keyof IFrame]: any;
|
|
10833
|
+
};
|
|
10269
10834
|
/**
|
|
10270
10835
|
* Global service for frame operations.
|
|
10271
10836
|
*
|
|
10272
10837
|
* Wraps FrameConnectionService for timeframe generation.
|
|
10273
10838
|
* Used internally by BacktestLogicPrivateService.
|
|
10274
10839
|
*/
|
|
10275
|
-
declare class FrameCoreService {
|
|
10840
|
+
declare class FrameCoreService implements TFrame {
|
|
10276
10841
|
private readonly loggerService;
|
|
10277
10842
|
private readonly frameConnectionService;
|
|
10278
10843
|
private readonly frameValidationService;
|
|
@@ -10282,16 +10847,24 @@ declare class FrameCoreService {
|
|
|
10282
10847
|
* @param frameName - Target frame name (e.g., "1m", "1h")
|
|
10283
10848
|
* @returns Promise resolving to array of Date objects
|
|
10284
10849
|
*/
|
|
10285
|
-
getTimeframe: (symbol: string, frameName:
|
|
10850
|
+
getTimeframe: (symbol: string, frameName: FrameName) => Promise<Date[]>;
|
|
10286
10851
|
}
|
|
10287
10852
|
|
|
10853
|
+
/**
|
|
10854
|
+
* Type definition for sizing methods.
|
|
10855
|
+
* Maps all keys of ISizing to any type.
|
|
10856
|
+
* Used for dynamic method routing in SizingGlobalService.
|
|
10857
|
+
*/
|
|
10858
|
+
type TSizing = {
|
|
10859
|
+
[key in keyof ISizing]: any;
|
|
10860
|
+
};
|
|
10288
10861
|
/**
|
|
10289
10862
|
* Global service for sizing operations.
|
|
10290
10863
|
*
|
|
10291
10864
|
* Wraps SizingConnectionService for position size calculation.
|
|
10292
10865
|
* Used internally by strategy execution and public API.
|
|
10293
10866
|
*/
|
|
10294
|
-
declare class SizingGlobalService {
|
|
10867
|
+
declare class SizingGlobalService implements TSizing {
|
|
10295
10868
|
private readonly loggerService;
|
|
10296
10869
|
private readonly sizingConnectionService;
|
|
10297
10870
|
private readonly sizingValidationService;
|
|
@@ -10307,21 +10880,29 @@ declare class SizingGlobalService {
|
|
|
10307
10880
|
}) => Promise<number>;
|
|
10308
10881
|
}
|
|
10309
10882
|
|
|
10883
|
+
/**
|
|
10884
|
+
* Type definition for risk methods.
|
|
10885
|
+
* Maps all keys of IRisk to any type.
|
|
10886
|
+
* Used for dynamic method routing in RiskGlobalService.
|
|
10887
|
+
*/
|
|
10888
|
+
type TRisk = {
|
|
10889
|
+
[key in keyof IRisk]: any;
|
|
10890
|
+
};
|
|
10310
10891
|
/**
|
|
10311
10892
|
* Global service for risk operations.
|
|
10312
10893
|
*
|
|
10313
10894
|
* Wraps RiskConnectionService for risk limit validation.
|
|
10314
10895
|
* Used internally by strategy execution and public API.
|
|
10315
10896
|
*/
|
|
10316
|
-
declare class RiskGlobalService {
|
|
10897
|
+
declare class RiskGlobalService implements TRisk {
|
|
10317
10898
|
private readonly loggerService;
|
|
10318
10899
|
private readonly riskConnectionService;
|
|
10319
10900
|
private readonly riskValidationService;
|
|
10320
10901
|
/**
|
|
10321
10902
|
* Validates risk configuration.
|
|
10322
|
-
* Memoized to avoid redundant validations for the same risk
|
|
10903
|
+
* Memoized to avoid redundant validations for the same risk-exchange-frame combination.
|
|
10323
10904
|
* Logs validation activity.
|
|
10324
|
-
* @param
|
|
10905
|
+
* @param payload - Payload with riskName, exchangeName and frameName
|
|
10325
10906
|
* @returns Promise that resolves when validation is complete
|
|
10326
10907
|
*/
|
|
10327
10908
|
private validate;
|
|
@@ -10334,8 +10915,8 @@ declare class RiskGlobalService {
|
|
|
10334
10915
|
*/
|
|
10335
10916
|
checkSignal: (params: IRiskCheckArgs, payload: {
|
|
10336
10917
|
riskName: RiskName;
|
|
10337
|
-
exchangeName:
|
|
10338
|
-
frameName:
|
|
10918
|
+
exchangeName: ExchangeName;
|
|
10919
|
+
frameName: FrameName;
|
|
10339
10920
|
backtest: boolean;
|
|
10340
10921
|
}) => Promise<boolean>;
|
|
10341
10922
|
/**
|
|
@@ -10345,10 +10926,10 @@ declare class RiskGlobalService {
|
|
|
10345
10926
|
* @param payload - Payload information (strategyName, riskName, exchangeName, frameName, backtest)
|
|
10346
10927
|
*/
|
|
10347
10928
|
addSignal: (symbol: string, payload: {
|
|
10348
|
-
strategyName:
|
|
10929
|
+
strategyName: StrategyName;
|
|
10349
10930
|
riskName: RiskName;
|
|
10350
|
-
exchangeName:
|
|
10351
|
-
frameName:
|
|
10931
|
+
exchangeName: ExchangeName;
|
|
10932
|
+
frameName: FrameName;
|
|
10352
10933
|
backtest: boolean;
|
|
10353
10934
|
}) => Promise<void>;
|
|
10354
10935
|
/**
|
|
@@ -10358,10 +10939,10 @@ declare class RiskGlobalService {
|
|
|
10358
10939
|
* @param payload - Payload information (strategyName, riskName, exchangeName, frameName, backtest)
|
|
10359
10940
|
*/
|
|
10360
10941
|
removeSignal: (symbol: string, payload: {
|
|
10361
|
-
strategyName:
|
|
10942
|
+
strategyName: StrategyName;
|
|
10362
10943
|
riskName: RiskName;
|
|
10363
|
-
exchangeName:
|
|
10364
|
-
frameName:
|
|
10944
|
+
exchangeName: ExchangeName;
|
|
10945
|
+
frameName: FrameName;
|
|
10365
10946
|
backtest: boolean;
|
|
10366
10947
|
}) => Promise<void>;
|
|
10367
10948
|
/**
|
|
@@ -10372,19 +10953,133 @@ declare class RiskGlobalService {
|
|
|
10372
10953
|
*/
|
|
10373
10954
|
clear: (payload?: {
|
|
10374
10955
|
riskName: RiskName;
|
|
10375
|
-
exchangeName:
|
|
10376
|
-
frameName:
|
|
10956
|
+
exchangeName: ExchangeName;
|
|
10957
|
+
frameName: FrameName;
|
|
10377
10958
|
backtest: boolean;
|
|
10378
10959
|
}) => Promise<void>;
|
|
10379
10960
|
}
|
|
10380
10961
|
|
|
10962
|
+
/**
|
|
10963
|
+
* Private service for walker orchestration (strategy comparison).
|
|
10964
|
+
*
|
|
10965
|
+
* Flow:
|
|
10966
|
+
* 1. Yields progress updates as each strategy completes
|
|
10967
|
+
* 2. Tracks best metric in real-time
|
|
10968
|
+
* 3. Returns final results with all strategies ranked
|
|
10969
|
+
*
|
|
10970
|
+
* Uses BacktestLogicPublicService internally for each strategy.
|
|
10971
|
+
*/
|
|
10972
|
+
declare class WalkerLogicPrivateService {
|
|
10973
|
+
private readonly loggerService;
|
|
10974
|
+
private readonly backtestLogicPublicService;
|
|
10975
|
+
private readonly backtestMarkdownService;
|
|
10976
|
+
private readonly walkerSchemaService;
|
|
10977
|
+
/**
|
|
10978
|
+
* Runs walker comparison for a symbol.
|
|
10979
|
+
*
|
|
10980
|
+
* Executes backtest for each strategy sequentially.
|
|
10981
|
+
* Yields WalkerContract after each strategy completes.
|
|
10982
|
+
*
|
|
10983
|
+
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
10984
|
+
* @param strategies - List of strategy names to compare
|
|
10985
|
+
* @param metric - Metric to use for comparison
|
|
10986
|
+
* @param context - Walker context with exchangeName, frameName, walkerName
|
|
10987
|
+
* @yields WalkerContract with progress after each strategy
|
|
10988
|
+
*
|
|
10989
|
+
* @example
|
|
10990
|
+
* ```typescript
|
|
10991
|
+
* for await (const progress of walkerLogic.run(
|
|
10992
|
+
* "BTCUSDT",
|
|
10993
|
+
* ["strategy-v1", "strategy-v2"],
|
|
10994
|
+
* "sharpeRatio",
|
|
10995
|
+
* {
|
|
10996
|
+
* exchangeName: "binance",
|
|
10997
|
+
* frameName: "1d-backtest",
|
|
10998
|
+
* walkerName: "my-optimizer"
|
|
10999
|
+
* }
|
|
11000
|
+
* )) {
|
|
11001
|
+
* console.log("Progress:", progress.strategiesTested, "/", progress.totalStrategies);
|
|
11002
|
+
* }
|
|
11003
|
+
* ```
|
|
11004
|
+
*/
|
|
11005
|
+
run(symbol: string, strategies: StrategyName[], metric: WalkerMetric, context: {
|
|
11006
|
+
exchangeName: ExchangeName;
|
|
11007
|
+
frameName: FrameName;
|
|
11008
|
+
walkerName: WalkerName;
|
|
11009
|
+
}): AsyncGenerator<WalkerContract>;
|
|
11010
|
+
}
|
|
11011
|
+
|
|
11012
|
+
/**
|
|
11013
|
+
* Type definition for public WalkerLogic service.
|
|
11014
|
+
* Omits private dependencies from WalkerLogicPrivateService.
|
|
11015
|
+
*/
|
|
11016
|
+
type IWalkerLogicPrivateService = Omit<WalkerLogicPrivateService, keyof {
|
|
11017
|
+
loggerService: never;
|
|
11018
|
+
walkerSchemaService: never;
|
|
11019
|
+
backtestMarkdownService: never;
|
|
11020
|
+
backtestLogicPublicService: never;
|
|
11021
|
+
}>;
|
|
11022
|
+
/**
|
|
11023
|
+
* Type definition for WalkerLogicPublicService.
|
|
11024
|
+
* Maps all keys of IWalkerLogicPrivateService to any type.
|
|
11025
|
+
*/
|
|
11026
|
+
type TWalkerLogicPrivateService = {
|
|
11027
|
+
[key in keyof IWalkerLogicPrivateService]: any;
|
|
11028
|
+
};
|
|
11029
|
+
/**
|
|
11030
|
+
* Public service for walker orchestration with context management.
|
|
11031
|
+
*
|
|
11032
|
+
* Wraps WalkerLogicPrivateService with MethodContextService to provide
|
|
11033
|
+
* implicit context propagation for strategyName, exchangeName, frameName, and walkerName.
|
|
11034
|
+
*
|
|
11035
|
+
* @example
|
|
11036
|
+
* ```typescript
|
|
11037
|
+
* const walkerLogicPublicService = inject(TYPES.walkerLogicPublicService);
|
|
11038
|
+
*
|
|
11039
|
+
* const results = await walkerLogicPublicService.run("BTCUSDT", {
|
|
11040
|
+
* walkerName: "my-optimizer",
|
|
11041
|
+
* exchangeName: "binance",
|
|
11042
|
+
* frameName: "1d-backtest",
|
|
11043
|
+
* strategies: ["strategy-v1", "strategy-v2"],
|
|
11044
|
+
* metric: "sharpeRatio",
|
|
11045
|
+
* });
|
|
11046
|
+
*
|
|
11047
|
+
* console.log("Best strategy:", results.bestStrategy);
|
|
11048
|
+
* ```
|
|
11049
|
+
*/
|
|
11050
|
+
declare class WalkerLogicPublicService implements TWalkerLogicPrivateService {
|
|
11051
|
+
private readonly loggerService;
|
|
11052
|
+
private readonly walkerLogicPrivateService;
|
|
11053
|
+
private readonly walkerSchemaService;
|
|
11054
|
+
/**
|
|
11055
|
+
* Runs walker comparison for a symbol with context propagation.
|
|
11056
|
+
*
|
|
11057
|
+
* Executes backtests for all strategies.
|
|
11058
|
+
*
|
|
11059
|
+
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
11060
|
+
* @param context - Walker context with strategies and metric
|
|
11061
|
+
*/
|
|
11062
|
+
run: (symbol: string, context: {
|
|
11063
|
+
walkerName: WalkerName;
|
|
11064
|
+
exchangeName: ExchangeName;
|
|
11065
|
+
frameName: FrameName;
|
|
11066
|
+
}) => AsyncGenerator<WalkerContract, any, any>;
|
|
11067
|
+
}
|
|
11068
|
+
|
|
11069
|
+
/**
|
|
11070
|
+
* Type definition for WalkerLogicPublicService.
|
|
11071
|
+
* Maps all keys of WalkerLogicPublicService to any type.
|
|
11072
|
+
*/
|
|
11073
|
+
type TWalkerLogicPublicService = {
|
|
11074
|
+
[key in keyof WalkerLogicPublicService]: any;
|
|
11075
|
+
};
|
|
10381
11076
|
/**
|
|
10382
11077
|
* Global service providing access to walker functionality.
|
|
10383
11078
|
*
|
|
10384
11079
|
* Simple wrapper around WalkerLogicPublicService for dependency injection.
|
|
10385
11080
|
* Used by public API exports.
|
|
10386
11081
|
*/
|
|
10387
|
-
declare class WalkerCommandService {
|
|
11082
|
+
declare class WalkerCommandService implements TWalkerLogicPublicService {
|
|
10388
11083
|
private readonly loggerService;
|
|
10389
11084
|
private readonly walkerLogicPublicService;
|
|
10390
11085
|
private readonly walkerSchemaService;
|
|
@@ -10401,9 +11096,9 @@ declare class WalkerCommandService {
|
|
|
10401
11096
|
* @param context - Walker context with strategies and metric
|
|
10402
11097
|
*/
|
|
10403
11098
|
run: (symbol: string, context: {
|
|
10404
|
-
walkerName:
|
|
10405
|
-
exchangeName:
|
|
10406
|
-
frameName:
|
|
11099
|
+
walkerName: WalkerName;
|
|
11100
|
+
exchangeName: ExchangeName;
|
|
11101
|
+
frameName: FrameName;
|
|
10407
11102
|
}) => AsyncGenerator<WalkerContract, any, any>;
|
|
10408
11103
|
}
|
|
10409
11104
|
|
|
@@ -10729,55 +11424,23 @@ declare class LiveLogicPrivateService {
|
|
|
10729
11424
|
}
|
|
10730
11425
|
|
|
10731
11426
|
/**
|
|
10732
|
-
*
|
|
10733
|
-
*
|
|
10734
|
-
* Flow:
|
|
10735
|
-
* 1. Yields progress updates as each strategy completes
|
|
10736
|
-
* 2. Tracks best metric in real-time
|
|
10737
|
-
* 3. Returns final results with all strategies ranked
|
|
10738
|
-
*
|
|
10739
|
-
* Uses BacktestLogicPublicService internally for each strategy.
|
|
11427
|
+
* Type definition for public BacktestLogic service.
|
|
11428
|
+
* Omits private dependencies from BacktestLogicPrivateService.
|
|
10740
11429
|
*/
|
|
10741
|
-
|
|
10742
|
-
|
|
10743
|
-
|
|
10744
|
-
|
|
10745
|
-
|
|
10746
|
-
|
|
10747
|
-
|
|
10748
|
-
|
|
10749
|
-
|
|
10750
|
-
|
|
10751
|
-
|
|
10752
|
-
|
|
10753
|
-
|
|
10754
|
-
|
|
10755
|
-
* @param context - Walker context with exchangeName, frameName, walkerName
|
|
10756
|
-
* @yields WalkerContract with progress after each strategy
|
|
10757
|
-
*
|
|
10758
|
-
* @example
|
|
10759
|
-
* ```typescript
|
|
10760
|
-
* for await (const progress of walkerLogic.run(
|
|
10761
|
-
* "BTCUSDT",
|
|
10762
|
-
* ["strategy-v1", "strategy-v2"],
|
|
10763
|
-
* "sharpeRatio",
|
|
10764
|
-
* {
|
|
10765
|
-
* exchangeName: "binance",
|
|
10766
|
-
* frameName: "1d-backtest",
|
|
10767
|
-
* walkerName: "my-optimizer"
|
|
10768
|
-
* }
|
|
10769
|
-
* )) {
|
|
10770
|
-
* console.log("Progress:", progress.strategiesTested, "/", progress.totalStrategies);
|
|
10771
|
-
* }
|
|
10772
|
-
* ```
|
|
10773
|
-
*/
|
|
10774
|
-
run(symbol: string, strategies: StrategyName[], metric: WalkerMetric, context: {
|
|
10775
|
-
exchangeName: string;
|
|
10776
|
-
frameName: string;
|
|
10777
|
-
walkerName: string;
|
|
10778
|
-
}): AsyncGenerator<WalkerContract>;
|
|
10779
|
-
}
|
|
10780
|
-
|
|
11430
|
+
type IBacktestLogicPrivateService = Omit<BacktestLogicPrivateService, keyof {
|
|
11431
|
+
loggerService: never;
|
|
11432
|
+
strategyCoreService: never;
|
|
11433
|
+
exchangeCoreService: never;
|
|
11434
|
+
frameCoreService: never;
|
|
11435
|
+
methodContextService: never;
|
|
11436
|
+
}>;
|
|
11437
|
+
/**
|
|
11438
|
+
* Type definition for BacktestLogicPublicService.
|
|
11439
|
+
* Maps all keys of IBacktestLogicPrivateService to any type.
|
|
11440
|
+
*/
|
|
11441
|
+
type TBacktestLogicPrivateService = {
|
|
11442
|
+
[key in keyof IBacktestLogicPrivateService]: any;
|
|
11443
|
+
};
|
|
10781
11444
|
/**
|
|
10782
11445
|
* Public service for backtest orchestration with context management.
|
|
10783
11446
|
*
|
|
@@ -10802,7 +11465,7 @@ declare class WalkerLogicPrivateService {
|
|
|
10802
11465
|
* }
|
|
10803
11466
|
* ```
|
|
10804
11467
|
*/
|
|
10805
|
-
declare class BacktestLogicPublicService {
|
|
11468
|
+
declare class BacktestLogicPublicService implements TBacktestLogicPrivateService {
|
|
10806
11469
|
private readonly loggerService;
|
|
10807
11470
|
private readonly backtestLogicPrivateService;
|
|
10808
11471
|
/**
|
|
@@ -10816,12 +11479,28 @@ declare class BacktestLogicPublicService {
|
|
|
10816
11479
|
* @returns Async generator yielding closed signals with PNL
|
|
10817
11480
|
*/
|
|
10818
11481
|
run: (symbol: string, context: {
|
|
10819
|
-
strategyName:
|
|
10820
|
-
exchangeName:
|
|
10821
|
-
frameName:
|
|
11482
|
+
strategyName: StrategyName;
|
|
11483
|
+
exchangeName: ExchangeName;
|
|
11484
|
+
frameName: FrameName;
|
|
10822
11485
|
}) => AsyncGenerator<IStrategyBacktestResult, void, unknown>;
|
|
10823
11486
|
}
|
|
10824
11487
|
|
|
11488
|
+
/**
|
|
11489
|
+
* Type definition for public LiveLogic service.
|
|
11490
|
+
* Omits private dependencies from LiveLogicPrivateService.
|
|
11491
|
+
*/
|
|
11492
|
+
type ILiveLogicPrivateService = Omit<LiveLogicPrivateService, keyof {
|
|
11493
|
+
loggerService: never;
|
|
11494
|
+
strategyCoreService: never;
|
|
11495
|
+
methodContextService: never;
|
|
11496
|
+
}>;
|
|
11497
|
+
/**
|
|
11498
|
+
* Type definition for LiveLogicPublicService.
|
|
11499
|
+
* Maps all keys of ILiveLogicPrivateService to any type.
|
|
11500
|
+
*/
|
|
11501
|
+
type TLiveLogicPrivateService = {
|
|
11502
|
+
[key in keyof ILiveLogicPrivateService]: any;
|
|
11503
|
+
};
|
|
10825
11504
|
/**
|
|
10826
11505
|
* Public service for live trading orchestration with context management.
|
|
10827
11506
|
*
|
|
@@ -10853,7 +11532,7 @@ declare class BacktestLogicPublicService {
|
|
|
10853
11532
|
* }
|
|
10854
11533
|
* ```
|
|
10855
11534
|
*/
|
|
10856
|
-
declare class LiveLogicPublicService {
|
|
11535
|
+
declare class LiveLogicPublicService implements TLiveLogicPrivateService {
|
|
10857
11536
|
private readonly loggerService;
|
|
10858
11537
|
private readonly liveLogicPrivateService;
|
|
10859
11538
|
/**
|
|
@@ -10868,58 +11547,25 @@ declare class LiveLogicPublicService {
|
|
|
10868
11547
|
* @returns Infinite async generator yielding opened and closed signals
|
|
10869
11548
|
*/
|
|
10870
11549
|
run: (symbol: string, context: {
|
|
10871
|
-
strategyName:
|
|
10872
|
-
exchangeName:
|
|
11550
|
+
strategyName: StrategyName;
|
|
11551
|
+
exchangeName: ExchangeName;
|
|
10873
11552
|
}) => AsyncGenerator<IStrategyTickResultOpened | IStrategyTickResultClosed, void, unknown>;
|
|
10874
11553
|
}
|
|
10875
11554
|
|
|
10876
11555
|
/**
|
|
10877
|
-
*
|
|
10878
|
-
*
|
|
10879
|
-
* Wraps WalkerLogicPrivateService with MethodContextService to provide
|
|
10880
|
-
* implicit context propagation for strategyName, exchangeName, frameName, and walkerName.
|
|
10881
|
-
*
|
|
10882
|
-
* @example
|
|
10883
|
-
* ```typescript
|
|
10884
|
-
* const walkerLogicPublicService = inject(TYPES.walkerLogicPublicService);
|
|
10885
|
-
*
|
|
10886
|
-
* const results = await walkerLogicPublicService.run("BTCUSDT", {
|
|
10887
|
-
* walkerName: "my-optimizer",
|
|
10888
|
-
* exchangeName: "binance",
|
|
10889
|
-
* frameName: "1d-backtest",
|
|
10890
|
-
* strategies: ["strategy-v1", "strategy-v2"],
|
|
10891
|
-
* metric: "sharpeRatio",
|
|
10892
|
-
* });
|
|
10893
|
-
*
|
|
10894
|
-
* console.log("Best strategy:", results.bestStrategy);
|
|
10895
|
-
* ```
|
|
11556
|
+
* Type definition for LiveLogicPublicService.
|
|
11557
|
+
* Maps all keys of LiveLogicPublicService to any type.
|
|
10896
11558
|
*/
|
|
10897
|
-
|
|
10898
|
-
|
|
10899
|
-
|
|
10900
|
-
private readonly walkerSchemaService;
|
|
10901
|
-
/**
|
|
10902
|
-
* Runs walker comparison for a symbol with context propagation.
|
|
10903
|
-
*
|
|
10904
|
-
* Executes backtests for all strategies.
|
|
10905
|
-
*
|
|
10906
|
-
* @param symbol - Trading pair symbol (e.g., "BTCUSDT")
|
|
10907
|
-
* @param context - Walker context with strategies and metric
|
|
10908
|
-
*/
|
|
10909
|
-
run: (symbol: string, context: {
|
|
10910
|
-
walkerName: string;
|
|
10911
|
-
exchangeName: string;
|
|
10912
|
-
frameName: string;
|
|
10913
|
-
}) => AsyncGenerator<WalkerContract, any, any>;
|
|
10914
|
-
}
|
|
10915
|
-
|
|
11559
|
+
type TLiveLogicPublicService = {
|
|
11560
|
+
[key in keyof LiveLogicPublicService]: any;
|
|
11561
|
+
};
|
|
10916
11562
|
/**
|
|
10917
11563
|
* Global service providing access to live trading functionality.
|
|
10918
11564
|
*
|
|
10919
11565
|
* Simple wrapper around LiveLogicPublicService for dependency injection.
|
|
10920
11566
|
* Used by public API exports.
|
|
10921
11567
|
*/
|
|
10922
|
-
declare class LiveCommandService {
|
|
11568
|
+
declare class LiveCommandService implements TLiveLogicPublicService {
|
|
10923
11569
|
private readonly loggerService;
|
|
10924
11570
|
private readonly liveLogicPublicService;
|
|
10925
11571
|
private readonly strategyValidationService;
|
|
@@ -10936,18 +11582,25 @@ declare class LiveCommandService {
|
|
|
10936
11582
|
* @returns Infinite async generator yielding opened and closed signals
|
|
10937
11583
|
*/
|
|
10938
11584
|
run: (symbol: string, context: {
|
|
10939
|
-
strategyName:
|
|
10940
|
-
exchangeName:
|
|
11585
|
+
strategyName: StrategyName;
|
|
11586
|
+
exchangeName: ExchangeName;
|
|
10941
11587
|
}) => AsyncGenerator<IStrategyTickResultOpened | IStrategyTickResultClosed, void, unknown>;
|
|
10942
11588
|
}
|
|
10943
11589
|
|
|
11590
|
+
/**
|
|
11591
|
+
* Type definition for BacktestLogicPublicService.
|
|
11592
|
+
* Maps all keys of BacktestLogicPublicService to any type.
|
|
11593
|
+
*/
|
|
11594
|
+
type TBacktestLogicPublicService = {
|
|
11595
|
+
[key in keyof BacktestLogicPublicService]: any;
|
|
11596
|
+
};
|
|
10944
11597
|
/**
|
|
10945
11598
|
* Global service providing access to backtest functionality.
|
|
10946
11599
|
*
|
|
10947
11600
|
* Simple wrapper around BacktestLogicPublicService for dependency injection.
|
|
10948
11601
|
* Used by public API exports.
|
|
10949
11602
|
*/
|
|
10950
|
-
declare class BacktestCommandService {
|
|
11603
|
+
declare class BacktestCommandService implements TBacktestLogicPublicService {
|
|
10951
11604
|
private readonly loggerService;
|
|
10952
11605
|
private readonly strategySchemaService;
|
|
10953
11606
|
private readonly riskValidationService;
|
|
@@ -10963,9 +11616,9 @@ declare class BacktestCommandService {
|
|
|
10963
11616
|
* @returns Async generator yielding closed signals with PNL
|
|
10964
11617
|
*/
|
|
10965
11618
|
run: (symbol: string, context: {
|
|
10966
|
-
strategyName:
|
|
10967
|
-
exchangeName:
|
|
10968
|
-
frameName:
|
|
11619
|
+
strategyName: StrategyName;
|
|
11620
|
+
exchangeName: ExchangeName;
|
|
11621
|
+
frameName: FrameName;
|
|
10969
11622
|
}) => AsyncGenerator<IStrategyBacktestResult, void, unknown>;
|
|
10970
11623
|
}
|
|
10971
11624
|
|
|
@@ -11369,7 +12022,7 @@ declare class OptimizerTemplateService implements IOptimizerTemplate {
|
|
|
11369
12022
|
* @param strategies - Array of strategy names to compare
|
|
11370
12023
|
* @returns Generated addWalker() call
|
|
11371
12024
|
*/
|
|
11372
|
-
getWalkerTemplate: (walkerName:
|
|
12025
|
+
getWalkerTemplate: (walkerName: WalkerName, exchangeName: ExchangeName, frameName: FrameName, strategies: string[]) => Promise<string>;
|
|
11373
12026
|
/**
|
|
11374
12027
|
* Generates Strategy configuration with LLM integration.
|
|
11375
12028
|
* Includes multi-timeframe analysis and signal generation.
|
|
@@ -11379,7 +12032,7 @@ declare class OptimizerTemplateService implements IOptimizerTemplate {
|
|
|
11379
12032
|
* @param prompt - Strategy logic from getPrompt()
|
|
11380
12033
|
* @returns Generated addStrategy() call with getSignal() function
|
|
11381
12034
|
*/
|
|
11382
|
-
getStrategyTemplate: (strategyName:
|
|
12035
|
+
getStrategyTemplate: (strategyName: StrategyName, interval: CandleInterval, prompt: string) => Promise<string>;
|
|
11383
12036
|
/**
|
|
11384
12037
|
* Generates Exchange configuration code.
|
|
11385
12038
|
* Uses CCXT Binance with standard formatters.
|
|
@@ -11399,7 +12052,7 @@ declare class OptimizerTemplateService implements IOptimizerTemplate {
|
|
|
11399
12052
|
* @param endDate - Frame end date
|
|
11400
12053
|
* @returns Generated addFrame() call
|
|
11401
12054
|
*/
|
|
11402
|
-
getFrameTemplate: (symbol: string, frameName:
|
|
12055
|
+
getFrameTemplate: (symbol: string, frameName: FrameName, interval: CandleInterval, startDate: Date, endDate: Date) => Promise<string>;
|
|
11403
12056
|
/**
|
|
11404
12057
|
* Generates launcher code to run Walker with event listeners.
|
|
11405
12058
|
* Includes progress tracking and completion handlers.
|
|
@@ -11408,7 +12061,7 @@ declare class OptimizerTemplateService implements IOptimizerTemplate {
|
|
|
11408
12061
|
* @param walkerName - Walker name to launch
|
|
11409
12062
|
* @returns Generated Walker.background() call with listeners
|
|
11410
12063
|
*/
|
|
11411
|
-
getLauncherTemplate: (symbol: string, walkerName:
|
|
12064
|
+
getLauncherTemplate: (symbol: string, walkerName: WalkerName) => Promise<string>;
|
|
11412
12065
|
/**
|
|
11413
12066
|
* Generates dumpJson() helper function for debug output.
|
|
11414
12067
|
* Saves LLM conversations and results to ./dump/strategy/{resultId}/
|
|
@@ -11569,7 +12222,7 @@ declare class ClientOptimizer implements IOptimizer {
|
|
|
11569
12222
|
* Type helper for optimizer method signatures.
|
|
11570
12223
|
* Maps IOptimizer interface methods to any return type.
|
|
11571
12224
|
*/
|
|
11572
|
-
type TOptimizer = {
|
|
12225
|
+
type TOptimizer$1 = {
|
|
11573
12226
|
[key in keyof IOptimizer]: any;
|
|
11574
12227
|
};
|
|
11575
12228
|
/**
|
|
@@ -11582,7 +12235,7 @@ type TOptimizer = {
|
|
|
11582
12235
|
* - Logger injection
|
|
11583
12236
|
* - Delegates to ClientOptimizer for actual operations
|
|
11584
12237
|
*/
|
|
11585
|
-
declare class OptimizerConnectionService implements TOptimizer {
|
|
12238
|
+
declare class OptimizerConnectionService implements TOptimizer$1 {
|
|
11586
12239
|
private readonly loggerService;
|
|
11587
12240
|
private readonly optimizerSchemaService;
|
|
11588
12241
|
private readonly optimizerTemplateService;
|
|
@@ -11622,6 +12275,14 @@ declare class OptimizerConnectionService implements TOptimizer {
|
|
|
11622
12275
|
dump: (symbol: string, optimizerName: string, path?: string) => Promise<void>;
|
|
11623
12276
|
}
|
|
11624
12277
|
|
|
12278
|
+
/**
|
|
12279
|
+
* Type definition for optimizer methods.
|
|
12280
|
+
* Maps all keys of IOptimizer to any type.
|
|
12281
|
+
* Used for dynamic method routing in OptimizerGlobalService.
|
|
12282
|
+
*/
|
|
12283
|
+
type TOptimizer = {
|
|
12284
|
+
[key in keyof IOptimizer]: any;
|
|
12285
|
+
};
|
|
11625
12286
|
/**
|
|
11626
12287
|
* Global service for optimizer operations with validation.
|
|
11627
12288
|
* Entry point for public API, performs validation before delegating to ConnectionService.
|
|
@@ -11631,7 +12292,7 @@ declare class OptimizerConnectionService implements TOptimizer {
|
|
|
11631
12292
|
* 2. Validate optimizer exists
|
|
11632
12293
|
* 3. Delegate to OptimizerConnectionService
|
|
11633
12294
|
*/
|
|
11634
|
-
declare class OptimizerGlobalService {
|
|
12295
|
+
declare class OptimizerGlobalService implements TOptimizer {
|
|
11635
12296
|
private readonly loggerService;
|
|
11636
12297
|
private readonly optimizerConnectionService;
|
|
11637
12298
|
private readonly optimizerValidationService;
|
|
@@ -11667,6 +12328,14 @@ declare class OptimizerGlobalService {
|
|
|
11667
12328
|
dump: (symbol: string, optimizerName: string, path?: string) => Promise<void>;
|
|
11668
12329
|
}
|
|
11669
12330
|
|
|
12331
|
+
/**
|
|
12332
|
+
* Type definition for partial methods.
|
|
12333
|
+
* Maps all keys of IPartial to any type.
|
|
12334
|
+
* Used for dynamic method routing in PartialGlobalService.
|
|
12335
|
+
*/
|
|
12336
|
+
type TPartial = {
|
|
12337
|
+
[key in keyof IPartial]: any;
|
|
12338
|
+
};
|
|
11670
12339
|
/**
|
|
11671
12340
|
* Global service for partial profit/loss tracking.
|
|
11672
12341
|
*
|
|
@@ -11696,7 +12365,7 @@ declare class OptimizerGlobalService {
|
|
|
11696
12365
|
* // Logs at global level → delegates to PartialConnectionService
|
|
11697
12366
|
* ```
|
|
11698
12367
|
*/
|
|
11699
|
-
declare class PartialGlobalService {
|
|
12368
|
+
declare class PartialGlobalService implements TPartial {
|
|
11700
12369
|
/**
|
|
11701
12370
|
* Logger service injected from DI container.
|
|
11702
12371
|
* Used for logging operations at global service level.
|
|
@@ -11721,9 +12390,9 @@ declare class PartialGlobalService {
|
|
|
11721
12390
|
private readonly riskValidationService;
|
|
11722
12391
|
/**
|
|
11723
12392
|
* Validates strategy and associated risk configuration.
|
|
11724
|
-
* Memoized to avoid redundant validations for the same strategy.
|
|
12393
|
+
* Memoized to avoid redundant validations for the same strategy-exchange-frame combination.
|
|
11725
12394
|
*
|
|
11726
|
-
* @param
|
|
12395
|
+
* @param context - Context with strategyName, exchangeName and frameName
|
|
11727
12396
|
* @param methodName - Name of the calling method for error tracking
|
|
11728
12397
|
*/
|
|
11729
12398
|
private validate;
|
|
@@ -11973,4 +12642,4 @@ declare const backtest: {
|
|
|
11973
12642
|
loggerService: LoggerService;
|
|
11974
12643
|
};
|
|
11975
12644
|
|
|
11976
|
-
export { Backtest, type BacktestDoneNotification, type BacktestStatisticsModel, type BootstrapNotification, Cache, type CandleInterval, type ColumnConfig, type ColumnModel, Constant, type CriticalErrorNotification, type DoneContract, type EntityId, Exchange, ExecutionContextService, type FrameInterval, type GlobalConfig, Heat, type HeatmapStatisticsModel, type ICandleData, type IExchangeSchema, type IFrameSchema, type IHeatmapRow, type IOptimizerCallbacks, type IOptimizerData, type IOptimizerFetchArgs, type IOptimizerFilterArgs, type IOptimizerRange, type IOptimizerSchema, type IOptimizerSource, type IOptimizerStrategy, type IOptimizerTemplate, type IPersistBase, type IPositionSizeATRParams, type IPositionSizeFixedPercentageParams, type IPositionSizeKellyParams, 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 LiveDoneNotification, type LiveStatisticsModel, type MessageModel, type MessageRole, MethodContextService, type MetricStats, Notification, type NotificationModel, Optimizer, Partial$1 as Partial, type PartialData, type PartialEvent, type PartialLossContract, type PartialLossNotification, type PartialProfitContract, type PartialProfitNotification, type PartialStatisticsModel, Performance, type PerformanceContract, type PerformanceMetricType, type PerformanceStatisticsModel, PersistBase, PersistPartialAdapter, PersistRiskAdapter, PersistScheduleAdapter, PersistSignalAdapter, type PingContract, PositionSize, type ProgressBacktestContract, type ProgressBacktestNotification, type ProgressOptimizerContract, type ProgressWalkerContract, Risk, type RiskContract, type RiskData, type RiskEvent, type RiskRejectionNotification, type RiskStatisticsModel, Schedule, type ScheduleData, type ScheduleStatisticsModel, type ScheduledEvent, type SignalCancelledNotification, type SignalClosedNotification, type SignalData, type SignalInterval, type SignalOpenedNotification, type SignalScheduledNotification, type TPersistBase, type TPersistBaseCtor, type TickEvent, type ValidationErrorNotification, Walker, type WalkerCompleteContract, type WalkerContract, type WalkerMetric, type SignalData$1 as WalkerSignalData, type WalkerStatisticsModel, addExchange, addFrame, addOptimizer, addRisk, addSizing, addStrategy, addWalker, cancel, dumpSignal, emitters, formatPrice, formatQuantity, getAveragePrice, getCandles, getColumns, getConfig, getDate, getDefaultColumns, getDefaultConfig, getMode, hasTradeContext, backtest as lib, listExchanges, listFrames, listOptimizers, listRisks, listSizings, listStrategies, listWalkers, listenBacktestProgress, listenDoneBacktest, listenDoneBacktestOnce, listenDoneLive, listenDoneLiveOnce, listenDoneWalker, listenDoneWalkerOnce, listenError, listenExit, listenOptimizerProgress, listenPartialLoss, listenPartialLossOnce, listenPartialProfit, listenPartialProfitOnce, listenPerformance, listenPing, listenPingOnce, listenRisk, listenRiskOnce, listenSignal, listenSignalBacktest, listenSignalBacktestOnce, listenSignalLive, listenSignalLiveOnce, listenSignalOnce, listenValidation, listenWalker, listenWalkerComplete, listenWalkerOnce, listenWalkerProgress, setColumns, setConfig, setLogger, stop, validate };
|
|
12645
|
+
export { Backtest, type BacktestDoneNotification, type BacktestStatisticsModel, type BootstrapNotification, Cache, type CandleInterval, type ColumnConfig, type ColumnModel, Constant, type CriticalErrorNotification, type DoneContract, type EntityId, Exchange, ExecutionContextService, type FrameInterval, type GlobalConfig, Heat, type HeatmapStatisticsModel, type ICandleData, type IExchangeSchema, type IFrameSchema, type IHeatmapRow, type IOptimizerCallbacks, type IOptimizerData, type IOptimizerFetchArgs, type IOptimizerFilterArgs, type IOptimizerRange, type IOptimizerSchema, type IOptimizerSource, type IOptimizerStrategy, type IOptimizerTemplate, type IPersistBase, type IPositionSizeATRParams, type IPositionSizeFixedPercentageParams, type IPositionSizeKellyParams, 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 LiveDoneNotification, type LiveStatisticsModel, type MessageModel, type MessageRole, MethodContextService, type MetricStats, Notification, type NotificationModel, Optimizer, Partial$1 as Partial, type PartialData, type PartialEvent, type PartialLossContract, type PartialLossNotification, type PartialProfitContract, type PartialProfitNotification, type PartialStatisticsModel, Performance, type PerformanceContract, type PerformanceMetricType, type PerformanceStatisticsModel, PersistBase, PersistPartialAdapter, PersistRiskAdapter, PersistScheduleAdapter, PersistSignalAdapter, type PingContract, PositionSize, type ProgressBacktestContract, type ProgressBacktestNotification, type ProgressOptimizerContract, type ProgressWalkerContract, Risk, type RiskContract, type RiskData, type RiskEvent, type RiskRejectionNotification, type RiskStatisticsModel, Schedule, type ScheduleData, type ScheduleStatisticsModel, type ScheduledEvent, type SignalCancelledNotification, type SignalClosedNotification, type SignalData, type SignalInterval, type SignalOpenedNotification, type SignalScheduledNotification, type TPersistBase, type TPersistBaseCtor, type TickEvent, type ValidationErrorNotification, Walker, type WalkerCompleteContract, type WalkerContract, type WalkerMetric, type SignalData$1 as WalkerSignalData, type WalkerStatisticsModel, addExchange, addFrame, addOptimizer, addRisk, addSizing, addStrategy, addWalker, cancel, dumpSignal, emitters, formatPrice, formatQuantity, getAveragePrice, getCandles, getColumns, getConfig, getDate, getDefaultColumns, getDefaultConfig, getMode, hasTradeContext, backtest as lib, listExchanges, listFrames, listOptimizers, listRisks, listSizings, listStrategies, listWalkers, listenBacktestProgress, listenDoneBacktest, listenDoneBacktestOnce, listenDoneLive, listenDoneLiveOnce, listenDoneWalker, listenDoneWalkerOnce, listenError, listenExit, listenOptimizerProgress, listenPartialLoss, listenPartialLossOnce, listenPartialProfit, listenPartialProfitOnce, listenPerformance, listenPing, listenPingOnce, listenRisk, listenRiskOnce, listenSignal, listenSignalBacktest, listenSignalBacktestOnce, listenSignalLive, listenSignalLiveOnce, listenSignalOnce, listenValidation, listenWalker, listenWalkerComplete, listenWalkerOnce, listenWalkerProgress, partialLoss, partialProfit, setColumns, setConfig, setLogger, stop, validate };
|