@tradejs/node 3.1.3 → 3.1.5
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 +46 -89
- package/dist/runtimeStrategies.mjs +46 -89
- 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
|
|
@@ -578,6 +576,23 @@ var resolveInstalledPackageVersion = async (projectRoot, packageName, manifest)
|
|
|
578
576
|
return null;
|
|
579
577
|
}
|
|
580
578
|
};
|
|
579
|
+
var resolveStrategyPackageName = async ({
|
|
580
|
+
pluginSource,
|
|
581
|
+
projectRoot
|
|
582
|
+
}) => {
|
|
583
|
+
if (!pluginSource) return null;
|
|
584
|
+
if (!pluginSource.startsWith(".") && !import_node_path.default.isAbsolute(pluginSource)) {
|
|
585
|
+
return pluginSource;
|
|
586
|
+
}
|
|
587
|
+
try {
|
|
588
|
+
const packageJson = JSON.parse(
|
|
589
|
+
await (0, import_promises.readFile)(import_node_path.default.join(projectRoot, "package.json"), "utf8")
|
|
590
|
+
);
|
|
591
|
+
return typeof packageJson.name === "string" && packageJson.name.trim() ? packageJson.name : null;
|
|
592
|
+
} catch {
|
|
593
|
+
return null;
|
|
594
|
+
}
|
|
595
|
+
};
|
|
581
596
|
var validateReleaseRuntimeCompatibility = async ({
|
|
582
597
|
release,
|
|
583
598
|
projectRoot,
|
|
@@ -588,13 +603,17 @@ var validateReleaseRuntimeCompatibility = async ({
|
|
|
588
603
|
release.strategyPackage,
|
|
589
604
|
packageManifest
|
|
590
605
|
);
|
|
591
|
-
if (release.strategyPackageVersion
|
|
606
|
+
if (release.strategyPackageVersion !== installedStrategyVersion) {
|
|
592
607
|
throw new Error(
|
|
593
608
|
`${release.strategyName} v${release.releaseVersion} requires ${release.strategyPackage}@${release.strategyPackageVersion}, image has ${installedStrategyVersion}`
|
|
594
609
|
);
|
|
595
610
|
}
|
|
596
|
-
const installedRuntimeVersion =
|
|
597
|
-
|
|
611
|
+
const installedRuntimeVersion = await resolveInstalledPackageVersion(
|
|
612
|
+
projectRoot,
|
|
613
|
+
"@tradejs/node",
|
|
614
|
+
packageManifest
|
|
615
|
+
);
|
|
616
|
+
if (release.runtimePackageVersion !== installedRuntimeVersion) {
|
|
598
617
|
throw new Error(
|
|
599
618
|
`${release.strategyName} v${release.releaseVersion} requires @tradejs/node@${release.runtimePackageVersion}, image has ${installedRuntimeVersion}`
|
|
600
619
|
);
|
|
@@ -603,24 +622,20 @@ var validateReleaseRuntimeCompatibility = async ({
|
|
|
603
622
|
var resolveAccountId = async ({
|
|
604
623
|
userName,
|
|
605
624
|
deployment,
|
|
606
|
-
|
|
607
|
-
universe,
|
|
608
|
-
legacyAccountId
|
|
625
|
+
universe
|
|
609
626
|
}) => {
|
|
610
|
-
const requestedAccountId = deployment?.accountId ?? legacyAccountId;
|
|
611
627
|
const account = await (0, import_tradingAccounts.resolveTradingAccount)({
|
|
612
628
|
userName,
|
|
613
|
-
accountId:
|
|
614
|
-
provider: deployment
|
|
629
|
+
accountId: deployment.accountId,
|
|
630
|
+
provider: deployment.provider,
|
|
615
631
|
universe
|
|
616
632
|
});
|
|
617
|
-
return account?.id ??
|
|
633
|
+
return account?.id ?? deployment.accountId;
|
|
618
634
|
};
|
|
619
635
|
var loadVersionedRuntimeStrategies = async ({
|
|
620
636
|
userName,
|
|
621
637
|
projectRoot,
|
|
622
|
-
deployment
|
|
623
|
-
connectorName
|
|
638
|
+
deployment
|
|
624
639
|
}) => {
|
|
625
640
|
const packageManifest = await readPackageManifest(projectRoot);
|
|
626
641
|
return Promise.all(
|
|
@@ -630,9 +645,14 @@ var loadVersionedRuntimeStrategies = async ({
|
|
|
630
645
|
`Deployment ${deployment.id} strategy ${reference.strategyName} has no releaseVersion`
|
|
631
646
|
);
|
|
632
647
|
}
|
|
633
|
-
if (
|
|
648
|
+
if (Object.keys(reference).some(
|
|
649
|
+
(key) => !["strategyName", "releaseVersion", "controlState"].includes(key)
|
|
650
|
+
)) {
|
|
651
|
+
throw new Error(`Deployment ${deployment.id} has invalid fields`);
|
|
652
|
+
}
|
|
653
|
+
if (!reference.controlState) {
|
|
634
654
|
throw new Error(
|
|
635
|
-
`Deployment ${deployment.id}
|
|
655
|
+
`Deployment ${deployment.id} strategy ${reference.strategyName} has no controlState`
|
|
636
656
|
);
|
|
637
657
|
}
|
|
638
658
|
const release = await (0, import_runtimeStrategyReleases.getRuntimeStrategyRelease)(
|
|
@@ -662,13 +682,12 @@ var loadVersionedRuntimeStrategies = async ({
|
|
|
662
682
|
const accountId = await resolveAccountId({
|
|
663
683
|
userName,
|
|
664
684
|
deployment,
|
|
665
|
-
connectorName,
|
|
666
685
|
universe
|
|
667
686
|
});
|
|
668
687
|
return {
|
|
669
688
|
strategyName: reference.strategyName,
|
|
670
689
|
releaseVersion: release.releaseVersion,
|
|
671
|
-
controlState: reference.controlState
|
|
690
|
+
controlState: reference.controlState,
|
|
672
691
|
interval,
|
|
673
692
|
universe,
|
|
674
693
|
accountId,
|
|
@@ -677,90 +696,24 @@ var loadVersionedRuntimeStrategies = async ({
|
|
|
677
696
|
runtimePackageVersion: release.runtimePackageVersion,
|
|
678
697
|
strategyCreator,
|
|
679
698
|
sourceStrategyConfig: release.config,
|
|
680
|
-
strategyConfig: release.config
|
|
681
|
-
// Symbol result configs are mutable legacy overlays and are not read by v2.
|
|
682
|
-
strategyResults: {}
|
|
699
|
+
strategyConfig: release.config
|
|
683
700
|
};
|
|
684
701
|
})
|
|
685
702
|
);
|
|
686
703
|
};
|
|
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
704
|
var loadResolvedRuntimeStrategies = async ({
|
|
738
705
|
userName,
|
|
739
706
|
projectRoot,
|
|
740
707
|
deployment,
|
|
741
|
-
connectorName = "bybit",
|
|
742
708
|
universe,
|
|
743
709
|
accountId,
|
|
744
710
|
interval
|
|
745
711
|
}) => {
|
|
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({
|
|
712
|
+
if (!deployment) throw new Error("Runtime deployment is required");
|
|
713
|
+
const strategies2 = await loadVersionedRuntimeStrategies({
|
|
755
714
|
userName,
|
|
756
715
|
projectRoot,
|
|
757
|
-
deployment
|
|
758
|
-
connectorName
|
|
759
|
-
}) : await loadLegacyRuntimeStrategies({
|
|
760
|
-
userName,
|
|
761
|
-
projectRoot,
|
|
762
|
-
deployment,
|
|
763
|
-
connectorName
|
|
716
|
+
deployment
|
|
764
717
|
});
|
|
765
718
|
const filtered = strategies2.filter(
|
|
766
719
|
(candidate) => (!universe || candidate.universe === universe) && (!interval || String(candidate.interval) === String(interval)) && (!accountId || candidate.accountId === accountId)
|
|
@@ -780,7 +733,11 @@ var getRuntimeStrategyPackageMetadata = async ({
|
|
|
780
733
|
projectRoot
|
|
781
734
|
}) => {
|
|
782
735
|
const packageManifest = await readPackageManifest(projectRoot);
|
|
783
|
-
const
|
|
736
|
+
const pluginSource = await getStrategyPluginSource(strategyName, projectRoot) ?? null;
|
|
737
|
+
const strategyPackage = await resolveStrategyPackageName({
|
|
738
|
+
pluginSource,
|
|
739
|
+
projectRoot
|
|
740
|
+
});
|
|
784
741
|
return {
|
|
785
742
|
strategyPackage,
|
|
786
743
|
strategyPackageVersion: await resolveInstalledPackageVersion(
|