@tradejs/node 3.1.27 → 3.1.28-beta.251

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.
@@ -1,16 +1,16 @@
1
1
  import {
2
2
  listRuntimeDeployments,
3
3
  loadResolvedRuntimeStrategies
4
- } from "./chunk-NQO2MFP6.mjs";
4
+ } from "./chunk-K2YQ3MQC.mjs";
5
5
  import {
6
6
  buildExchangeFallbackRuntimeTrades,
7
7
  takeClosedPnlMatch
8
- } from "./chunk-FB5NUEOQ.mjs";
8
+ } from "./chunk-OFVUEYUR.mjs";
9
9
  import {
10
10
  getConnectorCreatorByProvider
11
11
  } from "./chunk-QVKUROR2.mjs";
12
- import "./chunk-XHNJ757K.mjs";
13
- import "./chunk-IKRSNRP6.mjs";
12
+ import "./chunk-VQSGH7YA.mjs";
13
+ import "./chunk-UITD6LG6.mjs";
14
14
  import "./chunk-LZDXRXIU.mjs";
15
15
  import "./chunk-Y6FXYEAI.mjs";
16
16
 
@@ -249,6 +249,32 @@ var MIN_HOURS = 6;
249
249
  var MAX_HOURS = 24 * 90;
250
250
  var BYBIT_MAX_TIME_RANGE_MS = 7 * 24 * 60 * 60 * 1e3 - 1e3;
251
251
  var EXCHANGE_REQUEST_TIMEOUT_MS = 15e3;
252
+ var groupRuntimeTradesByIdentity = (trades, identities) => {
253
+ const grouped = /* @__PURE__ */ new Map();
254
+ for (const trade of trades) {
255
+ const matches = [...identities.entries()].filter(([, identity]) => {
256
+ if (trade.strategy !== identity.strategyName || String(trade.interval) !== String(identity.interval)) {
257
+ return false;
258
+ }
259
+ if (trade.deploymentId && trade.deploymentId !== identity.deploymentId) {
260
+ return false;
261
+ }
262
+ if (trade.accountId && trade.accountId !== identity.accountId) {
263
+ return false;
264
+ }
265
+ if (trade.universe && trade.universe !== identity.universe) {
266
+ return false;
267
+ }
268
+ return true;
269
+ });
270
+ if (matches.length !== 1) continue;
271
+ const [runtimeKey] = matches[0];
272
+ const bucket = grouped.get(runtimeKey) ?? [];
273
+ bucket.push(trade);
274
+ grouped.set(runtimeKey, bucket);
275
+ }
276
+ return grouped;
277
+ };
252
278
  var coerceHours = (value) => {
253
279
  const parsed = Number(value ?? Number.NaN);
254
280
  if (!Number.isFinite(parsed)) {
@@ -579,6 +605,7 @@ var loadRuntimeDashboard = async ({
579
605
  const syncedTrades = [...unsyncedTrades, ...syncedConnectorTrades];
580
606
  const fallbackTrades = [];
581
607
  for (const {
608
+ connector,
582
609
  strategyNames,
583
610
  entryRows,
584
611
  closedPnlRows,
@@ -591,7 +618,12 @@ var loadRuntimeDashboard = async ({
591
618
  openPositions: openPositionsSnapshot.positions,
592
619
  strategyNames,
593
620
  existingTrades: [...syncedTrades, ...fallbackTrades],
594
- endTime
621
+ endTime,
622
+ scope: {
623
+ accountId: connector.accountId,
624
+ deploymentId: connector.deploymentId,
625
+ universe: connector.universe
626
+ }
595
627
  })
596
628
  );
597
629
  }
@@ -634,6 +666,9 @@ var loadRuntimeDashboard = async ({
634
666
  });
635
667
  identityByKey.set(runtimeKey, {
636
668
  strategyName: resolvedStrategy.strategyName,
669
+ strategyModule: resolvedStrategy.strategyModule,
670
+ strategyPackage: resolvedStrategy.strategyPackage,
671
+ strategyPackageVersion: resolvedStrategy.strategyPackageVersion,
637
672
  configId: strategyConfigId,
638
673
  strategyRevision: resolvedStrategy.strategyRevision,
639
674
  controlState: resolvedStrategy.controlState,
@@ -642,6 +677,8 @@ var loadRuntimeDashboard = async ({
642
677
  accountId: deployment.accountId,
643
678
  accountLabel: accountsById.get(deployment.accountId)?.label,
644
679
  deploymentId: deployment.id,
680
+ deploymentLabel: deployment.label,
681
+ ...resolvedStrategy.generation ? { generation: resolvedStrategy.generation } : {},
645
682
  policyProfileId: strategyPolicyProfileId,
646
683
  enabled: resolvedStrategy.controlState !== "entries_paused",
647
684
  config: resolvedStrategy.strategyConfig,
@@ -650,12 +687,16 @@ var loadRuntimeDashboard = async ({
650
687
  });
651
688
  }
652
689
  }
690
+ const tradesByRuntimeKey = groupRuntimeTradesByIdentity(
691
+ allTrades,
692
+ identityByKey
693
+ );
653
694
  const strategies = await Promise.all(
654
695
  [...identityByKey.entries()].map(async ([runtimeKey, identity]) => {
655
696
  const { strategyName } = identity;
656
- const strategyTrades = allTrades.filter(
657
- (trade) => trade.strategy === strategyName && String(trade.interval) === String(identity.interval)
658
- ).sort((left, right) => right.entryTimestamp - left.entryTimestamp);
697
+ const strategyTrades = (tradesByRuntimeKey.get(runtimeKey) ?? []).sort(
698
+ (left, right) => right.entryTimestamp - left.entryTimestamp
699
+ );
659
700
  const orders = strategyTrades.sort((left, right) => {
660
701
  const leftDate = left.exitTimestamp ?? left.entryTimestamp;
661
702
  const rightDate = right.exitTimestamp ?? right.entryTimestamp;
@@ -670,14 +711,19 @@ var loadRuntimeDashboard = async ({
670
711
  return {
671
712
  runtimeKey,
672
713
  strategyName,
714
+ strategyModule: identity.strategyModule,
715
+ strategyPackage: identity.strategyPackage,
716
+ strategyPackageVersion: identity.strategyPackageVersion,
673
717
  configId: identity.configId,
674
718
  strategyRevision: identity.strategyRevision,
719
+ ...identity.generation ? { generation: identity.generation } : {},
675
720
  controlState: identity.controlState,
676
721
  interval: identity.interval,
677
722
  universe: identity.universe,
678
723
  accountId: identity.accountId,
679
724
  accountLabel: identity.accountLabel,
680
725
  deploymentId: identity.deploymentId,
726
+ deploymentLabel: identity.deploymentLabel,
681
727
  ...identity.selection ? { selection: identity.selection } : {},
682
728
  policyProfileId: identity.policyProfileId,
683
729
  connected: identity.connected,
@@ -8,6 +8,7 @@ interface RuntimePackageManifest {
8
8
  }
9
9
  interface ResolvedRuntimeStrategy {
10
10
  strategyName: string;
11
+ strategyModule: string;
11
12
  strategyRevision: string;
12
13
  deploymentCompositionId: string;
13
14
  generation?: string;
@@ -27,6 +28,7 @@ interface ResolvedRuntimeStrategy {
27
28
  }
28
29
  interface ResolvedStrategyComposition {
29
30
  strategyName: string;
31
+ strategyModule: string;
30
32
  strategyRevision: string;
31
33
  generation?: string;
32
34
  enabled: boolean;
@@ -93,9 +95,10 @@ declare const loadResolvedRuntimeStrategies: ({ userName, projectRoot, deploymen
93
95
  accountId?: string;
94
96
  interval?: Interval;
95
97
  }) => Promise<ResolvedRuntimeStrategy[]>;
96
- declare const getRuntimeStrategyPackageMetadata: ({ strategyName, projectRoot, }: {
98
+ declare const getRuntimeStrategyPackageMetadata: ({ strategyName, projectRoot, strategyModule, }: {
97
99
  strategyName: string;
98
100
  projectRoot: string;
101
+ strategyModule?: string;
99
102
  }) => Promise<{
100
103
  strategyPackage: string;
101
104
  strategyPackageVersion: string;
@@ -8,6 +8,7 @@ interface RuntimePackageManifest {
8
8
  }
9
9
  interface ResolvedRuntimeStrategy {
10
10
  strategyName: string;
11
+ strategyModule: string;
11
12
  strategyRevision: string;
12
13
  deploymentCompositionId: string;
13
14
  generation?: string;
@@ -27,6 +28,7 @@ interface ResolvedRuntimeStrategy {
27
28
  }
28
29
  interface ResolvedStrategyComposition {
29
30
  strategyName: string;
31
+ strategyModule: string;
30
32
  strategyRevision: string;
31
33
  generation?: string;
32
34
  enabled: boolean;
@@ -93,9 +95,10 @@ declare const loadResolvedRuntimeStrategies: ({ userName, projectRoot, deploymen
93
95
  accountId?: string;
94
96
  interval?: Interval;
95
97
  }) => Promise<ResolvedRuntimeStrategy[]>;
96
- declare const getRuntimeStrategyPackageMetadata: ({ strategyName, projectRoot, }: {
98
+ declare const getRuntimeStrategyPackageMetadata: ({ strategyName, projectRoot, strategyModule, }: {
97
99
  strategyName: string;
98
100
  projectRoot: string;
101
+ strategyModule?: string;
99
102
  }) => Promise<{
100
103
  strategyPackage: string;
101
104
  strategyPackageVersion: string;