@tradejs/node 3.1.10 → 3.1.11-beta.216

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.
@@ -37,7 +37,8 @@ var DEPLOYMENT_KEYS = /* @__PURE__ */ new Set([
37
37
  "assetClasses",
38
38
  "tickers"
39
39
  ]);
40
- var STRATEGY_KEYS = /* @__PURE__ */ new Set(["version", "enabled", "config"]);
40
+ var STRATEGY_KEYS = /* @__PURE__ */ new Set(["version", "enabled", "selection", "config"]);
41
+ var SELECTION_KEYS = /* @__PURE__ */ new Set(["tickers"]);
41
42
  var FORBIDDEN_CONFIG_KEYS = /* @__PURE__ */ new Set([
42
43
  "ACCOUNT_ID",
43
44
  "DEPLOYMENT_ID",
@@ -96,6 +97,16 @@ var resolveStrategyPackageName = async ({
96
97
  }
97
98
  };
98
99
  var verifyStringArray = (value) => value === void 0 || Array.isArray(value) && value.every((item) => typeof item === "string");
100
+ var verifyStrategySelection = (value) => value === void 0 || isRecord(value) && Object.keys(value).length === 1 && Object.keys(value).every((key) => SELECTION_KEYS.has(key)) && Array.isArray(value.tickers) && value.tickers.length > 0 && value.tickers.every(
101
+ (ticker) => typeof ticker === "string" && ticker.trim().length > 0
102
+ );
103
+ var cloneSelection = (selection) => selection ? { tickers: [...selection.tickers] } : void 0;
104
+ var resolveStrategySelection = ({
105
+ deployment,
106
+ strategy
107
+ }) => cloneSelection(
108
+ strategy.selection ?? (deployment.tickers ? { tickers: deployment.tickers } : void 0)
109
+ );
99
110
  var verifyDeploymentDeclaration = (deploymentId, value) => {
100
111
  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) {
101
112
  throw new Error(`Invalid runtime deployment declaration: ${deploymentId}`);
@@ -103,7 +114,7 @@ var verifyDeploymentDeclaration = (deploymentId, value) => {
103
114
  for (const [strategyName, strategyValue] of Object.entries(
104
115
  value.strategies
105
116
  )) {
106
- 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(
117
+ 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" || !verifyStrategySelection(strategyValue.selection) || !isRecord(strategyValue.config) || Object.keys(strategyValue.config).some(
107
118
  (key) => FORBIDDEN_CONFIG_KEYS.has(key)
108
119
  ) || !INTERVALS.has(String(strategyValue.config.INTERVAL)) || !["crypto", "tradfi"].includes(String(strategyValue.config.UNIVERSE))) {
109
120
  throw new Error(
@@ -136,12 +147,19 @@ var toRuntimeDeployment = ({
136
147
  accountId: declaration.accountId.trim(),
137
148
  enabled: deploymentEnabled,
138
149
  strategies: Object.entries(declaration.strategies).map(
139
- ([strategyName, strategy]) => ({
140
- strategyName,
141
- version: strategy.version,
142
- enabled: strategy.enabled,
143
- controlState: deploymentEnabled && strategy.enabled && !controls.deployments[id]?.[strategyName]?.entriesPaused ? "active" : "entries_paused"
144
- })
150
+ ([strategyName, strategy]) => {
151
+ const selection = resolveStrategySelection({
152
+ deployment: declaration,
153
+ strategy
154
+ });
155
+ return {
156
+ strategyName,
157
+ version: strategy.version,
158
+ enabled: strategy.enabled,
159
+ controlState: deploymentEnabled && strategy.enabled && !controls.deployments[id]?.[strategyName]?.entriesPaused ? "active" : "entries_paused",
160
+ ...selection ? { selection } : {}
161
+ };
162
+ }
145
163
  ),
146
164
  ...declaration.assetClasses ? { assetClasses: declaration.assetClasses } : {},
147
165
  ...declaration.tickers ? { tickers: declaration.tickers } : {}
@@ -250,6 +268,10 @@ var loadResolvedRuntimeStrategies = async ({
250
268
  const strategyView = deployment.strategies.find(
251
269
  (candidate) => candidate.strategyName === strategyName
252
270
  );
271
+ const selection = resolveStrategySelection({
272
+ deployment: declaration,
273
+ strategy: strategyDeclaration
274
+ });
253
275
  const strategyConfig = strategyDeclaration.config;
254
276
  const strategyUniverse = strategyConfig.UNIVERSE;
255
277
  const resolvedAccountId = await resolveAccountId({
@@ -270,7 +292,8 @@ var loadResolvedRuntimeStrategies = async ({
270
292
  runtimePackageVersion,
271
293
  strategyCreator,
272
294
  sourceStrategyConfig: strategyConfig,
273
- strategyConfig
295
+ strategyConfig,
296
+ ...selection ? { selection } : {}
274
297
  };
275
298
  }
276
299
  )
@@ -7264,7 +7264,8 @@ var DEPLOYMENT_KEYS = /* @__PURE__ */ new Set([
7264
7264
  "assetClasses",
7265
7265
  "tickers"
7266
7266
  ]);
7267
- var STRATEGY_KEYS = /* @__PURE__ */ new Set(["version", "enabled", "config"]);
7267
+ var STRATEGY_KEYS = /* @__PURE__ */ new Set(["version", "enabled", "selection", "config"]);
7268
+ var SELECTION_KEYS = /* @__PURE__ */ new Set(["tickers"]);
7268
7269
  var FORBIDDEN_CONFIG_KEYS = /* @__PURE__ */ new Set([
7269
7270
  "ACCOUNT_ID",
7270
7271
  "DEPLOYMENT_ID",
@@ -7323,6 +7324,16 @@ var resolveStrategyPackageName = async ({
7323
7324
  }
7324
7325
  };
7325
7326
  var verifyStringArray = (value) => value === void 0 || Array.isArray(value) && value.every((item) => typeof item === "string");
7327
+ var verifyStrategySelection = (value) => value === void 0 || isRecord(value) && Object.keys(value).length === 1 && Object.keys(value).every((key) => SELECTION_KEYS.has(key)) && Array.isArray(value.tickers) && value.tickers.length > 0 && value.tickers.every(
7328
+ (ticker) => typeof ticker === "string" && ticker.trim().length > 0
7329
+ );
7330
+ var cloneSelection = (selection) => selection ? { tickers: [...selection.tickers] } : void 0;
7331
+ var resolveStrategySelection = ({
7332
+ deployment,
7333
+ strategy
7334
+ }) => cloneSelection(
7335
+ strategy.selection ?? (deployment.tickers ? { tickers: deployment.tickers } : void 0)
7336
+ );
7326
7337
  var verifyDeploymentDeclaration = (deploymentId, value) => {
7327
7338
  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) {
7328
7339
  throw new Error(`Invalid runtime deployment declaration: ${deploymentId}`);
@@ -7330,7 +7341,7 @@ var verifyDeploymentDeclaration = (deploymentId, value) => {
7330
7341
  for (const [strategyName, strategyValue] of Object.entries(
7331
7342
  value.strategies
7332
7343
  )) {
7333
- 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(
7344
+ 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" || !verifyStrategySelection(strategyValue.selection) || !isRecord(strategyValue.config) || Object.keys(strategyValue.config).some(
7334
7345
  (key) => FORBIDDEN_CONFIG_KEYS.has(key)
7335
7346
  ) || !INTERVALS.has(String(strategyValue.config.INTERVAL)) || !["crypto", "tradfi"].includes(String(strategyValue.config.UNIVERSE))) {
7336
7347
  throw new Error(
@@ -7363,12 +7374,19 @@ var toRuntimeDeployment = ({
7363
7374
  accountId: declaration.accountId.trim(),
7364
7375
  enabled: deploymentEnabled,
7365
7376
  strategies: Object.entries(declaration.strategies).map(
7366
- ([strategyName, strategy]) => ({
7367
- strategyName,
7368
- version: strategy.version,
7369
- enabled: strategy.enabled,
7370
- controlState: deploymentEnabled && strategy.enabled && !controls.deployments[id]?.[strategyName]?.entriesPaused ? "active" : "entries_paused"
7371
- })
7377
+ ([strategyName, strategy]) => {
7378
+ const selection = resolveStrategySelection({
7379
+ deployment: declaration,
7380
+ strategy
7381
+ });
7382
+ return {
7383
+ strategyName,
7384
+ version: strategy.version,
7385
+ enabled: strategy.enabled,
7386
+ controlState: deploymentEnabled && strategy.enabled && !controls.deployments[id]?.[strategyName]?.entriesPaused ? "active" : "entries_paused",
7387
+ ...selection ? { selection } : {}
7388
+ };
7389
+ }
7372
7390
  ),
7373
7391
  ...declaration.assetClasses ? { assetClasses: declaration.assetClasses } : {},
7374
7392
  ...declaration.tickers ? { tickers: declaration.tickers } : {}
@@ -7469,6 +7487,10 @@ var loadResolvedRuntimeStrategies = async ({
7469
7487
  const strategyView = deployment.strategies.find(
7470
7488
  (candidate) => candidate.strategyName === strategyName
7471
7489
  );
7490
+ const selection = resolveStrategySelection({
7491
+ deployment: declaration,
7492
+ strategy: strategyDeclaration
7493
+ });
7472
7494
  const strategyConfig = strategyDeclaration.config;
7473
7495
  const strategyUniverse = strategyConfig.UNIVERSE;
7474
7496
  const resolvedAccountId = await resolveAccountId({
@@ -7489,7 +7511,8 @@ var loadResolvedRuntimeStrategies = async ({
7489
7511
  runtimePackageVersion,
7490
7512
  strategyCreator,
7491
7513
  sourceStrategyConfig: strategyConfig,
7492
- strategyConfig
7514
+ strategyConfig,
7515
+ ...selection ? { selection } : {}
7493
7516
  };
7494
7517
  }
7495
7518
  )
@@ -7835,7 +7858,8 @@ var loadRuntimeDashboard = async ({
7835
7858
  policyProfileId: strategyPolicyProfileId,
7836
7859
  enabled: resolvedStrategy.controlState !== "entries_paused",
7837
7860
  config: resolvedStrategy.strategyConfig,
7838
- connected: deployment.enabled
7861
+ connected: deployment.enabled,
7862
+ ...resolvedStrategy.selection ? { selection: resolvedStrategy.selection } : {}
7839
7863
  });
7840
7864
  }
7841
7865
  }
@@ -7879,6 +7903,7 @@ var loadRuntimeDashboard = async ({
7879
7903
  accountId: identity.accountId,
7880
7904
  accountLabel: identity.accountLabel,
7881
7905
  deploymentId: identity.deploymentId,
7906
+ ...identity.selection ? { selection: identity.selection } : {},
7882
7907
  policyProfileId: identity.policyProfileId,
7883
7908
  connected: identity.connected,
7884
7909
  enabled: identity.enabled,
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  listRuntimeDeployments,
3
3
  loadResolvedRuntimeStrategies
4
- } from "./chunk-LPHWIFLB.mjs";
4
+ } from "./chunk-7BAL7EN3.mjs";
5
5
  import {
6
6
  buildExchangeFallbackRuntimeTrades,
7
7
  takeClosedPnlMatch
@@ -569,7 +569,8 @@ var loadRuntimeDashboard = async ({
569
569
  policyProfileId: strategyPolicyProfileId,
570
570
  enabled: resolvedStrategy.controlState !== "entries_paused",
571
571
  config: resolvedStrategy.strategyConfig,
572
- connected: deployment.enabled
572
+ connected: deployment.enabled,
573
+ ...resolvedStrategy.selection ? { selection: resolvedStrategy.selection } : {}
573
574
  });
574
575
  }
575
576
  }
@@ -613,6 +614,7 @@ var loadRuntimeDashboard = async ({
613
614
  accountId: identity.accountId,
614
615
  accountLabel: identity.accountLabel,
615
616
  deploymentId: identity.deploymentId,
617
+ ...identity.selection ? { selection: identity.selection } : {},
616
618
  policyProfileId: identity.policyProfileId,
617
619
  connected: identity.connected,
618
620
  enabled: identity.enabled,
@@ -1,4 +1,4 @@
1
- import { RuntimeStrategyControlState, Interval, MarketUniverse, StrategyCreator, StrategyConfig, RuntimeDeployment, TradejsRuntimeDeclaration } from '@tradejs/types';
1
+ import { RuntimeStrategyControlState, Interval, MarketUniverse, StrategyCreator, StrategyConfig, RuntimeStrategySelection, RuntimeDeployment, TradejsRuntimeDeclaration } from '@tradejs/types';
2
2
 
3
3
  interface ResolvedRuntimeStrategy {
4
4
  strategyName: string;
@@ -14,6 +14,7 @@ interface ResolvedRuntimeStrategy {
14
14
  strategyCreator: StrategyCreator;
15
15
  sourceStrategyConfig: StrategyConfig;
16
16
  strategyConfig: StrategyConfig;
17
+ selection?: RuntimeStrategySelection;
17
18
  }
18
19
  declare const verifyRuntimeDeclaration: (value: unknown) => TradejsRuntimeDeclaration;
19
20
  declare const listRuntimeDeployments: ({ userName, projectRoot, }: {
@@ -1,4 +1,4 @@
1
- import { RuntimeStrategyControlState, Interval, MarketUniverse, StrategyCreator, StrategyConfig, RuntimeDeployment, TradejsRuntimeDeclaration } from '@tradejs/types';
1
+ import { RuntimeStrategyControlState, Interval, MarketUniverse, StrategyCreator, StrategyConfig, RuntimeStrategySelection, RuntimeDeployment, TradejsRuntimeDeclaration } from '@tradejs/types';
2
2
 
3
3
  interface ResolvedRuntimeStrategy {
4
4
  strategyName: string;
@@ -14,6 +14,7 @@ interface ResolvedRuntimeStrategy {
14
14
  strategyCreator: StrategyCreator;
15
15
  sourceStrategyConfig: StrategyConfig;
16
16
  strategyConfig: StrategyConfig;
17
+ selection?: RuntimeStrategySelection;
17
18
  }
18
19
  declare const verifyRuntimeDeclaration: (value: unknown) => TradejsRuntimeDeclaration;
19
20
  declare const listRuntimeDeployments: ({ userName, projectRoot, }: {
@@ -6261,7 +6261,8 @@ var DEPLOYMENT_KEYS = /* @__PURE__ */ new Set([
6261
6261
  "assetClasses",
6262
6262
  "tickers"
6263
6263
  ]);
6264
- var STRATEGY_KEYS = /* @__PURE__ */ new Set(["version", "enabled", "config"]);
6264
+ var STRATEGY_KEYS = /* @__PURE__ */ new Set(["version", "enabled", "selection", "config"]);
6265
+ var SELECTION_KEYS = /* @__PURE__ */ new Set(["tickers"]);
6265
6266
  var FORBIDDEN_CONFIG_KEYS = /* @__PURE__ */ new Set([
6266
6267
  "ACCOUNT_ID",
6267
6268
  "DEPLOYMENT_ID",
@@ -6320,6 +6321,16 @@ var resolveStrategyPackageName = async ({
6320
6321
  }
6321
6322
  };
6322
6323
  var verifyStringArray = (value) => value === void 0 || Array.isArray(value) && value.every((item) => typeof item === "string");
6324
+ var verifyStrategySelection = (value) => value === void 0 || isRecord(value) && Object.keys(value).length === 1 && Object.keys(value).every((key) => SELECTION_KEYS.has(key)) && Array.isArray(value.tickers) && value.tickers.length > 0 && value.tickers.every(
6325
+ (ticker) => typeof ticker === "string" && ticker.trim().length > 0
6326
+ );
6327
+ var cloneSelection = (selection) => selection ? { tickers: [...selection.tickers] } : void 0;
6328
+ var resolveStrategySelection = ({
6329
+ deployment,
6330
+ strategy
6331
+ }) => cloneSelection(
6332
+ strategy.selection ?? (deployment.tickers ? { tickers: deployment.tickers } : void 0)
6333
+ );
6323
6334
  var verifyDeploymentDeclaration = (deploymentId, value) => {
6324
6335
  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) {
6325
6336
  throw new Error(`Invalid runtime deployment declaration: ${deploymentId}`);
@@ -6327,7 +6338,7 @@ var verifyDeploymentDeclaration = (deploymentId, value) => {
6327
6338
  for (const [strategyName, strategyValue] of Object.entries(
6328
6339
  value.strategies
6329
6340
  )) {
6330
- 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(
6341
+ 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" || !verifyStrategySelection(strategyValue.selection) || !isRecord(strategyValue.config) || Object.keys(strategyValue.config).some(
6331
6342
  (key) => FORBIDDEN_CONFIG_KEYS.has(key)
6332
6343
  ) || !INTERVALS.has(String(strategyValue.config.INTERVAL)) || !["crypto", "tradfi"].includes(String(strategyValue.config.UNIVERSE))) {
6333
6344
  throw new Error(
@@ -6360,12 +6371,19 @@ var toRuntimeDeployment = ({
6360
6371
  accountId: declaration.accountId.trim(),
6361
6372
  enabled: deploymentEnabled,
6362
6373
  strategies: Object.entries(declaration.strategies).map(
6363
- ([strategyName, strategy]) => ({
6364
- strategyName,
6365
- version: strategy.version,
6366
- enabled: strategy.enabled,
6367
- controlState: deploymentEnabled && strategy.enabled && !controls.deployments[id]?.[strategyName]?.entriesPaused ? "active" : "entries_paused"
6368
- })
6374
+ ([strategyName, strategy]) => {
6375
+ const selection = resolveStrategySelection({
6376
+ deployment: declaration,
6377
+ strategy
6378
+ });
6379
+ return {
6380
+ strategyName,
6381
+ version: strategy.version,
6382
+ enabled: strategy.enabled,
6383
+ controlState: deploymentEnabled && strategy.enabled && !controls.deployments[id]?.[strategyName]?.entriesPaused ? "active" : "entries_paused",
6384
+ ...selection ? { selection } : {}
6385
+ };
6386
+ }
6369
6387
  ),
6370
6388
  ...declaration.assetClasses ? { assetClasses: declaration.assetClasses } : {},
6371
6389
  ...declaration.tickers ? { tickers: declaration.tickers } : {}
@@ -6474,6 +6492,10 @@ var loadResolvedRuntimeStrategies = async ({
6474
6492
  const strategyView = deployment.strategies.find(
6475
6493
  (candidate) => candidate.strategyName === strategyName
6476
6494
  );
6495
+ const selection = resolveStrategySelection({
6496
+ deployment: declaration,
6497
+ strategy: strategyDeclaration
6498
+ });
6477
6499
  const strategyConfig = strategyDeclaration.config;
6478
6500
  const strategyUniverse = strategyConfig.UNIVERSE;
6479
6501
  const resolvedAccountId = await resolveAccountId({
@@ -6494,7 +6516,8 @@ var loadResolvedRuntimeStrategies = async ({
6494
6516
  runtimePackageVersion,
6495
6517
  strategyCreator,
6496
6518
  sourceStrategyConfig: strategyConfig,
6497
- strategyConfig
6519
+ strategyConfig,
6520
+ ...selection ? { selection } : {}
6498
6521
  };
6499
6522
  }
6500
6523
  )
@@ -4,7 +4,7 @@ import {
4
4
  listRuntimeDeployments,
5
5
  loadResolvedRuntimeStrategies,
6
6
  verifyRuntimeDeclaration
7
- } from "./chunk-LPHWIFLB.mjs";
7
+ } from "./chunk-7BAL7EN3.mjs";
8
8
  import "./chunk-B6X2HEGL.mjs";
9
9
  import "./chunk-C3KRBNUR.mjs";
10
10
  import "./chunk-LZDXRXIU.mjs";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tradejs/node",
3
- "version": "3.1.10",
3
+ "version": "3.1.11-beta.216",
4
4
  "description": "Node-only runtime for the TradeJS TypeScript framework: strategies, backtests, Pine strategy loading, and plugin registries.",
5
5
  "keywords": [
6
6
  "tradejs",
@@ -85,9 +85,9 @@
85
85
  "dependencies": {
86
86
  "@langchain/core": "^1.2.3",
87
87
  "@langchain/openai": "^1.5.5",
88
- "@tradejs/core": "^3.1.10",
89
- "@tradejs/infra": "^3.1.10",
90
- "@tradejs/types": "^3.1.10",
88
+ "@tradejs/core": "^3.1.11-beta.216",
89
+ "@tradejs/infra": "^3.1.11-beta.216",
90
+ "@tradejs/types": "^3.1.11-beta.216",
91
91
  "chalk": "4.1.2",
92
92
  "ioredis": "5.11.1",
93
93
  "lodash": "^4.18.1",