@tradejs/node 3.1.8-beta.207 → 3.1.8-beta.212
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/dist/ai.mjs +3 -3
- package/dist/backtest.js +8 -6
- package/dist/backtest.mjs +7 -7
- package/dist/{chunk-SEQJ6V6B.mjs → chunk-733VVTWU.mjs} +1 -1
- package/dist/chunk-F7ODY5W4.mjs +322 -0
- package/dist/{chunk-WS5DYEVZ.mjs → chunk-LZDXRXIU.mjs} +3 -1
- package/dist/{chunk-XN7BC7XK.mjs → chunk-MEZIXBZ3.mjs} +1 -1
- package/dist/{chunk-3TWULKHV.mjs → chunk-QVKUROR2.mjs} +1 -1
- package/dist/{chunk-MCDICN3I.mjs → chunk-SVAUSZUE.mjs} +8 -8
- package/dist/cli.d.mts +2 -1
- package/dist/cli.d.ts +2 -1
- package/dist/cli.js +3 -1
- package/dist/cli.mjs +3 -3
- package/dist/connectors.js +3 -1
- package/dist/connectors.mjs +2 -2
- package/dist/registry.js +8 -6
- package/dist/registry.mjs +4 -4
- package/dist/runtimeDashboard.js +548 -275
- package/dist/runtimeDashboard.mjs +46 -267
- package/dist/runtimeStrategies.d.mts +16 -5
- package/dist/runtimeStrategies.d.ts +16 -5
- package/dist/runtimeStrategies.js +204 -103
- package/dist/runtimeStrategies.mjs +12 -219
- package/dist/strategies.js +8 -6
- package/dist/strategies.mjs +4 -4
- package/package.json +4 -4
|
@@ -30,13 +30,16 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/runtimeStrategies.ts
|
|
31
31
|
var runtimeStrategies_exports = {};
|
|
32
32
|
__export(runtimeStrategies_exports, {
|
|
33
|
+
getRuntimeDeployment: () => getRuntimeDeployment,
|
|
33
34
|
getRuntimeStrategyPackageMetadata: () => getRuntimeStrategyPackageMetadata,
|
|
34
|
-
|
|
35
|
+
listRuntimeDeployments: () => listRuntimeDeployments,
|
|
36
|
+
loadResolvedRuntimeStrategies: () => loadResolvedRuntimeStrategies,
|
|
37
|
+
verifyRuntimeDeclaration: () => verifyRuntimeDeclaration
|
|
35
38
|
});
|
|
36
39
|
module.exports = __toCommonJS(runtimeStrategies_exports);
|
|
37
40
|
var import_promises = require("fs/promises");
|
|
38
41
|
var import_node_path = __toESM(require("path"));
|
|
39
|
-
var
|
|
42
|
+
var import_runtimeControls = require("@tradejs/infra/runtimeControls");
|
|
40
43
|
var import_tradingAccounts = require("@tradejs/infra/tradingAccounts");
|
|
41
44
|
|
|
42
45
|
// src/strategy/manifests.ts
|
|
@@ -84,11 +87,13 @@ var normalizeConfig = (rawConfig) => {
|
|
|
84
87
|
const hooks = (0, import_config.normalizeTradejsConfigHooks)(
|
|
85
88
|
config.hooks
|
|
86
89
|
);
|
|
90
|
+
const runtime = config.runtime && typeof config.runtime === "object" && !Array.isArray(config.runtime) ? config.runtime : void 0;
|
|
87
91
|
return {
|
|
88
92
|
strategies: strategies2,
|
|
89
93
|
indicators,
|
|
90
94
|
connectors,
|
|
91
|
-
...hooks ? { hooks } : {}
|
|
95
|
+
...hooks ? { hooks } : {},
|
|
96
|
+
...runtime ? { runtime } : {}
|
|
92
97
|
};
|
|
93
98
|
};
|
|
94
99
|
var getNodeCreateRequire = () => {
|
|
@@ -543,6 +548,40 @@ var strategies = new Proxy(
|
|
|
543
548
|
);
|
|
544
549
|
|
|
545
550
|
// src/runtimeStrategies.ts
|
|
551
|
+
var INTERVALS = /* @__PURE__ */ new Set([
|
|
552
|
+
"1",
|
|
553
|
+
"3",
|
|
554
|
+
"5",
|
|
555
|
+
"15",
|
|
556
|
+
"30",
|
|
557
|
+
"60",
|
|
558
|
+
"120",
|
|
559
|
+
"240",
|
|
560
|
+
"360",
|
|
561
|
+
"720",
|
|
562
|
+
"D",
|
|
563
|
+
"W",
|
|
564
|
+
"M"
|
|
565
|
+
]);
|
|
566
|
+
var RUNTIME_KEYS = /* @__PURE__ */ new Set(["deployments"]);
|
|
567
|
+
var DEPLOYMENT_KEYS = /* @__PURE__ */ new Set([
|
|
568
|
+
"label",
|
|
569
|
+
"connectorName",
|
|
570
|
+
"provider",
|
|
571
|
+
"accountId",
|
|
572
|
+
"enabled",
|
|
573
|
+
"strategies",
|
|
574
|
+
"assetClasses",
|
|
575
|
+
"tickers"
|
|
576
|
+
]);
|
|
577
|
+
var STRATEGY_KEYS = /* @__PURE__ */ new Set(["version", "enabled", "config"]);
|
|
578
|
+
var FORBIDDEN_CONFIG_KEYS = /* @__PURE__ */ new Set([
|
|
579
|
+
"ACCOUNT_ID",
|
|
580
|
+
"DEPLOYMENT_ID",
|
|
581
|
+
"CONNECTOR_NAME",
|
|
582
|
+
"ENABLE"
|
|
583
|
+
]);
|
|
584
|
+
var isRecord = (value) => Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
546
585
|
var readPackageManifest = async (projectRoot) => {
|
|
547
586
|
const candidates = [
|
|
548
587
|
process.env.TRADEJS_RUNTIME_PACKAGE_MANIFEST,
|
|
@@ -593,31 +632,84 @@ var resolveStrategyPackageName = async ({
|
|
|
593
632
|
return null;
|
|
594
633
|
}
|
|
595
634
|
};
|
|
596
|
-
var
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
}) => {
|
|
601
|
-
const installedStrategyVersion = await resolveInstalledPackageVersion(
|
|
602
|
-
projectRoot,
|
|
603
|
-
release.strategyPackage,
|
|
604
|
-
packageManifest
|
|
605
|
-
);
|
|
606
|
-
if (release.strategyPackageVersion !== installedStrategyVersion) {
|
|
607
|
-
throw new Error(
|
|
608
|
-
`${release.strategyName} v${release.releaseVersion} requires ${release.strategyPackage}@${release.strategyPackageVersion}, image has ${installedStrategyVersion}`
|
|
609
|
-
);
|
|
635
|
+
var verifyStringArray = (value) => value === void 0 || Array.isArray(value) && value.every((item) => typeof item === "string");
|
|
636
|
+
var verifyDeploymentDeclaration = (deploymentId, value) => {
|
|
637
|
+
if (!deploymentId.trim() || !isRecord(value) || Object.keys(value).some((key) => !DEPLOYMENT_KEYS.has(key)) || typeof value.connectorName !== "string" || !value.connectorName.trim() || typeof value.accountId !== "string" || !value.accountId.trim() || value.label !== void 0 && typeof value.label !== "string" || value.provider !== void 0 && typeof value.provider !== "string" || value.enabled !== void 0 && typeof value.enabled !== "boolean" || !verifyStringArray(value.assetClasses) || !verifyStringArray(value.tickers) || !isRecord(value.strategies) || !Object.keys(value.strategies).length) {
|
|
638
|
+
throw new Error(`Invalid runtime deployment declaration: ${deploymentId}`);
|
|
610
639
|
}
|
|
611
|
-
const
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
640
|
+
for (const [strategyName, strategyValue] of Object.entries(
|
|
641
|
+
value.strategies
|
|
642
|
+
)) {
|
|
643
|
+
if (!strategyName.trim() || !isRecord(strategyValue) || Object.keys(strategyValue).some((key) => !STRATEGY_KEYS.has(key)) || !Number.isSafeInteger(strategyValue.version) || Number(strategyValue.version) <= 0 || typeof strategyValue.enabled !== "boolean" || !isRecord(strategyValue.config) || Object.keys(strategyValue.config).some(
|
|
644
|
+
(key) => FORBIDDEN_CONFIG_KEYS.has(key)
|
|
645
|
+
) || !INTERVALS.has(String(strategyValue.config.INTERVAL)) || !["crypto", "tradfi"].includes(String(strategyValue.config.UNIVERSE))) {
|
|
646
|
+
throw new Error(
|
|
647
|
+
`Invalid runtime strategy declaration: ${deploymentId}/${strategyName}`
|
|
648
|
+
);
|
|
649
|
+
}
|
|
620
650
|
}
|
|
651
|
+
return value;
|
|
652
|
+
};
|
|
653
|
+
var verifyRuntimeDeclaration = (value) => {
|
|
654
|
+
if (!isRecord(value) || Object.keys(value).some((key) => !RUNTIME_KEYS.has(key)) || !isRecord(value.deployments) || !Object.keys(value.deployments).length) {
|
|
655
|
+
throw new Error("Invalid runtime declaration");
|
|
656
|
+
}
|
|
657
|
+
for (const [deploymentId, deployment] of Object.entries(value.deployments)) {
|
|
658
|
+
verifyDeploymentDeclaration(deploymentId, deployment);
|
|
659
|
+
}
|
|
660
|
+
return value;
|
|
661
|
+
};
|
|
662
|
+
var toRuntimeDeployment = ({
|
|
663
|
+
id,
|
|
664
|
+
declaration,
|
|
665
|
+
controls
|
|
666
|
+
}) => {
|
|
667
|
+
const deploymentEnabled = declaration.enabled ?? true;
|
|
668
|
+
return {
|
|
669
|
+
id,
|
|
670
|
+
label: declaration.label?.trim() || id,
|
|
671
|
+
connectorName: declaration.connectorName.trim(),
|
|
672
|
+
provider: (declaration.provider || declaration.connectorName).trim().toLowerCase(),
|
|
673
|
+
accountId: declaration.accountId.trim(),
|
|
674
|
+
enabled: deploymentEnabled,
|
|
675
|
+
strategies: Object.entries(declaration.strategies).map(
|
|
676
|
+
([strategyName, strategy]) => ({
|
|
677
|
+
strategyName,
|
|
678
|
+
version: strategy.version,
|
|
679
|
+
enabled: strategy.enabled,
|
|
680
|
+
controlState: deploymentEnabled && strategy.enabled && !controls.deployments[id]?.[strategyName]?.entriesPaused ? "active" : "entries_paused"
|
|
681
|
+
})
|
|
682
|
+
),
|
|
683
|
+
...declaration.assetClasses ? { assetClasses: declaration.assetClasses } : {},
|
|
684
|
+
...declaration.tickers ? { tickers: declaration.tickers } : {}
|
|
685
|
+
};
|
|
686
|
+
};
|
|
687
|
+
var loadRuntimeDeclaration = async (projectRoot) => {
|
|
688
|
+
const projectConfig = await loadTradejsConfig(projectRoot);
|
|
689
|
+
if (!projectConfig.runtime) {
|
|
690
|
+
throw new Error("Runtime declaration is required in tradejs.config.ts");
|
|
691
|
+
}
|
|
692
|
+
return verifyRuntimeDeclaration(projectConfig.runtime);
|
|
693
|
+
};
|
|
694
|
+
var listRuntimeDeployments = async ({
|
|
695
|
+
userName,
|
|
696
|
+
projectRoot
|
|
697
|
+
}) => {
|
|
698
|
+
const [runtime, controls] = await Promise.all([
|
|
699
|
+
loadRuntimeDeclaration(projectRoot),
|
|
700
|
+
(0, import_runtimeControls.getRuntimeControls)(userName)
|
|
701
|
+
]);
|
|
702
|
+
return Object.entries(runtime.deployments).map(
|
|
703
|
+
([id, declaration]) => toRuntimeDeployment({ id, declaration, controls })
|
|
704
|
+
).sort((left, right) => left.label.localeCompare(right.label));
|
|
705
|
+
};
|
|
706
|
+
var getRuntimeDeployment = async ({
|
|
707
|
+
userName,
|
|
708
|
+
projectRoot,
|
|
709
|
+
deploymentId
|
|
710
|
+
}) => {
|
|
711
|
+
const deployments = await listRuntimeDeployments({ userName, projectRoot });
|
|
712
|
+
return deployments.find((deployment) => deployment.id === deploymentId) ?? null;
|
|
621
713
|
};
|
|
622
714
|
var resolveAccountId = async ({
|
|
623
715
|
userName,
|
|
@@ -635,89 +727,91 @@ var resolveAccountId = async ({
|
|
|
635
727
|
}
|
|
636
728
|
return account.id;
|
|
637
729
|
};
|
|
638
|
-
var loadVersionedRuntimeStrategies = async ({
|
|
639
|
-
userName,
|
|
640
|
-
projectRoot,
|
|
641
|
-
deployment
|
|
642
|
-
}) => {
|
|
643
|
-
const packageManifest = await readPackageManifest(projectRoot);
|
|
644
|
-
return Promise.all(
|
|
645
|
-
deployment.strategies.map(async (reference) => {
|
|
646
|
-
if (!Number.isSafeInteger(reference.releaseVersion) || !reference.releaseVersion) {
|
|
647
|
-
throw new Error(
|
|
648
|
-
`Deployment ${deployment.id} strategy ${reference.strategyName} has no releaseVersion`
|
|
649
|
-
);
|
|
650
|
-
}
|
|
651
|
-
if (Object.keys(reference).some(
|
|
652
|
-
(key) => !["strategyName", "releaseVersion", "controlState"].includes(key)
|
|
653
|
-
)) {
|
|
654
|
-
throw new Error(`Deployment ${deployment.id} has invalid fields`);
|
|
655
|
-
}
|
|
656
|
-
if (!reference.controlState) {
|
|
657
|
-
throw new Error(
|
|
658
|
-
`Deployment ${deployment.id} strategy ${reference.strategyName} has no controlState`
|
|
659
|
-
);
|
|
660
|
-
}
|
|
661
|
-
const release = await (0, import_runtimeStrategyReleases.getRuntimeStrategyRelease)(
|
|
662
|
-
userName,
|
|
663
|
-
reference.strategyName,
|
|
664
|
-
reference.releaseVersion
|
|
665
|
-
);
|
|
666
|
-
if (!release) {
|
|
667
|
-
throw new Error(
|
|
668
|
-
`Runtime release not found: ${reference.strategyName} v${reference.releaseVersion}`
|
|
669
|
-
);
|
|
670
|
-
}
|
|
671
|
-
await validateReleaseRuntimeCompatibility({
|
|
672
|
-
release,
|
|
673
|
-
projectRoot,
|
|
674
|
-
packageManifest
|
|
675
|
-
});
|
|
676
|
-
const strategyCreator = await getStrategyCreator(
|
|
677
|
-
reference.strategyName,
|
|
678
|
-
projectRoot
|
|
679
|
-
);
|
|
680
|
-
if (!strategyCreator) {
|
|
681
|
-
throw new Error(`Unknown strategy: ${reference.strategyName}`);
|
|
682
|
-
}
|
|
683
|
-
const interval = String(release.config.INTERVAL);
|
|
684
|
-
const universe = release.config.UNIVERSE;
|
|
685
|
-
const accountId = await resolveAccountId({
|
|
686
|
-
userName,
|
|
687
|
-
deployment,
|
|
688
|
-
universe
|
|
689
|
-
});
|
|
690
|
-
return {
|
|
691
|
-
strategyName: reference.strategyName,
|
|
692
|
-
releaseVersion: release.releaseVersion,
|
|
693
|
-
controlState: reference.controlState,
|
|
694
|
-
interval,
|
|
695
|
-
universe,
|
|
696
|
-
accountId,
|
|
697
|
-
strategyPackage: release.strategyPackage,
|
|
698
|
-
strategyPackageVersion: release.strategyPackageVersion,
|
|
699
|
-
runtimePackageVersion: release.runtimePackageVersion,
|
|
700
|
-
strategyCreator,
|
|
701
|
-
sourceStrategyConfig: release.config,
|
|
702
|
-
strategyConfig: release.config
|
|
703
|
-
};
|
|
704
|
-
})
|
|
705
|
-
);
|
|
706
|
-
};
|
|
707
730
|
var loadResolvedRuntimeStrategies = async ({
|
|
708
731
|
userName,
|
|
709
732
|
projectRoot,
|
|
710
|
-
|
|
733
|
+
deploymentId,
|
|
711
734
|
universe,
|
|
712
735
|
accountId,
|
|
713
736
|
interval
|
|
714
737
|
}) => {
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
userName,
|
|
718
|
-
projectRoot
|
|
719
|
-
|
|
738
|
+
const [runtime, controls, packageManifest] = await Promise.all([
|
|
739
|
+
loadRuntimeDeclaration(projectRoot),
|
|
740
|
+
(0, import_runtimeControls.getRuntimeControls)(userName),
|
|
741
|
+
readPackageManifest(projectRoot)
|
|
742
|
+
]);
|
|
743
|
+
const declaration = runtime.deployments[deploymentId];
|
|
744
|
+
if (!declaration) {
|
|
745
|
+
throw new Error(`Runtime deployment not found: ${deploymentId}`);
|
|
746
|
+
}
|
|
747
|
+
const deployment = toRuntimeDeployment({
|
|
748
|
+
id: deploymentId,
|
|
749
|
+
declaration,
|
|
750
|
+
controls
|
|
720
751
|
});
|
|
752
|
+
const strategies2 = await Promise.all(
|
|
753
|
+
Object.entries(declaration.strategies).map(
|
|
754
|
+
async ([strategyName, strategyDeclaration]) => {
|
|
755
|
+
const strategyCreator = await getStrategyCreator(
|
|
756
|
+
strategyName,
|
|
757
|
+
projectRoot
|
|
758
|
+
);
|
|
759
|
+
if (!strategyCreator) {
|
|
760
|
+
throw new Error(`Unknown strategy: ${strategyName}`);
|
|
761
|
+
}
|
|
762
|
+
const pluginSource = await getStrategyPluginSource(strategyName, projectRoot) ?? null;
|
|
763
|
+
const strategyPackage = await resolveStrategyPackageName({
|
|
764
|
+
pluginSource,
|
|
765
|
+
projectRoot
|
|
766
|
+
});
|
|
767
|
+
const [strategyPackageVersion, runtimePackageVersion] = await Promise.all([
|
|
768
|
+
resolveInstalledPackageVersion(
|
|
769
|
+
projectRoot,
|
|
770
|
+
strategyPackage,
|
|
771
|
+
packageManifest
|
|
772
|
+
),
|
|
773
|
+
resolveInstalledPackageVersion(
|
|
774
|
+
projectRoot,
|
|
775
|
+
"@tradejs/node",
|
|
776
|
+
packageManifest
|
|
777
|
+
)
|
|
778
|
+
]);
|
|
779
|
+
if (!strategyPackage || !strategyPackageVersion) {
|
|
780
|
+
throw new Error(
|
|
781
|
+
`Installed strategy package not found: ${strategyName}`
|
|
782
|
+
);
|
|
783
|
+
}
|
|
784
|
+
if (!runtimePackageVersion) {
|
|
785
|
+
throw new Error("Installed @tradejs/node package version not found");
|
|
786
|
+
}
|
|
787
|
+
const strategyView = deployment.strategies.find(
|
|
788
|
+
(candidate) => candidate.strategyName === strategyName
|
|
789
|
+
);
|
|
790
|
+
const strategyConfig = strategyDeclaration.config;
|
|
791
|
+
const strategyUniverse = strategyConfig.UNIVERSE;
|
|
792
|
+
const resolvedAccountId = await resolveAccountId({
|
|
793
|
+
userName,
|
|
794
|
+
deployment,
|
|
795
|
+
universe: strategyUniverse
|
|
796
|
+
});
|
|
797
|
+
return {
|
|
798
|
+
strategyName,
|
|
799
|
+
version: strategyDeclaration.version,
|
|
800
|
+
enabled: strategyDeclaration.enabled,
|
|
801
|
+
controlState: strategyView?.controlState ?? "entries_paused",
|
|
802
|
+
interval: String(strategyConfig.INTERVAL),
|
|
803
|
+
universe: strategyUniverse,
|
|
804
|
+
accountId: resolvedAccountId,
|
|
805
|
+
strategyPackage,
|
|
806
|
+
strategyPackageVersion,
|
|
807
|
+
runtimePackageVersion,
|
|
808
|
+
strategyCreator,
|
|
809
|
+
sourceStrategyConfig: strategyConfig,
|
|
810
|
+
strategyConfig
|
|
811
|
+
};
|
|
812
|
+
}
|
|
813
|
+
)
|
|
814
|
+
);
|
|
721
815
|
const filtered = strategies2.filter(
|
|
722
816
|
(candidate) => (!universe || candidate.universe === universe) && (!interval || String(candidate.interval) === String(interval)) && (!accountId || candidate.accountId === accountId)
|
|
723
817
|
);
|
|
@@ -748,11 +842,18 @@ var getRuntimeStrategyPackageMetadata = async ({
|
|
|
748
842
|
strategyPackage,
|
|
749
843
|
packageManifest
|
|
750
844
|
),
|
|
751
|
-
runtimePackageVersion:
|
|
845
|
+
runtimePackageVersion: await resolveInstalledPackageVersion(
|
|
846
|
+
projectRoot,
|
|
847
|
+
"@tradejs/node",
|
|
848
|
+
packageManifest
|
|
849
|
+
)
|
|
752
850
|
};
|
|
753
851
|
};
|
|
754
852
|
// Annotate the CommonJS export names for ESM import in node:
|
|
755
853
|
0 && (module.exports = {
|
|
854
|
+
getRuntimeDeployment,
|
|
756
855
|
getRuntimeStrategyPackageMetadata,
|
|
757
|
-
|
|
856
|
+
listRuntimeDeployments,
|
|
857
|
+
loadResolvedRuntimeStrategies,
|
|
858
|
+
verifyRuntimeDeclaration
|
|
758
859
|
});
|
|
@@ -1,224 +1,17 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
getRuntimeDeployment,
|
|
3
|
+
getRuntimeStrategyPackageMetadata,
|
|
4
|
+
listRuntimeDeployments,
|
|
5
|
+
loadResolvedRuntimeStrategies,
|
|
6
|
+
verifyRuntimeDeclaration
|
|
7
|
+
} from "./chunk-F7ODY5W4.mjs";
|
|
8
|
+
import "./chunk-MEZIXBZ3.mjs";
|
|
9
|
+
import "./chunk-LZDXRXIU.mjs";
|
|
6
10
|
import "./chunk-Y6FXYEAI.mjs";
|
|
7
|
-
|
|
8
|
-
// src/runtimeStrategies.ts
|
|
9
|
-
import { readFile } from "fs/promises";
|
|
10
|
-
import path from "path";
|
|
11
|
-
import { getRuntimeStrategyRelease } from "@tradejs/infra/runtimeStrategyReleases";
|
|
12
|
-
import { resolveTradingAccount } from "@tradejs/infra/tradingAccounts";
|
|
13
|
-
var readPackageManifest = async (projectRoot) => {
|
|
14
|
-
const candidates = [
|
|
15
|
-
process.env.TRADEJS_RUNTIME_PACKAGE_MANIFEST,
|
|
16
|
-
path.join(projectRoot, "runtime-package-manifest.json"),
|
|
17
|
-
"/app/runtime-package-manifest.json"
|
|
18
|
-
].filter((candidate) => Boolean(candidate));
|
|
19
|
-
for (const candidate of candidates) {
|
|
20
|
-
try {
|
|
21
|
-
return JSON.parse(
|
|
22
|
-
await readFile(candidate, "utf8")
|
|
23
|
-
);
|
|
24
|
-
} catch {
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
return { packages: {} };
|
|
28
|
-
};
|
|
29
|
-
var resolveInstalledPackageVersion = async (projectRoot, packageName, manifest) => {
|
|
30
|
-
if (!packageName || packageName === "runtime") return null;
|
|
31
|
-
const manifestVersion = manifest.packages?.[packageName];
|
|
32
|
-
if (manifestVersion) return manifestVersion;
|
|
33
|
-
try {
|
|
34
|
-
const packageJsonPath = path.join(
|
|
35
|
-
projectRoot,
|
|
36
|
-
"node_modules",
|
|
37
|
-
...packageName.split("/"),
|
|
38
|
-
"package.json"
|
|
39
|
-
);
|
|
40
|
-
const packageJson = JSON.parse(await readFile(packageJsonPath, "utf8"));
|
|
41
|
-
return packageJson.version ?? null;
|
|
42
|
-
} catch {
|
|
43
|
-
return null;
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
var resolveStrategyPackageName = async ({
|
|
47
|
-
pluginSource,
|
|
48
|
-
projectRoot
|
|
49
|
-
}) => {
|
|
50
|
-
if (!pluginSource) return null;
|
|
51
|
-
if (!pluginSource.startsWith(".") && !path.isAbsolute(pluginSource)) {
|
|
52
|
-
return pluginSource;
|
|
53
|
-
}
|
|
54
|
-
try {
|
|
55
|
-
const packageJson = JSON.parse(
|
|
56
|
-
await readFile(path.join(projectRoot, "package.json"), "utf8")
|
|
57
|
-
);
|
|
58
|
-
return typeof packageJson.name === "string" && packageJson.name.trim() ? packageJson.name : null;
|
|
59
|
-
} catch {
|
|
60
|
-
return null;
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
var validateReleaseRuntimeCompatibility = async ({
|
|
64
|
-
release,
|
|
65
|
-
projectRoot,
|
|
66
|
-
packageManifest
|
|
67
|
-
}) => {
|
|
68
|
-
const installedStrategyVersion = await resolveInstalledPackageVersion(
|
|
69
|
-
projectRoot,
|
|
70
|
-
release.strategyPackage,
|
|
71
|
-
packageManifest
|
|
72
|
-
);
|
|
73
|
-
if (release.strategyPackageVersion !== installedStrategyVersion) {
|
|
74
|
-
throw new Error(
|
|
75
|
-
`${release.strategyName} v${release.releaseVersion} requires ${release.strategyPackage}@${release.strategyPackageVersion}, image has ${installedStrategyVersion}`
|
|
76
|
-
);
|
|
77
|
-
}
|
|
78
|
-
const installedRuntimeVersion = await resolveInstalledPackageVersion(
|
|
79
|
-
projectRoot,
|
|
80
|
-
"@tradejs/node",
|
|
81
|
-
packageManifest
|
|
82
|
-
);
|
|
83
|
-
if (release.runtimePackageVersion !== installedRuntimeVersion) {
|
|
84
|
-
throw new Error(
|
|
85
|
-
`${release.strategyName} v${release.releaseVersion} requires @tradejs/node@${release.runtimePackageVersion}, image has ${installedRuntimeVersion}`
|
|
86
|
-
);
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
var resolveAccountId = async ({
|
|
90
|
-
userName,
|
|
91
|
-
deployment,
|
|
92
|
-
universe
|
|
93
|
-
}) => {
|
|
94
|
-
const account = await resolveTradingAccount({
|
|
95
|
-
userName,
|
|
96
|
-
accountId: deployment.accountId,
|
|
97
|
-
provider: deployment.provider,
|
|
98
|
-
universe
|
|
99
|
-
});
|
|
100
|
-
if (!account) {
|
|
101
|
-
throw new Error(`Trading account not found: ${deployment.accountId}`);
|
|
102
|
-
}
|
|
103
|
-
return account.id;
|
|
104
|
-
};
|
|
105
|
-
var loadVersionedRuntimeStrategies = async ({
|
|
106
|
-
userName,
|
|
107
|
-
projectRoot,
|
|
108
|
-
deployment
|
|
109
|
-
}) => {
|
|
110
|
-
const packageManifest = await readPackageManifest(projectRoot);
|
|
111
|
-
return Promise.all(
|
|
112
|
-
deployment.strategies.map(async (reference) => {
|
|
113
|
-
if (!Number.isSafeInteger(reference.releaseVersion) || !reference.releaseVersion) {
|
|
114
|
-
throw new Error(
|
|
115
|
-
`Deployment ${deployment.id} strategy ${reference.strategyName} has no releaseVersion`
|
|
116
|
-
);
|
|
117
|
-
}
|
|
118
|
-
if (Object.keys(reference).some(
|
|
119
|
-
(key) => !["strategyName", "releaseVersion", "controlState"].includes(key)
|
|
120
|
-
)) {
|
|
121
|
-
throw new Error(`Deployment ${deployment.id} has invalid fields`);
|
|
122
|
-
}
|
|
123
|
-
if (!reference.controlState) {
|
|
124
|
-
throw new Error(
|
|
125
|
-
`Deployment ${deployment.id} strategy ${reference.strategyName} has no controlState`
|
|
126
|
-
);
|
|
127
|
-
}
|
|
128
|
-
const release = await getRuntimeStrategyRelease(
|
|
129
|
-
userName,
|
|
130
|
-
reference.strategyName,
|
|
131
|
-
reference.releaseVersion
|
|
132
|
-
);
|
|
133
|
-
if (!release) {
|
|
134
|
-
throw new Error(
|
|
135
|
-
`Runtime release not found: ${reference.strategyName} v${reference.releaseVersion}`
|
|
136
|
-
);
|
|
137
|
-
}
|
|
138
|
-
await validateReleaseRuntimeCompatibility({
|
|
139
|
-
release,
|
|
140
|
-
projectRoot,
|
|
141
|
-
packageManifest
|
|
142
|
-
});
|
|
143
|
-
const strategyCreator = await getStrategyCreator(
|
|
144
|
-
reference.strategyName,
|
|
145
|
-
projectRoot
|
|
146
|
-
);
|
|
147
|
-
if (!strategyCreator) {
|
|
148
|
-
throw new Error(`Unknown strategy: ${reference.strategyName}`);
|
|
149
|
-
}
|
|
150
|
-
const interval = String(release.config.INTERVAL);
|
|
151
|
-
const universe = release.config.UNIVERSE;
|
|
152
|
-
const accountId = await resolveAccountId({
|
|
153
|
-
userName,
|
|
154
|
-
deployment,
|
|
155
|
-
universe
|
|
156
|
-
});
|
|
157
|
-
return {
|
|
158
|
-
strategyName: reference.strategyName,
|
|
159
|
-
releaseVersion: release.releaseVersion,
|
|
160
|
-
controlState: reference.controlState,
|
|
161
|
-
interval,
|
|
162
|
-
universe,
|
|
163
|
-
accountId,
|
|
164
|
-
strategyPackage: release.strategyPackage,
|
|
165
|
-
strategyPackageVersion: release.strategyPackageVersion,
|
|
166
|
-
runtimePackageVersion: release.runtimePackageVersion,
|
|
167
|
-
strategyCreator,
|
|
168
|
-
sourceStrategyConfig: release.config,
|
|
169
|
-
strategyConfig: release.config
|
|
170
|
-
};
|
|
171
|
-
})
|
|
172
|
-
);
|
|
173
|
-
};
|
|
174
|
-
var loadResolvedRuntimeStrategies = async ({
|
|
175
|
-
userName,
|
|
176
|
-
projectRoot,
|
|
177
|
-
deployment,
|
|
178
|
-
universe,
|
|
179
|
-
accountId,
|
|
180
|
-
interval
|
|
181
|
-
}) => {
|
|
182
|
-
if (!deployment) throw new Error("Runtime deployment is required");
|
|
183
|
-
const strategies = await loadVersionedRuntimeStrategies({
|
|
184
|
-
userName,
|
|
185
|
-
projectRoot,
|
|
186
|
-
deployment
|
|
187
|
-
});
|
|
188
|
-
const filtered = strategies.filter(
|
|
189
|
-
(candidate) => (!universe || candidate.universe === universe) && (!interval || String(candidate.interval) === String(interval)) && (!accountId || candidate.accountId === accountId)
|
|
190
|
-
);
|
|
191
|
-
const identities = /* @__PURE__ */ new Set();
|
|
192
|
-
for (const candidate of filtered) {
|
|
193
|
-
const identity = `${candidate.strategyName}:${candidate.accountId ?? "default"}`;
|
|
194
|
-
if (identities.has(identity)) {
|
|
195
|
-
throw new Error(`Runtime strategy conflict: ${identity}`);
|
|
196
|
-
}
|
|
197
|
-
identities.add(identity);
|
|
198
|
-
}
|
|
199
|
-
return filtered;
|
|
200
|
-
};
|
|
201
|
-
var getRuntimeStrategyPackageMetadata = async ({
|
|
202
|
-
strategyName,
|
|
203
|
-
projectRoot
|
|
204
|
-
}) => {
|
|
205
|
-
const packageManifest = await readPackageManifest(projectRoot);
|
|
206
|
-
const pluginSource = await getStrategyPluginSource(strategyName, projectRoot) ?? null;
|
|
207
|
-
const strategyPackage = await resolveStrategyPackageName({
|
|
208
|
-
pluginSource,
|
|
209
|
-
projectRoot
|
|
210
|
-
});
|
|
211
|
-
return {
|
|
212
|
-
strategyPackage,
|
|
213
|
-
strategyPackageVersion: await resolveInstalledPackageVersion(
|
|
214
|
-
projectRoot,
|
|
215
|
-
strategyPackage,
|
|
216
|
-
packageManifest
|
|
217
|
-
),
|
|
218
|
-
runtimePackageVersion: packageManifest.packages?.["@tradejs/node"] ?? null
|
|
219
|
-
};
|
|
220
|
-
};
|
|
221
11
|
export {
|
|
12
|
+
getRuntimeDeployment,
|
|
222
13
|
getRuntimeStrategyPackageMetadata,
|
|
223
|
-
|
|
14
|
+
listRuntimeDeployments,
|
|
15
|
+
loadResolvedRuntimeStrategies,
|
|
16
|
+
verifyRuntimeDeclaration
|
|
224
17
|
};
|
package/dist/strategies.js
CHANGED
|
@@ -712,11 +712,13 @@ var normalizeConfig = (rawConfig) => {
|
|
|
712
712
|
const hooks = (0, import_config.normalizeTradejsConfigHooks)(
|
|
713
713
|
config.hooks
|
|
714
714
|
);
|
|
715
|
+
const runtime = config.runtime && typeof config.runtime === "object" && !Array.isArray(config.runtime) ? config.runtime : void 0;
|
|
715
716
|
return {
|
|
716
717
|
strategies: strategies2,
|
|
717
718
|
indicators,
|
|
718
719
|
connectors,
|
|
719
|
-
...hooks ? { hooks } : {}
|
|
720
|
+
...hooks ? { hooks } : {},
|
|
721
|
+
...runtime ? { runtime } : {}
|
|
720
722
|
};
|
|
721
723
|
};
|
|
722
724
|
var getNodeCreateRequire = () => {
|
|
@@ -4546,7 +4548,7 @@ var executeEntryOrder = async ({
|
|
|
4546
4548
|
deploymentId: signal.deploymentId,
|
|
4547
4549
|
policyProfileId: signal.policyProfileId,
|
|
4548
4550
|
runtimeConfigId: signal.runtimeConfigId,
|
|
4549
|
-
|
|
4551
|
+
runtimeVersion: signal.runtimeVersion,
|
|
4550
4552
|
runtimeLineage: signal.runtimeLineage,
|
|
4551
4553
|
...signal.aiAnalysis ? { aiAnalysis: signal.aiAnalysis } : {}
|
|
4552
4554
|
});
|
|
@@ -5457,7 +5459,7 @@ var createStrategyRuntime = ({
|
|
|
5457
5459
|
deploymentId: requestedDeploymentId,
|
|
5458
5460
|
policyProfileId,
|
|
5459
5461
|
runtimeConfigId,
|
|
5460
|
-
|
|
5462
|
+
runtimeVersion,
|
|
5461
5463
|
entriesPaused = false,
|
|
5462
5464
|
runtimeLineage,
|
|
5463
5465
|
runtimeConfigSnapshot,
|
|
@@ -6129,8 +6131,8 @@ var createStrategyRuntime = ({
|
|
|
6129
6131
|
signal.signalId = `${signal.signalId}:${runtimeConfigId}`;
|
|
6130
6132
|
}
|
|
6131
6133
|
}
|
|
6132
|
-
if (
|
|
6133
|
-
signal.
|
|
6134
|
+
if (runtimeVersion) {
|
|
6135
|
+
signal.runtimeVersion = runtimeVersion;
|
|
6134
6136
|
}
|
|
6135
6137
|
if (decisionHookCtx.policyProfileId) {
|
|
6136
6138
|
signal.policyProfileId = decisionHookCtx.policyProfileId;
|
|
@@ -6243,7 +6245,7 @@ var createStrategyRuntime = ({
|
|
|
6243
6245
|
if (signal) {
|
|
6244
6246
|
signal.orderStatus = "skipped";
|
|
6245
6247
|
signal.orderSkipReason = skipReason;
|
|
6246
|
-
signal.
|
|
6248
|
+
signal.runtimeVersion = runtimeVersion;
|
|
6247
6249
|
}
|
|
6248
6250
|
return signal ?? skipReason;
|
|
6249
6251
|
}
|
package/dist/strategies.mjs
CHANGED
|
@@ -22,7 +22,7 @@ import {
|
|
|
22
22
|
resolveHyperliquidPerpFromSignalSymbol,
|
|
23
23
|
resolveStrategyConfig,
|
|
24
24
|
validateEntryProtectionAtArrival
|
|
25
|
-
} from "./chunk-
|
|
25
|
+
} from "./chunk-SVAUSZUE.mjs";
|
|
26
26
|
import {
|
|
27
27
|
DEFAULT_AI_MODEL,
|
|
28
28
|
MAX_AI_SERIES_POINTS,
|
|
@@ -39,7 +39,7 @@ import {
|
|
|
39
39
|
runAiPrompt,
|
|
40
40
|
runAiPromptLocal,
|
|
41
41
|
trimSeriesDeep
|
|
42
|
-
} from "./chunk-
|
|
42
|
+
} from "./chunk-733VVTWU.mjs";
|
|
43
43
|
import {
|
|
44
44
|
ensureIndicatorPluginsLoaded,
|
|
45
45
|
ensureStrategyPluginsLoaded,
|
|
@@ -54,8 +54,8 @@ import {
|
|
|
54
54
|
registerStrategyEntries,
|
|
55
55
|
resetStrategyRegistryCache,
|
|
56
56
|
strategies
|
|
57
|
-
} from "./chunk-
|
|
58
|
-
import "./chunk-
|
|
57
|
+
} from "./chunk-MEZIXBZ3.mjs";
|
|
58
|
+
import "./chunk-LZDXRXIU.mjs";
|
|
59
59
|
import "./chunk-Y6FXYEAI.mjs";
|
|
60
60
|
|
|
61
61
|
// src/strategies.ts
|