nexustrade 1.4.0 → 1.6.0

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/README.md CHANGED
@@ -23,6 +23,71 @@ npm install nexustrade
23
23
 
24
24
  **Zero runtime dependencies.** ESM and CommonJS builds ship together, with types.
25
25
 
26
+ ## MCP server
27
+
28
+ NexusTrade also exposes the platform as a hosted, remote Model Context Protocol
29
+ server. Modern MCP clients connect directly to the production Streamable HTTP
30
+ endpoint and discover NexusTrade OAuth automatically:
31
+
32
+ ```bash
33
+ claude mcp add --transport http nexustrade https://nexustrade.io/api/mcp
34
+ ```
35
+
36
+ Cursor and other remote-capable clients use:
37
+
38
+ ```json
39
+ {
40
+ "mcpServers": {
41
+ "nexustrade": {
42
+ "url": "https://nexustrade.io/api/mcp"
43
+ }
44
+ }
45
+ }
46
+ ```
47
+
48
+ For Claude Desktop and other stdio-only clients, use the established
49
+ `mcp-remote` bridge—no clone or local NexusTrade server is required:
50
+
51
+ ```json
52
+ {
53
+ "mcpServers": {
54
+ "nexustrade": {
55
+ "command": "npx",
56
+ "args": [
57
+ "-y",
58
+ "mcp-remote@latest",
59
+ "https://nexustrade.io/api/mcp",
60
+ "--transport",
61
+ "http-only"
62
+ ]
63
+ }
64
+ }
65
+ }
66
+ ```
67
+
68
+ The live server exposes more than 120 tools across market research, portfolio
69
+ construction, backtesting, optimization, walk-forward validation, managed
70
+ compute, Aurora agents, paper trading, and controlled brokerage operations.
71
+ Its creator-marketplace tools cover the full strategy adoption path:
72
+
73
+ - `search_creators` discovers public creators and their marketplace portfolios.
74
+ - `subscribe_portfolio` validates a monetized listing and returns a safe
75
+ checkout preview; the user completes payment in NexusTrade, never through the
76
+ MCP tool.
77
+ - `fork_shared_portfolio` creates a one-time editable copy of a marketplace
78
+ strategy in a new or existing portfolio.
79
+ - `copy_trade_shared` continuously mirrors an accessible strategy into a paper
80
+ or live portfolio at an explicit allocation.
81
+
82
+ See the [developer guide](https://nexustrade.io/developers), the
83
+ [utility tool reference](https://nexustrade.io/docs/api-reference/mcp-tools-utility),
84
+ and the [Aurora tool reference](https://nexustrade.io/docs/api-reference/mcp-tools-aurora).
85
+
86
+ Research and historical results are not investment advice and do not guarantee
87
+ future performance. Keep paper and live modes explicit. Tools that can affect
88
+ portfolios, schedules, or brokerage orders remain subject to the authenticated
89
+ account's NexusTrade permissions and approval controls.
90
+
26
91
  ## Quickstart
27
92
 
28
93
  ```ts
@@ -216,6 +281,11 @@ await client.listPortfolios({ includePaper: true, includePositions: true });
216
281
  await client.getPortfolio(portfolioId);
217
282
  ```
218
283
 
284
+ Fetched portfolio handles include a typed, read-only `policy` snapshot. Trading
285
+ policy changes are intentionally unavailable through the SDK; edit them in
286
+ Portfolio Settings. `PortfolioHandle.toJSON()` omits the snapshot so a fetched
287
+ portfolio cannot accidentally submit policy changes through an authoring call.
288
+
219
289
  `listPortfolios` filters with `includePaper`, `includeLive`, `includeInactive`,
220
290
  `includeChatPortfolios`, `search`, `limit`, and `page`. `includePositions`
221
291
  defaults off when `search` is set.
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.portfolio = exports.sessionFlatten = exports.strategy = exports.closeOption = exports.greeksTrigger = exports.daysHeldTrigger = exports.dteTrigger = exports.pnlTrigger = exports.rebalanceOption = exports.sleeve = exports.structureTemplate = exports.openOption = exports.againstParent = exports.optionsBuilder = exports.leg = exports.dynamicRebalance = exports.launchAgent = exports.alert = exports.sell = exports.buy = exports.selectPercentile = exports.selectTop = exports.filter = exports.RebalanceNetBenefit = exports.RebalanceExpectedBenefit = exports.RebalanceEstimatedCost = exports.RebalancePlannedTurnover = exports.RebalanceAllocationDrift = exports.volatilityTarget = exports.maximumDiversificationAllocation = exports.riskParityAllocation = exports.meanVarianceAllocation = exports.always = exports.multi = exports.exactly = exports.fewerThan = exports.atMost = exports.atLeast = exports.or = exports.and = exports.neq = exports.eq = exports.lte = exports.gte = exports.lt = exports.gt = exports.cryptoAsset = exports.stockAsset = exports.PORTFOLIO_WIDE = exports.CANDIDATE = void 0;
4
- exports.geneUniversePipelineFilter = exports.geneSelectTopLimit = exports.geneDteBracket = exports.geneStrikeDistance = exports.geneOptionDelta = exports.geneExposurePolicy = exports.geneAllocationPolicy = exports.geneStructureKind = exports.geneTakeProfitPct = exports.geneRollTriggerDte = exports.geneDeploymentPct = exports.geneTotalBudgetPct = exports.geneAllocationPct = exports.geneBuyingPowerPct = exports.geneRankSignal = exports.geneEntryCooldownDays = exports.geneExitCondition = exports.geneEntryCondition = exports.geneSubject = exports.optimization = exports.walkForward = exports.backtest = exports.SMA = exports.RSI = exports.PriceStdDev = exports.EMA = exports.BBand = void 0;
4
+ exports.geneUniversePipelineFilter = exports.geneSelectTopLimit = exports.geneMaxSpreadPct = exports.geneDteBracket = exports.geneStrikeDistance = exports.geneOptionDelta = exports.geneExposurePolicy = exports.geneAllocationPolicy = exports.geneStructureKind = exports.geneStopLossPct = exports.geneTakeProfitPct = exports.geneRollTriggerDte = exports.geneDeploymentPct = exports.geneTotalBudgetPct = exports.geneAllocationPct = exports.geneBuyingPowerPct = exports.geneRankSignal = exports.geneEntryCooldownDays = exports.geneExitCondition = exports.geneEntryCondition = exports.geneSubject = exports.optimization = exports.walkForward = exports.backtest = exports.SMA = exports.RSI = exports.PriceStdDev = exports.EMA = exports.BBand = void 0;
5
5
  exports.universe = universe;
6
6
  exports.AbsoluteValue = AbsoluteValue;
7
7
  exports.AverageTrueRange = AverageTrueRange;
@@ -1699,21 +1699,29 @@ const geneDeploymentPct = (strategyIndex, values) => ({
1699
1699
  });
1700
1700
  exports.geneDeploymentPct = geneDeploymentPct;
1701
1701
  /** Sweep RollTriggerDte (Action scope) over a value set. */
1702
- const geneRollTriggerDte = (strategyIndex, values) => ({
1702
+ const geneRollTriggerDte = (values, strategyIndex) => ({
1703
1703
  field: "RollTriggerDte",
1704
1704
  scope: "Action",
1705
- target: { scope: "Action", field: "RollTriggerDte", strategyIndex },
1705
+ target: { scope: "Action", field: "RollTriggerDte", ...(strategyIndex === undefined ? {} : { strategyIndex }) },
1706
1706
  values: values,
1707
1707
  });
1708
1708
  exports.geneRollTriggerDte = geneRollTriggerDte;
1709
1709
  /** Sweep TakeProfitPct (Action scope) over a value set. */
1710
- const geneTakeProfitPct = (strategyIndex, values) => ({
1710
+ const geneTakeProfitPct = (values, strategyIndex) => ({
1711
1711
  field: "TakeProfitPct",
1712
1712
  scope: "Action",
1713
- target: { scope: "Action", field: "TakeProfitPct", strategyIndex },
1713
+ target: { scope: "Action", field: "TakeProfitPct", ...(strategyIndex === undefined ? {} : { strategyIndex }) },
1714
1714
  values: values,
1715
1715
  });
1716
1716
  exports.geneTakeProfitPct = geneTakeProfitPct;
1717
+ /** Sweep StopLossPct (Action scope) over a value set. */
1718
+ const geneStopLossPct = (values, strategyIndex) => ({
1719
+ field: "StopLossPct",
1720
+ scope: "Action",
1721
+ target: { scope: "Action", field: "StopLossPct", ...(strategyIndex === undefined ? {} : { strategyIndex }) },
1722
+ values: values,
1723
+ });
1724
+ exports.geneStopLossPct = geneStopLossPct;
1717
1725
  /** Sweep StructureKind (Action scope) over a value set. */
1718
1726
  const geneStructureKind = (strategyIndex, values) => ({
1719
1727
  field: "StructureKind",
@@ -1762,6 +1770,14 @@ const geneDteBracket = (strategyIndex, legIndex, values) => ({
1762
1770
  values: values,
1763
1771
  });
1764
1772
  exports.geneDteBracket = geneDteBracket;
1773
+ /** Sweep MaxSpreadPct (OptionLeg scope) over a value set. */
1774
+ const geneMaxSpreadPct = (strategyIndex, legIndex, values) => ({
1775
+ field: "MaxSpreadPct",
1776
+ scope: "OptionLeg",
1777
+ target: { scope: "OptionLeg", field: "MaxSpreadPct", strategyIndex, legIndex },
1778
+ values: values,
1779
+ });
1780
+ exports.geneMaxSpreadPct = geneMaxSpreadPct;
1765
1781
  /** Sweep SelectTopLimit (UniversePipeline scope) over a value set. */
1766
1782
  const geneSelectTopLimit = (strategyIndex, stageIndex, values) => ({
1767
1783
  field: "SelectTopLimit",
@@ -49,6 +49,43 @@ const client_ts_1 = require("./client.js");
49
49
  function isJsonObject(value) {
50
50
  return typeof value === "object" && value !== null && !Array.isArray(value);
51
51
  }
52
+ function isStringArray(value) {
53
+ return Array.isArray(value) && value.every((item) => typeof item === "string");
54
+ }
55
+ function isReadonlyPortfolioPolicy(value) {
56
+ if (!isJsonObject(value) || value.schemaVersion !== 2)
57
+ return false;
58
+ const stock = value.stockEligibility;
59
+ const automation = value.automatedApproval;
60
+ if (!isJsonObject(stock) || !isJsonObject(automation))
61
+ return false;
62
+ const industry = stock.industryFilter;
63
+ return (typeof value.revision === "number" &&
64
+ Number.isSafeInteger(value.revision) &&
65
+ value.revision >= 0 &&
66
+ typeof stock.minimumMarketCapUsd === "number" &&
67
+ Number.isSafeInteger(stock.minimumMarketCapUsd) &&
68
+ stock.minimumMarketCapUsd >= 0 &&
69
+ (stock.maximumMarketCapUsd === null ||
70
+ (typeof stock.maximumMarketCapUsd === "number" &&
71
+ Number.isSafeInteger(stock.maximumMarketCapUsd) &&
72
+ stock.maximumMarketCapUsd >= stock.minimumMarketCapUsd)) &&
73
+ isJsonObject(industry) &&
74
+ (industry.mode === "ALL" || industry.mode === "INCLUDE_ONLY") &&
75
+ (industry.match === "ANY" || industry.match === "ALL") &&
76
+ isStringArray(industry.industries) &&
77
+ stock.missingMarketCapBehavior === "EXCLUDE" &&
78
+ stock.missingIndustryBehavior === "EXCLUDE_WHEN_FILTER_SET" &&
79
+ stock.appliesTo === "DYNAMIC_STOCK_UNIVERSES" &&
80
+ typeof automation.enabled === "boolean" &&
81
+ typeof automation.maxAutomatedTradesPerDay === "number" &&
82
+ Number.isSafeInteger(automation.maxAutomatedTradesPerDay) &&
83
+ automation.maxAutomatedTradesPerDay >= 1 &&
84
+ automation.maxAutomatedTradesPerDay <= 25 &&
85
+ automation.countingUnit === "TRADE_ACTION" &&
86
+ automation.dailyWindow === "AMERICA_NEW_YORK_CALENDAR_DAY" &&
87
+ (value.updatedAt === undefined || typeof value.updatedAt === "string"));
88
+ }
52
89
  function encodePathSegment(value) {
53
90
  return encodeURIComponent(value);
54
91
  }
@@ -70,6 +107,11 @@ class PortfolioHandle {
70
107
  createdAt;
71
108
  updatedAt;
72
109
  brokerage;
110
+ /** Server-owned snapshot. It is intentionally omitted from authoring payloads. */
111
+ #policy;
112
+ get policy() {
113
+ return this.#policy;
114
+ }
73
115
  #transport;
74
116
  constructor(data, options = {}) {
75
117
  const record = { ...data };
@@ -112,6 +154,9 @@ class PortfolioHandle {
112
154
  this.updatedAt = record.updatedAt;
113
155
  if (typeof record.brokerage === "string")
114
156
  this.brokerage = record.brokerage;
157
+ if (isReadonlyPortfolioPolicy(record.policy)) {
158
+ this.#policy = record.policy;
159
+ }
115
160
  for (const [key, value] of Object.entries(record)) {
116
161
  if (key === "name" ||
117
162
  key === "initialValue" ||
@@ -125,7 +170,8 @@ class PortfolioHandle {
125
170
  key === "strategyNames" ||
126
171
  key === "createdAt" ||
127
172
  key === "updatedAt" ||
128
- key === "brokerage") {
173
+ key === "brokerage" ||
174
+ key === "policy") {
129
175
  continue;
130
176
  }
131
177
  // `__proto__`/`constructor` arrive as own enumerable keys from
@@ -1260,13 +1260,13 @@ export interface JobRequest {
1260
1260
  args: Record<string, unknown>;
1261
1261
  }
1262
1262
  export interface BacktestConfig {
1263
- /** Backtest start date (ISO format, e.g. 2024-01-01) */
1263
+ /** Backtest start date (ISO format, e.g. 2024-01-01). For interval=Minute, default first-look is the last 90 inclusive calendar days and the selected range cannot exceed 365 days. Do not use 2010-01-01 or a multi-year span on Minute. */
1264
1264
  startDate: string;
1265
- /** Backtest end date (ISO format, e.g. 2024-12-31) */
1265
+ /** Backtest end date (ISO format, e.g. 2024-12-31). Minute hard max is 365 days from start_date; extend a survivor in a later run instead of splitting into yearly Minute jobs. */
1266
1266
  endDate: string;
1267
1267
  /** Benchmark for comparisonValue (buy-and-hold of this ticker). Defaults to SPY if omitted — use SPY only for broad equity/market strategies. For single-name options, set to that underlying (AAPL options → AAPL). For multi-name options books, run separate backtests with each material underlying as baseline (AAPL for AAPL sleeve, MSFT for MSFT), or equal-weight B&H of the traded universe — do not default to SPY. */
1268
1268
  baselineSymbol?: string;
1269
- /** Time interval: Day or Minute (default Day) */
1269
+ /** Time interval: Day or Minute (default Day). Minute is a daytrade tape — first-look 90 days, hard max 365 days. */
1270
1270
  interval?: "Day" | "Minute";
1271
1271
  /** Starting portfolio value (default 10000) Range 1..inf. */
1272
1272
  initialValue?: number;
@@ -1276,7 +1276,7 @@ export interface BacktestConfig {
1276
1276
  feeConfig?: FeeConfig;
1277
1277
  }
1278
1278
  export interface WalkForwardConfig {
1279
- /** Global calendar start for the walk-forward study (ISO date). */
1279
+ /** Global calendar start for the walk-forward study (ISO date). Minute seed first-look is 90 days; each Minute evaluation window still cannot exceed 365 days. */
1280
1280
  globalStartDate: string;
1281
1281
  /** Global calendar end for the walk-forward study (ISO date). */
1282
1282
  globalEndDate: string;
@@ -1340,9 +1340,9 @@ export interface WalkForwardConfig {
1340
1340
  genes?: Gene[];
1341
1341
  }
1342
1342
  export interface OptimizationConfig {
1343
- /** Optimization start date (ISO format, e.g. 2024-01-01) */
1343
+ /** Optimization start date (ISO format, e.g. 2024-01-01). Minute interval inherits the backtest cap: first-look 90 days, hard max 365 days. */
1344
1344
  startDate: string;
1345
- /** Optimization end date (ISO format, e.g. 2024-12-31) */
1345
+ /** Optimization end date (ISO format, e.g. 2024-12-31). Minute selected range cannot exceed 365 days. */
1346
1346
  endDate: string;
1347
1347
  /** Fitness functions: sharpeRatio, sortinoRatio, maxDrawdown, avgDrawdown, percentChange, dollarsSold, ulcerPerformanceIndex, participationRate, distinctUnderlyingsTraded, medianDeployment */
1348
1348
  fitnessFunctions?: ("sharpeRatio" | "sortinoRatio" | "maxDrawdown" | "avgDrawdown" | "percentChange" | "dollarsSold" | "ulcerPerformanceIndex" | "participationRate" | "distinctUnderlyingsTraded" | "medianDeployment")[];
@@ -1408,9 +1408,11 @@ export declare const geneTotalBudgetPct: (strategyIndex: number, values: number[
1408
1408
  /** Sweep DeploymentPct (Action scope) over a value set. */
1409
1409
  export declare const geneDeploymentPct: (strategyIndex: number, values: number[]) => Gene;
1410
1410
  /** Sweep RollTriggerDte (Action scope) over a value set. */
1411
- export declare const geneRollTriggerDte: (strategyIndex: number, values: number[]) => Gene;
1411
+ export declare const geneRollTriggerDte: (values: number[], strategyIndex?: number) => Gene;
1412
1412
  /** Sweep TakeProfitPct (Action scope) over a value set. */
1413
- export declare const geneTakeProfitPct: (strategyIndex: number, values: number[]) => Gene;
1413
+ export declare const geneTakeProfitPct: (values: number[], strategyIndex?: number) => Gene;
1414
+ /** Sweep StopLossPct (Action scope) over a value set. */
1415
+ export declare const geneStopLossPct: (values: number[], strategyIndex?: number) => Gene;
1414
1416
  /** Sweep StructureKind (Action scope) over a value set. */
1415
1417
  export declare const geneStructureKind: (strategyIndex: number, values: string[]) => Gene;
1416
1418
  /** Sweep AllocationPolicy (Action scope) over a value set. */
@@ -1432,6 +1434,8 @@ export declare const geneStrikeDistance: (strategyIndex: number, legIndex: numbe
1432
1434
  }[]) => Gene;
1433
1435
  /** Sweep DteBracket (OptionLeg scope) over a value set. */
1434
1436
  export declare const geneDteBracket: (strategyIndex: number, legIndex: number, values: [number, number][]) => Gene;
1437
+ /** Sweep MaxSpreadPct (OptionLeg scope) over a value set. */
1438
+ export declare const geneMaxSpreadPct: (strategyIndex: number, legIndex: number, values: number[]) => Gene;
1435
1439
  /** Sweep SelectTopLimit (UniversePipeline scope) over a value set. */
1436
1440
  export declare const geneSelectTopLimit: (strategyIndex: number, stageIndex: number, values: number[]) => Gene;
1437
1441
  /** Sweep UniversePipelineFilter (UniversePipeline scope) over a value set. */
@@ -1526,17 +1526,24 @@ export const geneDeploymentPct = (strategyIndex, values) => ({
1526
1526
  values: values,
1527
1527
  });
1528
1528
  /** Sweep RollTriggerDte (Action scope) over a value set. */
1529
- export const geneRollTriggerDte = (strategyIndex, values) => ({
1529
+ export const geneRollTriggerDte = (values, strategyIndex) => ({
1530
1530
  field: "RollTriggerDte",
1531
1531
  scope: "Action",
1532
- target: { scope: "Action", field: "RollTriggerDte", strategyIndex },
1532
+ target: { scope: "Action", field: "RollTriggerDte", ...(strategyIndex === undefined ? {} : { strategyIndex }) },
1533
1533
  values: values,
1534
1534
  });
1535
1535
  /** Sweep TakeProfitPct (Action scope) over a value set. */
1536
- export const geneTakeProfitPct = (strategyIndex, values) => ({
1536
+ export const geneTakeProfitPct = (values, strategyIndex) => ({
1537
1537
  field: "TakeProfitPct",
1538
1538
  scope: "Action",
1539
- target: { scope: "Action", field: "TakeProfitPct", strategyIndex },
1539
+ target: { scope: "Action", field: "TakeProfitPct", ...(strategyIndex === undefined ? {} : { strategyIndex }) },
1540
+ values: values,
1541
+ });
1542
+ /** Sweep StopLossPct (Action scope) over a value set. */
1543
+ export const geneStopLossPct = (values, strategyIndex) => ({
1544
+ field: "StopLossPct",
1545
+ scope: "Action",
1546
+ target: { scope: "Action", field: "StopLossPct", ...(strategyIndex === undefined ? {} : { strategyIndex }) },
1540
1547
  values: values,
1541
1548
  });
1542
1549
  /** Sweep StructureKind (Action scope) over a value set. */
@@ -1581,6 +1588,13 @@ export const geneDteBracket = (strategyIndex, legIndex, values) => ({
1581
1588
  target: { scope: "OptionLeg", field: "DteBracket", strategyIndex, legIndex },
1582
1589
  values: values,
1583
1590
  });
1591
+ /** Sweep MaxSpreadPct (OptionLeg scope) over a value set. */
1592
+ export const geneMaxSpreadPct = (strategyIndex, legIndex, values) => ({
1593
+ field: "MaxSpreadPct",
1594
+ scope: "OptionLeg",
1595
+ target: { scope: "OptionLeg", field: "MaxSpreadPct", strategyIndex, legIndex },
1596
+ values: values,
1597
+ });
1584
1598
  /** Sweep SelectTopLimit (UniversePipeline scope) over a value set. */
1585
1599
  export const geneSelectTopLimit = (strategyIndex, stageIndex, values) => ({
1586
1600
  field: "SelectTopLimit",
@@ -3,5 +3,5 @@ export type { AgentEvent, AgentRunOptions } from "./agent.js";
3
3
  export { HttpTransport, NexusTradeApiError, NexusTradeClient, createCustomIndicator, createPortfolio, waitForOperation, } from "./client.js";
4
4
  export type { CustomIndicatorInput, CustomIndicatorPointInput, HttpTransportOptions, JsonObject, JsonValue, ListPortfoliosOptions, NexusTradeClientOptions, RequestOptions, Transport, UploadTransport, WaitOptions, } from "./client.js";
5
5
  export { PortfolioHandle, portfolioHandleFromWire, } from "./portfolio.js";
6
- export type { DeployOutcome, DeployResult, PortfolioHandleOptions, PortfolioListResult, PortfolioType, } from "./portfolio.js";
6
+ export type { DeployOutcome, DeployResult, PortfolioHandleOptions, PortfolioListResult, PortfolioType, ReadonlyPortfolioPolicy, } from "./portfolio.js";
7
7
  export * from "./generated/ntSdk.generated.js";
@@ -32,6 +32,29 @@ export interface PortfolioHandleOptions {
32
32
  id?: string | null;
33
33
  transport?: Transport;
34
34
  }
35
+ export interface ReadonlyPortfolioPolicy {
36
+ readonly schemaVersion: 2;
37
+ readonly revision: number;
38
+ readonly stockEligibility: {
39
+ readonly minimumMarketCapUsd: number;
40
+ readonly maximumMarketCapUsd: number | null;
41
+ readonly industryFilter: {
42
+ readonly mode: "ALL" | "INCLUDE_ONLY";
43
+ readonly match: "ANY" | "ALL";
44
+ readonly industries: readonly string[];
45
+ };
46
+ readonly missingMarketCapBehavior: "EXCLUDE";
47
+ readonly missingIndustryBehavior: "EXCLUDE_WHEN_FILTER_SET";
48
+ readonly appliesTo: "DYNAMIC_STOCK_UNIVERSES";
49
+ };
50
+ readonly automatedApproval: {
51
+ readonly enabled: boolean;
52
+ readonly maxAutomatedTradesPerDay: number;
53
+ readonly countingUnit: "TRADE_ACTION";
54
+ readonly dailyWindow: "AMERICA_NEW_YORK_CALENDAR_DAY";
55
+ };
56
+ readonly updatedAt?: string;
57
+ }
35
58
  /** Runtime portfolio object. Implements the generated `Portfolio` shape. */
36
59
  export declare class PortfolioHandle implements Portfolio {
37
60
  #private;
@@ -51,6 +74,7 @@ export declare class PortfolioHandle implements Portfolio {
51
74
  createdAt?: string;
52
75
  updatedAt?: string;
53
76
  brokerage?: string;
77
+ get policy(): ReadonlyPortfolioPolicy | undefined;
54
78
  constructor(data: Portfolio | JsonObject, options?: PortfolioHandleOptions);
55
79
  static from(data: Portfolio | JsonObject, options?: PortfolioHandleOptions): PortfolioHandle;
56
80
  /** Omit `id` — class fields would otherwise serialize as `"id": null`. */
@@ -12,6 +12,43 @@ import { NexusTradeApiError, NO_HTTP_STATUS, } from "./client.js";
12
12
  function isJsonObject(value) {
13
13
  return typeof value === "object" && value !== null && !Array.isArray(value);
14
14
  }
15
+ function isStringArray(value) {
16
+ return Array.isArray(value) && value.every((item) => typeof item === "string");
17
+ }
18
+ function isReadonlyPortfolioPolicy(value) {
19
+ if (!isJsonObject(value) || value.schemaVersion !== 2)
20
+ return false;
21
+ const stock = value.stockEligibility;
22
+ const automation = value.automatedApproval;
23
+ if (!isJsonObject(stock) || !isJsonObject(automation))
24
+ return false;
25
+ const industry = stock.industryFilter;
26
+ return (typeof value.revision === "number" &&
27
+ Number.isSafeInteger(value.revision) &&
28
+ value.revision >= 0 &&
29
+ typeof stock.minimumMarketCapUsd === "number" &&
30
+ Number.isSafeInteger(stock.minimumMarketCapUsd) &&
31
+ stock.minimumMarketCapUsd >= 0 &&
32
+ (stock.maximumMarketCapUsd === null ||
33
+ (typeof stock.maximumMarketCapUsd === "number" &&
34
+ Number.isSafeInteger(stock.maximumMarketCapUsd) &&
35
+ stock.maximumMarketCapUsd >= stock.minimumMarketCapUsd)) &&
36
+ isJsonObject(industry) &&
37
+ (industry.mode === "ALL" || industry.mode === "INCLUDE_ONLY") &&
38
+ (industry.match === "ANY" || industry.match === "ALL") &&
39
+ isStringArray(industry.industries) &&
40
+ stock.missingMarketCapBehavior === "EXCLUDE" &&
41
+ stock.missingIndustryBehavior === "EXCLUDE_WHEN_FILTER_SET" &&
42
+ stock.appliesTo === "DYNAMIC_STOCK_UNIVERSES" &&
43
+ typeof automation.enabled === "boolean" &&
44
+ typeof automation.maxAutomatedTradesPerDay === "number" &&
45
+ Number.isSafeInteger(automation.maxAutomatedTradesPerDay) &&
46
+ automation.maxAutomatedTradesPerDay >= 1 &&
47
+ automation.maxAutomatedTradesPerDay <= 25 &&
48
+ automation.countingUnit === "TRADE_ACTION" &&
49
+ automation.dailyWindow === "AMERICA_NEW_YORK_CALENDAR_DAY" &&
50
+ (value.updatedAt === undefined || typeof value.updatedAt === "string"));
51
+ }
15
52
  function encodePathSegment(value) {
16
53
  return encodeURIComponent(value);
17
54
  }
@@ -33,6 +70,11 @@ export class PortfolioHandle {
33
70
  createdAt;
34
71
  updatedAt;
35
72
  brokerage;
73
+ /** Server-owned snapshot. It is intentionally omitted from authoring payloads. */
74
+ #policy;
75
+ get policy() {
76
+ return this.#policy;
77
+ }
36
78
  #transport;
37
79
  constructor(data, options = {}) {
38
80
  const record = { ...data };
@@ -75,6 +117,9 @@ export class PortfolioHandle {
75
117
  this.updatedAt = record.updatedAt;
76
118
  if (typeof record.brokerage === "string")
77
119
  this.brokerage = record.brokerage;
120
+ if (isReadonlyPortfolioPolicy(record.policy)) {
121
+ this.#policy = record.policy;
122
+ }
78
123
  for (const [key, value] of Object.entries(record)) {
79
124
  if (key === "name" ||
80
125
  key === "initialValue" ||
@@ -88,7 +133,8 @@ export class PortfolioHandle {
88
133
  key === "strategyNames" ||
89
134
  key === "createdAt" ||
90
135
  key === "updatedAt" ||
91
- key === "brokerage") {
136
+ key === "brokerage" ||
137
+ key === "policy") {
92
138
  continue;
93
139
  }
94
140
  // `__proto__`/`constructor` arrive as own enumerable keys from
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nexustrade",
3
- "version": "1.4.0",
3
+ "version": "1.6.0",
4
4
  "description": "Typed TypeScript SDK for NexusTrade portfolio authoring, backtesting, and optimization",
5
5
  "license": "MIT",
6
6
  "author": "Starks Technology",