backtest-kit 1.6.3 → 1.6.4
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 +131 -38
- package/build/index.mjs +131 -38
- package/package.json +1 -1
- package/types.d.ts +13 -7
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
# 🧿 Backtest Kit
|
|
4
4
|
|
|
5
|
-
> A TypeScript framework for backtesting and live trading strategies on multi-asset, crypto or
|
|
5
|
+
> A TypeScript framework for backtesting and live trading strategies on multi-asset, crypto, forex or [DEX (peer-to-peer marketplace)](https://en.wikipedia.org/wiki/Decentralized_finance#Decentralized_exchanges) with crash-safe persistence, signal validation, and AI optimization.
|
|
6
6
|
|
|
7
7
|

|
|
8
8
|
|
package/build/index.cjs
CHANGED
|
@@ -3760,6 +3760,15 @@ const GET_RISK_FN = (dto, backtest, self) => {
|
|
|
3760
3760
|
...dto.riskList.map((riskName) => self.riskConnectionService.getRisk(riskName, backtest)),
|
|
3761
3761
|
]);
|
|
3762
3762
|
};
|
|
3763
|
+
/**
|
|
3764
|
+
* Creates a unique key for memoizing ClientStrategy instances.
|
|
3765
|
+
* Key format: "symbol:strategyName:backtest" or "symbol:strategyName:live"
|
|
3766
|
+
* @param symbol - Trading pair symbol
|
|
3767
|
+
* @param strategyName - Name of the strategy
|
|
3768
|
+
* @param backtest - Whether running in backtest mode
|
|
3769
|
+
* @returns Unique string key for memoization
|
|
3770
|
+
*/
|
|
3771
|
+
const CREATE_KEY_FN$9 = (symbol, strategyName, backtest) => `${symbol}:${strategyName}:${backtest ? "backtest" : "live"}`;
|
|
3763
3772
|
/**
|
|
3764
3773
|
* Callback function for emitting ping events to pingSubject.
|
|
3765
3774
|
*
|
|
@@ -3820,7 +3829,7 @@ class StrategyConnectionService {
|
|
|
3820
3829
|
* @param strategyName - Name of registered strategy schema
|
|
3821
3830
|
* @returns Configured ClientStrategy instance
|
|
3822
3831
|
*/
|
|
3823
|
-
this.getStrategy = functoolsKit.memoize(([symbol, strategyName, backtest]) =>
|
|
3832
|
+
this.getStrategy = functoolsKit.memoize(([symbol, strategyName, backtest]) => CREATE_KEY_FN$9(symbol, strategyName, backtest), (symbol, strategyName, backtest) => {
|
|
3824
3833
|
const { riskName = "", riskList = [], getSignal, interval, callbacks, } = this.strategySchemaService.get(strategyName);
|
|
3825
3834
|
return new ClientStrategy({
|
|
3826
3835
|
symbol,
|
|
@@ -3987,7 +3996,7 @@ class StrategyConnectionService {
|
|
|
3987
3996
|
ctx,
|
|
3988
3997
|
});
|
|
3989
3998
|
if (ctx) {
|
|
3990
|
-
const key =
|
|
3999
|
+
const key = CREATE_KEY_FN$9(ctx.symbol, ctx.strategyName, backtest);
|
|
3991
4000
|
this.getStrategy.clear(key);
|
|
3992
4001
|
}
|
|
3993
4002
|
else {
|
|
@@ -4590,6 +4599,14 @@ class ClientRisk {
|
|
|
4590
4599
|
}
|
|
4591
4600
|
}
|
|
4592
4601
|
|
|
4602
|
+
/**
|
|
4603
|
+
* Creates a unique key for memoizing ClientRisk instances.
|
|
4604
|
+
* Key format: "riskName:backtest" or "riskName:live"
|
|
4605
|
+
* @param riskName - Name of the risk schema
|
|
4606
|
+
* @param backtest - Whether running in backtest mode
|
|
4607
|
+
* @returns Unique string key for memoization
|
|
4608
|
+
*/
|
|
4609
|
+
const CREATE_KEY_FN$8 = (riskName, backtest) => `${riskName}:${backtest ? "backtest" : "live"}`;
|
|
4593
4610
|
/**
|
|
4594
4611
|
* Callback function for emitting risk rejection events to riskSubject.
|
|
4595
4612
|
*
|
|
@@ -4661,7 +4678,7 @@ class RiskConnectionService {
|
|
|
4661
4678
|
* @param backtest - True if backtest mode, false if live mode
|
|
4662
4679
|
* @returns Configured ClientRisk instance
|
|
4663
4680
|
*/
|
|
4664
|
-
this.getRisk = functoolsKit.memoize(([riskName, backtest]) =>
|
|
4681
|
+
this.getRisk = functoolsKit.memoize(([riskName, backtest]) => CREATE_KEY_FN$8(riskName, backtest), (riskName, backtest) => {
|
|
4665
4682
|
const schema = this.riskSchemaService.get(riskName);
|
|
4666
4683
|
return new ClientRisk({
|
|
4667
4684
|
...schema,
|
|
@@ -4719,15 +4736,21 @@ class RiskConnectionService {
|
|
|
4719
4736
|
/**
|
|
4720
4737
|
* Clears the cached ClientRisk instance for the given risk name.
|
|
4721
4738
|
*
|
|
4722
|
-
* @param
|
|
4739
|
+
* @param backtest - Whether running in backtest mode
|
|
4740
|
+
* @param ctx - Optional context with riskName (clears all if not provided)
|
|
4723
4741
|
*/
|
|
4724
|
-
this.clear = async (backtest,
|
|
4742
|
+
this.clear = async (backtest, ctx) => {
|
|
4725
4743
|
this.loggerService.log("riskConnectionService clear", {
|
|
4726
|
-
|
|
4744
|
+
ctx,
|
|
4727
4745
|
backtest,
|
|
4728
4746
|
});
|
|
4729
|
-
|
|
4730
|
-
|
|
4747
|
+
if (ctx) {
|
|
4748
|
+
const key = CREATE_KEY_FN$8(ctx.riskName, backtest);
|
|
4749
|
+
this.getRisk.clear(key);
|
|
4750
|
+
}
|
|
4751
|
+
else {
|
|
4752
|
+
this.getRisk.clear();
|
|
4753
|
+
}
|
|
4731
4754
|
};
|
|
4732
4755
|
}
|
|
4733
4756
|
}
|
|
@@ -5256,19 +5279,20 @@ class RiskGlobalService {
|
|
|
5256
5279
|
};
|
|
5257
5280
|
/**
|
|
5258
5281
|
* Clears risk data.
|
|
5259
|
-
* If
|
|
5260
|
-
* If no
|
|
5261
|
-
* @param
|
|
5282
|
+
* If ctx is provided, clears data for that specific risk instance.
|
|
5283
|
+
* If no ctx is provided, clears all risk data.
|
|
5284
|
+
* @param backtest - Whether running in backtest mode
|
|
5285
|
+
* @param ctx - Optional context with riskName (clears all if not provided)
|
|
5262
5286
|
*/
|
|
5263
|
-
this.clear = async (backtest,
|
|
5287
|
+
this.clear = async (backtest, ctx) => {
|
|
5264
5288
|
this.loggerService.log("riskGlobalService clear", {
|
|
5265
|
-
|
|
5289
|
+
ctx,
|
|
5266
5290
|
backtest,
|
|
5267
5291
|
});
|
|
5268
|
-
if (
|
|
5269
|
-
await this.validate(riskName);
|
|
5292
|
+
if (ctx) {
|
|
5293
|
+
await this.validate(ctx.riskName);
|
|
5270
5294
|
}
|
|
5271
|
-
return await this.riskConnectionService.clear(backtest,
|
|
5295
|
+
return await this.riskConnectionService.clear(backtest, ctx);
|
|
5272
5296
|
};
|
|
5273
5297
|
}
|
|
5274
5298
|
}
|
|
@@ -7761,6 +7785,15 @@ const COLUMN_CONFIG = {
|
|
|
7761
7785
|
*/
|
|
7762
7786
|
const DEFAULT_COLUMNS = Object.freeze({ ...COLUMN_CONFIG });
|
|
7763
7787
|
|
|
7788
|
+
/**
|
|
7789
|
+
* Creates a unique key for memoizing ReportStorage instances.
|
|
7790
|
+
* Key format: "symbol:strategyName:backtest" or "symbol:strategyName:live"
|
|
7791
|
+
* @param symbol - Trading pair symbol
|
|
7792
|
+
* @param strategyName - Name of the strategy
|
|
7793
|
+
* @param backtest - Whether running in backtest mode
|
|
7794
|
+
* @returns Unique string key for memoization
|
|
7795
|
+
*/
|
|
7796
|
+
const CREATE_KEY_FN$7 = (symbol, strategyName, backtest) => `${symbol}:${strategyName}:${backtest ? "backtest" : "live"}`;
|
|
7764
7797
|
/**
|
|
7765
7798
|
* Checks if a value is unsafe for display (not a number, NaN, or Infinity).
|
|
7766
7799
|
*
|
|
@@ -7969,7 +8002,7 @@ class BacktestMarkdownService {
|
|
|
7969
8002
|
* Memoized function to get or create ReportStorage for a symbol-strategy-backtest triple.
|
|
7970
8003
|
* Each symbol-strategy-backtest combination gets its own isolated storage instance.
|
|
7971
8004
|
*/
|
|
7972
|
-
this.getStorage = functoolsKit.memoize(([symbol, strategyName, backtest]) =>
|
|
8005
|
+
this.getStorage = functoolsKit.memoize(([symbol, strategyName, backtest]) => CREATE_KEY_FN$7(symbol, strategyName, backtest), () => new ReportStorage$5());
|
|
7973
8006
|
/**
|
|
7974
8007
|
* Processes tick events and accumulates closed signals.
|
|
7975
8008
|
* Should be called from IStrategyCallbacks.onTick.
|
|
@@ -8107,7 +8140,7 @@ class BacktestMarkdownService {
|
|
|
8107
8140
|
ctx,
|
|
8108
8141
|
});
|
|
8109
8142
|
if (ctx) {
|
|
8110
|
-
const key =
|
|
8143
|
+
const key = CREATE_KEY_FN$7(ctx.symbol, ctx.strategyName, backtest);
|
|
8111
8144
|
this.getStorage.clear(key);
|
|
8112
8145
|
}
|
|
8113
8146
|
else {
|
|
@@ -8132,6 +8165,15 @@ class BacktestMarkdownService {
|
|
|
8132
8165
|
}
|
|
8133
8166
|
}
|
|
8134
8167
|
|
|
8168
|
+
/**
|
|
8169
|
+
* Creates a unique key for memoizing ReportStorage instances.
|
|
8170
|
+
* Key format: "symbol:strategyName:backtest" or "symbol:strategyName:live"
|
|
8171
|
+
* @param symbol - Trading pair symbol
|
|
8172
|
+
* @param strategyName - Name of the strategy
|
|
8173
|
+
* @param backtest - Whether running in backtest mode
|
|
8174
|
+
* @returns Unique string key for memoization
|
|
8175
|
+
*/
|
|
8176
|
+
const CREATE_KEY_FN$6 = (symbol, strategyName, backtest) => `${symbol}:${strategyName}:${backtest ? "backtest" : "live"}`;
|
|
8135
8177
|
/**
|
|
8136
8178
|
* Checks if a value is unsafe for display (not a number, NaN, or Infinity).
|
|
8137
8179
|
*
|
|
@@ -8461,7 +8503,7 @@ class LiveMarkdownService {
|
|
|
8461
8503
|
* Memoized function to get or create ReportStorage for a symbol-strategy-backtest triple.
|
|
8462
8504
|
* Each symbol-strategy-backtest combination gets its own isolated storage instance.
|
|
8463
8505
|
*/
|
|
8464
|
-
this.getStorage = functoolsKit.memoize(([symbol, strategyName, backtest]) =>
|
|
8506
|
+
this.getStorage = functoolsKit.memoize(([symbol, strategyName, backtest]) => CREATE_KEY_FN$6(symbol, strategyName, backtest), () => new ReportStorage$4());
|
|
8465
8507
|
/**
|
|
8466
8508
|
* Processes tick events and accumulates all event types.
|
|
8467
8509
|
* Should be called from IStrategyCallbacks.onTick.
|
|
@@ -8609,7 +8651,7 @@ class LiveMarkdownService {
|
|
|
8609
8651
|
ctx,
|
|
8610
8652
|
});
|
|
8611
8653
|
if (ctx) {
|
|
8612
|
-
const key =
|
|
8654
|
+
const key = CREATE_KEY_FN$6(ctx.symbol, ctx.strategyName, backtest);
|
|
8613
8655
|
this.getStorage.clear(key);
|
|
8614
8656
|
}
|
|
8615
8657
|
else {
|
|
@@ -8634,6 +8676,15 @@ class LiveMarkdownService {
|
|
|
8634
8676
|
}
|
|
8635
8677
|
}
|
|
8636
8678
|
|
|
8679
|
+
/**
|
|
8680
|
+
* Creates a unique key for memoizing ReportStorage instances.
|
|
8681
|
+
* Key format: "symbol:strategyName:backtest" or "symbol:strategyName:live"
|
|
8682
|
+
* @param symbol - Trading pair symbol
|
|
8683
|
+
* @param strategyName - Name of the strategy
|
|
8684
|
+
* @param backtest - Whether running in backtest mode
|
|
8685
|
+
* @returns Unique string key for memoization
|
|
8686
|
+
*/
|
|
8687
|
+
const CREATE_KEY_FN$5 = (symbol, strategyName, backtest) => `${symbol}:${strategyName}:${backtest ? "backtest" : "live"}`;
|
|
8637
8688
|
/** Maximum number of events to store in schedule reports */
|
|
8638
8689
|
const MAX_EVENTS$4 = 250;
|
|
8639
8690
|
/**
|
|
@@ -8869,7 +8920,7 @@ class ScheduleMarkdownService {
|
|
|
8869
8920
|
* Memoized function to get or create ReportStorage for a symbol-strategy-backtest triple.
|
|
8870
8921
|
* Each symbol-strategy-backtest combination gets its own isolated storage instance.
|
|
8871
8922
|
*/
|
|
8872
|
-
this.getStorage = functoolsKit.memoize(([symbol, strategyName, backtest]) =>
|
|
8923
|
+
this.getStorage = functoolsKit.memoize(([symbol, strategyName, backtest]) => CREATE_KEY_FN$5(symbol, strategyName, backtest), () => new ReportStorage$3());
|
|
8873
8924
|
/**
|
|
8874
8925
|
* Processes tick events and accumulates scheduled/opened/cancelled events.
|
|
8875
8926
|
* Should be called from signalEmitter subscription.
|
|
@@ -9011,7 +9062,7 @@ class ScheduleMarkdownService {
|
|
|
9011
9062
|
ctx,
|
|
9012
9063
|
});
|
|
9013
9064
|
if (ctx) {
|
|
9014
|
-
const key =
|
|
9065
|
+
const key = CREATE_KEY_FN$5(ctx.symbol, ctx.strategyName, backtest);
|
|
9015
9066
|
this.getStorage.clear(key);
|
|
9016
9067
|
}
|
|
9017
9068
|
else {
|
|
@@ -9036,6 +9087,15 @@ class ScheduleMarkdownService {
|
|
|
9036
9087
|
}
|
|
9037
9088
|
}
|
|
9038
9089
|
|
|
9090
|
+
/**
|
|
9091
|
+
* Creates a unique key for memoizing PerformanceStorage instances.
|
|
9092
|
+
* Key format: "symbol:strategyName:backtest" or "symbol:strategyName:live"
|
|
9093
|
+
* @param symbol - Trading pair symbol
|
|
9094
|
+
* @param strategyName - Name of the strategy
|
|
9095
|
+
* @param backtest - Whether running in backtest mode
|
|
9096
|
+
* @returns Unique string key for memoization
|
|
9097
|
+
*/
|
|
9098
|
+
const CREATE_KEY_FN$4 = (symbol, strategyName, backtest) => `${symbol}:${strategyName}:${backtest ? "backtest" : "live"}`;
|
|
9039
9099
|
/**
|
|
9040
9100
|
* Calculates percentile value from sorted array.
|
|
9041
9101
|
*/
|
|
@@ -9253,7 +9313,7 @@ class PerformanceMarkdownService {
|
|
|
9253
9313
|
* Memoized function to get or create PerformanceStorage for a symbol-strategy-backtest triple.
|
|
9254
9314
|
* Each symbol-strategy-backtest combination gets its own isolated storage instance.
|
|
9255
9315
|
*/
|
|
9256
|
-
this.getStorage = functoolsKit.memoize(([symbol, strategyName, backtest]) =>
|
|
9316
|
+
this.getStorage = functoolsKit.memoize(([symbol, strategyName, backtest]) => CREATE_KEY_FN$4(symbol, strategyName, backtest), () => new PerformanceStorage());
|
|
9257
9317
|
/**
|
|
9258
9318
|
* Processes performance events and accumulates metrics.
|
|
9259
9319
|
* Should be called from performance tracking code.
|
|
@@ -9358,7 +9418,7 @@ class PerformanceMarkdownService {
|
|
|
9358
9418
|
ctx,
|
|
9359
9419
|
});
|
|
9360
9420
|
if (ctx) {
|
|
9361
|
-
const key =
|
|
9421
|
+
const key = CREATE_KEY_FN$4(ctx.symbol, ctx.strategyName, backtest);
|
|
9362
9422
|
this.getStorage.clear(key);
|
|
9363
9423
|
}
|
|
9364
9424
|
else {
|
|
@@ -9785,6 +9845,14 @@ class WalkerMarkdownService {
|
|
|
9785
9845
|
}
|
|
9786
9846
|
}
|
|
9787
9847
|
|
|
9848
|
+
/**
|
|
9849
|
+
* Creates a unique key for memoizing HeatmapStorage instances.
|
|
9850
|
+
* Key format: "strategyName:backtest" or "strategyName:live"
|
|
9851
|
+
* @param strategyName - Name of the strategy
|
|
9852
|
+
* @param backtest - Whether running in backtest mode
|
|
9853
|
+
* @returns Unique string key for memoization
|
|
9854
|
+
*/
|
|
9855
|
+
const CREATE_KEY_FN$3 = (strategyName, backtest) => `${strategyName}:${backtest ? "backtest" : "live"}`;
|
|
9788
9856
|
const HEATMAP_METHOD_NAME_GET_DATA = "HeatMarkdownService.getData";
|
|
9789
9857
|
const HEATMAP_METHOD_NAME_GET_REPORT = "HeatMarkdownService.getReport";
|
|
9790
9858
|
const HEATMAP_METHOD_NAME_DUMP = "HeatMarkdownService.dump";
|
|
@@ -10128,7 +10196,7 @@ class HeatMarkdownService {
|
|
|
10128
10196
|
* Memoized function to get or create HeatmapStorage for a strategy and backtest mode.
|
|
10129
10197
|
* Each strategy + backtest mode combination gets its own isolated heatmap storage instance.
|
|
10130
10198
|
*/
|
|
10131
|
-
this.getStorage = functoolsKit.memoize(([strategyName, backtest]) =>
|
|
10199
|
+
this.getStorage = functoolsKit.memoize(([strategyName, backtest]) => CREATE_KEY_FN$3(strategyName, backtest), () => new HeatmapStorage());
|
|
10132
10200
|
/**
|
|
10133
10201
|
* Processes tick events and accumulates closed signals.
|
|
10134
10202
|
* Should be called from signal emitter subscription.
|
|
@@ -10264,7 +10332,7 @@ class HeatMarkdownService {
|
|
|
10264
10332
|
ctx,
|
|
10265
10333
|
});
|
|
10266
10334
|
if (ctx) {
|
|
10267
|
-
const key =
|
|
10335
|
+
const key = CREATE_KEY_FN$3(ctx.strategyName, backtest);
|
|
10268
10336
|
this.getStorage.clear(key);
|
|
10269
10337
|
}
|
|
10270
10338
|
else {
|
|
@@ -12474,6 +12542,15 @@ class ClientPartial {
|
|
|
12474
12542
|
}
|
|
12475
12543
|
}
|
|
12476
12544
|
|
|
12545
|
+
/**
|
|
12546
|
+
* Creates a unique key for memoizing ClientPartial instances.
|
|
12547
|
+
* Key format: "signalId:backtest" or "signalId:live"
|
|
12548
|
+
*
|
|
12549
|
+
* @param signalId - Signal ID
|
|
12550
|
+
* @param backtest - Whether running in backtest mode
|
|
12551
|
+
* @returns Unique string key for memoization
|
|
12552
|
+
*/
|
|
12553
|
+
const CREATE_KEY_FN$2 = (signalId, backtest) => `${signalId}:${backtest ? "backtest" : "live"}`;
|
|
12477
12554
|
/**
|
|
12478
12555
|
* Callback function for emitting profit events to partialProfitSubject.
|
|
12479
12556
|
*
|
|
@@ -12571,7 +12648,7 @@ class PartialConnectionService {
|
|
|
12571
12648
|
* Key format: "signalId:backtest" or "signalId:live"
|
|
12572
12649
|
* Value: ClientPartial instance with logger and event emitters
|
|
12573
12650
|
*/
|
|
12574
|
-
this.getPartial = functoolsKit.memoize(([signalId, backtest]) =>
|
|
12651
|
+
this.getPartial = functoolsKit.memoize(([signalId, backtest]) => CREATE_KEY_FN$2(signalId, backtest), (signalId, backtest) => {
|
|
12575
12652
|
return new ClientPartial({
|
|
12576
12653
|
signalId,
|
|
12577
12654
|
logger: this.loggerService,
|
|
@@ -12661,12 +12738,19 @@ class PartialConnectionService {
|
|
|
12661
12738
|
const partial = this.getPartial(data.id, backtest);
|
|
12662
12739
|
await partial.waitForInit(symbol, data.strategyName);
|
|
12663
12740
|
await partial.clear(symbol, data, priceClose, backtest);
|
|
12664
|
-
const key =
|
|
12741
|
+
const key = CREATE_KEY_FN$2(data.id, backtest);
|
|
12665
12742
|
this.getPartial.clear(key);
|
|
12666
12743
|
};
|
|
12667
12744
|
}
|
|
12668
12745
|
}
|
|
12669
12746
|
|
|
12747
|
+
/**
|
|
12748
|
+
* Creates a unique key for memoizing ReportStorage instances.
|
|
12749
|
+
* Key format: "symbol:strategyName:backtest" or "symbol:strategyName:live"
|
|
12750
|
+
* @param param0 - Tuple of symbol, strategyName and backtest boolean
|
|
12751
|
+
* @returns Unique string key for memoization
|
|
12752
|
+
*/
|
|
12753
|
+
const CREATE_KEY_FN$1 = ([symbol, strategyName, backtest]) => `${symbol}:${strategyName}:${backtest ? "backtest" : "live"}`;
|
|
12670
12754
|
/** Maximum number of events to store in partial reports */
|
|
12671
12755
|
const MAX_EVENTS$1 = 250;
|
|
12672
12756
|
/**
|
|
@@ -12841,7 +12925,7 @@ class PartialMarkdownService {
|
|
|
12841
12925
|
* Memoized function to get or create ReportStorage for a symbol-strategy-backtest triple.
|
|
12842
12926
|
* Each symbol-strategy-backtest combination gets its own isolated storage instance.
|
|
12843
12927
|
*/
|
|
12844
|
-
this.getStorage = functoolsKit.memoize(
|
|
12928
|
+
this.getStorage = functoolsKit.memoize(CREATE_KEY_FN$1, () => new ReportStorage$1());
|
|
12845
12929
|
/**
|
|
12846
12930
|
* Processes profit events and accumulates them.
|
|
12847
12931
|
* Should be called from partialProfitSubject subscription.
|
|
@@ -12988,7 +13072,7 @@ class PartialMarkdownService {
|
|
|
12988
13072
|
ctx,
|
|
12989
13073
|
});
|
|
12990
13074
|
if (ctx) {
|
|
12991
|
-
const key =
|
|
13075
|
+
const key = CREATE_KEY_FN$1([ctx.symbol, ctx.strategyName, backtest]);
|
|
12992
13076
|
this.getStorage.clear(key);
|
|
12993
13077
|
}
|
|
12994
13078
|
else {
|
|
@@ -13423,6 +13507,15 @@ class ConfigValidationService {
|
|
|
13423
13507
|
}
|
|
13424
13508
|
}
|
|
13425
13509
|
|
|
13510
|
+
/**
|
|
13511
|
+
* Creates a unique key for memoizing ReportStorage instances.
|
|
13512
|
+
* Key format: "symbol:strategyName:backtest" or "symbol:strategyName:live"
|
|
13513
|
+
* @param symbol - Trading pair symbol
|
|
13514
|
+
* @param strategyName - Name of the strategy
|
|
13515
|
+
* @param backtest - Whether running in backtest mode
|
|
13516
|
+
* @returns Unique string key for memoization
|
|
13517
|
+
*/
|
|
13518
|
+
const CREATE_KEY_FN = (symbol, strategyName, backtest) => `${symbol}:${strategyName}:${backtest ? "backtest" : "live"}`;
|
|
13426
13519
|
/** Maximum number of events to store in risk reports */
|
|
13427
13520
|
const MAX_EVENTS = 250;
|
|
13428
13521
|
/**
|
|
@@ -13567,7 +13660,7 @@ class RiskMarkdownService {
|
|
|
13567
13660
|
* Memoized function to get or create ReportStorage for a symbol-strategy-backtest triple.
|
|
13568
13661
|
* Each symbol-strategy-backtest combination gets its own isolated storage instance.
|
|
13569
13662
|
*/
|
|
13570
|
-
this.getStorage = functoolsKit.memoize(([symbol, strategyName, backtest]) =>
|
|
13663
|
+
this.getStorage = functoolsKit.memoize(([symbol, strategyName, backtest]) => CREATE_KEY_FN(symbol, strategyName, backtest), () => new ReportStorage());
|
|
13571
13664
|
/**
|
|
13572
13665
|
* Processes risk rejection events and accumulates them.
|
|
13573
13666
|
* Should be called from riskSubject subscription.
|
|
@@ -13695,7 +13788,7 @@ class RiskMarkdownService {
|
|
|
13695
13788
|
ctx,
|
|
13696
13789
|
});
|
|
13697
13790
|
if (ctx) {
|
|
13698
|
-
const key =
|
|
13791
|
+
const key = CREATE_KEY_FN(ctx.symbol, ctx.strategyName, backtest);
|
|
13699
13792
|
this.getStorage.clear(key);
|
|
13700
13793
|
}
|
|
13701
13794
|
else {
|
|
@@ -16407,8 +16500,8 @@ class BacktestInstance {
|
|
|
16407
16500
|
}
|
|
16408
16501
|
{
|
|
16409
16502
|
const { riskName, riskList } = backtest$1.strategySchemaService.get(context.strategyName);
|
|
16410
|
-
riskName && backtest$1.riskGlobalService.clear(true, riskName);
|
|
16411
|
-
riskList && riskList.forEach((riskName) => backtest$1.riskGlobalService.clear(true, riskName));
|
|
16503
|
+
riskName && backtest$1.riskGlobalService.clear(true, { riskName });
|
|
16504
|
+
riskList && riskList.forEach((riskName) => backtest$1.riskGlobalService.clear(true, { riskName }));
|
|
16412
16505
|
}
|
|
16413
16506
|
return backtest$1.backtestCommandService.run(symbol, context);
|
|
16414
16507
|
};
|
|
@@ -17081,8 +17174,8 @@ class LiveInstance {
|
|
|
17081
17174
|
}
|
|
17082
17175
|
{
|
|
17083
17176
|
const { riskName, riskList } = backtest$1.strategySchemaService.get(context.strategyName);
|
|
17084
|
-
riskName && backtest$1.riskGlobalService.clear(false, riskName);
|
|
17085
|
-
riskList && riskList.forEach((riskName) => backtest$1.riskGlobalService.clear(false, riskName));
|
|
17177
|
+
riskName && backtest$1.riskGlobalService.clear(false, { riskName });
|
|
17178
|
+
riskList && riskList.forEach((riskName) => backtest$1.riskGlobalService.clear(false, { riskName }));
|
|
17086
17179
|
}
|
|
17087
17180
|
return backtest$1.liveCommandService.run(symbol, context);
|
|
17088
17181
|
};
|
|
@@ -18033,9 +18126,9 @@ class WalkerInstance {
|
|
|
18033
18126
|
}
|
|
18034
18127
|
{
|
|
18035
18128
|
const { riskName, riskList } = backtest$1.strategySchemaService.get(strategyName);
|
|
18036
|
-
riskName && backtest$1.riskGlobalService.clear(true, riskName);
|
|
18129
|
+
riskName && backtest$1.riskGlobalService.clear(true, { riskName });
|
|
18037
18130
|
riskList &&
|
|
18038
|
-
riskList.forEach((riskName) => backtest$1.riskGlobalService.clear(true, riskName));
|
|
18131
|
+
riskList.forEach((riskName) => backtest$1.riskGlobalService.clear(true, { riskName }));
|
|
18039
18132
|
}
|
|
18040
18133
|
}
|
|
18041
18134
|
return backtest$1.walkerCommandService.run(symbol, {
|
package/build/index.mjs
CHANGED
|
@@ -3758,6 +3758,15 @@ const GET_RISK_FN = (dto, backtest, self) => {
|
|
|
3758
3758
|
...dto.riskList.map((riskName) => self.riskConnectionService.getRisk(riskName, backtest)),
|
|
3759
3759
|
]);
|
|
3760
3760
|
};
|
|
3761
|
+
/**
|
|
3762
|
+
* Creates a unique key for memoizing ClientStrategy instances.
|
|
3763
|
+
* Key format: "symbol:strategyName:backtest" or "symbol:strategyName:live"
|
|
3764
|
+
* @param symbol - Trading pair symbol
|
|
3765
|
+
* @param strategyName - Name of the strategy
|
|
3766
|
+
* @param backtest - Whether running in backtest mode
|
|
3767
|
+
* @returns Unique string key for memoization
|
|
3768
|
+
*/
|
|
3769
|
+
const CREATE_KEY_FN$9 = (symbol, strategyName, backtest) => `${symbol}:${strategyName}:${backtest ? "backtest" : "live"}`;
|
|
3761
3770
|
/**
|
|
3762
3771
|
* Callback function for emitting ping events to pingSubject.
|
|
3763
3772
|
*
|
|
@@ -3818,7 +3827,7 @@ class StrategyConnectionService {
|
|
|
3818
3827
|
* @param strategyName - Name of registered strategy schema
|
|
3819
3828
|
* @returns Configured ClientStrategy instance
|
|
3820
3829
|
*/
|
|
3821
|
-
this.getStrategy = memoize(([symbol, strategyName, backtest]) =>
|
|
3830
|
+
this.getStrategy = memoize(([symbol, strategyName, backtest]) => CREATE_KEY_FN$9(symbol, strategyName, backtest), (symbol, strategyName, backtest) => {
|
|
3822
3831
|
const { riskName = "", riskList = [], getSignal, interval, callbacks, } = this.strategySchemaService.get(strategyName);
|
|
3823
3832
|
return new ClientStrategy({
|
|
3824
3833
|
symbol,
|
|
@@ -3985,7 +3994,7 @@ class StrategyConnectionService {
|
|
|
3985
3994
|
ctx,
|
|
3986
3995
|
});
|
|
3987
3996
|
if (ctx) {
|
|
3988
|
-
const key =
|
|
3997
|
+
const key = CREATE_KEY_FN$9(ctx.symbol, ctx.strategyName, backtest);
|
|
3989
3998
|
this.getStrategy.clear(key);
|
|
3990
3999
|
}
|
|
3991
4000
|
else {
|
|
@@ -4588,6 +4597,14 @@ class ClientRisk {
|
|
|
4588
4597
|
}
|
|
4589
4598
|
}
|
|
4590
4599
|
|
|
4600
|
+
/**
|
|
4601
|
+
* Creates a unique key for memoizing ClientRisk instances.
|
|
4602
|
+
* Key format: "riskName:backtest" or "riskName:live"
|
|
4603
|
+
* @param riskName - Name of the risk schema
|
|
4604
|
+
* @param backtest - Whether running in backtest mode
|
|
4605
|
+
* @returns Unique string key for memoization
|
|
4606
|
+
*/
|
|
4607
|
+
const CREATE_KEY_FN$8 = (riskName, backtest) => `${riskName}:${backtest ? "backtest" : "live"}`;
|
|
4591
4608
|
/**
|
|
4592
4609
|
* Callback function for emitting risk rejection events to riskSubject.
|
|
4593
4610
|
*
|
|
@@ -4659,7 +4676,7 @@ class RiskConnectionService {
|
|
|
4659
4676
|
* @param backtest - True if backtest mode, false if live mode
|
|
4660
4677
|
* @returns Configured ClientRisk instance
|
|
4661
4678
|
*/
|
|
4662
|
-
this.getRisk = memoize(([riskName, backtest]) =>
|
|
4679
|
+
this.getRisk = memoize(([riskName, backtest]) => CREATE_KEY_FN$8(riskName, backtest), (riskName, backtest) => {
|
|
4663
4680
|
const schema = this.riskSchemaService.get(riskName);
|
|
4664
4681
|
return new ClientRisk({
|
|
4665
4682
|
...schema,
|
|
@@ -4717,15 +4734,21 @@ class RiskConnectionService {
|
|
|
4717
4734
|
/**
|
|
4718
4735
|
* Clears the cached ClientRisk instance for the given risk name.
|
|
4719
4736
|
*
|
|
4720
|
-
* @param
|
|
4737
|
+
* @param backtest - Whether running in backtest mode
|
|
4738
|
+
* @param ctx - Optional context with riskName (clears all if not provided)
|
|
4721
4739
|
*/
|
|
4722
|
-
this.clear = async (backtest,
|
|
4740
|
+
this.clear = async (backtest, ctx) => {
|
|
4723
4741
|
this.loggerService.log("riskConnectionService clear", {
|
|
4724
|
-
|
|
4742
|
+
ctx,
|
|
4725
4743
|
backtest,
|
|
4726
4744
|
});
|
|
4727
|
-
|
|
4728
|
-
|
|
4745
|
+
if (ctx) {
|
|
4746
|
+
const key = CREATE_KEY_FN$8(ctx.riskName, backtest);
|
|
4747
|
+
this.getRisk.clear(key);
|
|
4748
|
+
}
|
|
4749
|
+
else {
|
|
4750
|
+
this.getRisk.clear();
|
|
4751
|
+
}
|
|
4729
4752
|
};
|
|
4730
4753
|
}
|
|
4731
4754
|
}
|
|
@@ -5254,19 +5277,20 @@ class RiskGlobalService {
|
|
|
5254
5277
|
};
|
|
5255
5278
|
/**
|
|
5256
5279
|
* Clears risk data.
|
|
5257
|
-
* If
|
|
5258
|
-
* If no
|
|
5259
|
-
* @param
|
|
5280
|
+
* If ctx is provided, clears data for that specific risk instance.
|
|
5281
|
+
* If no ctx is provided, clears all risk data.
|
|
5282
|
+
* @param backtest - Whether running in backtest mode
|
|
5283
|
+
* @param ctx - Optional context with riskName (clears all if not provided)
|
|
5260
5284
|
*/
|
|
5261
|
-
this.clear = async (backtest,
|
|
5285
|
+
this.clear = async (backtest, ctx) => {
|
|
5262
5286
|
this.loggerService.log("riskGlobalService clear", {
|
|
5263
|
-
|
|
5287
|
+
ctx,
|
|
5264
5288
|
backtest,
|
|
5265
5289
|
});
|
|
5266
|
-
if (
|
|
5267
|
-
await this.validate(riskName);
|
|
5290
|
+
if (ctx) {
|
|
5291
|
+
await this.validate(ctx.riskName);
|
|
5268
5292
|
}
|
|
5269
|
-
return await this.riskConnectionService.clear(backtest,
|
|
5293
|
+
return await this.riskConnectionService.clear(backtest, ctx);
|
|
5270
5294
|
};
|
|
5271
5295
|
}
|
|
5272
5296
|
}
|
|
@@ -7759,6 +7783,15 @@ const COLUMN_CONFIG = {
|
|
|
7759
7783
|
*/
|
|
7760
7784
|
const DEFAULT_COLUMNS = Object.freeze({ ...COLUMN_CONFIG });
|
|
7761
7785
|
|
|
7786
|
+
/**
|
|
7787
|
+
* Creates a unique key for memoizing ReportStorage instances.
|
|
7788
|
+
* Key format: "symbol:strategyName:backtest" or "symbol:strategyName:live"
|
|
7789
|
+
* @param symbol - Trading pair symbol
|
|
7790
|
+
* @param strategyName - Name of the strategy
|
|
7791
|
+
* @param backtest - Whether running in backtest mode
|
|
7792
|
+
* @returns Unique string key for memoization
|
|
7793
|
+
*/
|
|
7794
|
+
const CREATE_KEY_FN$7 = (symbol, strategyName, backtest) => `${symbol}:${strategyName}:${backtest ? "backtest" : "live"}`;
|
|
7762
7795
|
/**
|
|
7763
7796
|
* Checks if a value is unsafe for display (not a number, NaN, or Infinity).
|
|
7764
7797
|
*
|
|
@@ -7967,7 +8000,7 @@ class BacktestMarkdownService {
|
|
|
7967
8000
|
* Memoized function to get or create ReportStorage for a symbol-strategy-backtest triple.
|
|
7968
8001
|
* Each symbol-strategy-backtest combination gets its own isolated storage instance.
|
|
7969
8002
|
*/
|
|
7970
|
-
this.getStorage = memoize(([symbol, strategyName, backtest]) =>
|
|
8003
|
+
this.getStorage = memoize(([symbol, strategyName, backtest]) => CREATE_KEY_FN$7(symbol, strategyName, backtest), () => new ReportStorage$5());
|
|
7971
8004
|
/**
|
|
7972
8005
|
* Processes tick events and accumulates closed signals.
|
|
7973
8006
|
* Should be called from IStrategyCallbacks.onTick.
|
|
@@ -8105,7 +8138,7 @@ class BacktestMarkdownService {
|
|
|
8105
8138
|
ctx,
|
|
8106
8139
|
});
|
|
8107
8140
|
if (ctx) {
|
|
8108
|
-
const key =
|
|
8141
|
+
const key = CREATE_KEY_FN$7(ctx.symbol, ctx.strategyName, backtest);
|
|
8109
8142
|
this.getStorage.clear(key);
|
|
8110
8143
|
}
|
|
8111
8144
|
else {
|
|
@@ -8130,6 +8163,15 @@ class BacktestMarkdownService {
|
|
|
8130
8163
|
}
|
|
8131
8164
|
}
|
|
8132
8165
|
|
|
8166
|
+
/**
|
|
8167
|
+
* Creates a unique key for memoizing ReportStorage instances.
|
|
8168
|
+
* Key format: "symbol:strategyName:backtest" or "symbol:strategyName:live"
|
|
8169
|
+
* @param symbol - Trading pair symbol
|
|
8170
|
+
* @param strategyName - Name of the strategy
|
|
8171
|
+
* @param backtest - Whether running in backtest mode
|
|
8172
|
+
* @returns Unique string key for memoization
|
|
8173
|
+
*/
|
|
8174
|
+
const CREATE_KEY_FN$6 = (symbol, strategyName, backtest) => `${symbol}:${strategyName}:${backtest ? "backtest" : "live"}`;
|
|
8133
8175
|
/**
|
|
8134
8176
|
* Checks if a value is unsafe for display (not a number, NaN, or Infinity).
|
|
8135
8177
|
*
|
|
@@ -8459,7 +8501,7 @@ class LiveMarkdownService {
|
|
|
8459
8501
|
* Memoized function to get or create ReportStorage for a symbol-strategy-backtest triple.
|
|
8460
8502
|
* Each symbol-strategy-backtest combination gets its own isolated storage instance.
|
|
8461
8503
|
*/
|
|
8462
|
-
this.getStorage = memoize(([symbol, strategyName, backtest]) =>
|
|
8504
|
+
this.getStorage = memoize(([symbol, strategyName, backtest]) => CREATE_KEY_FN$6(symbol, strategyName, backtest), () => new ReportStorage$4());
|
|
8463
8505
|
/**
|
|
8464
8506
|
* Processes tick events and accumulates all event types.
|
|
8465
8507
|
* Should be called from IStrategyCallbacks.onTick.
|
|
@@ -8607,7 +8649,7 @@ class LiveMarkdownService {
|
|
|
8607
8649
|
ctx,
|
|
8608
8650
|
});
|
|
8609
8651
|
if (ctx) {
|
|
8610
|
-
const key =
|
|
8652
|
+
const key = CREATE_KEY_FN$6(ctx.symbol, ctx.strategyName, backtest);
|
|
8611
8653
|
this.getStorage.clear(key);
|
|
8612
8654
|
}
|
|
8613
8655
|
else {
|
|
@@ -8632,6 +8674,15 @@ class LiveMarkdownService {
|
|
|
8632
8674
|
}
|
|
8633
8675
|
}
|
|
8634
8676
|
|
|
8677
|
+
/**
|
|
8678
|
+
* Creates a unique key for memoizing ReportStorage instances.
|
|
8679
|
+
* Key format: "symbol:strategyName:backtest" or "symbol:strategyName:live"
|
|
8680
|
+
* @param symbol - Trading pair symbol
|
|
8681
|
+
* @param strategyName - Name of the strategy
|
|
8682
|
+
* @param backtest - Whether running in backtest mode
|
|
8683
|
+
* @returns Unique string key for memoization
|
|
8684
|
+
*/
|
|
8685
|
+
const CREATE_KEY_FN$5 = (symbol, strategyName, backtest) => `${symbol}:${strategyName}:${backtest ? "backtest" : "live"}`;
|
|
8635
8686
|
/** Maximum number of events to store in schedule reports */
|
|
8636
8687
|
const MAX_EVENTS$4 = 250;
|
|
8637
8688
|
/**
|
|
@@ -8867,7 +8918,7 @@ class ScheduleMarkdownService {
|
|
|
8867
8918
|
* Memoized function to get or create ReportStorage for a symbol-strategy-backtest triple.
|
|
8868
8919
|
* Each symbol-strategy-backtest combination gets its own isolated storage instance.
|
|
8869
8920
|
*/
|
|
8870
|
-
this.getStorage = memoize(([symbol, strategyName, backtest]) =>
|
|
8921
|
+
this.getStorage = memoize(([symbol, strategyName, backtest]) => CREATE_KEY_FN$5(symbol, strategyName, backtest), () => new ReportStorage$3());
|
|
8871
8922
|
/**
|
|
8872
8923
|
* Processes tick events and accumulates scheduled/opened/cancelled events.
|
|
8873
8924
|
* Should be called from signalEmitter subscription.
|
|
@@ -9009,7 +9060,7 @@ class ScheduleMarkdownService {
|
|
|
9009
9060
|
ctx,
|
|
9010
9061
|
});
|
|
9011
9062
|
if (ctx) {
|
|
9012
|
-
const key =
|
|
9063
|
+
const key = CREATE_KEY_FN$5(ctx.symbol, ctx.strategyName, backtest);
|
|
9013
9064
|
this.getStorage.clear(key);
|
|
9014
9065
|
}
|
|
9015
9066
|
else {
|
|
@@ -9034,6 +9085,15 @@ class ScheduleMarkdownService {
|
|
|
9034
9085
|
}
|
|
9035
9086
|
}
|
|
9036
9087
|
|
|
9088
|
+
/**
|
|
9089
|
+
* Creates a unique key for memoizing PerformanceStorage instances.
|
|
9090
|
+
* Key format: "symbol:strategyName:backtest" or "symbol:strategyName:live"
|
|
9091
|
+
* @param symbol - Trading pair symbol
|
|
9092
|
+
* @param strategyName - Name of the strategy
|
|
9093
|
+
* @param backtest - Whether running in backtest mode
|
|
9094
|
+
* @returns Unique string key for memoization
|
|
9095
|
+
*/
|
|
9096
|
+
const CREATE_KEY_FN$4 = (symbol, strategyName, backtest) => `${symbol}:${strategyName}:${backtest ? "backtest" : "live"}`;
|
|
9037
9097
|
/**
|
|
9038
9098
|
* Calculates percentile value from sorted array.
|
|
9039
9099
|
*/
|
|
@@ -9251,7 +9311,7 @@ class PerformanceMarkdownService {
|
|
|
9251
9311
|
* Memoized function to get or create PerformanceStorage for a symbol-strategy-backtest triple.
|
|
9252
9312
|
* Each symbol-strategy-backtest combination gets its own isolated storage instance.
|
|
9253
9313
|
*/
|
|
9254
|
-
this.getStorage = memoize(([symbol, strategyName, backtest]) =>
|
|
9314
|
+
this.getStorage = memoize(([symbol, strategyName, backtest]) => CREATE_KEY_FN$4(symbol, strategyName, backtest), () => new PerformanceStorage());
|
|
9255
9315
|
/**
|
|
9256
9316
|
* Processes performance events and accumulates metrics.
|
|
9257
9317
|
* Should be called from performance tracking code.
|
|
@@ -9356,7 +9416,7 @@ class PerformanceMarkdownService {
|
|
|
9356
9416
|
ctx,
|
|
9357
9417
|
});
|
|
9358
9418
|
if (ctx) {
|
|
9359
|
-
const key =
|
|
9419
|
+
const key = CREATE_KEY_FN$4(ctx.symbol, ctx.strategyName, backtest);
|
|
9360
9420
|
this.getStorage.clear(key);
|
|
9361
9421
|
}
|
|
9362
9422
|
else {
|
|
@@ -9783,6 +9843,14 @@ class WalkerMarkdownService {
|
|
|
9783
9843
|
}
|
|
9784
9844
|
}
|
|
9785
9845
|
|
|
9846
|
+
/**
|
|
9847
|
+
* Creates a unique key for memoizing HeatmapStorage instances.
|
|
9848
|
+
* Key format: "strategyName:backtest" or "strategyName:live"
|
|
9849
|
+
* @param strategyName - Name of the strategy
|
|
9850
|
+
* @param backtest - Whether running in backtest mode
|
|
9851
|
+
* @returns Unique string key for memoization
|
|
9852
|
+
*/
|
|
9853
|
+
const CREATE_KEY_FN$3 = (strategyName, backtest) => `${strategyName}:${backtest ? "backtest" : "live"}`;
|
|
9786
9854
|
const HEATMAP_METHOD_NAME_GET_DATA = "HeatMarkdownService.getData";
|
|
9787
9855
|
const HEATMAP_METHOD_NAME_GET_REPORT = "HeatMarkdownService.getReport";
|
|
9788
9856
|
const HEATMAP_METHOD_NAME_DUMP = "HeatMarkdownService.dump";
|
|
@@ -10126,7 +10194,7 @@ class HeatMarkdownService {
|
|
|
10126
10194
|
* Memoized function to get or create HeatmapStorage for a strategy and backtest mode.
|
|
10127
10195
|
* Each strategy + backtest mode combination gets its own isolated heatmap storage instance.
|
|
10128
10196
|
*/
|
|
10129
|
-
this.getStorage = memoize(([strategyName, backtest]) =>
|
|
10197
|
+
this.getStorage = memoize(([strategyName, backtest]) => CREATE_KEY_FN$3(strategyName, backtest), () => new HeatmapStorage());
|
|
10130
10198
|
/**
|
|
10131
10199
|
* Processes tick events and accumulates closed signals.
|
|
10132
10200
|
* Should be called from signal emitter subscription.
|
|
@@ -10262,7 +10330,7 @@ class HeatMarkdownService {
|
|
|
10262
10330
|
ctx,
|
|
10263
10331
|
});
|
|
10264
10332
|
if (ctx) {
|
|
10265
|
-
const key =
|
|
10333
|
+
const key = CREATE_KEY_FN$3(ctx.strategyName, backtest);
|
|
10266
10334
|
this.getStorage.clear(key);
|
|
10267
10335
|
}
|
|
10268
10336
|
else {
|
|
@@ -12472,6 +12540,15 @@ class ClientPartial {
|
|
|
12472
12540
|
}
|
|
12473
12541
|
}
|
|
12474
12542
|
|
|
12543
|
+
/**
|
|
12544
|
+
* Creates a unique key for memoizing ClientPartial instances.
|
|
12545
|
+
* Key format: "signalId:backtest" or "signalId:live"
|
|
12546
|
+
*
|
|
12547
|
+
* @param signalId - Signal ID
|
|
12548
|
+
* @param backtest - Whether running in backtest mode
|
|
12549
|
+
* @returns Unique string key for memoization
|
|
12550
|
+
*/
|
|
12551
|
+
const CREATE_KEY_FN$2 = (signalId, backtest) => `${signalId}:${backtest ? "backtest" : "live"}`;
|
|
12475
12552
|
/**
|
|
12476
12553
|
* Callback function for emitting profit events to partialProfitSubject.
|
|
12477
12554
|
*
|
|
@@ -12569,7 +12646,7 @@ class PartialConnectionService {
|
|
|
12569
12646
|
* Key format: "signalId:backtest" or "signalId:live"
|
|
12570
12647
|
* Value: ClientPartial instance with logger and event emitters
|
|
12571
12648
|
*/
|
|
12572
|
-
this.getPartial = memoize(([signalId, backtest]) =>
|
|
12649
|
+
this.getPartial = memoize(([signalId, backtest]) => CREATE_KEY_FN$2(signalId, backtest), (signalId, backtest) => {
|
|
12573
12650
|
return new ClientPartial({
|
|
12574
12651
|
signalId,
|
|
12575
12652
|
logger: this.loggerService,
|
|
@@ -12659,12 +12736,19 @@ class PartialConnectionService {
|
|
|
12659
12736
|
const partial = this.getPartial(data.id, backtest);
|
|
12660
12737
|
await partial.waitForInit(symbol, data.strategyName);
|
|
12661
12738
|
await partial.clear(symbol, data, priceClose, backtest);
|
|
12662
|
-
const key =
|
|
12739
|
+
const key = CREATE_KEY_FN$2(data.id, backtest);
|
|
12663
12740
|
this.getPartial.clear(key);
|
|
12664
12741
|
};
|
|
12665
12742
|
}
|
|
12666
12743
|
}
|
|
12667
12744
|
|
|
12745
|
+
/**
|
|
12746
|
+
* Creates a unique key for memoizing ReportStorage instances.
|
|
12747
|
+
* Key format: "symbol:strategyName:backtest" or "symbol:strategyName:live"
|
|
12748
|
+
* @param param0 - Tuple of symbol, strategyName and backtest boolean
|
|
12749
|
+
* @returns Unique string key for memoization
|
|
12750
|
+
*/
|
|
12751
|
+
const CREATE_KEY_FN$1 = ([symbol, strategyName, backtest]) => `${symbol}:${strategyName}:${backtest ? "backtest" : "live"}`;
|
|
12668
12752
|
/** Maximum number of events to store in partial reports */
|
|
12669
12753
|
const MAX_EVENTS$1 = 250;
|
|
12670
12754
|
/**
|
|
@@ -12839,7 +12923,7 @@ class PartialMarkdownService {
|
|
|
12839
12923
|
* Memoized function to get or create ReportStorage for a symbol-strategy-backtest triple.
|
|
12840
12924
|
* Each symbol-strategy-backtest combination gets its own isolated storage instance.
|
|
12841
12925
|
*/
|
|
12842
|
-
this.getStorage = memoize(
|
|
12926
|
+
this.getStorage = memoize(CREATE_KEY_FN$1, () => new ReportStorage$1());
|
|
12843
12927
|
/**
|
|
12844
12928
|
* Processes profit events and accumulates them.
|
|
12845
12929
|
* Should be called from partialProfitSubject subscription.
|
|
@@ -12986,7 +13070,7 @@ class PartialMarkdownService {
|
|
|
12986
13070
|
ctx,
|
|
12987
13071
|
});
|
|
12988
13072
|
if (ctx) {
|
|
12989
|
-
const key =
|
|
13073
|
+
const key = CREATE_KEY_FN$1([ctx.symbol, ctx.strategyName, backtest]);
|
|
12990
13074
|
this.getStorage.clear(key);
|
|
12991
13075
|
}
|
|
12992
13076
|
else {
|
|
@@ -13421,6 +13505,15 @@ class ConfigValidationService {
|
|
|
13421
13505
|
}
|
|
13422
13506
|
}
|
|
13423
13507
|
|
|
13508
|
+
/**
|
|
13509
|
+
* Creates a unique key for memoizing ReportStorage instances.
|
|
13510
|
+
* Key format: "symbol:strategyName:backtest" or "symbol:strategyName:live"
|
|
13511
|
+
* @param symbol - Trading pair symbol
|
|
13512
|
+
* @param strategyName - Name of the strategy
|
|
13513
|
+
* @param backtest - Whether running in backtest mode
|
|
13514
|
+
* @returns Unique string key for memoization
|
|
13515
|
+
*/
|
|
13516
|
+
const CREATE_KEY_FN = (symbol, strategyName, backtest) => `${symbol}:${strategyName}:${backtest ? "backtest" : "live"}`;
|
|
13424
13517
|
/** Maximum number of events to store in risk reports */
|
|
13425
13518
|
const MAX_EVENTS = 250;
|
|
13426
13519
|
/**
|
|
@@ -13565,7 +13658,7 @@ class RiskMarkdownService {
|
|
|
13565
13658
|
* Memoized function to get or create ReportStorage for a symbol-strategy-backtest triple.
|
|
13566
13659
|
* Each symbol-strategy-backtest combination gets its own isolated storage instance.
|
|
13567
13660
|
*/
|
|
13568
|
-
this.getStorage = memoize(([symbol, strategyName, backtest]) =>
|
|
13661
|
+
this.getStorage = memoize(([symbol, strategyName, backtest]) => CREATE_KEY_FN(symbol, strategyName, backtest), () => new ReportStorage());
|
|
13569
13662
|
/**
|
|
13570
13663
|
* Processes risk rejection events and accumulates them.
|
|
13571
13664
|
* Should be called from riskSubject subscription.
|
|
@@ -13693,7 +13786,7 @@ class RiskMarkdownService {
|
|
|
13693
13786
|
ctx,
|
|
13694
13787
|
});
|
|
13695
13788
|
if (ctx) {
|
|
13696
|
-
const key =
|
|
13789
|
+
const key = CREATE_KEY_FN(ctx.symbol, ctx.strategyName, backtest);
|
|
13697
13790
|
this.getStorage.clear(key);
|
|
13698
13791
|
}
|
|
13699
13792
|
else {
|
|
@@ -16405,8 +16498,8 @@ class BacktestInstance {
|
|
|
16405
16498
|
}
|
|
16406
16499
|
{
|
|
16407
16500
|
const { riskName, riskList } = backtest$1.strategySchemaService.get(context.strategyName);
|
|
16408
|
-
riskName && backtest$1.riskGlobalService.clear(true, riskName);
|
|
16409
|
-
riskList && riskList.forEach((riskName) => backtest$1.riskGlobalService.clear(true, riskName));
|
|
16501
|
+
riskName && backtest$1.riskGlobalService.clear(true, { riskName });
|
|
16502
|
+
riskList && riskList.forEach((riskName) => backtest$1.riskGlobalService.clear(true, { riskName }));
|
|
16410
16503
|
}
|
|
16411
16504
|
return backtest$1.backtestCommandService.run(symbol, context);
|
|
16412
16505
|
};
|
|
@@ -17079,8 +17172,8 @@ class LiveInstance {
|
|
|
17079
17172
|
}
|
|
17080
17173
|
{
|
|
17081
17174
|
const { riskName, riskList } = backtest$1.strategySchemaService.get(context.strategyName);
|
|
17082
|
-
riskName && backtest$1.riskGlobalService.clear(false, riskName);
|
|
17083
|
-
riskList && riskList.forEach((riskName) => backtest$1.riskGlobalService.clear(false, riskName));
|
|
17175
|
+
riskName && backtest$1.riskGlobalService.clear(false, { riskName });
|
|
17176
|
+
riskList && riskList.forEach((riskName) => backtest$1.riskGlobalService.clear(false, { riskName }));
|
|
17084
17177
|
}
|
|
17085
17178
|
return backtest$1.liveCommandService.run(symbol, context);
|
|
17086
17179
|
};
|
|
@@ -18031,9 +18124,9 @@ class WalkerInstance {
|
|
|
18031
18124
|
}
|
|
18032
18125
|
{
|
|
18033
18126
|
const { riskName, riskList } = backtest$1.strategySchemaService.get(strategyName);
|
|
18034
|
-
riskName && backtest$1.riskGlobalService.clear(true, riskName);
|
|
18127
|
+
riskName && backtest$1.riskGlobalService.clear(true, { riskName });
|
|
18035
18128
|
riskList &&
|
|
18036
|
-
riskList.forEach((riskName) => backtest$1.riskGlobalService.clear(true, riskName));
|
|
18129
|
+
riskList.forEach((riskName) => backtest$1.riskGlobalService.clear(true, { riskName }));
|
|
18037
18130
|
}
|
|
18038
18131
|
}
|
|
18039
18132
|
return backtest$1.walkerCommandService.run(symbol, {
|
package/package.json
CHANGED
package/types.d.ts
CHANGED
|
@@ -8937,7 +8937,7 @@ declare class RiskConnectionService {
|
|
|
8937
8937
|
* @param backtest - True if backtest mode, false if live mode
|
|
8938
8938
|
* @returns Configured ClientRisk instance
|
|
8939
8939
|
*/
|
|
8940
|
-
getRisk: ((riskName: RiskName, backtest: boolean) => ClientRisk) & functools_kit.IClearableMemoize
|
|
8940
|
+
getRisk: ((riskName: RiskName, backtest: boolean) => ClientRisk) & functools_kit.IClearableMemoize<`${string}:backtest` | `${string}:live`> & functools_kit.IControlMemoize<`${string}:backtest` | `${string}:live`, ClientRisk>;
|
|
8941
8941
|
/**
|
|
8942
8942
|
* Checks if a signal should be allowed based on risk limits.
|
|
8943
8943
|
*
|
|
@@ -8980,9 +8980,12 @@ declare class RiskConnectionService {
|
|
|
8980
8980
|
/**
|
|
8981
8981
|
* Clears the cached ClientRisk instance for the given risk name.
|
|
8982
8982
|
*
|
|
8983
|
-
* @param
|
|
8983
|
+
* @param backtest - Whether running in backtest mode
|
|
8984
|
+
* @param ctx - Optional context with riskName (clears all if not provided)
|
|
8984
8985
|
*/
|
|
8985
|
-
clear: (backtest: boolean,
|
|
8986
|
+
clear: (backtest: boolean, ctx?: {
|
|
8987
|
+
riskName: RiskName;
|
|
8988
|
+
}) => Promise<void>;
|
|
8986
8989
|
}
|
|
8987
8990
|
|
|
8988
8991
|
/**
|
|
@@ -9674,11 +9677,14 @@ declare class RiskGlobalService {
|
|
|
9674
9677
|
}) => Promise<void>;
|
|
9675
9678
|
/**
|
|
9676
9679
|
* Clears risk data.
|
|
9677
|
-
* If
|
|
9678
|
-
* If no
|
|
9679
|
-
* @param
|
|
9680
|
+
* If ctx is provided, clears data for that specific risk instance.
|
|
9681
|
+
* If no ctx is provided, clears all risk data.
|
|
9682
|
+
* @param backtest - Whether running in backtest mode
|
|
9683
|
+
* @param ctx - Optional context with riskName (clears all if not provided)
|
|
9680
9684
|
*/
|
|
9681
|
-
clear: (backtest: boolean,
|
|
9685
|
+
clear: (backtest: boolean, ctx?: {
|
|
9686
|
+
riskName: RiskName;
|
|
9687
|
+
}) => Promise<void>;
|
|
9682
9688
|
}
|
|
9683
9689
|
|
|
9684
9690
|
/**
|