@tradejs/node 3.1.2 → 3.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/backtest.js +6 -20
- package/dist/backtest.mjs +5 -5
- package/dist/{chunk-W26Y6IRP.mjs → chunk-MCDICN3I.mjs} +6 -23
- package/dist/registry.js +6 -20
- package/dist/registry.mjs +1 -1
- package/dist/runtimeDashboard.js +255 -6794
- package/dist/runtimeDashboard.mjs +34 -158
- package/dist/runtimeStrategies.d.mts +6 -10
- package/dist/runtimeStrategies.d.ts +6 -10
- package/dist/runtimeStrategies.js +24 -88
- package/dist/runtimeStrategies.mjs +24 -88
- package/dist/strategies.d.mts +1 -1
- package/dist/strategies.d.ts +1 -1
- package/dist/strategies.js +6 -20
- package/dist/strategies.mjs +371 -8
- package/package.json +4 -4
- package/dist/chunk-LAJ7NA3Q.mjs +0 -377
|
@@ -2,28 +2,20 @@ import {
|
|
|
2
2
|
buildExchangeFallbackRuntimeTrades,
|
|
3
3
|
takeClosedPnlMatch
|
|
4
4
|
} from "./chunk-FB5NUEOQ.mjs";
|
|
5
|
-
import "./chunk-LAJ7NA3Q.mjs";
|
|
6
5
|
import {
|
|
7
6
|
getConnectorCreatorByProvider
|
|
8
7
|
} from "./chunk-3TWULKHV.mjs";
|
|
9
|
-
import "./chunk-W26Y6IRP.mjs";
|
|
10
|
-
import "./chunk-SEQJ6V6B.mjs";
|
|
11
|
-
import {
|
|
12
|
-
getAvailableStrategyNames
|
|
13
|
-
} from "./chunk-XN7BC7XK.mjs";
|
|
14
8
|
import "./chunk-WS5DYEVZ.mjs";
|
|
15
9
|
import "./chunk-Y6FXYEAI.mjs";
|
|
16
10
|
|
|
17
11
|
// src/runtimeDashboard.ts
|
|
18
12
|
import { getRuntimeStorageDayKeys } from "@tradejs/core/time";
|
|
19
13
|
import { logger } from "@tradejs/infra/logger";
|
|
20
|
-
import { strategyLogicConfigFingerprint } from "@tradejs/infra/strategyReleaseEvidence";
|
|
21
14
|
import {
|
|
22
15
|
listTradingAccounts,
|
|
23
16
|
resolveTradingAccount
|
|
24
17
|
} from "@tradejs/infra/tradingAccounts";
|
|
25
18
|
import { listRuntimeDeployments } from "@tradejs/infra/runtimeDeployments";
|
|
26
|
-
import { loadRuntimeStrategyConfigs as loadStoredRuntimeStrategyConfigs } from "@tradejs/infra/runtimeStrategyConfigs";
|
|
27
19
|
import { getRuntimeStrategyRelease } from "@tradejs/infra/runtimeStrategyReleases";
|
|
28
20
|
import {
|
|
29
21
|
getData as getData2,
|
|
@@ -36,7 +28,6 @@ import {
|
|
|
36
28
|
isRuntimeTradeRecord,
|
|
37
29
|
selectTradesForWindow,
|
|
38
30
|
toRuntimeTradeView,
|
|
39
|
-
assignLegacyRuntimeTradeAccountScopes,
|
|
40
31
|
buildRuntimeStrategyIdentityKey
|
|
41
32
|
} from "@tradejs/core/runtimeTrades";
|
|
42
33
|
|
|
@@ -469,31 +460,6 @@ var coerceHours = (value) => {
|
|
|
469
460
|
}
|
|
470
461
|
return Math.min(MAX_HOURS, Math.max(MIN_HOURS, Math.trunc(parsed)));
|
|
471
462
|
};
|
|
472
|
-
var isRuntimeStrategyConfigEnabled = (config) => {
|
|
473
|
-
if (!config || typeof config !== "object" || Array.isArray(config)) {
|
|
474
|
-
return false;
|
|
475
|
-
}
|
|
476
|
-
return config.ENABLE !== false;
|
|
477
|
-
};
|
|
478
|
-
var loadRuntimeStrategyConfigs = async (userName) => {
|
|
479
|
-
return (await loadStoredRuntimeStrategyConfigs(userName)).map(
|
|
480
|
-
({ strategyConfig, ...record }) => ({
|
|
481
|
-
...record,
|
|
482
|
-
config: strategyConfig
|
|
483
|
-
})
|
|
484
|
-
);
|
|
485
|
-
};
|
|
486
|
-
var loadConfiguredStrategyNames = async (projectRoot) => {
|
|
487
|
-
try {
|
|
488
|
-
return await getAvailableStrategyNames(projectRoot);
|
|
489
|
-
} catch (error) {
|
|
490
|
-
logger.warn(
|
|
491
|
-
"strategies runtime: failed to load configured strategies: %s",
|
|
492
|
-
error?.message || String(error)
|
|
493
|
-
);
|
|
494
|
-
return [];
|
|
495
|
-
}
|
|
496
|
-
};
|
|
497
463
|
var resolveConnectorCreatorByProvider = async (provider, projectRoot) => await getConnectorCreatorByProvider(provider, projectRoot) ?? await getConnectorCreatorByProvider(DEFAULT_PROVIDER, projectRoot) ?? null;
|
|
498
464
|
var resolveConnectorAccountId = async ({
|
|
499
465
|
userName,
|
|
@@ -687,8 +653,6 @@ var loadRuntimeDashboard = async ({
|
|
|
687
653
|
universe: "crypto"
|
|
688
654
|
});
|
|
689
655
|
const [
|
|
690
|
-
runtimeStrategyConfigs,
|
|
691
|
-
configuredStrategyNames,
|
|
692
656
|
runtimeTrades,
|
|
693
657
|
activeOrderIds,
|
|
694
658
|
closedPnlRows,
|
|
@@ -697,8 +661,6 @@ var loadRuntimeDashboard = async ({
|
|
|
697
661
|
runtimeDeployments,
|
|
698
662
|
tradingAccounts
|
|
699
663
|
] = await Promise.all([
|
|
700
|
-
loadRuntimeStrategyConfigs(userName),
|
|
701
|
-
loadConfiguredStrategyNames(projectRoot),
|
|
702
664
|
loadRuntimeTrades(userName, { startTime, endTime }),
|
|
703
665
|
loadActiveRuntimeOrderIds(userName),
|
|
704
666
|
loadClosedPnlRows({
|
|
@@ -739,10 +701,11 @@ var loadRuntimeDashboard = async ({
|
|
|
739
701
|
});
|
|
740
702
|
const syncedTrades = [...unsyncedTrades, ...syncedConnectorTrades];
|
|
741
703
|
const fallbackStrategyNames = [
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
704
|
+
...new Set(
|
|
705
|
+
runtimeDeployments.flatMap(
|
|
706
|
+
(deployment) => deployment.strategies.map(({ strategyName }) => strategyName)
|
|
707
|
+
)
|
|
708
|
+
)
|
|
746
709
|
];
|
|
747
710
|
const fallbackTrades = buildExchangeFallbackRuntimeTrades({
|
|
748
711
|
entryRows,
|
|
@@ -755,146 +718,71 @@ var loadRuntimeDashboard = async ({
|
|
|
755
718
|
const allTrades = [...syncedTrades, ...fallbackTrades].filter(
|
|
756
719
|
isRuntimeTradeRecord
|
|
757
720
|
);
|
|
758
|
-
const connectedSet = new Set(
|
|
759
|
-
runtimeStrategyConfigs.map(
|
|
760
|
-
({ strategyName, configId }) => `${strategyName}:${configId}`
|
|
761
|
-
)
|
|
762
|
-
);
|
|
763
721
|
const accountsById = new Map(
|
|
764
722
|
tradingAccounts.map((account) => [account.id, account])
|
|
765
723
|
);
|
|
766
724
|
const runtimeIdentityKey = (trade) => buildRuntimeStrategyIdentityKey({
|
|
767
725
|
strategyName: trade.strategy,
|
|
768
|
-
configId: trade.runtimeReleaseVersion ? `v${trade.runtimeReleaseVersion}` :
|
|
726
|
+
configId: trade.runtimeReleaseVersion ? `v${trade.runtimeReleaseVersion}` : void 0,
|
|
769
727
|
universe: trade.universe,
|
|
770
728
|
accountId: trade.accountId,
|
|
771
729
|
deploymentId: trade.deploymentId,
|
|
772
730
|
policyProfileId: trade.policyProfileId
|
|
773
731
|
});
|
|
774
732
|
const identityByKey = /* @__PURE__ */ new Map();
|
|
775
|
-
const runtimeConfigAccountScopes = new Array();
|
|
776
|
-
const versionedBindings = /* @__PURE__ */ new Set();
|
|
777
733
|
for (const deployment of runtimeDeployments) {
|
|
778
734
|
for (const deploymentStrategy of deployment.strategies) {
|
|
779
|
-
const release =
|
|
735
|
+
const release = await getRuntimeStrategyRelease(
|
|
780
736
|
userName,
|
|
781
737
|
deploymentStrategy.strategyName,
|
|
782
738
|
deploymentStrategy.releaseVersion
|
|
783
|
-
).catch((error) => {
|
|
784
|
-
logger.warn(
|
|
785
|
-
"strategies runtime: failed to load %s v%s: %s",
|
|
786
|
-
deploymentStrategy.strategyName,
|
|
787
|
-
deploymentStrategy.releaseVersion,
|
|
788
|
-
String(error)
|
|
789
|
-
);
|
|
790
|
-
return null;
|
|
791
|
-
}) : null;
|
|
792
|
-
const deploymentConfig = release?.config ?? (deploymentStrategy.config && typeof deploymentStrategy.config === "object" && !Array.isArray(deploymentStrategy.config) ? deploymentStrategy.config : void 0);
|
|
793
|
-
const releaseUniverse = release?.config.UNIVERSE === "tradfi" ? "tradfi" : "crypto";
|
|
794
|
-
const releaseInterval = String(
|
|
795
|
-
release?.config.INTERVAL ?? deployment.interval
|
|
796
739
|
);
|
|
797
|
-
|
|
798
|
-
|
|
740
|
+
if (!release) {
|
|
741
|
+
throw new Error(
|
|
742
|
+
`Runtime release not found: ${deploymentStrategy.strategyName} v${deploymentStrategy.releaseVersion}`
|
|
743
|
+
);
|
|
744
|
+
}
|
|
745
|
+
const releaseUniverse = release.config.UNIVERSE === "tradfi" ? "tradfi" : "crypto";
|
|
746
|
+
const releaseInterval = String(release.config.INTERVAL);
|
|
747
|
+
const releaseConfigId = `v${deploymentStrategy.releaseVersion}`;
|
|
748
|
+
const releasePolicyProfileId = typeof release.config.POLICY_PROFILE_ID === "string" ? release.config.POLICY_PROFILE_ID : void 0;
|
|
799
749
|
const runtimeKey = buildRuntimeStrategyIdentityKey({
|
|
800
750
|
strategyName: deploymentStrategy.strategyName,
|
|
801
751
|
configId: releaseConfigId,
|
|
802
|
-
universe:
|
|
752
|
+
universe: releaseUniverse,
|
|
803
753
|
accountId: deployment.accountId,
|
|
804
754
|
deploymentId: deployment.id,
|
|
805
755
|
policyProfileId: releasePolicyProfileId
|
|
806
756
|
});
|
|
807
|
-
if (deploymentStrategy.releaseVersion) {
|
|
808
|
-
versionedBindings.add(
|
|
809
|
-
`${deploymentStrategy.strategyName}:${deployment.accountId}`
|
|
810
|
-
);
|
|
811
|
-
}
|
|
812
757
|
identityByKey.set(runtimeKey, {
|
|
813
758
|
strategyName: deploymentStrategy.strategyName,
|
|
814
759
|
configId: releaseConfigId,
|
|
815
760
|
releaseVersion: deploymentStrategy.releaseVersion,
|
|
816
|
-
controlState: deploymentStrategy.controlState
|
|
761
|
+
controlState: deploymentStrategy.controlState,
|
|
817
762
|
interval: releaseInterval,
|
|
818
|
-
universe:
|
|
763
|
+
universe: releaseUniverse,
|
|
819
764
|
accountId: deployment.accountId,
|
|
820
765
|
accountLabel: accountsById.get(deployment.accountId)?.label,
|
|
821
766
|
deploymentId: deployment.id,
|
|
822
767
|
policyProfileId: releasePolicyProfileId,
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
connected: Boolean(release && deployment.enabled),
|
|
827
|
-
configFingerprint: deploymentConfig ? strategyLogicConfigFingerprint(deploymentConfig) : void 0
|
|
768
|
+
enabled: deployment.enabled && deploymentStrategy.controlState !== "entries_paused",
|
|
769
|
+
config: release.config,
|
|
770
|
+
connected: deployment.enabled
|
|
828
771
|
});
|
|
829
772
|
}
|
|
830
773
|
}
|
|
831
|
-
|
|
832
|
-
const universe = runtimeConfig.config.UNIVERSE === "tradfi" ? "tradfi" : "crypto";
|
|
833
|
-
const configuredAccountId = typeof runtimeConfig.config.ACCOUNT_ID === "string" && runtimeConfig.config.ACCOUNT_ID.trim() ? runtimeConfig.config.ACCOUNT_ID.trim() : void 0;
|
|
834
|
-
const resolvedAccount = await resolveTradingAccount({
|
|
835
|
-
userName,
|
|
836
|
-
accountId: configuredAccountId,
|
|
837
|
-
provider,
|
|
838
|
-
universe
|
|
839
|
-
}).catch(() => null);
|
|
840
|
-
const accountId = resolvedAccount?.id ?? configuredAccountId;
|
|
841
|
-
if (versionedBindings.has(
|
|
842
|
-
`${runtimeConfig.strategyName}:${accountId ?? "default"}`
|
|
843
|
-
)) {
|
|
844
|
-
continue;
|
|
845
|
-
}
|
|
846
|
-
runtimeConfigAccountScopes.push({
|
|
847
|
-
strategyName: runtimeConfig.strategyName,
|
|
848
|
-
configId: runtimeConfig.configId,
|
|
849
|
-
universe,
|
|
850
|
-
accountId
|
|
851
|
-
});
|
|
852
|
-
const runtimeKey = buildRuntimeStrategyIdentityKey({
|
|
853
|
-
strategyName: runtimeConfig.strategyName,
|
|
854
|
-
configId: runtimeConfig.configId,
|
|
855
|
-
universe,
|
|
856
|
-
accountId
|
|
857
|
-
});
|
|
858
|
-
identityByKey.set(runtimeKey, {
|
|
859
|
-
strategyName: runtimeConfig.strategyName,
|
|
860
|
-
configId: runtimeConfig.configId,
|
|
861
|
-
interval: String(runtimeConfig.config.INTERVAL ?? "15"),
|
|
862
|
-
universe,
|
|
863
|
-
accountId,
|
|
864
|
-
accountLabel: accountId ? accountsById.get(accountId)?.label : void 0,
|
|
865
|
-
enabled: isRuntimeStrategyConfigEnabled(runtimeConfig.config),
|
|
866
|
-
config: runtimeConfig.config,
|
|
867
|
-
connected: true,
|
|
868
|
-
configFingerprint: strategyLogicConfigFingerprint(runtimeConfig.config)
|
|
869
|
-
});
|
|
870
|
-
}
|
|
871
|
-
const accountScopedTrades = assignLegacyRuntimeTradeAccountScopes(
|
|
872
|
-
allTrades,
|
|
873
|
-
runtimeConfigAccountScopes
|
|
874
|
-
);
|
|
774
|
+
const accountScopedTrades = allTrades;
|
|
875
775
|
for (const trade of accountScopedTrades) {
|
|
876
776
|
const key = runtimeIdentityKey(trade);
|
|
877
|
-
const
|
|
878
|
-
|
|
879
|
-
const releaseCompositionId = configuredCompositionId && observedCompositionId && configuredCompositionId !== observedCompositionId ? void 0 : observedCompositionId ?? configuredCompositionId;
|
|
777
|
+
const configuredIdentity = identityByKey.get(key);
|
|
778
|
+
if (!configuredIdentity) continue;
|
|
880
779
|
const releaseVersion = trade.runtimeReleaseVersion ?? (trade.runtimeLineage?.schemaVersion === 2 ? trade.runtimeLineage.releaseVersion : void 0);
|
|
780
|
+
if (releaseVersion !== configuredIdentity.releaseVersion) continue;
|
|
881
781
|
identityByKey.set(key, {
|
|
882
|
-
...
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
interval: String(trade.interval ?? "15"),
|
|
887
|
-
universe: trade.universe ?? "crypto",
|
|
888
|
-
accountId: trade.accountId,
|
|
889
|
-
accountLabel: trade.accountId ? accountsById.get(trade.accountId)?.label : void 0,
|
|
890
|
-
deploymentId: trade.deploymentId,
|
|
891
|
-
policyProfileId: trade.policyProfileId,
|
|
892
|
-
releaseCompositionId,
|
|
893
|
-
configFingerprint: trade.runtimeLineage?.schemaVersion === 1 ? trade.runtimeLineage.configFingerprint : void 0,
|
|
894
|
-
gateFingerprint: trade.runtimeLineage?.schemaVersion === 1 ? trade.runtimeLineage.gateFingerprint : void 0,
|
|
895
|
-
contextFingerprint: trade.runtimeLineage?.schemaVersion === 1 ? trade.runtimeLineage.contextFingerprint : void 0,
|
|
896
|
-
gitSha: trade.runtimeLineage?.schemaVersion === 1 ? trade.runtimeLineage.gitSha ?? void 0 : void 0,
|
|
897
|
-
maxLossValue: trade.runtimeLineage?.maxLossValue ?? void 0
|
|
782
|
+
...configuredIdentity,
|
|
783
|
+
interval: String(
|
|
784
|
+
trade.interval ?? configuredIdentity.interval
|
|
785
|
+
)
|
|
898
786
|
});
|
|
899
787
|
}
|
|
900
788
|
const evidenceTimelines = await loadStrategyEvidenceTimelines({
|
|
@@ -903,12 +791,6 @@ var loadRuntimeDashboard = async ({
|
|
|
903
791
|
selectors: [...identityByKey.values()].map((identity) => ({
|
|
904
792
|
strategy: identity.strategyName,
|
|
905
793
|
releaseVersion: identity.releaseVersion,
|
|
906
|
-
compositionId: identity.releaseCompositionId,
|
|
907
|
-
configFingerprint: identity.configFingerprint,
|
|
908
|
-
gateFingerprint: identity.gateFingerprint,
|
|
909
|
-
contextFingerprint: identity.contextFingerprint,
|
|
910
|
-
gitSha: identity.gitSha,
|
|
911
|
-
maxLossValue: identity.maxLossValue,
|
|
912
794
|
requireCompleteLineage: true
|
|
913
795
|
})),
|
|
914
796
|
startTime,
|
|
@@ -928,7 +810,7 @@ var loadRuntimeDashboard = async ({
|
|
|
928
810
|
startTime,
|
|
929
811
|
endTime
|
|
930
812
|
});
|
|
931
|
-
const effectiveStrategyConfig = identity.config
|
|
813
|
+
const effectiveStrategyConfig = identity.config;
|
|
932
814
|
return {
|
|
933
815
|
runtimeKey,
|
|
934
816
|
strategyName,
|
|
@@ -941,8 +823,8 @@ var loadRuntimeDashboard = async ({
|
|
|
941
823
|
accountLabel: identity.accountLabel,
|
|
942
824
|
deploymentId: identity.deploymentId,
|
|
943
825
|
policyProfileId: identity.policyProfileId,
|
|
944
|
-
connected: identity.connected
|
|
945
|
-
enabled: identity.enabled
|
|
826
|
+
connected: identity.connected,
|
|
827
|
+
enabled: identity.enabled,
|
|
946
828
|
config: effectiveStrategyConfig,
|
|
947
829
|
symbols: [...new Set(strategyTrades.map((trade) => trade.symbol))],
|
|
948
830
|
stat: analytics.stat,
|
|
@@ -952,16 +834,10 @@ var loadRuntimeDashboard = async ({
|
|
|
952
834
|
strategyEvidenceTimelineSelectorKey({
|
|
953
835
|
strategy: strategyName,
|
|
954
836
|
releaseVersion: identity.releaseVersion,
|
|
955
|
-
compositionId: identity.releaseCompositionId,
|
|
956
|
-
configFingerprint: identity.configFingerprint,
|
|
957
|
-
gateFingerprint: identity.gateFingerprint,
|
|
958
|
-
contextFingerprint: identity.contextFingerprint,
|
|
959
|
-
gitSha: identity.gitSha,
|
|
960
|
-
maxLossValue: identity.maxLossValue,
|
|
961
837
|
requireCompleteLineage: true
|
|
962
838
|
})
|
|
963
839
|
) ?? {
|
|
964
|
-
status: "
|
|
840
|
+
status: "not_attached",
|
|
965
841
|
observedFrom: null,
|
|
966
842
|
markers: []
|
|
967
843
|
},
|
|
@@ -1,27 +1,23 @@
|
|
|
1
|
-
import { RuntimeStrategyControlState, Interval, MarketUniverse, StrategyCreator, StrategyConfig,
|
|
1
|
+
import { RuntimeStrategyControlState, Interval, MarketUniverse, StrategyCreator, StrategyConfig, RuntimeDeployment } from '@tradejs/types';
|
|
2
2
|
|
|
3
3
|
interface ResolvedRuntimeStrategy {
|
|
4
4
|
strategyName: string;
|
|
5
|
-
|
|
6
|
-
configId?: string;
|
|
7
|
-
releaseVersion?: number;
|
|
5
|
+
releaseVersion: number;
|
|
8
6
|
controlState: RuntimeStrategyControlState;
|
|
9
7
|
interval: Interval;
|
|
10
8
|
universe: MarketUniverse;
|
|
11
9
|
accountId?: string;
|
|
12
|
-
strategyPackage
|
|
13
|
-
strategyPackageVersion
|
|
14
|
-
runtimePackageVersion
|
|
10
|
+
strategyPackage: string;
|
|
11
|
+
strategyPackageVersion: string;
|
|
12
|
+
runtimePackageVersion: string;
|
|
15
13
|
strategyCreator: StrategyCreator;
|
|
16
14
|
sourceStrategyConfig: StrategyConfig;
|
|
17
15
|
strategyConfig: StrategyConfig;
|
|
18
|
-
strategyResults: StrategyResults;
|
|
19
16
|
}
|
|
20
|
-
declare const loadResolvedRuntimeStrategies: ({ userName, projectRoot, deployment,
|
|
17
|
+
declare const loadResolvedRuntimeStrategies: ({ userName, projectRoot, deployment, universe, accountId, interval, }: {
|
|
21
18
|
userName: string;
|
|
22
19
|
projectRoot: string;
|
|
23
20
|
deployment?: RuntimeDeployment | null;
|
|
24
|
-
connectorName?: string;
|
|
25
21
|
universe?: MarketUniverse;
|
|
26
22
|
accountId?: string;
|
|
27
23
|
interval?: Interval;
|
|
@@ -1,27 +1,23 @@
|
|
|
1
|
-
import { RuntimeStrategyControlState, Interval, MarketUniverse, StrategyCreator, StrategyConfig,
|
|
1
|
+
import { RuntimeStrategyControlState, Interval, MarketUniverse, StrategyCreator, StrategyConfig, RuntimeDeployment } from '@tradejs/types';
|
|
2
2
|
|
|
3
3
|
interface ResolvedRuntimeStrategy {
|
|
4
4
|
strategyName: string;
|
|
5
|
-
|
|
6
|
-
configId?: string;
|
|
7
|
-
releaseVersion?: number;
|
|
5
|
+
releaseVersion: number;
|
|
8
6
|
controlState: RuntimeStrategyControlState;
|
|
9
7
|
interval: Interval;
|
|
10
8
|
universe: MarketUniverse;
|
|
11
9
|
accountId?: string;
|
|
12
|
-
strategyPackage
|
|
13
|
-
strategyPackageVersion
|
|
14
|
-
runtimePackageVersion
|
|
10
|
+
strategyPackage: string;
|
|
11
|
+
strategyPackageVersion: string;
|
|
12
|
+
runtimePackageVersion: string;
|
|
15
13
|
strategyCreator: StrategyCreator;
|
|
16
14
|
sourceStrategyConfig: StrategyConfig;
|
|
17
15
|
strategyConfig: StrategyConfig;
|
|
18
|
-
strategyResults: StrategyResults;
|
|
19
16
|
}
|
|
20
|
-
declare const loadResolvedRuntimeStrategies: ({ userName, projectRoot, deployment,
|
|
17
|
+
declare const loadResolvedRuntimeStrategies: ({ userName, projectRoot, deployment, universe, accountId, interval, }: {
|
|
21
18
|
userName: string;
|
|
22
19
|
projectRoot: string;
|
|
23
20
|
deployment?: RuntimeDeployment | null;
|
|
24
|
-
connectorName?: string;
|
|
25
21
|
universe?: MarketUniverse;
|
|
26
22
|
accountId?: string;
|
|
27
23
|
interval?: Interval;
|
|
@@ -36,9 +36,7 @@ __export(runtimeStrategies_exports, {
|
|
|
36
36
|
module.exports = __toCommonJS(runtimeStrategies_exports);
|
|
37
37
|
var import_promises = require("fs/promises");
|
|
38
38
|
var import_node_path = __toESM(require("path"));
|
|
39
|
-
var import_redis = require("@tradejs/infra/redis");
|
|
40
39
|
var import_runtimeStrategyReleases = require("@tradejs/infra/runtimeStrategyReleases");
|
|
41
|
-
var import_runtimeStrategyConfigs = require("@tradejs/infra/runtimeStrategyConfigs");
|
|
42
40
|
var import_tradingAccounts = require("@tradejs/infra/tradingAccounts");
|
|
43
41
|
|
|
44
42
|
// src/strategy/manifests.ts
|
|
@@ -588,13 +586,17 @@ var validateReleaseRuntimeCompatibility = async ({
|
|
|
588
586
|
release.strategyPackage,
|
|
589
587
|
packageManifest
|
|
590
588
|
);
|
|
591
|
-
if (release.strategyPackageVersion
|
|
589
|
+
if (release.strategyPackageVersion !== installedStrategyVersion) {
|
|
592
590
|
throw new Error(
|
|
593
591
|
`${release.strategyName} v${release.releaseVersion} requires ${release.strategyPackage}@${release.strategyPackageVersion}, image has ${installedStrategyVersion}`
|
|
594
592
|
);
|
|
595
593
|
}
|
|
596
|
-
const installedRuntimeVersion =
|
|
597
|
-
|
|
594
|
+
const installedRuntimeVersion = await resolveInstalledPackageVersion(
|
|
595
|
+
projectRoot,
|
|
596
|
+
"@tradejs/node",
|
|
597
|
+
packageManifest
|
|
598
|
+
);
|
|
599
|
+
if (release.runtimePackageVersion !== installedRuntimeVersion) {
|
|
598
600
|
throw new Error(
|
|
599
601
|
`${release.strategyName} v${release.releaseVersion} requires @tradejs/node@${release.runtimePackageVersion}, image has ${installedRuntimeVersion}`
|
|
600
602
|
);
|
|
@@ -603,24 +605,20 @@ var validateReleaseRuntimeCompatibility = async ({
|
|
|
603
605
|
var resolveAccountId = async ({
|
|
604
606
|
userName,
|
|
605
607
|
deployment,
|
|
606
|
-
|
|
607
|
-
universe,
|
|
608
|
-
legacyAccountId
|
|
608
|
+
universe
|
|
609
609
|
}) => {
|
|
610
|
-
const requestedAccountId = deployment?.accountId ?? legacyAccountId;
|
|
611
610
|
const account = await (0, import_tradingAccounts.resolveTradingAccount)({
|
|
612
611
|
userName,
|
|
613
|
-
accountId:
|
|
614
|
-
provider: deployment
|
|
612
|
+
accountId: deployment.accountId,
|
|
613
|
+
provider: deployment.provider,
|
|
615
614
|
universe
|
|
616
615
|
});
|
|
617
|
-
return account?.id ??
|
|
616
|
+
return account?.id ?? deployment.accountId;
|
|
618
617
|
};
|
|
619
618
|
var loadVersionedRuntimeStrategies = async ({
|
|
620
619
|
userName,
|
|
621
620
|
projectRoot,
|
|
622
|
-
deployment
|
|
623
|
-
connectorName
|
|
621
|
+
deployment
|
|
624
622
|
}) => {
|
|
625
623
|
const packageManifest = await readPackageManifest(projectRoot);
|
|
626
624
|
return Promise.all(
|
|
@@ -630,9 +628,14 @@ var loadVersionedRuntimeStrategies = async ({
|
|
|
630
628
|
`Deployment ${deployment.id} strategy ${reference.strategyName} has no releaseVersion`
|
|
631
629
|
);
|
|
632
630
|
}
|
|
633
|
-
if (
|
|
631
|
+
if (Object.keys(reference).some(
|
|
632
|
+
(key) => !["strategyName", "releaseVersion", "controlState"].includes(key)
|
|
633
|
+
)) {
|
|
634
|
+
throw new Error(`Deployment ${deployment.id} has invalid fields`);
|
|
635
|
+
}
|
|
636
|
+
if (!reference.controlState) {
|
|
634
637
|
throw new Error(
|
|
635
|
-
`Deployment ${deployment.id}
|
|
638
|
+
`Deployment ${deployment.id} strategy ${reference.strategyName} has no controlState`
|
|
636
639
|
);
|
|
637
640
|
}
|
|
638
641
|
const release = await (0, import_runtimeStrategyReleases.getRuntimeStrategyRelease)(
|
|
@@ -662,13 +665,12 @@ var loadVersionedRuntimeStrategies = async ({
|
|
|
662
665
|
const accountId = await resolveAccountId({
|
|
663
666
|
userName,
|
|
664
667
|
deployment,
|
|
665
|
-
connectorName,
|
|
666
668
|
universe
|
|
667
669
|
});
|
|
668
670
|
return {
|
|
669
671
|
strategyName: reference.strategyName,
|
|
670
672
|
releaseVersion: release.releaseVersion,
|
|
671
|
-
controlState: reference.controlState
|
|
673
|
+
controlState: reference.controlState,
|
|
672
674
|
interval,
|
|
673
675
|
universe,
|
|
674
676
|
accountId,
|
|
@@ -677,90 +679,24 @@ var loadVersionedRuntimeStrategies = async ({
|
|
|
677
679
|
runtimePackageVersion: release.runtimePackageVersion,
|
|
678
680
|
strategyCreator,
|
|
679
681
|
sourceStrategyConfig: release.config,
|
|
680
|
-
strategyConfig: release.config
|
|
681
|
-
// Symbol result configs are mutable legacy overlays and are not read by v2.
|
|
682
|
-
strategyResults: {}
|
|
682
|
+
strategyConfig: release.config
|
|
683
683
|
};
|
|
684
684
|
})
|
|
685
685
|
);
|
|
686
686
|
};
|
|
687
|
-
var loadLegacyRuntimeStrategies = async ({
|
|
688
|
-
userName,
|
|
689
|
-
projectRoot,
|
|
690
|
-
deployment,
|
|
691
|
-
connectorName
|
|
692
|
-
}) => {
|
|
693
|
-
const deploymentStrategies = new Map(
|
|
694
|
-
(deployment?.strategies ?? []).map((strategy) => [
|
|
695
|
-
strategy.strategyName,
|
|
696
|
-
strategy
|
|
697
|
-
])
|
|
698
|
-
);
|
|
699
|
-
const candidates = await Promise.all(
|
|
700
|
-
(await (0, import_runtimeStrategyConfigs.loadRuntimeStrategyConfigs)(userName)).map(async (record) => {
|
|
701
|
-
const binding = deploymentStrategies.get(record.strategyName);
|
|
702
|
-
if (binding?.enabled === false || record.strategyConfig.ENABLE === false) {
|
|
703
|
-
return null;
|
|
704
|
-
}
|
|
705
|
-
const universe = record.strategyConfig.UNIVERSE === "tradfi" ? "tradfi" : "crypto";
|
|
706
|
-
const interval = String(
|
|
707
|
-
record.strategyConfig.INTERVAL ?? "15"
|
|
708
|
-
);
|
|
709
|
-
const accountId = await resolveAccountId({
|
|
710
|
-
userName,
|
|
711
|
-
deployment,
|
|
712
|
-
connectorName,
|
|
713
|
-
universe,
|
|
714
|
-
legacyAccountId: typeof record.strategyConfig.ACCOUNT_ID === "string" ? record.strategyConfig.ACCOUNT_ID : void 0
|
|
715
|
-
});
|
|
716
|
-
const [strategyCreator, strategyResults] = await Promise.all([
|
|
717
|
-
getStrategyCreator(record.strategyName, projectRoot),
|
|
718
|
-
(0, import_redis.getData)(import_redis.redisKeys.strategyResults(userName, record.strategyName), {})
|
|
719
|
-
]);
|
|
720
|
-
if (!strategyCreator) return null;
|
|
721
|
-
return {
|
|
722
|
-
strategyName: record.strategyName,
|
|
723
|
-
configId: record.configId,
|
|
724
|
-
controlState: "active",
|
|
725
|
-
interval,
|
|
726
|
-
universe,
|
|
727
|
-
accountId,
|
|
728
|
-
strategyCreator,
|
|
729
|
-
sourceStrategyConfig: record.strategyConfig,
|
|
730
|
-
strategyConfig: record.strategyConfig,
|
|
731
|
-
strategyResults: strategyResults ?? {}
|
|
732
|
-
};
|
|
733
|
-
})
|
|
734
|
-
);
|
|
735
|
-
return candidates.filter(Boolean);
|
|
736
|
-
};
|
|
737
687
|
var loadResolvedRuntimeStrategies = async ({
|
|
738
688
|
userName,
|
|
739
689
|
projectRoot,
|
|
740
690
|
deployment,
|
|
741
|
-
connectorName = "bybit",
|
|
742
691
|
universe,
|
|
743
692
|
accountId,
|
|
744
693
|
interval
|
|
745
694
|
}) => {
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
);
|
|
749
|
-
if (hasVersionedReferences && deployment?.strategies.some((strategy) => strategy.releaseVersion == null)) {
|
|
750
|
-
throw new Error(
|
|
751
|
-
`Deployment ${deployment.id} mixes legacy configs and versioned releases`
|
|
752
|
-
);
|
|
753
|
-
}
|
|
754
|
-
const strategies2 = hasVersionedReferences ? await loadVersionedRuntimeStrategies({
|
|
755
|
-
userName,
|
|
756
|
-
projectRoot,
|
|
757
|
-
deployment,
|
|
758
|
-
connectorName
|
|
759
|
-
}) : await loadLegacyRuntimeStrategies({
|
|
695
|
+
if (!deployment) throw new Error("Runtime deployment is required");
|
|
696
|
+
const strategies2 = await loadVersionedRuntimeStrategies({
|
|
760
697
|
userName,
|
|
761
698
|
projectRoot,
|
|
762
|
-
deployment
|
|
763
|
-
connectorName
|
|
699
|
+
deployment
|
|
764
700
|
});
|
|
765
701
|
const filtered = strategies2.filter(
|
|
766
702
|
(candidate) => (!universe || candidate.universe === universe) && (!interval || String(candidate.interval) === String(interval)) && (!accountId || candidate.accountId === accountId)
|