backtest-kit 6.4.0 → 6.5.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/README.md +1 -1
- package/build/index.cjs +258 -53
- package/build/index.mjs +258 -53
- package/package.json +1 -1
- package/types.d.ts +164 -39
package/build/index.mjs
CHANGED
|
@@ -2709,6 +2709,12 @@ const METHOD_NAME_RELEASE_LOCK = "CandleUtils.releaseLock";
|
|
|
2709
2709
|
class CandleUtils {
|
|
2710
2710
|
constructor() {
|
|
2711
2711
|
this._lock = new Lock();
|
|
2712
|
+
/**
|
|
2713
|
+
* Acquires the candle fetch mutex if CC_ENABLE_CANDLE_FETCH_MUTEX is enabled.
|
|
2714
|
+
* Prevents concurrent candle fetches from the same exchange.
|
|
2715
|
+
*
|
|
2716
|
+
* @param source - Caller identifier for logging
|
|
2717
|
+
*/
|
|
2712
2718
|
this.acquireLock = async (source) => {
|
|
2713
2719
|
bt.loggerService.info(METHOD_NAME_ACQUIRE_LOCK, {
|
|
2714
2720
|
source,
|
|
@@ -2718,6 +2724,12 @@ class CandleUtils {
|
|
|
2718
2724
|
}
|
|
2719
2725
|
return await this._lock.acquireLock();
|
|
2720
2726
|
};
|
|
2727
|
+
/**
|
|
2728
|
+
* Releases the candle fetch mutex if CC_ENABLE_CANDLE_FETCH_MUTEX is enabled.
|
|
2729
|
+
* Must be called after acquireLock, typically in a finally block.
|
|
2730
|
+
*
|
|
2731
|
+
* @param source - Caller identifier for logging
|
|
2732
|
+
*/
|
|
2721
2733
|
this.releaseLock = async (source) => {
|
|
2722
2734
|
bt.loggerService.info(METHOD_NAME_RELEASE_LOCK, {
|
|
2723
2735
|
source,
|
|
@@ -14296,6 +14308,20 @@ class StrategyCoreService {
|
|
|
14296
14308
|
await this.validate(context);
|
|
14297
14309
|
return await this.strategyConnectionService.getTotalCostClosed(backtest, symbol, context);
|
|
14298
14310
|
};
|
|
14311
|
+
/**
|
|
14312
|
+
* Returns the effective (DCA-averaged) entry price for the current pending signal.
|
|
14313
|
+
*
|
|
14314
|
+
* This is the harmonic mean of all _entry prices, which is the correct
|
|
14315
|
+
* cost-basis price used in all PNL calculations.
|
|
14316
|
+
* With no DCA entries, equals the original priceOpen.
|
|
14317
|
+
*
|
|
14318
|
+
* Returns null if no pending signal exists.
|
|
14319
|
+
*
|
|
14320
|
+
* @param backtest - Whether running in backtest mode
|
|
14321
|
+
* @param symbol - Trading pair symbol
|
|
14322
|
+
* @param context - Execution context with strategyName, exchangeName, frameName
|
|
14323
|
+
* @returns Promise resolving to effective entry price or null
|
|
14324
|
+
*/
|
|
14299
14325
|
this.getPositionEffectivePrice = async (backtest, symbol, context) => {
|
|
14300
14326
|
this.loggerService.log("strategyCoreService getPositionEffectivePrice", {
|
|
14301
14327
|
symbol,
|
|
@@ -14304,6 +14330,19 @@ class StrategyCoreService {
|
|
|
14304
14330
|
await this.validate(context);
|
|
14305
14331
|
return await this.strategyConnectionService.getPositionEffectivePrice(backtest, symbol, context);
|
|
14306
14332
|
};
|
|
14333
|
+
/**
|
|
14334
|
+
* Returns the number of DCA entries made for the current pending signal.
|
|
14335
|
+
*
|
|
14336
|
+
* 1 = original entry only (no DCA).
|
|
14337
|
+
* Increases by 1 with each successful commitAverageBuy().
|
|
14338
|
+
*
|
|
14339
|
+
* Returns null if no pending signal exists.
|
|
14340
|
+
*
|
|
14341
|
+
* @param backtest - Whether running in backtest mode
|
|
14342
|
+
* @param symbol - Trading pair symbol
|
|
14343
|
+
* @param context - Execution context with strategyName, exchangeName, frameName
|
|
14344
|
+
* @returns Promise resolving to entry count or null
|
|
14345
|
+
*/
|
|
14307
14346
|
this.getPositionInvestedCount = async (backtest, symbol, context) => {
|
|
14308
14347
|
this.loggerService.log("strategyCoreService getPositionInvestedCount", {
|
|
14309
14348
|
symbol,
|
|
@@ -14312,6 +14351,19 @@ class StrategyCoreService {
|
|
|
14312
14351
|
await this.validate(context);
|
|
14313
14352
|
return await this.strategyConnectionService.getPositionInvestedCount(backtest, symbol, context);
|
|
14314
14353
|
};
|
|
14354
|
+
/**
|
|
14355
|
+
* Returns the total invested cost basis in dollars for the current pending signal.
|
|
14356
|
+
*
|
|
14357
|
+
* Equal to entryCount × $100 (COST_BASIS_PER_ENTRY).
|
|
14358
|
+
* 1 entry = $100, 2 entries = $200, etc.
|
|
14359
|
+
*
|
|
14360
|
+
* Returns null if no pending signal exists.
|
|
14361
|
+
*
|
|
14362
|
+
* @param backtest - Whether running in backtest mode
|
|
14363
|
+
* @param symbol - Trading pair symbol
|
|
14364
|
+
* @param context - Execution context with strategyName, exchangeName, frameName
|
|
14365
|
+
* @returns Promise resolving to total invested cost in dollars or null
|
|
14366
|
+
*/
|
|
14315
14367
|
this.getPositionInvestedCost = async (backtest, symbol, context) => {
|
|
14316
14368
|
this.loggerService.log("strategyCoreService getPositionInvestedCost", {
|
|
14317
14369
|
symbol,
|
|
@@ -14320,6 +14372,20 @@ class StrategyCoreService {
|
|
|
14320
14372
|
await this.validate(context);
|
|
14321
14373
|
return await this.strategyConnectionService.getPositionInvestedCost(backtest, symbol, context);
|
|
14322
14374
|
};
|
|
14375
|
+
/**
|
|
14376
|
+
* Returns the unrealized PNL percentage for the current pending signal at currentPrice.
|
|
14377
|
+
*
|
|
14378
|
+
* Accounts for partial closes, DCA entries, slippage and fees
|
|
14379
|
+
* (delegates to toProfitLossDto).
|
|
14380
|
+
*
|
|
14381
|
+
* Returns null if no pending signal exists.
|
|
14382
|
+
*
|
|
14383
|
+
* @param backtest - Whether running in backtest mode
|
|
14384
|
+
* @param symbol - Trading pair symbol
|
|
14385
|
+
* @param currentPrice - Current market price
|
|
14386
|
+
* @param context - Execution context with strategyName, exchangeName, frameName
|
|
14387
|
+
* @returns Promise resolving to pnlPercentage or null
|
|
14388
|
+
*/
|
|
14323
14389
|
this.getPositionPnlPercent = async (backtest, symbol, currentPrice, context) => {
|
|
14324
14390
|
this.loggerService.log("strategyCoreService getPositionPnlPercent", {
|
|
14325
14391
|
symbol,
|
|
@@ -14329,6 +14395,20 @@ class StrategyCoreService {
|
|
|
14329
14395
|
await this.validate(context);
|
|
14330
14396
|
return await this.strategyConnectionService.getPositionPnlPercent(backtest, symbol, currentPrice, context);
|
|
14331
14397
|
};
|
|
14398
|
+
/**
|
|
14399
|
+
* Returns the unrealized PNL in dollars for the current pending signal at currentPrice.
|
|
14400
|
+
*
|
|
14401
|
+
* Calculated as: pnlPercentage / 100 × totalInvestedCost
|
|
14402
|
+
* Accounts for partial closes, DCA entries, slippage and fees.
|
|
14403
|
+
*
|
|
14404
|
+
* Returns null if no pending signal exists.
|
|
14405
|
+
*
|
|
14406
|
+
* @param backtest - Whether running in backtest mode
|
|
14407
|
+
* @param symbol - Trading pair symbol
|
|
14408
|
+
* @param currentPrice - Current market price
|
|
14409
|
+
* @param context - Execution context with strategyName, exchangeName, frameName
|
|
14410
|
+
* @returns Promise resolving to pnl in dollars or null
|
|
14411
|
+
*/
|
|
14332
14412
|
this.getPositionPnlCost = async (backtest, symbol, currentPrice, context) => {
|
|
14333
14413
|
this.loggerService.log("strategyCoreService getPositionPnlCost", {
|
|
14334
14414
|
symbol,
|
|
@@ -14338,6 +14418,27 @@ class StrategyCoreService {
|
|
|
14338
14418
|
await this.validate(context);
|
|
14339
14419
|
return await this.strategyConnectionService.getPositionPnlCost(backtest, symbol, currentPrice, context);
|
|
14340
14420
|
};
|
|
14421
|
+
/**
|
|
14422
|
+
* Returns the list of DCA entry prices for the current pending signal.
|
|
14423
|
+
*
|
|
14424
|
+
* The first element is always the original priceOpen (initial entry).
|
|
14425
|
+
* Each subsequent element is a price added by commitAverageBuy().
|
|
14426
|
+
*
|
|
14427
|
+
* Returns null if no pending signal exists.
|
|
14428
|
+
* Returns a single-element array [priceOpen] if no DCA entries were made.
|
|
14429
|
+
*
|
|
14430
|
+
* @param backtest - Whether running in backtest mode
|
|
14431
|
+
* @param symbol - Trading pair symbol
|
|
14432
|
+
* @param context - Execution context with strategyName, exchangeName, frameName
|
|
14433
|
+
* @returns Promise resolving to array of entry prices or null
|
|
14434
|
+
*
|
|
14435
|
+
* @example
|
|
14436
|
+
* ```typescript
|
|
14437
|
+
* // No DCA: [43000]
|
|
14438
|
+
* // One DCA: [43000, 42000]
|
|
14439
|
+
* // Two DCA: [43000, 42000, 41500]
|
|
14440
|
+
* ```
|
|
14441
|
+
*/
|
|
14341
14442
|
this.getPositionLevels = async (backtest, symbol, context) => {
|
|
14342
14443
|
this.loggerService.log("strategyCoreService getPositionLevels", {
|
|
14343
14444
|
symbol,
|
|
@@ -14346,6 +14447,20 @@ class StrategyCoreService {
|
|
|
14346
14447
|
await this.validate(context);
|
|
14347
14448
|
return await this.strategyConnectionService.getPositionLevels(backtest, symbol, context);
|
|
14348
14449
|
};
|
|
14450
|
+
/**
|
|
14451
|
+
* Returns the list of partial closes for the current pending signal.
|
|
14452
|
+
*
|
|
14453
|
+
* Each entry records a partial profit or loss close event with its type,
|
|
14454
|
+
* percent closed, price at close, cost basis snapshot, and entry count at close.
|
|
14455
|
+
*
|
|
14456
|
+
* Returns null if no pending signal exists.
|
|
14457
|
+
* Returns an empty array if no partial closes have been executed.
|
|
14458
|
+
*
|
|
14459
|
+
* @param backtest - Whether running in backtest mode
|
|
14460
|
+
* @param symbol - Trading pair symbol
|
|
14461
|
+
* @param context - Execution context with strategyName, exchangeName, frameName
|
|
14462
|
+
* @returns Promise resolving to array of partial close records or null
|
|
14463
|
+
*/
|
|
14349
14464
|
this.getPositionPartials = async (backtest, symbol, context) => {
|
|
14350
14465
|
this.loggerService.log("strategyCoreService getPositionPartials", {
|
|
14351
14466
|
symbol,
|
|
@@ -14354,6 +14469,27 @@ class StrategyCoreService {
|
|
|
14354
14469
|
await this.validate(context);
|
|
14355
14470
|
return await this.strategyConnectionService.getPositionPartials(backtest, symbol, context);
|
|
14356
14471
|
};
|
|
14472
|
+
/**
|
|
14473
|
+
* Returns the list of DCA entry prices and costs for the current pending signal.
|
|
14474
|
+
*
|
|
14475
|
+
* Each entry records the price and cost of a single position entry.
|
|
14476
|
+
* The first element is always the original priceOpen (initial entry).
|
|
14477
|
+
* Each subsequent element is an entry added by averageBuy().
|
|
14478
|
+
*
|
|
14479
|
+
* Returns null if no pending signal exists.
|
|
14480
|
+
* Returns a single-element array [{ price: priceOpen, cost }] if no DCA entries were made.
|
|
14481
|
+
*
|
|
14482
|
+
* @param backtest - Whether running in backtest mode
|
|
14483
|
+
* @param symbol - Trading pair symbol
|
|
14484
|
+
* @param context - Execution context with strategyName, exchangeName, frameName
|
|
14485
|
+
* @returns Promise resolving to array of entry records or null
|
|
14486
|
+
*
|
|
14487
|
+
* @example
|
|
14488
|
+
* ```typescript
|
|
14489
|
+
* // No DCA: [{ price: 43000, cost: 100 }]
|
|
14490
|
+
* // One DCA: [{ price: 43000, cost: 100 }, { price: 42000, cost: 100 }]
|
|
14491
|
+
* ```
|
|
14492
|
+
*/
|
|
14357
14493
|
this.getPositionEntries = async (backtest, symbol, context) => {
|
|
14358
14494
|
this.loggerService.log("strategyCoreService getPositionEntries", {
|
|
14359
14495
|
symbol,
|
|
@@ -14735,6 +14871,28 @@ class StrategyCoreService {
|
|
|
14735
14871
|
await this.validate(context);
|
|
14736
14872
|
return await this.strategyConnectionService.partialLoss(backtest, symbol, percentToClose, currentPrice, context);
|
|
14737
14873
|
};
|
|
14874
|
+
/**
|
|
14875
|
+
* Checks whether `trailingStop` would succeed without executing it.
|
|
14876
|
+
* Validates context, then delegates to StrategyConnectionService.validateTrailingStop().
|
|
14877
|
+
*
|
|
14878
|
+
* @param backtest - Whether running in backtest mode
|
|
14879
|
+
* @param symbol - Trading pair symbol
|
|
14880
|
+
* @param percentShift - Percentage shift of ORIGINAL SL distance [-100, 100], excluding 0
|
|
14881
|
+
* @param currentPrice - Current market price to validate against
|
|
14882
|
+
* @param context - Execution context with strategyName, exchangeName, frameName
|
|
14883
|
+
* @returns Promise<boolean> - true if `trailingStop` would execute, false otherwise
|
|
14884
|
+
*/
|
|
14885
|
+
this.validateTrailingStop = async (backtest, symbol, percentShift, currentPrice, context) => {
|
|
14886
|
+
this.loggerService.log("strategyCoreService validateTrailingStop", {
|
|
14887
|
+
symbol,
|
|
14888
|
+
percentShift,
|
|
14889
|
+
currentPrice,
|
|
14890
|
+
context,
|
|
14891
|
+
backtest,
|
|
14892
|
+
});
|
|
14893
|
+
await this.validate(context);
|
|
14894
|
+
return await this.strategyConnectionService.validateTrailingStop(backtest, symbol, percentShift, currentPrice, context);
|
|
14895
|
+
};
|
|
14738
14896
|
/**
|
|
14739
14897
|
* Adjusts the trailing stop-loss distance for an active pending signal.
|
|
14740
14898
|
*
|
|
@@ -14748,7 +14906,7 @@ class StrategyCoreService {
|
|
|
14748
14906
|
* @param percentShift - Percentage adjustment to SL distance (-100 to 100)
|
|
14749
14907
|
* @param currentPrice - Current market price to check for intrusion
|
|
14750
14908
|
* @param context - Execution context with strategyName, exchangeName, frameName
|
|
14751
|
-
* @returns Promise
|
|
14909
|
+
* @returns Promise<boolean> - true if trailing SL was updated, false otherwise
|
|
14752
14910
|
*
|
|
14753
14911
|
* @example
|
|
14754
14912
|
* ```typescript
|
|
@@ -14763,8 +14921,8 @@ class StrategyCoreService {
|
|
|
14763
14921
|
* );
|
|
14764
14922
|
* ```
|
|
14765
14923
|
*/
|
|
14766
|
-
this.
|
|
14767
|
-
this.loggerService.log("strategyCoreService
|
|
14924
|
+
this.trailingStop = async (backtest, symbol, percentShift, currentPrice, context) => {
|
|
14925
|
+
this.loggerService.log("strategyCoreService trailingStop", {
|
|
14768
14926
|
symbol,
|
|
14769
14927
|
percentShift,
|
|
14770
14928
|
currentPrice,
|
|
@@ -14772,21 +14930,21 @@ class StrategyCoreService {
|
|
|
14772
14930
|
backtest,
|
|
14773
14931
|
});
|
|
14774
14932
|
await this.validate(context);
|
|
14775
|
-
return await this.strategyConnectionService.
|
|
14933
|
+
return await this.strategyConnectionService.trailingStop(backtest, symbol, percentShift, currentPrice, context);
|
|
14776
14934
|
};
|
|
14777
14935
|
/**
|
|
14778
|
-
* Checks whether `
|
|
14779
|
-
* Validates context, then delegates to StrategyConnectionService.
|
|
14936
|
+
* Checks whether `trailingTake` would succeed without executing it.
|
|
14937
|
+
* Validates context, then delegates to StrategyConnectionService.validateTrailingTake().
|
|
14780
14938
|
*
|
|
14781
14939
|
* @param backtest - Whether running in backtest mode
|
|
14782
14940
|
* @param symbol - Trading pair symbol
|
|
14783
|
-
* @param percentShift - Percentage
|
|
14941
|
+
* @param percentShift - Percentage adjustment to ORIGINAL TP distance [-100, 100], excluding 0
|
|
14784
14942
|
* @param currentPrice - Current market price to validate against
|
|
14785
14943
|
* @param context - Execution context with strategyName, exchangeName, frameName
|
|
14786
|
-
* @returns Promise<boolean> - true if `
|
|
14944
|
+
* @returns Promise<boolean> - true if `trailingTake` would execute, false otherwise
|
|
14787
14945
|
*/
|
|
14788
|
-
this.
|
|
14789
|
-
this.loggerService.log("strategyCoreService
|
|
14946
|
+
this.validateTrailingTake = async (backtest, symbol, percentShift, currentPrice, context) => {
|
|
14947
|
+
this.loggerService.log("strategyCoreService validateTrailingTake", {
|
|
14790
14948
|
symbol,
|
|
14791
14949
|
percentShift,
|
|
14792
14950
|
currentPrice,
|
|
@@ -14794,7 +14952,7 @@ class StrategyCoreService {
|
|
|
14794
14952
|
backtest,
|
|
14795
14953
|
});
|
|
14796
14954
|
await this.validate(context);
|
|
14797
|
-
return await this.strategyConnectionService.
|
|
14955
|
+
return await this.strategyConnectionService.validateTrailingTake(backtest, symbol, percentShift, currentPrice, context);
|
|
14798
14956
|
};
|
|
14799
14957
|
/**
|
|
14800
14958
|
* Adjusts the trailing take-profit distance for an active pending signal.
|
|
@@ -14805,7 +14963,7 @@ class StrategyCoreService {
|
|
|
14805
14963
|
* @param percentShift - Percentage adjustment to TP distance (-100 to 100)
|
|
14806
14964
|
* @param currentPrice - Current market price to check for intrusion
|
|
14807
14965
|
* @param context - Strategy context with strategyName, exchangeName, frameName
|
|
14808
|
-
* @returns Promise
|
|
14966
|
+
* @returns Promise<boolean> - true if trailing TP was updated, false otherwise
|
|
14809
14967
|
*
|
|
14810
14968
|
* @example
|
|
14811
14969
|
* ```typescript
|
|
@@ -14820,8 +14978,8 @@ class StrategyCoreService {
|
|
|
14820
14978
|
* );
|
|
14821
14979
|
* ```
|
|
14822
14980
|
*/
|
|
14823
|
-
this.
|
|
14824
|
-
this.loggerService.log("strategyCoreService
|
|
14981
|
+
this.trailingTake = async (backtest, symbol, percentShift, currentPrice, context) => {
|
|
14982
|
+
this.loggerService.log("strategyCoreService trailingTake", {
|
|
14825
14983
|
symbol,
|
|
14826
14984
|
percentShift,
|
|
14827
14985
|
currentPrice,
|
|
@@ -14829,29 +14987,27 @@ class StrategyCoreService {
|
|
|
14829
14987
|
backtest,
|
|
14830
14988
|
});
|
|
14831
14989
|
await this.validate(context);
|
|
14832
|
-
return await this.strategyConnectionService.
|
|
14990
|
+
return await this.strategyConnectionService.trailingTake(backtest, symbol, percentShift, currentPrice, context);
|
|
14833
14991
|
};
|
|
14834
14992
|
/**
|
|
14835
|
-
* Checks whether `
|
|
14836
|
-
* Validates context, then delegates to StrategyConnectionService.
|
|
14993
|
+
* Checks whether `breakeven` would succeed without executing it.
|
|
14994
|
+
* Validates context, then delegates to StrategyConnectionService.validateBreakeven().
|
|
14837
14995
|
*
|
|
14838
14996
|
* @param backtest - Whether running in backtest mode
|
|
14839
14997
|
* @param symbol - Trading pair symbol
|
|
14840
|
-
* @param percentShift - Percentage adjustment to ORIGINAL TP distance [-100, 100], excluding 0
|
|
14841
14998
|
* @param currentPrice - Current market price to validate against
|
|
14842
14999
|
* @param context - Execution context with strategyName, exchangeName, frameName
|
|
14843
|
-
* @returns Promise<boolean> - true if `
|
|
15000
|
+
* @returns Promise<boolean> - true if `breakeven` would execute, false otherwise
|
|
14844
15001
|
*/
|
|
14845
|
-
this.
|
|
14846
|
-
this.loggerService.log("strategyCoreService
|
|
15002
|
+
this.validateBreakeven = async (backtest, symbol, currentPrice, context) => {
|
|
15003
|
+
this.loggerService.log("strategyCoreService validateBreakeven", {
|
|
14847
15004
|
symbol,
|
|
14848
|
-
percentShift,
|
|
14849
15005
|
currentPrice,
|
|
14850
15006
|
context,
|
|
14851
15007
|
backtest,
|
|
14852
15008
|
});
|
|
14853
15009
|
await this.validate(context);
|
|
14854
|
-
return await this.strategyConnectionService.
|
|
15010
|
+
return await this.strategyConnectionService.validateBreakeven(backtest, symbol, currentPrice, context);
|
|
14855
15011
|
};
|
|
14856
15012
|
/**
|
|
14857
15013
|
* Moves stop-loss to breakeven when price reaches threshold.
|
|
@@ -14873,26 +15029,6 @@ class StrategyCoreService {
|
|
|
14873
15029
|
* );
|
|
14874
15030
|
* ```
|
|
14875
15031
|
*/
|
|
14876
|
-
this.validateBreakeven = async (backtest, symbol, currentPrice, context) => {
|
|
14877
|
-
this.loggerService.log("strategyCoreService validateBreakeven", {
|
|
14878
|
-
symbol,
|
|
14879
|
-
currentPrice,
|
|
14880
|
-
context,
|
|
14881
|
-
backtest,
|
|
14882
|
-
});
|
|
14883
|
-
await this.validate(context);
|
|
14884
|
-
return await this.strategyConnectionService.validateBreakeven(backtest, symbol, currentPrice, context);
|
|
14885
|
-
};
|
|
14886
|
-
/**
|
|
14887
|
-
* Checks whether `breakeven` would succeed without executing it.
|
|
14888
|
-
* Validates context, then delegates to StrategyConnectionService.validateBreakeven().
|
|
14889
|
-
*
|
|
14890
|
-
* @param backtest - Whether running in backtest mode
|
|
14891
|
-
* @param symbol - Trading pair symbol
|
|
14892
|
-
* @param currentPrice - Current market price to validate against
|
|
14893
|
-
* @param context - Execution context with strategyName, exchangeName, frameName
|
|
14894
|
-
* @returns Promise<boolean> - true if `breakeven` would execute, false otherwise
|
|
14895
|
-
*/
|
|
14896
15032
|
this.breakeven = async (backtest, symbol, currentPrice, context) => {
|
|
14897
15033
|
this.loggerService.log("strategyCoreService breakeven", {
|
|
14898
15034
|
symbol,
|
|
@@ -14937,16 +15073,14 @@ class StrategyCoreService {
|
|
|
14937
15073
|
return await this.strategyConnectionService.activateScheduled(backtest, symbol, context, activateId);
|
|
14938
15074
|
};
|
|
14939
15075
|
/**
|
|
14940
|
-
*
|
|
14941
|
-
*
|
|
14942
|
-
* Validates strategy existence and delegates to connection service
|
|
14943
|
-
* to add a new averaging entry to the position.
|
|
15076
|
+
* Checks whether `averageBuy` would succeed without executing it.
|
|
15077
|
+
* Validates context, then delegates to StrategyConnectionService.validateAverageBuy().
|
|
14944
15078
|
*
|
|
14945
15079
|
* @param backtest - Whether running in backtest mode
|
|
14946
15080
|
* @param symbol - Trading pair symbol
|
|
14947
|
-
* @param currentPrice - New entry price to
|
|
15081
|
+
* @param currentPrice - New entry price to validate
|
|
14948
15082
|
* @param context - Execution context with strategyName, exchangeName, frameName
|
|
14949
|
-
* @returns Promise<boolean> - true if
|
|
15083
|
+
* @returns Promise<boolean> - true if `averageBuy` would execute, false otherwise
|
|
14950
15084
|
*/
|
|
14951
15085
|
this.validateAverageBuy = async (backtest, symbol, currentPrice, context) => {
|
|
14952
15086
|
this.loggerService.log("strategyCoreService validateAverageBuy", {
|
|
@@ -14959,14 +15093,17 @@ class StrategyCoreService {
|
|
|
14959
15093
|
return await this.strategyConnectionService.validateAverageBuy(backtest, symbol, currentPrice, context);
|
|
14960
15094
|
};
|
|
14961
15095
|
/**
|
|
14962
|
-
*
|
|
14963
|
-
*
|
|
15096
|
+
* Adds a new DCA entry to the active pending signal.
|
|
15097
|
+
*
|
|
15098
|
+
* Validates strategy existence and delegates to connection service
|
|
15099
|
+
* to add a new averaging entry to the position.
|
|
14964
15100
|
*
|
|
14965
15101
|
* @param backtest - Whether running in backtest mode
|
|
14966
15102
|
* @param symbol - Trading pair symbol
|
|
14967
|
-
* @param currentPrice - New entry price to
|
|
15103
|
+
* @param currentPrice - New entry price to add to the averaging history
|
|
15104
|
+
* @param cost - Cost basis for this entry in dollars
|
|
14968
15105
|
* @param context - Execution context with strategyName, exchangeName, frameName
|
|
14969
|
-
* @returns Promise<boolean> - true if
|
|
15106
|
+
* @returns Promise<boolean> - true if entry added, false if rejected
|
|
14970
15107
|
*/
|
|
14971
15108
|
this.averageBuy = async (backtest, symbol, currentPrice, context, cost) => {
|
|
14972
15109
|
this.loggerService.log("strategyCoreService averageBuy", {
|
|
@@ -47921,6 +48058,13 @@ class StoragePersistBacktestUtils {
|
|
|
47921
48058
|
await this.waitForInit();
|
|
47922
48059
|
return Array.from(this._signals.values());
|
|
47923
48060
|
};
|
|
48061
|
+
/**
|
|
48062
|
+
* Handles active ping event for an opened signal.
|
|
48063
|
+
* Updates the signal's PnL and timestamp if the event is newer than the stored state.
|
|
48064
|
+
* Persists updated state to disk.
|
|
48065
|
+
*
|
|
48066
|
+
* @param event - Active ping contract with signal data and current price
|
|
48067
|
+
*/
|
|
47924
48068
|
this.handleActivePing = async (event) => {
|
|
47925
48069
|
bt.loggerService.info(STORAGE_BACKTEST_METHOD_NAME_HANDLE_ACTIVE_PING, {
|
|
47926
48070
|
signalId: event.data.id,
|
|
@@ -47944,6 +48088,13 @@ class StoragePersistBacktestUtils {
|
|
|
47944
48088
|
});
|
|
47945
48089
|
await this._updateStorage();
|
|
47946
48090
|
};
|
|
48091
|
+
/**
|
|
48092
|
+
* Handles schedule ping event for a scheduled signal.
|
|
48093
|
+
* Updates the signal's data and timestamp if the event is newer than the stored state.
|
|
48094
|
+
* Persists updated state to disk.
|
|
48095
|
+
*
|
|
48096
|
+
* @param event - Schedule ping contract with signal data and current price
|
|
48097
|
+
*/
|
|
47947
48098
|
this.handleSchedulePing = async (event) => {
|
|
47948
48099
|
bt.loggerService.info(STORAGE_BACKTEST_METHOD_NAME_HANDLE_SCHEDULE_PING, {
|
|
47949
48100
|
signalId: event.data.id,
|
|
@@ -48115,6 +48266,13 @@ class StorageMemoryBacktestUtils {
|
|
|
48115
48266
|
bt.loggerService.info(STORAGE_MEMORY_BACKTEST_METHOD_NAME_LIST);
|
|
48116
48267
|
return Array.from(this._signals.values());
|
|
48117
48268
|
};
|
|
48269
|
+
/**
|
|
48270
|
+
* Handles active ping event for an opened signal.
|
|
48271
|
+
* Updates the signal's PnL and timestamp if the event is newer than the stored state.
|
|
48272
|
+
* In-memory only — no disk persistence.
|
|
48273
|
+
*
|
|
48274
|
+
* @param event - Active ping contract with signal data and current price
|
|
48275
|
+
*/
|
|
48118
48276
|
this.handleActivePing = async (event) => {
|
|
48119
48277
|
bt.loggerService.info(STORAGE_MEMORY_BACKTEST_METHOD_NAME_HANDLE_ACTIVE_PING, {
|
|
48120
48278
|
signalId: event.data.id,
|
|
@@ -48136,6 +48294,13 @@ class StorageMemoryBacktestUtils {
|
|
|
48136
48294
|
updatedAt: event.timestamp,
|
|
48137
48295
|
});
|
|
48138
48296
|
};
|
|
48297
|
+
/**
|
|
48298
|
+
* Handles schedule ping event for a scheduled signal.
|
|
48299
|
+
* Updates the signal's data and timestamp if the event is newer than the stored state.
|
|
48300
|
+
* In-memory only — no disk persistence.
|
|
48301
|
+
*
|
|
48302
|
+
* @param event - Schedule ping contract with signal data and current price
|
|
48303
|
+
*/
|
|
48139
48304
|
this.handleSchedulePing = async (event) => {
|
|
48140
48305
|
bt.loggerService.info(STORAGE_MEMORY_BACKTEST_METHOD_NAME_HANDLE_SCHEDULE_PING, {
|
|
48141
48306
|
signalId: event.data.id,
|
|
@@ -48215,8 +48380,14 @@ class StorageDummyBacktestUtils {
|
|
|
48215
48380
|
this.list = async () => {
|
|
48216
48381
|
return [];
|
|
48217
48382
|
};
|
|
48383
|
+
/**
|
|
48384
|
+
* No-op handler for active ping events (dummy adapter discards all writes).
|
|
48385
|
+
*/
|
|
48218
48386
|
this.handleActivePing = async () => {
|
|
48219
48387
|
};
|
|
48388
|
+
/**
|
|
48389
|
+
* No-op handler for schedule ping events (dummy adapter discards all writes).
|
|
48390
|
+
*/
|
|
48220
48391
|
this.handleSchedulePing = async () => {
|
|
48221
48392
|
};
|
|
48222
48393
|
}
|
|
@@ -48363,6 +48534,13 @@ class StoragePersistLiveUtils {
|
|
|
48363
48534
|
await this.waitForInit();
|
|
48364
48535
|
return Array.from(this._signals.values());
|
|
48365
48536
|
};
|
|
48537
|
+
/**
|
|
48538
|
+
* Handles active ping event for an opened signal.
|
|
48539
|
+
* Updates the signal's PnL and timestamp if the event is newer than the stored state.
|
|
48540
|
+
* Persists updated state to disk.
|
|
48541
|
+
*
|
|
48542
|
+
* @param event - Active ping contract with signal data and current price
|
|
48543
|
+
*/
|
|
48366
48544
|
this.handleActivePing = async (event) => {
|
|
48367
48545
|
bt.loggerService.info(STORAGE_LIVE_METHOD_NAME_HANDLE_ACTIVE_PING, {
|
|
48368
48546
|
signalId: event.data.id,
|
|
@@ -48386,6 +48564,13 @@ class StoragePersistLiveUtils {
|
|
|
48386
48564
|
});
|
|
48387
48565
|
await this._updateStorage();
|
|
48388
48566
|
};
|
|
48567
|
+
/**
|
|
48568
|
+
* Handles schedule ping event for a scheduled signal.
|
|
48569
|
+
* Updates the signal's data and timestamp if the event is newer than the stored state.
|
|
48570
|
+
* Persists updated state to disk.
|
|
48571
|
+
*
|
|
48572
|
+
* @param event - Schedule ping contract with signal data and current price
|
|
48573
|
+
*/
|
|
48389
48574
|
this.handleSchedulePing = async (event) => {
|
|
48390
48575
|
bt.loggerService.info(STORAGE_LIVE_METHOD_NAME_HANDLE_SCHEDULE_PING, {
|
|
48391
48576
|
signalId: event.data.id,
|
|
@@ -48557,6 +48742,13 @@ class StorageMemoryLiveUtils {
|
|
|
48557
48742
|
bt.loggerService.info(STORAGE_MEMORY_LIVE_METHOD_NAME_LIST);
|
|
48558
48743
|
return Array.from(this._signals.values());
|
|
48559
48744
|
};
|
|
48745
|
+
/**
|
|
48746
|
+
* Handles active ping event for an opened signal.
|
|
48747
|
+
* Updates the signal's PnL and timestamp if the event is newer than the stored state.
|
|
48748
|
+
* In-memory only — no disk persistence.
|
|
48749
|
+
*
|
|
48750
|
+
* @param event - Active ping contract with signal data and current price
|
|
48751
|
+
*/
|
|
48560
48752
|
this.handleActivePing = async (event) => {
|
|
48561
48753
|
bt.loggerService.info(STORAGE_MEMORY_LIVE_METHOD_NAME_HANDLE_ACTIVE_PING, {
|
|
48562
48754
|
signalId: event.data.id,
|
|
@@ -48578,6 +48770,13 @@ class StorageMemoryLiveUtils {
|
|
|
48578
48770
|
updatedAt: event.timestamp,
|
|
48579
48771
|
});
|
|
48580
48772
|
};
|
|
48773
|
+
/**
|
|
48774
|
+
* Handles schedule ping event for a scheduled signal.
|
|
48775
|
+
* Updates the signal's data and timestamp if the event is newer than the stored state.
|
|
48776
|
+
* In-memory only — no disk persistence.
|
|
48777
|
+
*
|
|
48778
|
+
* @param event - Schedule ping contract with signal data and current price
|
|
48779
|
+
*/
|
|
48581
48780
|
this.handleSchedulePing = async (event) => {
|
|
48582
48781
|
bt.loggerService.info(STORAGE_MEMORY_LIVE_METHOD_NAME_HANDLE_SCHEDULE_PING, {
|
|
48583
48782
|
signalId: event.data.id,
|
|
@@ -48657,8 +48856,14 @@ class StorageDummyLiveUtils {
|
|
|
48657
48856
|
this.list = async () => {
|
|
48658
48857
|
return [];
|
|
48659
48858
|
};
|
|
48859
|
+
/**
|
|
48860
|
+
* No-op handler for active ping events (dummy adapter discards all writes).
|
|
48861
|
+
*/
|
|
48660
48862
|
this.handleActivePing = async () => {
|
|
48661
48863
|
};
|
|
48864
|
+
/**
|
|
48865
|
+
* No-op handler for schedule ping events (dummy adapter discards all writes).
|
|
48866
|
+
*/
|
|
48662
48867
|
this.handleSchedulePing = async () => {
|
|
48663
48868
|
};
|
|
48664
48869
|
}
|