backtest-kit 9.8.0 → 9.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 +263 -129
- package/build/index.mjs +263 -129
- package/package.json +1 -1
- package/types.d.ts +95 -22
package/build/index.cjs
CHANGED
|
@@ -37412,7 +37412,19 @@ class BrokerProxy {
|
|
|
37412
37412
|
*/
|
|
37413
37413
|
class BrokerAdapter {
|
|
37414
37414
|
constructor() {
|
|
37415
|
-
|
|
37415
|
+
/** Factory producing the active `BrokerProxy` instance */
|
|
37416
|
+
this._brokerFactory = () => null;
|
|
37417
|
+
/**
|
|
37418
|
+
* Lazily constructs the `BrokerProxy` from the registered factory and
|
|
37419
|
+
* memoizes the result via `singleshot`.
|
|
37420
|
+
*
|
|
37421
|
+
* The proxy is built on the first call and cached for all subsequent calls.
|
|
37422
|
+
* Returns `null` when no adapter has been registered via `useBrokerAdapter()`.
|
|
37423
|
+
*
|
|
37424
|
+
* Reset via `clear()` so the next call rebuilds from the current factory
|
|
37425
|
+
* (e.g. when `process.cwd()` changes between strategy iterations).
|
|
37426
|
+
*/
|
|
37427
|
+
this.getInstance = functoolsKit.singleshot(() => this._brokerFactory());
|
|
37416
37428
|
/**
|
|
37417
37429
|
* Forwards a signal-open event to the registered broker adapter.
|
|
37418
37430
|
*
|
|
@@ -37446,7 +37458,10 @@ class BrokerAdapter {
|
|
|
37446
37458
|
if (payload.backtest) {
|
|
37447
37459
|
return;
|
|
37448
37460
|
}
|
|
37449
|
-
|
|
37461
|
+
const instance = this.getInstance();
|
|
37462
|
+
if (instance) {
|
|
37463
|
+
await instance.onSignalOpenCommit(payload);
|
|
37464
|
+
}
|
|
37450
37465
|
};
|
|
37451
37466
|
/**
|
|
37452
37467
|
* Forwards a signal-close event to the registered broker adapter.
|
|
@@ -37484,7 +37499,10 @@ class BrokerAdapter {
|
|
|
37484
37499
|
if (payload.backtest) {
|
|
37485
37500
|
return;
|
|
37486
37501
|
}
|
|
37487
|
-
|
|
37502
|
+
const instance = this.getInstance();
|
|
37503
|
+
if (instance) {
|
|
37504
|
+
await instance.onSignalCloseCommit(payload);
|
|
37505
|
+
}
|
|
37488
37506
|
};
|
|
37489
37507
|
/**
|
|
37490
37508
|
* Intercepts a partial-profit close before DI-core mutation.
|
|
@@ -37520,7 +37538,10 @@ class BrokerAdapter {
|
|
|
37520
37538
|
if (payload.backtest) {
|
|
37521
37539
|
return;
|
|
37522
37540
|
}
|
|
37523
|
-
|
|
37541
|
+
const instance = this.getInstance();
|
|
37542
|
+
if (instance) {
|
|
37543
|
+
await instance.onPartialProfitCommit(payload);
|
|
37544
|
+
}
|
|
37524
37545
|
};
|
|
37525
37546
|
/**
|
|
37526
37547
|
* Intercepts a partial-loss close before DI-core mutation.
|
|
@@ -37556,7 +37577,10 @@ class BrokerAdapter {
|
|
|
37556
37577
|
if (payload.backtest) {
|
|
37557
37578
|
return;
|
|
37558
37579
|
}
|
|
37559
|
-
|
|
37580
|
+
const instance = this.getInstance();
|
|
37581
|
+
if (instance) {
|
|
37582
|
+
await instance.onPartialLossCommit(payload);
|
|
37583
|
+
}
|
|
37560
37584
|
};
|
|
37561
37585
|
/**
|
|
37562
37586
|
* Intercepts a trailing stop-loss update before DI-core mutation.
|
|
@@ -37592,7 +37616,10 @@ class BrokerAdapter {
|
|
|
37592
37616
|
if (payload.backtest) {
|
|
37593
37617
|
return;
|
|
37594
37618
|
}
|
|
37595
|
-
|
|
37619
|
+
const instance = this.getInstance();
|
|
37620
|
+
if (instance) {
|
|
37621
|
+
await instance.onTrailingStopCommit(payload);
|
|
37622
|
+
}
|
|
37596
37623
|
};
|
|
37597
37624
|
/**
|
|
37598
37625
|
* Intercepts a trailing take-profit update before DI-core mutation.
|
|
@@ -37628,7 +37655,10 @@ class BrokerAdapter {
|
|
|
37628
37655
|
if (payload.backtest) {
|
|
37629
37656
|
return;
|
|
37630
37657
|
}
|
|
37631
|
-
|
|
37658
|
+
const instance = this.getInstance();
|
|
37659
|
+
if (instance) {
|
|
37660
|
+
await instance.onTrailingTakeCommit(payload);
|
|
37661
|
+
}
|
|
37632
37662
|
};
|
|
37633
37663
|
/**
|
|
37634
37664
|
* Intercepts a breakeven operation before DI-core mutation.
|
|
@@ -37665,7 +37695,10 @@ class BrokerAdapter {
|
|
|
37665
37695
|
if (payload.backtest) {
|
|
37666
37696
|
return;
|
|
37667
37697
|
}
|
|
37668
|
-
|
|
37698
|
+
const instance = this.getInstance();
|
|
37699
|
+
if (instance) {
|
|
37700
|
+
await instance.onBreakevenCommit(payload);
|
|
37701
|
+
}
|
|
37669
37702
|
};
|
|
37670
37703
|
/**
|
|
37671
37704
|
* Intercepts a DCA average-buy entry before DI-core mutation.
|
|
@@ -37701,7 +37734,10 @@ class BrokerAdapter {
|
|
|
37701
37734
|
if (payload.backtest) {
|
|
37702
37735
|
return;
|
|
37703
37736
|
}
|
|
37704
|
-
|
|
37737
|
+
const instance = this.getInstance();
|
|
37738
|
+
if (instance) {
|
|
37739
|
+
await instance.onAverageBuyCommit(payload);
|
|
37740
|
+
}
|
|
37705
37741
|
};
|
|
37706
37742
|
/**
|
|
37707
37743
|
* Registers a broker adapter instance or constructor to receive commit* callbacks.
|
|
@@ -37725,11 +37761,12 @@ class BrokerAdapter {
|
|
|
37725
37761
|
this.useBrokerAdapter = (broker) => {
|
|
37726
37762
|
backtest.loggerService.info(BROKER_METHOD_NAME_USE_BROKER_ADAPTER, {});
|
|
37727
37763
|
if (typeof broker === "function") {
|
|
37728
|
-
|
|
37729
|
-
|
|
37730
|
-
|
|
37764
|
+
this._brokerFactory = () => new BrokerProxy(Reflect.construct(broker, []));
|
|
37765
|
+
}
|
|
37766
|
+
else {
|
|
37767
|
+
this._brokerFactory = () => new BrokerProxy(broker);
|
|
37731
37768
|
}
|
|
37732
|
-
this.
|
|
37769
|
+
this.getInstance.clear();
|
|
37733
37770
|
};
|
|
37734
37771
|
/**
|
|
37735
37772
|
* Activates the broker: subscribes to syncSubject for signal-open / signal-close routing.
|
|
@@ -37756,7 +37793,8 @@ class BrokerAdapter {
|
|
|
37756
37793
|
*/
|
|
37757
37794
|
this.enable = functoolsKit.singleshot(() => {
|
|
37758
37795
|
backtest.loggerService.info(BROKER_METHOD_NAME_ENABLE, {});
|
|
37759
|
-
|
|
37796
|
+
const instance = this.getInstance();
|
|
37797
|
+
if (!instance) {
|
|
37760
37798
|
this.enable.clear();
|
|
37761
37799
|
throw new Error("No broker instance provided. Call Broker.useBrokerAdapter first.");
|
|
37762
37800
|
}
|
|
@@ -37844,7 +37882,7 @@ class BrokerAdapter {
|
|
|
37844
37882
|
*/
|
|
37845
37883
|
this.clear = () => {
|
|
37846
37884
|
backtest.loggerService.info(BROKER_METHOD_NAME_CLEAR, {});
|
|
37847
|
-
this.
|
|
37885
|
+
this.getInstance.clear();
|
|
37848
37886
|
this.enable.clear();
|
|
37849
37887
|
};
|
|
37850
37888
|
}
|
|
@@ -48864,8 +48902,16 @@ class RecentMemoryLiveUtils {
|
|
|
48864
48902
|
*/
|
|
48865
48903
|
class RecentBacktestAdapter {
|
|
48866
48904
|
constructor() {
|
|
48867
|
-
/**
|
|
48868
|
-
this.
|
|
48905
|
+
/** Factory producing the active storage utils instance */
|
|
48906
|
+
this._recentBacktestFactory = () => new RecentMemoryBacktestUtils();
|
|
48907
|
+
/**
|
|
48908
|
+
* Lazily constructs the storage utils from the registered factory and memoizes
|
|
48909
|
+
* the result via `singleshot`.
|
|
48910
|
+
*
|
|
48911
|
+
* The instance is built on the first call and cached for all subsequent calls.
|
|
48912
|
+
* Reset via `clear()` so the next call rebuilds from the current factory.
|
|
48913
|
+
*/
|
|
48914
|
+
this.getInstance = functoolsKit.singleshot(() => this._recentBacktestFactory());
|
|
48869
48915
|
/**
|
|
48870
48916
|
* Handles active ping event.
|
|
48871
48917
|
* Proxies call to the underlying storage adapter.
|
|
@@ -48875,7 +48921,7 @@ class RecentBacktestAdapter {
|
|
|
48875
48921
|
backtest.loggerService.info(RECENT_BACKTEST_ADAPTER_METHOD_NAME_HANDLE_ACTIVE_PING, {
|
|
48876
48922
|
signalId: event.data.id,
|
|
48877
48923
|
});
|
|
48878
|
-
return await this.
|
|
48924
|
+
return await this.getInstance().handleActivePing(event);
|
|
48879
48925
|
};
|
|
48880
48926
|
/**
|
|
48881
48927
|
* Retrieves the latest signal for the given context.
|
|
@@ -48896,7 +48942,7 @@ class RecentBacktestAdapter {
|
|
|
48896
48942
|
frameName,
|
|
48897
48943
|
backtest: backtest$1,
|
|
48898
48944
|
});
|
|
48899
|
-
return await this.
|
|
48945
|
+
return await this.getInstance().getLatestSignal(symbol, strategyName, exchangeName, frameName, backtest$1, when);
|
|
48900
48946
|
};
|
|
48901
48947
|
/**
|
|
48902
48948
|
* Returns the number of whole minutes elapsed since the latest signal's creation timestamp.
|
|
@@ -48920,7 +48966,7 @@ class RecentBacktestAdapter {
|
|
|
48920
48966
|
backtest: backtest$1,
|
|
48921
48967
|
timestamp,
|
|
48922
48968
|
});
|
|
48923
|
-
const signal = await this.
|
|
48969
|
+
const signal = await this.getInstance().getLatestSignal(symbol, strategyName, exchangeName, frameName, backtest$1, new Date(timestamp));
|
|
48924
48970
|
if (!signal) {
|
|
48925
48971
|
return null;
|
|
48926
48972
|
}
|
|
@@ -48933,7 +48979,8 @@ class RecentBacktestAdapter {
|
|
|
48933
48979
|
*/
|
|
48934
48980
|
this.useRecentAdapter = (Ctor) => {
|
|
48935
48981
|
backtest.loggerService.info(RECENT_BACKTEST_ADAPTER_METHOD_NAME_USE_ADAPTER);
|
|
48936
|
-
this.
|
|
48982
|
+
this._recentBacktestFactory = () => Reflect.construct(Ctor, []);
|
|
48983
|
+
this.getInstance.clear();
|
|
48937
48984
|
};
|
|
48938
48985
|
/**
|
|
48939
48986
|
* Switches to persistent storage adapter.
|
|
@@ -48941,7 +48988,8 @@ class RecentBacktestAdapter {
|
|
|
48941
48988
|
*/
|
|
48942
48989
|
this.usePersist = () => {
|
|
48943
48990
|
backtest.loggerService.info(RECENT_BACKTEST_ADAPTER_METHOD_NAME_USE_PERSIST);
|
|
48944
|
-
this.
|
|
48991
|
+
this._recentBacktestFactory = () => new RecentPersistBacktestUtils();
|
|
48992
|
+
this.getInstance.clear();
|
|
48945
48993
|
};
|
|
48946
48994
|
/**
|
|
48947
48995
|
* Switches to in-memory storage adapter (default).
|
|
@@ -48949,14 +48997,17 @@ class RecentBacktestAdapter {
|
|
|
48949
48997
|
*/
|
|
48950
48998
|
this.useMemory = () => {
|
|
48951
48999
|
backtest.loggerService.info(RECENT_BACKTEST_ADAPTER_METHOD_NAME_USE_MEMORY);
|
|
48952
|
-
this.
|
|
49000
|
+
this._recentBacktestFactory = () => new RecentMemoryBacktestUtils();
|
|
49001
|
+
this.getInstance.clear();
|
|
48953
49002
|
};
|
|
48954
49003
|
/**
|
|
48955
|
-
* Clears the
|
|
49004
|
+
* Clears the memoized utils instance.
|
|
49005
|
+
* Call this when process.cwd() changes between strategy iterations
|
|
49006
|
+
* so a new instance is created with the updated base path.
|
|
48956
49007
|
*/
|
|
48957
49008
|
this.clear = () => {
|
|
48958
49009
|
backtest.loggerService.info(RECENT_BACKTEST_ADAPTER_METHOD_NAME_CLEAR);
|
|
48959
|
-
this.
|
|
49010
|
+
this.getInstance.clear();
|
|
48960
49011
|
};
|
|
48961
49012
|
}
|
|
48962
49013
|
}
|
|
@@ -48971,8 +49022,16 @@ class RecentBacktestAdapter {
|
|
|
48971
49022
|
*/
|
|
48972
49023
|
class RecentLiveAdapter {
|
|
48973
49024
|
constructor() {
|
|
48974
|
-
/**
|
|
48975
|
-
this.
|
|
49025
|
+
/** Factory producing the active storage utils instance */
|
|
49026
|
+
this._recentLiveFactory = () => new RecentPersistLiveUtils();
|
|
49027
|
+
/**
|
|
49028
|
+
* Lazily constructs the storage utils from the registered factory and memoizes
|
|
49029
|
+
* the result via `singleshot`.
|
|
49030
|
+
*
|
|
49031
|
+
* The instance is built on the first call and cached for all subsequent calls.
|
|
49032
|
+
* Reset via `clear()` so the next call rebuilds from the current factory.
|
|
49033
|
+
*/
|
|
49034
|
+
this.getInstance = functoolsKit.singleshot(() => this._recentLiveFactory());
|
|
48976
49035
|
/**
|
|
48977
49036
|
* Handles active ping event.
|
|
48978
49037
|
* Proxies call to the underlying storage adapter.
|
|
@@ -48982,7 +49041,7 @@ class RecentLiveAdapter {
|
|
|
48982
49041
|
backtest.loggerService.info(RECENT_LIVE_ADAPTER_METHOD_NAME_HANDLE_ACTIVE_PING, {
|
|
48983
49042
|
signalId: event.data.id,
|
|
48984
49043
|
});
|
|
48985
|
-
return await this.
|
|
49044
|
+
return await this.getInstance().handleActivePing(event);
|
|
48986
49045
|
};
|
|
48987
49046
|
/**
|
|
48988
49047
|
* Retrieves the latest signal for the given context.
|
|
@@ -49003,7 +49062,7 @@ class RecentLiveAdapter {
|
|
|
49003
49062
|
frameName,
|
|
49004
49063
|
backtest: backtest$1,
|
|
49005
49064
|
});
|
|
49006
|
-
return await this.
|
|
49065
|
+
return await this.getInstance().getLatestSignal(symbol, strategyName, exchangeName, frameName, backtest$1, when);
|
|
49007
49066
|
};
|
|
49008
49067
|
/**
|
|
49009
49068
|
* Returns the number of whole minutes elapsed since the latest signal's creation timestamp.
|
|
@@ -49027,7 +49086,7 @@ class RecentLiveAdapter {
|
|
|
49027
49086
|
backtest: backtest$1,
|
|
49028
49087
|
timestamp,
|
|
49029
49088
|
});
|
|
49030
|
-
const signal = await this.
|
|
49089
|
+
const signal = await this.getInstance().getLatestSignal(symbol, strategyName, exchangeName, frameName, backtest$1, new Date(timestamp));
|
|
49031
49090
|
if (!signal) {
|
|
49032
49091
|
return null;
|
|
49033
49092
|
}
|
|
@@ -49040,7 +49099,8 @@ class RecentLiveAdapter {
|
|
|
49040
49099
|
*/
|
|
49041
49100
|
this.useRecentAdapter = (Ctor) => {
|
|
49042
49101
|
backtest.loggerService.info(RECENT_LIVE_ADAPTER_METHOD_NAME_USE_ADAPTER);
|
|
49043
|
-
this.
|
|
49102
|
+
this._recentLiveFactory = () => Reflect.construct(Ctor, []);
|
|
49103
|
+
this.getInstance.clear();
|
|
49044
49104
|
};
|
|
49045
49105
|
/**
|
|
49046
49106
|
* Switches to persistent storage adapter (default).
|
|
@@ -49048,7 +49108,8 @@ class RecentLiveAdapter {
|
|
|
49048
49108
|
*/
|
|
49049
49109
|
this.usePersist = () => {
|
|
49050
49110
|
backtest.loggerService.info(RECENT_LIVE_ADAPTER_METHOD_NAME_USE_PERSIST);
|
|
49051
|
-
this.
|
|
49111
|
+
this._recentLiveFactory = () => new RecentPersistLiveUtils();
|
|
49112
|
+
this.getInstance.clear();
|
|
49052
49113
|
};
|
|
49053
49114
|
/**
|
|
49054
49115
|
* Switches to in-memory storage adapter.
|
|
@@ -49056,14 +49117,17 @@ class RecentLiveAdapter {
|
|
|
49056
49117
|
*/
|
|
49057
49118
|
this.useMemory = () => {
|
|
49058
49119
|
backtest.loggerService.info(RECENT_LIVE_ADAPTER_METHOD_NAME_USE_MEMORY);
|
|
49059
|
-
this.
|
|
49120
|
+
this._recentLiveFactory = () => new RecentMemoryLiveUtils();
|
|
49121
|
+
this.getInstance.clear();
|
|
49060
49122
|
};
|
|
49061
49123
|
/**
|
|
49062
|
-
* Clears the
|
|
49124
|
+
* Clears the memoized utils instance.
|
|
49125
|
+
* Call this when process.cwd() changes between strategy iterations
|
|
49126
|
+
* so a new instance is created with the updated base path.
|
|
49063
49127
|
*/
|
|
49064
49128
|
this.clear = () => {
|
|
49065
49129
|
backtest.loggerService.info(RECENT_LIVE_ADAPTER_METHOD_NAME_CLEAR);
|
|
49066
|
-
this.
|
|
49130
|
+
this.getInstance.clear();
|
|
49067
49131
|
};
|
|
49068
49132
|
}
|
|
49069
49133
|
}
|
|
@@ -54388,16 +54452,26 @@ class LogDummyUtils {
|
|
|
54388
54452
|
*/
|
|
54389
54453
|
class LogAdapter {
|
|
54390
54454
|
constructor() {
|
|
54391
|
-
/**
|
|
54392
|
-
this.
|
|
54455
|
+
/** Factory producing the active log utils instance */
|
|
54456
|
+
this._logFactory = () => new LogMemoryUtils();
|
|
54457
|
+
/**
|
|
54458
|
+
* Lazily constructs the log utils from the registered factory and memoizes
|
|
54459
|
+
* the result via `singleshot`.
|
|
54460
|
+
*
|
|
54461
|
+
* The instance is built on the first call and cached for all subsequent calls.
|
|
54462
|
+
* Reset via `clear()` so the next call rebuilds from the current factory
|
|
54463
|
+
* (e.g. when `process.cwd()` changes between strategy iterations).
|
|
54464
|
+
*/
|
|
54465
|
+
this.getInstance = functoolsKit.singleshot(() => this._logFactory());
|
|
54393
54466
|
/**
|
|
54394
54467
|
* Lists all stored log entries.
|
|
54395
54468
|
* Proxies call to the underlying log adapter.
|
|
54396
54469
|
* @returns Array of all log entries
|
|
54397
54470
|
*/
|
|
54398
54471
|
this.getList = async () => {
|
|
54399
|
-
|
|
54400
|
-
|
|
54472
|
+
const log = this.getInstance();
|
|
54473
|
+
if (log.getList) {
|
|
54474
|
+
return await log.getList();
|
|
54401
54475
|
}
|
|
54402
54476
|
return [];
|
|
54403
54477
|
};
|
|
@@ -54408,8 +54482,9 @@ class LogAdapter {
|
|
|
54408
54482
|
* @param args - Additional arguments
|
|
54409
54483
|
*/
|
|
54410
54484
|
this.log = (topic, ...args) => {
|
|
54411
|
-
|
|
54412
|
-
|
|
54485
|
+
const log = this.getInstance();
|
|
54486
|
+
if (log.log) {
|
|
54487
|
+
log.log(topic, ...args);
|
|
54413
54488
|
}
|
|
54414
54489
|
};
|
|
54415
54490
|
/**
|
|
@@ -54419,8 +54494,9 @@ class LogAdapter {
|
|
|
54419
54494
|
* @param args - Additional arguments
|
|
54420
54495
|
*/
|
|
54421
54496
|
this.debug = (topic, ...args) => {
|
|
54422
|
-
|
|
54423
|
-
|
|
54497
|
+
const log = this.getInstance();
|
|
54498
|
+
if (log.debug) {
|
|
54499
|
+
log.debug(topic, ...args);
|
|
54424
54500
|
}
|
|
54425
54501
|
};
|
|
54426
54502
|
/**
|
|
@@ -54430,8 +54506,9 @@ class LogAdapter {
|
|
|
54430
54506
|
* @param args - Additional arguments
|
|
54431
54507
|
*/
|
|
54432
54508
|
this.info = (topic, ...args) => {
|
|
54433
|
-
|
|
54434
|
-
|
|
54509
|
+
const log = this.getInstance();
|
|
54510
|
+
if (log.info) {
|
|
54511
|
+
log.info(topic, ...args);
|
|
54435
54512
|
}
|
|
54436
54513
|
};
|
|
54437
54514
|
/**
|
|
@@ -54441,8 +54518,9 @@ class LogAdapter {
|
|
|
54441
54518
|
* @param args - Additional arguments
|
|
54442
54519
|
*/
|
|
54443
54520
|
this.warn = (topic, ...args) => {
|
|
54444
|
-
|
|
54445
|
-
|
|
54521
|
+
const log = this.getInstance();
|
|
54522
|
+
if (log.warn) {
|
|
54523
|
+
log.warn(topic, ...args);
|
|
54446
54524
|
}
|
|
54447
54525
|
};
|
|
54448
54526
|
/**
|
|
@@ -54452,7 +54530,8 @@ class LogAdapter {
|
|
|
54452
54530
|
*/
|
|
54453
54531
|
this.useLogger = (Ctor) => {
|
|
54454
54532
|
backtest.loggerService.info(LOG_ADAPTER_METHOD_NAME_USE_LOGGER);
|
|
54455
|
-
this.
|
|
54533
|
+
this._logFactory = () => Reflect.construct(Ctor, []);
|
|
54534
|
+
this.getInstance.clear();
|
|
54456
54535
|
};
|
|
54457
54536
|
/**
|
|
54458
54537
|
* Switches to persistent log adapter.
|
|
@@ -54460,7 +54539,8 @@ class LogAdapter {
|
|
|
54460
54539
|
*/
|
|
54461
54540
|
this.usePersist = () => {
|
|
54462
54541
|
backtest.loggerService.info(LOG_ADAPTER_METHOD_NAME_USE_PERSIST);
|
|
54463
|
-
this.
|
|
54542
|
+
this._logFactory = () => new LogPersistUtils();
|
|
54543
|
+
this.getInstance.clear();
|
|
54464
54544
|
};
|
|
54465
54545
|
/**
|
|
54466
54546
|
* Switches to in-memory log adapter (default).
|
|
@@ -54468,7 +54548,8 @@ class LogAdapter {
|
|
|
54468
54548
|
*/
|
|
54469
54549
|
this.useMemory = () => {
|
|
54470
54550
|
backtest.loggerService.info(LOG_ADAPTER_METHOD_NAME_USE_MEMORY);
|
|
54471
|
-
this.
|
|
54551
|
+
this._logFactory = () => new LogMemoryUtils();
|
|
54552
|
+
this.getInstance.clear();
|
|
54472
54553
|
};
|
|
54473
54554
|
/**
|
|
54474
54555
|
* Switches to dummy log adapter.
|
|
@@ -54476,7 +54557,8 @@ class LogAdapter {
|
|
|
54476
54557
|
*/
|
|
54477
54558
|
this.useDummy = () => {
|
|
54478
54559
|
backtest.loggerService.info(LOG_ADAPTER_METHOD_NAME_USE_DUMMY);
|
|
54479
|
-
this.
|
|
54560
|
+
this._logFactory = () => new LogDummyUtils();
|
|
54561
|
+
this.getInstance.clear();
|
|
54480
54562
|
};
|
|
54481
54563
|
/**
|
|
54482
54564
|
* Switches to JSONL file log adapter.
|
|
@@ -54486,18 +54568,22 @@ class LogAdapter {
|
|
|
54486
54568
|
* @param fileName - Base file name without extension (default: "log")
|
|
54487
54569
|
* @param dirName - Directory for the JSONL file (default: ./dump/log)
|
|
54488
54570
|
*/
|
|
54489
|
-
this.useJsonl = (fileName = "log.jsonl", dirName
|
|
54571
|
+
this.useJsonl = (fileName = "log.jsonl", dirName) => {
|
|
54490
54572
|
backtest.loggerService.info(LOG_ADAPTER_METHOD_NAME_USE_JSONL);
|
|
54491
|
-
this.
|
|
54573
|
+
this._logFactory = () => {
|
|
54574
|
+
const dir = dirName || path.join(process.cwd(), "./dump/log");
|
|
54575
|
+
return new LogJsonlUtils(fileName, dir);
|
|
54576
|
+
};
|
|
54577
|
+
this.getInstance.clear();
|
|
54492
54578
|
};
|
|
54493
54579
|
/**
|
|
54494
|
-
* Clears the
|
|
54580
|
+
* Clears the memoized log instance.
|
|
54495
54581
|
* Call this when process.cwd() changes between strategy iterations
|
|
54496
54582
|
* so a new adapter instance is created with the updated base path.
|
|
54497
54583
|
*/
|
|
54498
54584
|
this.clear = () => {
|
|
54499
54585
|
backtest.loggerService.info(LOG_ADAPTER_METHOD_NAME_CLEAR);
|
|
54500
|
-
this.
|
|
54586
|
+
this.getInstance.clear();
|
|
54501
54587
|
};
|
|
54502
54588
|
}
|
|
54503
54589
|
}
|
|
@@ -58389,15 +58475,23 @@ class StorageDummyLiveUtils {
|
|
|
58389
58475
|
*/
|
|
58390
58476
|
class StorageBacktestAdapter {
|
|
58391
58477
|
constructor() {
|
|
58392
|
-
/**
|
|
58393
|
-
this.
|
|
58478
|
+
/** Factory producing the active storage utils instance */
|
|
58479
|
+
this._signalBacktestFactory = () => new StorageMemoryBacktestUtils();
|
|
58480
|
+
/**
|
|
58481
|
+
* Lazily constructs the storage utils from the registered factory and memoizes
|
|
58482
|
+
* the result via `singleshot`.
|
|
58483
|
+
*
|
|
58484
|
+
* The instance is built on the first call and cached for all subsequent calls.
|
|
58485
|
+
* Reset via `clear()` so the next call rebuilds from the current factory.
|
|
58486
|
+
*/
|
|
58487
|
+
this.getInstance = functoolsKit.singleshot(() => this._signalBacktestFactory());
|
|
58394
58488
|
/**
|
|
58395
58489
|
* Handles signal opened event.
|
|
58396
58490
|
* Proxies call to the underlying storage adapter.
|
|
58397
58491
|
* @param tick - The opened signal tick data
|
|
58398
58492
|
*/
|
|
58399
58493
|
this.handleOpened = async (tick) => {
|
|
58400
|
-
return await this.
|
|
58494
|
+
return await this.getInstance().handleOpened(tick);
|
|
58401
58495
|
};
|
|
58402
58496
|
/**
|
|
58403
58497
|
* Handles signal closed event.
|
|
@@ -58405,7 +58499,7 @@ class StorageBacktestAdapter {
|
|
|
58405
58499
|
* @param tick - The closed signal tick data
|
|
58406
58500
|
*/
|
|
58407
58501
|
this.handleClosed = async (tick) => {
|
|
58408
|
-
return await this.
|
|
58502
|
+
return await this.getInstance().handleClosed(tick);
|
|
58409
58503
|
};
|
|
58410
58504
|
/**
|
|
58411
58505
|
* Handles signal scheduled event.
|
|
@@ -58413,7 +58507,7 @@ class StorageBacktestAdapter {
|
|
|
58413
58507
|
* @param tick - The scheduled signal tick data
|
|
58414
58508
|
*/
|
|
58415
58509
|
this.handleScheduled = async (tick) => {
|
|
58416
|
-
return await this.
|
|
58510
|
+
return await this.getInstance().handleScheduled(tick);
|
|
58417
58511
|
};
|
|
58418
58512
|
/**
|
|
58419
58513
|
* Handles signal cancelled event.
|
|
@@ -58421,7 +58515,7 @@ class StorageBacktestAdapter {
|
|
|
58421
58515
|
* @param tick - The cancelled signal tick data
|
|
58422
58516
|
*/
|
|
58423
58517
|
this.handleCancelled = async (tick) => {
|
|
58424
|
-
return await this.
|
|
58518
|
+
return await this.getInstance().handleCancelled(tick);
|
|
58425
58519
|
};
|
|
58426
58520
|
/**
|
|
58427
58521
|
* Finds a signal by its ID.
|
|
@@ -58430,7 +58524,7 @@ class StorageBacktestAdapter {
|
|
|
58430
58524
|
* @returns The signal row or null if not found
|
|
58431
58525
|
*/
|
|
58432
58526
|
this.findById = async (id) => {
|
|
58433
|
-
return await this.
|
|
58527
|
+
return await this.getInstance().findById(id);
|
|
58434
58528
|
};
|
|
58435
58529
|
/**
|
|
58436
58530
|
* Lists all stored signals.
|
|
@@ -58438,13 +58532,13 @@ class StorageBacktestAdapter {
|
|
|
58438
58532
|
* @returns Array of all signal rows
|
|
58439
58533
|
*/
|
|
58440
58534
|
this.list = async () => {
|
|
58441
|
-
return await this.
|
|
58535
|
+
return await this.getInstance().list();
|
|
58442
58536
|
};
|
|
58443
58537
|
this.handleActivePing = async (event) => {
|
|
58444
|
-
return await this.
|
|
58538
|
+
return await this.getInstance().handleActivePing(event);
|
|
58445
58539
|
};
|
|
58446
58540
|
this.handleSchedulePing = async (event) => {
|
|
58447
|
-
return await this.
|
|
58541
|
+
return await this.getInstance().handleSchedulePing(event);
|
|
58448
58542
|
};
|
|
58449
58543
|
/**
|
|
58450
58544
|
* Sets the storage adapter constructor.
|
|
@@ -58454,7 +58548,8 @@ class StorageBacktestAdapter {
|
|
|
58454
58548
|
*/
|
|
58455
58549
|
this.useStorageAdapter = (Ctor) => {
|
|
58456
58550
|
backtest.loggerService.info(STORAGE_BACKTEST_ADAPTER_METHOD_NAME_USE_ADAPTER);
|
|
58457
|
-
this.
|
|
58551
|
+
this._signalBacktestFactory = () => Reflect.construct(Ctor, []);
|
|
58552
|
+
this.getInstance.clear();
|
|
58458
58553
|
};
|
|
58459
58554
|
/**
|
|
58460
58555
|
* Switches to dummy storage adapter.
|
|
@@ -58462,7 +58557,8 @@ class StorageBacktestAdapter {
|
|
|
58462
58557
|
*/
|
|
58463
58558
|
this.useDummy = () => {
|
|
58464
58559
|
backtest.loggerService.info(STORAGE_BACKTEST_ADAPTER_METHOD_NAME_USE_DUMMY);
|
|
58465
|
-
this.
|
|
58560
|
+
this._signalBacktestFactory = () => new StorageDummyBacktestUtils();
|
|
58561
|
+
this.getInstance.clear();
|
|
58466
58562
|
};
|
|
58467
58563
|
/**
|
|
58468
58564
|
* Switches to persistent storage adapter (default).
|
|
@@ -58470,7 +58566,8 @@ class StorageBacktestAdapter {
|
|
|
58470
58566
|
*/
|
|
58471
58567
|
this.usePersist = () => {
|
|
58472
58568
|
backtest.loggerService.info(STORAGE_BACKTEST_ADAPTER_METHOD_NAME_USE_PERSIST);
|
|
58473
|
-
this.
|
|
58569
|
+
this._signalBacktestFactory = () => new StoragePersistBacktestUtils();
|
|
58570
|
+
this.getInstance.clear();
|
|
58474
58571
|
};
|
|
58475
58572
|
/**
|
|
58476
58573
|
* Switches to in-memory storage adapter.
|
|
@@ -58478,16 +58575,17 @@ class StorageBacktestAdapter {
|
|
|
58478
58575
|
*/
|
|
58479
58576
|
this.useMemory = () => {
|
|
58480
58577
|
backtest.loggerService.info(STORAGE_BACKTEST_ADAPTER_METHOD_NAME_USE_MEMORY);
|
|
58481
|
-
this.
|
|
58578
|
+
this._signalBacktestFactory = () => new StorageMemoryBacktestUtils();
|
|
58579
|
+
this.getInstance.clear();
|
|
58482
58580
|
};
|
|
58483
58581
|
/**
|
|
58484
|
-
* Clears the
|
|
58582
|
+
* Clears the memoized utils instance.
|
|
58485
58583
|
* Call this when process.cwd() changes between strategy iterations
|
|
58486
58584
|
* so a new instance is created with the updated base path.
|
|
58487
58585
|
*/
|
|
58488
58586
|
this.clear = () => {
|
|
58489
58587
|
backtest.loggerService.info(STORAGE_BACKTEST_ADAPTER_METHOD_NAME_CLEAR);
|
|
58490
|
-
this.
|
|
58588
|
+
this.getInstance.clear();
|
|
58491
58589
|
};
|
|
58492
58590
|
}
|
|
58493
58591
|
}
|
|
@@ -58502,15 +58600,23 @@ class StorageBacktestAdapter {
|
|
|
58502
58600
|
*/
|
|
58503
58601
|
class StorageLiveAdapter {
|
|
58504
58602
|
constructor() {
|
|
58505
|
-
/**
|
|
58506
|
-
this.
|
|
58603
|
+
/** Factory producing the active storage utils instance */
|
|
58604
|
+
this._signalLiveFactory = () => new StoragePersistLiveUtils();
|
|
58605
|
+
/**
|
|
58606
|
+
* Lazily constructs the storage utils from the registered factory and memoizes
|
|
58607
|
+
* the result via `singleshot`.
|
|
58608
|
+
*
|
|
58609
|
+
* The instance is built on the first call and cached for all subsequent calls.
|
|
58610
|
+
* Reset via `clear()` so the next call rebuilds from the current factory.
|
|
58611
|
+
*/
|
|
58612
|
+
this.getInstance = functoolsKit.singleshot(() => this._signalLiveFactory());
|
|
58507
58613
|
/**
|
|
58508
58614
|
* Handles signal opened event.
|
|
58509
58615
|
* Proxies call to the underlying storage adapter.
|
|
58510
58616
|
* @param tick - The opened signal tick data
|
|
58511
58617
|
*/
|
|
58512
58618
|
this.handleOpened = async (tick) => {
|
|
58513
|
-
return await this.
|
|
58619
|
+
return await this.getInstance().handleOpened(tick);
|
|
58514
58620
|
};
|
|
58515
58621
|
/**
|
|
58516
58622
|
* Handles signal closed event.
|
|
@@ -58518,7 +58624,7 @@ class StorageLiveAdapter {
|
|
|
58518
58624
|
* @param tick - The closed signal tick data
|
|
58519
58625
|
*/
|
|
58520
58626
|
this.handleClosed = async (tick) => {
|
|
58521
|
-
return await this.
|
|
58627
|
+
return await this.getInstance().handleClosed(tick);
|
|
58522
58628
|
};
|
|
58523
58629
|
/**
|
|
58524
58630
|
* Handles signal scheduled event.
|
|
@@ -58526,7 +58632,7 @@ class StorageLiveAdapter {
|
|
|
58526
58632
|
* @param tick - The scheduled signal tick data
|
|
58527
58633
|
*/
|
|
58528
58634
|
this.handleScheduled = async (tick) => {
|
|
58529
|
-
return await this.
|
|
58635
|
+
return await this.getInstance().handleScheduled(tick);
|
|
58530
58636
|
};
|
|
58531
58637
|
/**
|
|
58532
58638
|
* Handles signal cancelled event.
|
|
@@ -58534,7 +58640,7 @@ class StorageLiveAdapter {
|
|
|
58534
58640
|
* @param tick - The cancelled signal tick data
|
|
58535
58641
|
*/
|
|
58536
58642
|
this.handleCancelled = async (tick) => {
|
|
58537
|
-
return await this.
|
|
58643
|
+
return await this.getInstance().handleCancelled(tick);
|
|
58538
58644
|
};
|
|
58539
58645
|
/**
|
|
58540
58646
|
* Finds a signal by its ID.
|
|
@@ -58543,7 +58649,7 @@ class StorageLiveAdapter {
|
|
|
58543
58649
|
* @returns The signal row or null if not found
|
|
58544
58650
|
*/
|
|
58545
58651
|
this.findById = async (id) => {
|
|
58546
|
-
return await this.
|
|
58652
|
+
return await this.getInstance().findById(id);
|
|
58547
58653
|
};
|
|
58548
58654
|
/**
|
|
58549
58655
|
* Lists all stored signals.
|
|
@@ -58551,13 +58657,13 @@ class StorageLiveAdapter {
|
|
|
58551
58657
|
* @returns Array of all signal rows
|
|
58552
58658
|
*/
|
|
58553
58659
|
this.list = async () => {
|
|
58554
|
-
return await this.
|
|
58660
|
+
return await this.getInstance().list();
|
|
58555
58661
|
};
|
|
58556
58662
|
this.handleActivePing = async (event) => {
|
|
58557
|
-
return await this.
|
|
58663
|
+
return await this.getInstance().handleActivePing(event);
|
|
58558
58664
|
};
|
|
58559
58665
|
this.handleSchedulePing = async (event) => {
|
|
58560
|
-
return await this.
|
|
58666
|
+
return await this.getInstance().handleSchedulePing(event);
|
|
58561
58667
|
};
|
|
58562
58668
|
/**
|
|
58563
58669
|
* Sets the storage adapter constructor.
|
|
@@ -58567,7 +58673,8 @@ class StorageLiveAdapter {
|
|
|
58567
58673
|
*/
|
|
58568
58674
|
this.useStorageAdapter = (Ctor) => {
|
|
58569
58675
|
backtest.loggerService.info(STORAGE_LIVE_ADAPTER_METHOD_NAME_USE_ADAPTER);
|
|
58570
|
-
this.
|
|
58676
|
+
this._signalLiveFactory = () => Reflect.construct(Ctor, []);
|
|
58677
|
+
this.getInstance.clear();
|
|
58571
58678
|
};
|
|
58572
58679
|
/**
|
|
58573
58680
|
* Switches to dummy storage adapter.
|
|
@@ -58575,7 +58682,8 @@ class StorageLiveAdapter {
|
|
|
58575
58682
|
*/
|
|
58576
58683
|
this.useDummy = () => {
|
|
58577
58684
|
backtest.loggerService.info(STORAGE_LIVE_ADAPTER_METHOD_NAME_USE_DUMMY);
|
|
58578
|
-
this.
|
|
58685
|
+
this._signalLiveFactory = () => new StorageDummyLiveUtils();
|
|
58686
|
+
this.getInstance.clear();
|
|
58579
58687
|
};
|
|
58580
58688
|
/**
|
|
58581
58689
|
* Switches to persistent storage adapter (default).
|
|
@@ -58583,7 +58691,8 @@ class StorageLiveAdapter {
|
|
|
58583
58691
|
*/
|
|
58584
58692
|
this.usePersist = () => {
|
|
58585
58693
|
backtest.loggerService.info(STORAGE_LIVE_ADAPTER_METHOD_NAME_USE_PERSIST);
|
|
58586
|
-
this.
|
|
58694
|
+
this._signalLiveFactory = () => new StoragePersistLiveUtils();
|
|
58695
|
+
this.getInstance.clear();
|
|
58587
58696
|
};
|
|
58588
58697
|
/**
|
|
58589
58698
|
* Switches to in-memory storage adapter.
|
|
@@ -58591,16 +58700,17 @@ class StorageLiveAdapter {
|
|
|
58591
58700
|
*/
|
|
58592
58701
|
this.useMemory = () => {
|
|
58593
58702
|
backtest.loggerService.info(STORAGE_LIVE_ADAPTER_METHOD_NAME_USE_MEMORY);
|
|
58594
|
-
this.
|
|
58703
|
+
this._signalLiveFactory = () => new StorageMemoryLiveUtils();
|
|
58704
|
+
this.getInstance.clear();
|
|
58595
58705
|
};
|
|
58596
58706
|
/**
|
|
58597
|
-
* Clears the
|
|
58707
|
+
* Clears the memoized utils instance.
|
|
58598
58708
|
* Call this when process.cwd() changes between strategy iterations
|
|
58599
58709
|
* so a new instance is created with the updated base path.
|
|
58600
58710
|
*/
|
|
58601
58711
|
this.clear = () => {
|
|
58602
58712
|
backtest.loggerService.info(STORAGE_LIVE_ADAPTER_METHOD_NAME_CLEAR);
|
|
58603
|
-
this.
|
|
58713
|
+
this.getInstance.clear();
|
|
58604
58714
|
};
|
|
58605
58715
|
}
|
|
58606
58716
|
}
|
|
@@ -60716,18 +60826,26 @@ class NotificationPersistLiveUtils {
|
|
|
60716
60826
|
*/
|
|
60717
60827
|
class NotificationBacktestAdapter {
|
|
60718
60828
|
constructor() {
|
|
60719
|
-
/**
|
|
60720
|
-
this.
|
|
60829
|
+
/** Factory producing the active notification utils instance */
|
|
60830
|
+
this._notificationBacktestFactory = () => new NotificationMemoryBacktestUtils();
|
|
60831
|
+
/**
|
|
60832
|
+
* Lazily constructs the notification utils from the registered factory and
|
|
60833
|
+
* memoizes the result via `singleshot`.
|
|
60834
|
+
*
|
|
60835
|
+
* The instance is built on the first call and cached for all subsequent calls.
|
|
60836
|
+
* Reset via `clear()` so the next call rebuilds from the current factory.
|
|
60837
|
+
*/
|
|
60838
|
+
this.getInstance = functoolsKit.singleshot(() => this._notificationBacktestFactory());
|
|
60721
60839
|
/**
|
|
60722
60840
|
* Handles signal events.
|
|
60723
60841
|
* Proxies call to the underlying notification adapter.
|
|
60724
60842
|
* @param data - The strategy tick result data
|
|
60725
60843
|
*/
|
|
60726
60844
|
this.handleSignal = async (data) => {
|
|
60727
|
-
return await this.
|
|
60845
|
+
return await this.getInstance().handleSignal(data);
|
|
60728
60846
|
};
|
|
60729
60847
|
this.handleSignalNotify = async (data) => {
|
|
60730
|
-
return await this.
|
|
60848
|
+
return await this.getInstance().handleSignalNotify(data);
|
|
60731
60849
|
};
|
|
60732
60850
|
/**
|
|
60733
60851
|
* Handles partial profit availability event.
|
|
@@ -60735,7 +60853,7 @@ class NotificationBacktestAdapter {
|
|
|
60735
60853
|
* @param data - The partial profit contract data
|
|
60736
60854
|
*/
|
|
60737
60855
|
this.handlePartialProfit = async (data) => {
|
|
60738
|
-
return await this.
|
|
60856
|
+
return await this.getInstance().handlePartialProfit(data);
|
|
60739
60857
|
};
|
|
60740
60858
|
/**
|
|
60741
60859
|
* Handles partial loss availability event.
|
|
@@ -60743,7 +60861,7 @@ class NotificationBacktestAdapter {
|
|
|
60743
60861
|
* @param data - The partial loss contract data
|
|
60744
60862
|
*/
|
|
60745
60863
|
this.handlePartialLoss = async (data) => {
|
|
60746
|
-
return await this.
|
|
60864
|
+
return await this.getInstance().handlePartialLoss(data);
|
|
60747
60865
|
};
|
|
60748
60866
|
/**
|
|
60749
60867
|
* Handles breakeven availability event.
|
|
@@ -60751,7 +60869,7 @@ class NotificationBacktestAdapter {
|
|
|
60751
60869
|
* @param data - The breakeven contract data
|
|
60752
60870
|
*/
|
|
60753
60871
|
this.handleBreakeven = async (data) => {
|
|
60754
|
-
return await this.
|
|
60872
|
+
return await this.getInstance().handleBreakeven(data);
|
|
60755
60873
|
};
|
|
60756
60874
|
/**
|
|
60757
60875
|
* Handles strategy commit events.
|
|
@@ -60759,7 +60877,7 @@ class NotificationBacktestAdapter {
|
|
|
60759
60877
|
* @param data - The strategy commit contract data
|
|
60760
60878
|
*/
|
|
60761
60879
|
this.handleStrategyCommit = async (data) => {
|
|
60762
|
-
return await this.
|
|
60880
|
+
return await this.getInstance().handleStrategyCommit(data);
|
|
60763
60881
|
};
|
|
60764
60882
|
/**
|
|
60765
60883
|
* Handles signal sync events (signal-open, signal-close).
|
|
@@ -60767,7 +60885,7 @@ class NotificationBacktestAdapter {
|
|
|
60767
60885
|
* @param data - The signal sync contract data
|
|
60768
60886
|
*/
|
|
60769
60887
|
this.handleSync = functoolsKit.trycatch(async (data) => {
|
|
60770
|
-
return await this.
|
|
60888
|
+
return await this.getInstance().handleSync(data);
|
|
60771
60889
|
}, {
|
|
60772
60890
|
defaultValue: null,
|
|
60773
60891
|
});
|
|
@@ -60777,7 +60895,7 @@ class NotificationBacktestAdapter {
|
|
|
60777
60895
|
* @param data - The risk contract data
|
|
60778
60896
|
*/
|
|
60779
60897
|
this.handleRisk = async (data) => {
|
|
60780
|
-
return await this.
|
|
60898
|
+
return await this.getInstance().handleRisk(data);
|
|
60781
60899
|
};
|
|
60782
60900
|
/**
|
|
60783
60901
|
* Handles error event.
|
|
@@ -60785,7 +60903,7 @@ class NotificationBacktestAdapter {
|
|
|
60785
60903
|
* @param error - The error object
|
|
60786
60904
|
*/
|
|
60787
60905
|
this.handleError = async (error) => {
|
|
60788
|
-
return await this.
|
|
60906
|
+
return await this.getInstance().handleError(error);
|
|
60789
60907
|
};
|
|
60790
60908
|
/**
|
|
60791
60909
|
* Handles critical error event.
|
|
@@ -60793,7 +60911,7 @@ class NotificationBacktestAdapter {
|
|
|
60793
60911
|
* @param error - The error object
|
|
60794
60912
|
*/
|
|
60795
60913
|
this.handleCriticalError = async (error) => {
|
|
60796
|
-
return await this.
|
|
60914
|
+
return await this.getInstance().handleCriticalError(error);
|
|
60797
60915
|
};
|
|
60798
60916
|
/**
|
|
60799
60917
|
* Handles validation error event.
|
|
@@ -60801,7 +60919,7 @@ class NotificationBacktestAdapter {
|
|
|
60801
60919
|
* @param error - The error object
|
|
60802
60920
|
*/
|
|
60803
60921
|
this.handleValidationError = async (error) => {
|
|
60804
|
-
return await this.
|
|
60922
|
+
return await this.getInstance().handleValidationError(error);
|
|
60805
60923
|
};
|
|
60806
60924
|
/**
|
|
60807
60925
|
* Gets all stored notifications.
|
|
@@ -60809,14 +60927,14 @@ class NotificationBacktestAdapter {
|
|
|
60809
60927
|
* @returns Array of all notification models
|
|
60810
60928
|
*/
|
|
60811
60929
|
this.getData = async () => {
|
|
60812
|
-
return await this.
|
|
60930
|
+
return await this.getInstance().getData();
|
|
60813
60931
|
};
|
|
60814
60932
|
/**
|
|
60815
60933
|
* Clears all stored notifications.
|
|
60816
60934
|
* Proxies call to the underlying notification adapter.
|
|
60817
60935
|
*/
|
|
60818
60936
|
this.dispose = async () => {
|
|
60819
|
-
return await this.
|
|
60937
|
+
return await this.getInstance().dispose();
|
|
60820
60938
|
};
|
|
60821
60939
|
/**
|
|
60822
60940
|
* Sets the notification adapter constructor.
|
|
@@ -60826,7 +60944,8 @@ class NotificationBacktestAdapter {
|
|
|
60826
60944
|
*/
|
|
60827
60945
|
this.useNotificationAdapter = (Ctor) => {
|
|
60828
60946
|
backtest.loggerService.info(NOTIFICATION_BACKTEST_ADAPTER_METHOD_NAME_USE_ADAPTER);
|
|
60829
|
-
this.
|
|
60947
|
+
this._notificationBacktestFactory = () => Reflect.construct(Ctor, []);
|
|
60948
|
+
this.getInstance.clear();
|
|
60830
60949
|
};
|
|
60831
60950
|
/**
|
|
60832
60951
|
* Switches to dummy notification adapter.
|
|
@@ -60834,7 +60953,8 @@ class NotificationBacktestAdapter {
|
|
|
60834
60953
|
*/
|
|
60835
60954
|
this.useDummy = () => {
|
|
60836
60955
|
backtest.loggerService.info(NOTIFICATION_BACKTEST_ADAPTER_METHOD_NAME_USE_DUMMY);
|
|
60837
|
-
this.
|
|
60956
|
+
this._notificationBacktestFactory = () => new NotificationDummyBacktestUtils();
|
|
60957
|
+
this.getInstance.clear();
|
|
60838
60958
|
};
|
|
60839
60959
|
/**
|
|
60840
60960
|
* Switches to in-memory notification adapter (default).
|
|
@@ -60842,7 +60962,8 @@ class NotificationBacktestAdapter {
|
|
|
60842
60962
|
*/
|
|
60843
60963
|
this.useMemory = () => {
|
|
60844
60964
|
backtest.loggerService.info(NOTIFICATION_BACKTEST_ADAPTER_METHOD_NAME_USE_MEMORY);
|
|
60845
|
-
this.
|
|
60965
|
+
this._notificationBacktestFactory = () => new NotificationMemoryBacktestUtils();
|
|
60966
|
+
this.getInstance.clear();
|
|
60846
60967
|
};
|
|
60847
60968
|
/**
|
|
60848
60969
|
* Switches to persistent notification adapter.
|
|
@@ -60850,16 +60971,17 @@ class NotificationBacktestAdapter {
|
|
|
60850
60971
|
*/
|
|
60851
60972
|
this.usePersist = () => {
|
|
60852
60973
|
backtest.loggerService.info(NOTIFICATION_BACKTEST_ADAPTER_METHOD_NAME_USE_PERSIST);
|
|
60853
|
-
this.
|
|
60974
|
+
this._notificationBacktestFactory = () => new NotificationPersistBacktestUtils();
|
|
60975
|
+
this.getInstance.clear();
|
|
60854
60976
|
};
|
|
60855
60977
|
/**
|
|
60856
|
-
*
|
|
60978
|
+
* Clears the memoized utils instance.
|
|
60857
60979
|
* Call this when process.cwd() changes between strategy iterations
|
|
60858
60980
|
* so a new instance is created with the updated base path.
|
|
60859
60981
|
*/
|
|
60860
60982
|
this.clear = () => {
|
|
60861
60983
|
backtest.loggerService.info(NOTIFICATION_BACKTEST_ADAPTER_METHOD_NAME_CLEAR);
|
|
60862
|
-
this.
|
|
60984
|
+
this.getInstance.clear();
|
|
60863
60985
|
};
|
|
60864
60986
|
}
|
|
60865
60987
|
}
|
|
@@ -60874,18 +60996,26 @@ class NotificationBacktestAdapter {
|
|
|
60874
60996
|
*/
|
|
60875
60997
|
class NotificationLiveAdapter {
|
|
60876
60998
|
constructor() {
|
|
60877
|
-
/**
|
|
60878
|
-
this.
|
|
60999
|
+
/** Factory producing the active notification utils instance */
|
|
61000
|
+
this._notificationLiveFactory = () => new NotificationMemoryLiveUtils();
|
|
61001
|
+
/**
|
|
61002
|
+
* Lazily constructs the notification utils from the registered factory and
|
|
61003
|
+
* memoizes the result via `singleshot`.
|
|
61004
|
+
*
|
|
61005
|
+
* The instance is built on the first call and cached for all subsequent calls.
|
|
61006
|
+
* Reset via `clear()` so the next call rebuilds from the current factory.
|
|
61007
|
+
*/
|
|
61008
|
+
this.getInstance = functoolsKit.singleshot(() => this._notificationLiveFactory());
|
|
60879
61009
|
/**
|
|
60880
61010
|
* Handles signal events.
|
|
60881
61011
|
* Proxies call to the underlying notification adapter.
|
|
60882
61012
|
* @param data - The strategy tick result data
|
|
60883
61013
|
*/
|
|
60884
61014
|
this.handleSignal = async (data) => {
|
|
60885
|
-
return await this.
|
|
61015
|
+
return await this.getInstance().handleSignal(data);
|
|
60886
61016
|
};
|
|
60887
61017
|
this.handleSignalNotify = async (data) => {
|
|
60888
|
-
return await this.
|
|
61018
|
+
return await this.getInstance().handleSignalNotify(data);
|
|
60889
61019
|
};
|
|
60890
61020
|
/**
|
|
60891
61021
|
* Handles partial profit availability event.
|
|
@@ -60893,7 +61023,7 @@ class NotificationLiveAdapter {
|
|
|
60893
61023
|
* @param data - The partial profit contract data
|
|
60894
61024
|
*/
|
|
60895
61025
|
this.handlePartialProfit = async (data) => {
|
|
60896
|
-
return await this.
|
|
61026
|
+
return await this.getInstance().handlePartialProfit(data);
|
|
60897
61027
|
};
|
|
60898
61028
|
/**
|
|
60899
61029
|
* Handles partial loss availability event.
|
|
@@ -60901,7 +61031,7 @@ class NotificationLiveAdapter {
|
|
|
60901
61031
|
* @param data - The partial loss contract data
|
|
60902
61032
|
*/
|
|
60903
61033
|
this.handlePartialLoss = async (data) => {
|
|
60904
|
-
return await this.
|
|
61034
|
+
return await this.getInstance().handlePartialLoss(data);
|
|
60905
61035
|
};
|
|
60906
61036
|
/**
|
|
60907
61037
|
* Handles breakeven availability event.
|
|
@@ -60909,7 +61039,7 @@ class NotificationLiveAdapter {
|
|
|
60909
61039
|
* @param data - The breakeven contract data
|
|
60910
61040
|
*/
|
|
60911
61041
|
this.handleBreakeven = async (data) => {
|
|
60912
|
-
return await this.
|
|
61042
|
+
return await this.getInstance().handleBreakeven(data);
|
|
60913
61043
|
};
|
|
60914
61044
|
/**
|
|
60915
61045
|
* Handles strategy commit events.
|
|
@@ -60917,7 +61047,7 @@ class NotificationLiveAdapter {
|
|
|
60917
61047
|
* @param data - The strategy commit contract data
|
|
60918
61048
|
*/
|
|
60919
61049
|
this.handleStrategyCommit = async (data) => {
|
|
60920
|
-
return await this.
|
|
61050
|
+
return await this.getInstance().handleStrategyCommit(data);
|
|
60921
61051
|
};
|
|
60922
61052
|
/**
|
|
60923
61053
|
* Handles signal sync events (signal-open, signal-close).
|
|
@@ -60925,7 +61055,7 @@ class NotificationLiveAdapter {
|
|
|
60925
61055
|
* @param data - The signal sync contract data
|
|
60926
61056
|
*/
|
|
60927
61057
|
this.handleSync = functoolsKit.trycatch(async (data) => {
|
|
60928
|
-
return await this.
|
|
61058
|
+
return await this.getInstance().handleSync(data);
|
|
60929
61059
|
}, {
|
|
60930
61060
|
defaultValue: null,
|
|
60931
61061
|
});
|
|
@@ -60935,7 +61065,7 @@ class NotificationLiveAdapter {
|
|
|
60935
61065
|
* @param data - The risk contract data
|
|
60936
61066
|
*/
|
|
60937
61067
|
this.handleRisk = async (data) => {
|
|
60938
|
-
return await this.
|
|
61068
|
+
return await this.getInstance().handleRisk(data);
|
|
60939
61069
|
};
|
|
60940
61070
|
/**
|
|
60941
61071
|
* Handles error event.
|
|
@@ -60943,7 +61073,7 @@ class NotificationLiveAdapter {
|
|
|
60943
61073
|
* @param error - The error object
|
|
60944
61074
|
*/
|
|
60945
61075
|
this.handleError = async (error) => {
|
|
60946
|
-
return await this.
|
|
61076
|
+
return await this.getInstance().handleError(error);
|
|
60947
61077
|
};
|
|
60948
61078
|
/**
|
|
60949
61079
|
* Handles critical error event.
|
|
@@ -60951,7 +61081,7 @@ class NotificationLiveAdapter {
|
|
|
60951
61081
|
* @param error - The error object
|
|
60952
61082
|
*/
|
|
60953
61083
|
this.handleCriticalError = async (error) => {
|
|
60954
|
-
return await this.
|
|
61084
|
+
return await this.getInstance().handleCriticalError(error);
|
|
60955
61085
|
};
|
|
60956
61086
|
/**
|
|
60957
61087
|
* Handles validation error event.
|
|
@@ -60959,7 +61089,7 @@ class NotificationLiveAdapter {
|
|
|
60959
61089
|
* @param error - The error object
|
|
60960
61090
|
*/
|
|
60961
61091
|
this.handleValidationError = async (error) => {
|
|
60962
|
-
return await this.
|
|
61092
|
+
return await this.getInstance().handleValidationError(error);
|
|
60963
61093
|
};
|
|
60964
61094
|
/**
|
|
60965
61095
|
* Gets all stored notifications.
|
|
@@ -60967,14 +61097,14 @@ class NotificationLiveAdapter {
|
|
|
60967
61097
|
* @returns Array of all notification models
|
|
60968
61098
|
*/
|
|
60969
61099
|
this.getData = async () => {
|
|
60970
|
-
return await this.
|
|
61100
|
+
return await this.getInstance().getData();
|
|
60971
61101
|
};
|
|
60972
61102
|
/**
|
|
60973
61103
|
* Clears all stored notifications.
|
|
60974
61104
|
* Proxies call to the underlying notification adapter.
|
|
60975
61105
|
*/
|
|
60976
61106
|
this.dispose = async () => {
|
|
60977
|
-
return await this.
|
|
61107
|
+
return await this.getInstance().dispose();
|
|
60978
61108
|
};
|
|
60979
61109
|
/**
|
|
60980
61110
|
* Sets the notification adapter constructor.
|
|
@@ -60984,7 +61114,8 @@ class NotificationLiveAdapter {
|
|
|
60984
61114
|
*/
|
|
60985
61115
|
this.useNotificationAdapter = (Ctor) => {
|
|
60986
61116
|
backtest.loggerService.info(NOTIFICATION_LIVE_ADAPTER_METHOD_NAME_USE_ADAPTER);
|
|
60987
|
-
this.
|
|
61117
|
+
this._notificationLiveFactory = () => Reflect.construct(Ctor, []);
|
|
61118
|
+
this.getInstance.clear();
|
|
60988
61119
|
};
|
|
60989
61120
|
/**
|
|
60990
61121
|
* Switches to dummy notification adapter.
|
|
@@ -60992,7 +61123,8 @@ class NotificationLiveAdapter {
|
|
|
60992
61123
|
*/
|
|
60993
61124
|
this.useDummy = () => {
|
|
60994
61125
|
backtest.loggerService.info(NOTIFICATION_LIVE_ADAPTER_METHOD_NAME_USE_DUMMY);
|
|
60995
|
-
this.
|
|
61126
|
+
this._notificationLiveFactory = () => new NotificationDummyLiveUtils();
|
|
61127
|
+
this.getInstance.clear();
|
|
60996
61128
|
};
|
|
60997
61129
|
/**
|
|
60998
61130
|
* Switches to in-memory notification adapter (default).
|
|
@@ -61000,7 +61132,8 @@ class NotificationLiveAdapter {
|
|
|
61000
61132
|
*/
|
|
61001
61133
|
this.useMemory = () => {
|
|
61002
61134
|
backtest.loggerService.info(NOTIFICATION_LIVE_ADAPTER_METHOD_NAME_USE_MEMORY);
|
|
61003
|
-
this.
|
|
61135
|
+
this._notificationLiveFactory = () => new NotificationMemoryLiveUtils();
|
|
61136
|
+
this.getInstance.clear();
|
|
61004
61137
|
};
|
|
61005
61138
|
/**
|
|
61006
61139
|
* Switches to persistent notification adapter.
|
|
@@ -61008,16 +61141,17 @@ class NotificationLiveAdapter {
|
|
|
61008
61141
|
*/
|
|
61009
61142
|
this.usePersist = () => {
|
|
61010
61143
|
backtest.loggerService.info(NOTIFICATION_LIVE_ADAPTER_METHOD_NAME_USE_PERSIST);
|
|
61011
|
-
this.
|
|
61144
|
+
this._notificationLiveFactory = () => new NotificationPersistLiveUtils();
|
|
61145
|
+
this.getInstance.clear();
|
|
61012
61146
|
};
|
|
61013
61147
|
/**
|
|
61014
|
-
*
|
|
61148
|
+
* Clears the memoized utils instance.
|
|
61015
61149
|
* Call this when process.cwd() changes between strategy iterations
|
|
61016
61150
|
* so a new instance is created with the updated base path.
|
|
61017
61151
|
*/
|
|
61018
61152
|
this.clear = () => {
|
|
61019
61153
|
backtest.loggerService.info(NOTIFICATION_LIVE_ADAPTER_METHOD_NAME_CLEAR);
|
|
61020
|
-
this.
|
|
61154
|
+
this.getInstance.clear();
|
|
61021
61155
|
};
|
|
61022
61156
|
}
|
|
61023
61157
|
}
|