backtest-kit 10.2.0 → 11.0.0
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 +27 -3
- package/build/index.mjs +31 -7
- package/package.json +1 -1
- package/types.d.ts +10 -2
package/build/index.cjs
CHANGED
|
@@ -818,6 +818,13 @@ const beforeStartSubject = new functoolsKit.Subject();
|
|
|
818
818
|
* Emits when the engine has completed processing a signal.
|
|
819
819
|
*/
|
|
820
820
|
const afterEndSubject = new functoolsKit.Subject();
|
|
821
|
+
/**
|
|
822
|
+
* Emitter for `@backtest-kit/cli`, which notifies the application
|
|
823
|
+
* that all modules have been initialized.
|
|
824
|
+
*
|
|
825
|
+
* Send entry absolute path to the consumer
|
|
826
|
+
*/
|
|
827
|
+
const entrySubject = new functoolsKit.BehaviorSubject();
|
|
821
828
|
|
|
822
829
|
var emitters = /*#__PURE__*/Object.freeze({
|
|
823
830
|
__proto__: null,
|
|
@@ -829,6 +836,7 @@ var emitters = /*#__PURE__*/Object.freeze({
|
|
|
829
836
|
doneBacktestSubject: doneBacktestSubject,
|
|
830
837
|
doneLiveSubject: doneLiveSubject,
|
|
831
838
|
doneWalkerSubject: doneWalkerSubject,
|
|
839
|
+
entrySubject: entrySubject,
|
|
832
840
|
errorEmitter: errorEmitter,
|
|
833
841
|
exitEmitter: exitEmitter,
|
|
834
842
|
highestProfitSubject: highestProfitSubject,
|
|
@@ -6584,7 +6592,7 @@ const INTERVAL_MINUTES$8 = {
|
|
|
6584
6592
|
* Used to indicate that the actual pendingAt will be set upon activation.
|
|
6585
6593
|
*/
|
|
6586
6594
|
const SCHEDULED_SIGNAL_PENDING_MOCK = 0;
|
|
6587
|
-
const TIMEOUT_SYMBOL = Symbol('timeout');
|
|
6595
|
+
const TIMEOUT_SYMBOL$1 = Symbol('timeout');
|
|
6588
6596
|
/**
|
|
6589
6597
|
* Calls onSignalSync callback for signal-open event.
|
|
6590
6598
|
*
|
|
@@ -7006,7 +7014,7 @@ const GET_SIGNAL_FN = functoolsKit.trycatch(async (self) => {
|
|
|
7006
7014
|
const timeoutMs = GLOBAL_CONFIG.CC_MAX_SIGNAL_GENERATION_SECONDS * 1000;
|
|
7007
7015
|
const signal = await Promise.race([
|
|
7008
7016
|
self.params.getSignal(self.params.execution.context.symbol, self.params.execution.context.when, currentPrice),
|
|
7009
|
-
functoolsKit.sleep(timeoutMs).then(() => TIMEOUT_SYMBOL),
|
|
7017
|
+
functoolsKit.sleep(timeoutMs).then(() => TIMEOUT_SYMBOL$1),
|
|
7010
7018
|
]);
|
|
7011
7019
|
if (typeof signal === "symbol") {
|
|
7012
7020
|
throw new Error(`Timeout for ${self.params.method.context.strategyName} symbol=${self.params.execution.context.symbol}`);
|
|
@@ -37581,8 +37589,9 @@ function getActionSchema(actionName) {
|
|
|
37581
37589
|
}
|
|
37582
37590
|
|
|
37583
37591
|
const WAIT_FOR_READY_METHOD_NAME = "init.waitForReady";
|
|
37584
|
-
const MAX_WAIT_SECONDS =
|
|
37592
|
+
const MAX_WAIT_SECONDS = 45;
|
|
37585
37593
|
const SECOND_DELAY = 1000;
|
|
37594
|
+
const TIMEOUT_SYMBOL = Symbol('timeout');
|
|
37586
37595
|
/**
|
|
37587
37596
|
* Blocks until the schema registries needed to start trading are populated.
|
|
37588
37597
|
*
|
|
@@ -37620,6 +37629,18 @@ const SECOND_DELAY = 1000;
|
|
|
37620
37629
|
*/
|
|
37621
37630
|
async function waitForReady(isBacktest = true) {
|
|
37622
37631
|
backtest.loggerService.info(WAIT_FOR_READY_METHOD_NAME, { isBacktest });
|
|
37632
|
+
if (entrySubject.data) {
|
|
37633
|
+
return;
|
|
37634
|
+
}
|
|
37635
|
+
if (entrySubject.hasListeners) {
|
|
37636
|
+
backtest.loggerService.debug(`${WAIT_FOR_READY_METHOD_NAME} waiting for entrySubject`);
|
|
37637
|
+
const result = await Promise.race([
|
|
37638
|
+
entrySubject.toPromise(),
|
|
37639
|
+
functoolsKit.sleep(MAX_WAIT_SECONDS * SECOND_DELAY).then(() => TIMEOUT_SYMBOL)
|
|
37640
|
+
]);
|
|
37641
|
+
typeof result === "symbol" && console.log("waitForReady timeout");
|
|
37642
|
+
return;
|
|
37643
|
+
}
|
|
37623
37644
|
for (let i = 0; i !== MAX_WAIT_SECONDS; i++) {
|
|
37624
37645
|
const [exchangeList, frameList, strategyList] = await Promise.all([
|
|
37625
37646
|
backtest.exchangeValidationService.list(),
|
|
@@ -37650,6 +37671,9 @@ async function waitForReady(isBacktest = true) {
|
|
|
37650
37671
|
await functoolsKit.sleep(SECOND_DELAY);
|
|
37651
37672
|
continue;
|
|
37652
37673
|
}
|
|
37674
|
+
if (i === MAX_WAIT_SECONDS - 1) {
|
|
37675
|
+
console.log("waitForReady timeout");
|
|
37676
|
+
}
|
|
37653
37677
|
break;
|
|
37654
37678
|
}
|
|
37655
37679
|
}
|
package/build/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createActivator } from 'di-kit';
|
|
2
2
|
import { scoped } from 'di-scoped';
|
|
3
3
|
import { singleton } from 'di-singleton';
|
|
4
|
-
import { Subject, makeExtendable, singleshot, getErrorMessage, memoize, not, errorData, trycatch, retry, queued, sleep, randomString, str, isObject, ToolRegistry, typo, and, Source, resolveDocuments, timeout, TIMEOUT_SYMBOL as TIMEOUT_SYMBOL$
|
|
4
|
+
import { Subject, BehaviorSubject, makeExtendable, singleshot, getErrorMessage, memoize, not, errorData, trycatch, retry, queued, sleep, randomString, str, isObject, ToolRegistry, typo, and, Source, resolveDocuments, timeout, TIMEOUT_SYMBOL as TIMEOUT_SYMBOL$2, compose, waitForNext, singlerun } from 'functools-kit';
|
|
5
5
|
import * as fs from 'fs/promises';
|
|
6
6
|
import fs__default from 'fs/promises';
|
|
7
7
|
import path, { join, dirname } from 'path';
|
|
@@ -798,6 +798,13 @@ const beforeStartSubject = new Subject();
|
|
|
798
798
|
* Emits when the engine has completed processing a signal.
|
|
799
799
|
*/
|
|
800
800
|
const afterEndSubject = new Subject();
|
|
801
|
+
/**
|
|
802
|
+
* Emitter for `@backtest-kit/cli`, which notifies the application
|
|
803
|
+
* that all modules have been initialized.
|
|
804
|
+
*
|
|
805
|
+
* Send entry absolute path to the consumer
|
|
806
|
+
*/
|
|
807
|
+
const entrySubject = new BehaviorSubject();
|
|
801
808
|
|
|
802
809
|
var emitters = /*#__PURE__*/Object.freeze({
|
|
803
810
|
__proto__: null,
|
|
@@ -809,6 +816,7 @@ var emitters = /*#__PURE__*/Object.freeze({
|
|
|
809
816
|
doneBacktestSubject: doneBacktestSubject,
|
|
810
817
|
doneLiveSubject: doneLiveSubject,
|
|
811
818
|
doneWalkerSubject: doneWalkerSubject,
|
|
819
|
+
entrySubject: entrySubject,
|
|
812
820
|
errorEmitter: errorEmitter,
|
|
813
821
|
exitEmitter: exitEmitter,
|
|
814
822
|
highestProfitSubject: highestProfitSubject,
|
|
@@ -6564,7 +6572,7 @@ const INTERVAL_MINUTES$8 = {
|
|
|
6564
6572
|
* Used to indicate that the actual pendingAt will be set upon activation.
|
|
6565
6573
|
*/
|
|
6566
6574
|
const SCHEDULED_SIGNAL_PENDING_MOCK = 0;
|
|
6567
|
-
const TIMEOUT_SYMBOL = Symbol('timeout');
|
|
6575
|
+
const TIMEOUT_SYMBOL$1 = Symbol('timeout');
|
|
6568
6576
|
/**
|
|
6569
6577
|
* Calls onSignalSync callback for signal-open event.
|
|
6570
6578
|
*
|
|
@@ -6986,7 +6994,7 @@ const GET_SIGNAL_FN = trycatch(async (self) => {
|
|
|
6986
6994
|
const timeoutMs = GLOBAL_CONFIG.CC_MAX_SIGNAL_GENERATION_SECONDS * 1000;
|
|
6987
6995
|
const signal = await Promise.race([
|
|
6988
6996
|
self.params.getSignal(self.params.execution.context.symbol, self.params.execution.context.when, currentPrice),
|
|
6989
|
-
sleep(timeoutMs).then(() => TIMEOUT_SYMBOL),
|
|
6997
|
+
sleep(timeoutMs).then(() => TIMEOUT_SYMBOL$1),
|
|
6990
6998
|
]);
|
|
6991
6999
|
if (typeof signal === "symbol") {
|
|
6992
7000
|
throw new Error(`Timeout for ${self.params.method.context.strategyName} symbol=${self.params.execution.context.symbol}`);
|
|
@@ -23252,7 +23260,7 @@ class MarkdownFileBase {
|
|
|
23252
23260
|
timestamp: getContextTimestamp(),
|
|
23253
23261
|
}) + "\n";
|
|
23254
23262
|
const status = await this[WRITE_SAFE_SYMBOL$1](line);
|
|
23255
|
-
if (status === TIMEOUT_SYMBOL$
|
|
23263
|
+
if (status === TIMEOUT_SYMBOL$2) {
|
|
23256
23264
|
throw new Error(`Timeout writing to markdown ${this.markdownName}`);
|
|
23257
23265
|
}
|
|
23258
23266
|
}
|
|
@@ -23545,7 +23553,7 @@ class ReportBase {
|
|
|
23545
23553
|
timestamp: getContextTimestamp(),
|
|
23546
23554
|
}) + "\n";
|
|
23547
23555
|
const status = await this[WRITE_SAFE_SYMBOL$1](line);
|
|
23548
|
-
if (status === TIMEOUT_SYMBOL$
|
|
23556
|
+
if (status === TIMEOUT_SYMBOL$2) {
|
|
23549
23557
|
throw new Error(`Timeout writing to report ${this.reportName}`);
|
|
23550
23558
|
}
|
|
23551
23559
|
}
|
|
@@ -37561,8 +37569,9 @@ function getActionSchema(actionName) {
|
|
|
37561
37569
|
}
|
|
37562
37570
|
|
|
37563
37571
|
const WAIT_FOR_READY_METHOD_NAME = "init.waitForReady";
|
|
37564
|
-
const MAX_WAIT_SECONDS =
|
|
37572
|
+
const MAX_WAIT_SECONDS = 45;
|
|
37565
37573
|
const SECOND_DELAY = 1000;
|
|
37574
|
+
const TIMEOUT_SYMBOL = Symbol('timeout');
|
|
37566
37575
|
/**
|
|
37567
37576
|
* Blocks until the schema registries needed to start trading are populated.
|
|
37568
37577
|
*
|
|
@@ -37600,6 +37609,18 @@ const SECOND_DELAY = 1000;
|
|
|
37600
37609
|
*/
|
|
37601
37610
|
async function waitForReady(isBacktest = true) {
|
|
37602
37611
|
backtest.loggerService.info(WAIT_FOR_READY_METHOD_NAME, { isBacktest });
|
|
37612
|
+
if (entrySubject.data) {
|
|
37613
|
+
return;
|
|
37614
|
+
}
|
|
37615
|
+
if (entrySubject.hasListeners) {
|
|
37616
|
+
backtest.loggerService.debug(`${WAIT_FOR_READY_METHOD_NAME} waiting for entrySubject`);
|
|
37617
|
+
const result = await Promise.race([
|
|
37618
|
+
entrySubject.toPromise(),
|
|
37619
|
+
sleep(MAX_WAIT_SECONDS * SECOND_DELAY).then(() => TIMEOUT_SYMBOL)
|
|
37620
|
+
]);
|
|
37621
|
+
typeof result === "symbol" && console.log("waitForReady timeout");
|
|
37622
|
+
return;
|
|
37623
|
+
}
|
|
37603
37624
|
for (let i = 0; i !== MAX_WAIT_SECONDS; i++) {
|
|
37604
37625
|
const [exchangeList, frameList, strategyList] = await Promise.all([
|
|
37605
37626
|
backtest.exchangeValidationService.list(),
|
|
@@ -37630,6 +37651,9 @@ async function waitForReady(isBacktest = true) {
|
|
|
37630
37651
|
await sleep(SECOND_DELAY);
|
|
37631
37652
|
continue;
|
|
37632
37653
|
}
|
|
37654
|
+
if (i === MAX_WAIT_SECONDS - 1) {
|
|
37655
|
+
console.log("waitForReady timeout");
|
|
37656
|
+
}
|
|
37633
37657
|
break;
|
|
37634
37658
|
}
|
|
37635
37659
|
}
|
|
@@ -55421,7 +55445,7 @@ class LogJsonlUtils {
|
|
|
55421
55445
|
await this[WAIT_FOR_INIT_SYMBOL]();
|
|
55422
55446
|
const line = JSON.stringify(entry) + "\n";
|
|
55423
55447
|
const status = await this[WRITE_SAFE_SYMBOL](line);
|
|
55424
|
-
if (status === TIMEOUT_SYMBOL$
|
|
55448
|
+
if (status === TIMEOUT_SYMBOL$2) {
|
|
55425
55449
|
throw new Error(`LogJsonlUtils timeout writing to file=${this._filePath}`);
|
|
55426
55450
|
}
|
|
55427
55451
|
};
|
package/package.json
CHANGED
package/types.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as di_scoped from 'di-scoped';
|
|
2
2
|
import * as functools_kit from 'functools-kit';
|
|
3
|
-
import { Subject } from 'functools-kit';
|
|
3
|
+
import { Subject, BehaviorSubject } from 'functools-kit';
|
|
4
4
|
import { WriteStream } from 'fs';
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -29091,6 +29091,13 @@ declare const beforeStartSubject: Subject<BeforeStartContract>;
|
|
|
29091
29091
|
* Emits when the engine has completed processing a signal.
|
|
29092
29092
|
*/
|
|
29093
29093
|
declare const afterEndSubject: Subject<AfterEndContract>;
|
|
29094
|
+
/**
|
|
29095
|
+
* Emitter for `@backtest-kit/cli`, which notifies the application
|
|
29096
|
+
* that all modules have been initialized.
|
|
29097
|
+
*
|
|
29098
|
+
* Send entry absolute path to the consumer
|
|
29099
|
+
*/
|
|
29100
|
+
declare const entrySubject: BehaviorSubject<string>;
|
|
29094
29101
|
|
|
29095
29102
|
declare const emitters_activePingSubject: typeof activePingSubject;
|
|
29096
29103
|
declare const emitters_afterEndSubject: typeof afterEndSubject;
|
|
@@ -29100,6 +29107,7 @@ declare const emitters_breakevenSubject: typeof breakevenSubject;
|
|
|
29100
29107
|
declare const emitters_doneBacktestSubject: typeof doneBacktestSubject;
|
|
29101
29108
|
declare const emitters_doneLiveSubject: typeof doneLiveSubject;
|
|
29102
29109
|
declare const emitters_doneWalkerSubject: typeof doneWalkerSubject;
|
|
29110
|
+
declare const emitters_entrySubject: typeof entrySubject;
|
|
29103
29111
|
declare const emitters_errorEmitter: typeof errorEmitter;
|
|
29104
29112
|
declare const emitters_exitEmitter: typeof exitEmitter;
|
|
29105
29113
|
declare const emitters_highestProfitSubject: typeof highestProfitSubject;
|
|
@@ -29124,7 +29132,7 @@ declare const emitters_walkerCompleteSubject: typeof walkerCompleteSubject;
|
|
|
29124
29132
|
declare const emitters_walkerEmitter: typeof walkerEmitter;
|
|
29125
29133
|
declare const emitters_walkerStopSubject: typeof walkerStopSubject;
|
|
29126
29134
|
declare namespace emitters {
|
|
29127
|
-
export { emitters_activePingSubject as activePingSubject, emitters_afterEndSubject as afterEndSubject, emitters_backtestScheduleOpenSubject as backtestScheduleOpenSubject, emitters_beforeStartSubject as beforeStartSubject, emitters_breakevenSubject as breakevenSubject, emitters_doneBacktestSubject as doneBacktestSubject, emitters_doneLiveSubject as doneLiveSubject, emitters_doneWalkerSubject as doneWalkerSubject, emitters_errorEmitter as errorEmitter, emitters_exitEmitter as exitEmitter, emitters_highestProfitSubject as highestProfitSubject, emitters_idlePingSubject as idlePingSubject, emitters_maxDrawdownSubject as maxDrawdownSubject, emitters_partialLossSubject as partialLossSubject, emitters_partialProfitSubject as partialProfitSubject, emitters_performanceEmitter as performanceEmitter, emitters_progressBacktestEmitter as progressBacktestEmitter, emitters_progressWalkerEmitter as progressWalkerEmitter, emitters_riskSubject as riskSubject, emitters_schedulePingSubject as schedulePingSubject, emitters_shutdownEmitter as shutdownEmitter, emitters_signalBacktestEmitter as signalBacktestEmitter, emitters_signalEmitter as signalEmitter, emitters_signalLiveEmitter as signalLiveEmitter, emitters_signalNotifySubject as signalNotifySubject, emitters_strategyCommitSubject as strategyCommitSubject, emitters_syncSubject as syncSubject, emitters_validationSubject as validationSubject, emitters_walkerCompleteSubject as walkerCompleteSubject, emitters_walkerEmitter as walkerEmitter, emitters_walkerStopSubject as walkerStopSubject };
|
|
29135
|
+
export { emitters_activePingSubject as activePingSubject, emitters_afterEndSubject as afterEndSubject, emitters_backtestScheduleOpenSubject as backtestScheduleOpenSubject, emitters_beforeStartSubject as beforeStartSubject, emitters_breakevenSubject as breakevenSubject, emitters_doneBacktestSubject as doneBacktestSubject, emitters_doneLiveSubject as doneLiveSubject, emitters_doneWalkerSubject as doneWalkerSubject, emitters_entrySubject as entrySubject, emitters_errorEmitter as errorEmitter, emitters_exitEmitter as exitEmitter, emitters_highestProfitSubject as highestProfitSubject, emitters_idlePingSubject as idlePingSubject, emitters_maxDrawdownSubject as maxDrawdownSubject, emitters_partialLossSubject as partialLossSubject, emitters_partialProfitSubject as partialProfitSubject, emitters_performanceEmitter as performanceEmitter, emitters_progressBacktestEmitter as progressBacktestEmitter, emitters_progressWalkerEmitter as progressWalkerEmitter, emitters_riskSubject as riskSubject, emitters_schedulePingSubject as schedulePingSubject, emitters_shutdownEmitter as shutdownEmitter, emitters_signalBacktestEmitter as signalBacktestEmitter, emitters_signalEmitter as signalEmitter, emitters_signalLiveEmitter as signalLiveEmitter, emitters_signalNotifySubject as signalNotifySubject, emitters_strategyCommitSubject as strategyCommitSubject, emitters_syncSubject as syncSubject, emitters_validationSubject as validationSubject, emitters_walkerCompleteSubject as walkerCompleteSubject, emitters_walkerEmitter as walkerEmitter, emitters_walkerStopSubject as walkerStopSubject };
|
|
29128
29136
|
}
|
|
29129
29137
|
|
|
29130
29138
|
/**
|