nexustrade 1.27.0 → 1.28.1
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 +19 -5
- package/dist/cjs/client.js +23 -0
- package/dist/cjs/generated/ntSdk.generated.js +20 -0
- package/dist/cjs/portfolio.js +56 -1
- package/dist/esm/client.d.ts +1 -1
- package/dist/esm/client.js +23 -0
- package/dist/esm/generated/ntSdk.generated.d.ts +35 -0
- package/dist/esm/generated/ntSdk.generated.js +18 -0
- package/dist/esm/portfolio.d.ts +7 -1
- package/dist/esm/portfolio.js +56 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -239,7 +239,7 @@ price target. Live option strategies must choose an explicit Limit policy.
|
|
|
239
239
|
|
|
240
240
|
| Group | Examples |
|
|
241
241
|
| ------------------- | -------------------------------------------------------------------------------------------- |
|
|
242
|
-
| **Price & volume** | `Price` `OpeningPrice` `HighOfDay` `VWAP` `Volume` `GapPercentage`
|
|
242
|
+
| **Price & volume** | `Price` `OpeningPrice` `HighOfDay` `MinuteBarHigh` `MinuteBarLow` `VWAP` `Volume` `GapPercentage` |
|
|
243
243
|
| **Technicals** | `SMA` `EMA` `RSI` `BollingerBand` `AverageTrueRange` `CrossAbove` |
|
|
244
244
|
| **Position state** | `PositionValue` `PositionPercentChange` `PositionMaxDrawdown` |
|
|
245
245
|
| **Portfolio state** | `PortfolioValue` `BuyingPower` `MaxDrawdown` `InitialValue` |
|
|
@@ -404,10 +404,23 @@ array is deleted. Carry unchanged strategies through verbatim, including the
|
|
|
404
404
|
Market. `removeStrategies` takes strategy ids from a fetched portfolio; removal
|
|
405
405
|
by name is rejected.
|
|
406
406
|
|
|
407
|
-
|
|
408
|
-
policy
|
|
409
|
-
|
|
410
|
-
|
|
407
|
+
Stock eligibility is part of what you author. Pass
|
|
408
|
+
`policy: { stockEligibility }` to `portfolio(...)`, or call
|
|
409
|
+
`setStockEligibility(...)` on a handle, to set market-cap bounds, an industry
|
|
410
|
+
filter, `missingMarketCapBehavior`, or `shareClassBehavior`. Omitted fields take
|
|
411
|
+
the defaults. A GOOG/GOOGL pairs book needs `ALL_CLASSES`, because the default
|
|
412
|
+
keeps one share class per company:
|
|
413
|
+
|
|
414
|
+
```ts
|
|
415
|
+
const pair = portfolio("GOOG/GOOGL pair", strategies, {
|
|
416
|
+
policy: { stockEligibility: { shareClassBehavior: "ALL_CLASSES" } },
|
|
417
|
+
});
|
|
418
|
+
```
|
|
419
|
+
|
|
420
|
+
Automated trading is never authored. Only the owner enables it, in Portfolio
|
|
421
|
+
Settings, and a policy that names `automatedApproval` is refused before it is
|
|
422
|
+
sent. Fetched handles include a typed, read-only `policy` snapshot; saving or
|
|
423
|
+
deploying a copy of one carries its stock eligibility and nothing else.
|
|
411
424
|
|
|
412
425
|
`listPortfolios` filters with `includePaper`, `includeLive`, `includeInactive`,
|
|
413
426
|
`includeChatPortfolios`, `search`, `limit`, and `page`. `includePositions`
|
|
@@ -809,6 +822,7 @@ is missing here, so this list cannot drift from the code.
|
|
|
809
822
|
| `backtest({ startDate, endDate, idempotencyKey })` | Backtest it, preferring the saved id |
|
|
810
823
|
| `deploy({ frequency })` | Mint the real paper portfolio (new id) |
|
|
811
824
|
| `undeploy()` | Deactivate its deployment |
|
|
825
|
+
| `setStockEligibility(eligibility)` | Set the stock eligibility it will send |
|
|
812
826
|
|
|
813
827
|
## Authentication
|
|
814
828
|
|
package/dist/cjs/client.js
CHANGED
|
@@ -655,6 +655,29 @@ function pointKindPoints(points, pointKind, aggregatePeriod) {
|
|
|
655
655
|
}
|
|
656
656
|
return row;
|
|
657
657
|
}
|
|
658
|
+
if (aggregatePeriod === "1min") {
|
|
659
|
+
// One completed bar: timestamp is the bar open, available at bar close.
|
|
660
|
+
if (eventDay ||
|
|
661
|
+
!eventTime ||
|
|
662
|
+
eventTime.getUTCSeconds() !== 0 ||
|
|
663
|
+
eventTime.getUTCMilliseconds() !== 0) {
|
|
664
|
+
throw new Error(`Point ${index + 1}: 1min timestamp must be the bar-open instant with an explicit UTC offset and no seconds.`);
|
|
665
|
+
}
|
|
666
|
+
const barClose = new Date(eventTime.getTime() + 60_000);
|
|
667
|
+
if (row.availableAt === undefined) {
|
|
668
|
+
row.availableAt = barClose.toISOString();
|
|
669
|
+
}
|
|
670
|
+
else {
|
|
671
|
+
const explicit = availableDay ? addUtcDays(availableDay, 1) : availableTime;
|
|
672
|
+
if (!explicit || explicit.getTime() < barClose.getTime()) {
|
|
673
|
+
throw new Error(`Point ${index + 1}: availableAt precedes the 1min bar close.`);
|
|
674
|
+
}
|
|
675
|
+
if (availableDay) {
|
|
676
|
+
row.availableAt = utcMidnight(explicit);
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
return row;
|
|
680
|
+
}
|
|
658
681
|
if (!eventTime) {
|
|
659
682
|
throw new Error(`Point ${index + 1}: aggregate timestamp must be date-only or include an explicit UTC offset.`);
|
|
660
683
|
}
|
|
@@ -76,6 +76,8 @@ exports.MaximumPrice = MaximumPrice;
|
|
|
76
76
|
exports.Min = Min;
|
|
77
77
|
exports.MinimumPrice = MinimumPrice;
|
|
78
78
|
exports.Minus = Minus;
|
|
79
|
+
exports.MinuteBarHigh = MinuteBarHigh;
|
|
80
|
+
exports.MinuteBarLow = MinuteBarLow;
|
|
79
81
|
exports.MinutesAfterOpen = MinutesAfterOpen;
|
|
80
82
|
exports.MinutesSinceAgent = MinutesSinceAgent;
|
|
81
83
|
exports.MinutesSinceAlert = MinutesSinceAlert;
|
|
@@ -1287,6 +1289,24 @@ function Minus(left, right) {
|
|
|
1287
1289
|
d.indicators = [left, right];
|
|
1288
1290
|
return d;
|
|
1289
1291
|
}
|
|
1292
|
+
/**
|
|
1293
|
+
* MinuteBarHigh indicator.
|
|
1294
|
+
* @param asset Ticker name (ex. SPY, BTC)
|
|
1295
|
+
*/
|
|
1296
|
+
function MinuteBarHigh(asset) {
|
|
1297
|
+
const d = { type: "MinuteBarHigh" };
|
|
1298
|
+
setAsset(d, "targetAsset", asset);
|
|
1299
|
+
return d;
|
|
1300
|
+
}
|
|
1301
|
+
/**
|
|
1302
|
+
* MinuteBarLow indicator.
|
|
1303
|
+
* @param asset Ticker name (ex. SPY, BTC)
|
|
1304
|
+
*/
|
|
1305
|
+
function MinuteBarLow(asset) {
|
|
1306
|
+
const d = { type: "MinuteBarLow" };
|
|
1307
|
+
setAsset(d, "targetAsset", asset);
|
|
1308
|
+
return d;
|
|
1309
|
+
}
|
|
1290
1310
|
/**
|
|
1291
1311
|
* MinutesAfterOpen indicator.
|
|
1292
1312
|
*/
|
package/dist/cjs/portfolio.js
CHANGED
|
@@ -76,6 +76,8 @@ function isReadonlyPortfolioPolicy(value) {
|
|
|
76
76
|
isStringArray(industry.industries) &&
|
|
77
77
|
(stock.missingMarketCapBehavior === "EXCLUDE" ||
|
|
78
78
|
stock.missingMarketCapBehavior === "INCLUDE") &&
|
|
79
|
+
(stock.shareClassBehavior === "ONE_PER_COMPANY" ||
|
|
80
|
+
stock.shareClassBehavior === "ALL_CLASSES") &&
|
|
79
81
|
stock.missingIndustryBehavior === "EXCLUDE_WHEN_FILTER_SET" &&
|
|
80
82
|
stock.appliesTo === "DYNAMIC_STOCK_UNIVERSES" &&
|
|
81
83
|
typeof automation.enabled === "boolean" &&
|
|
@@ -87,6 +89,37 @@ function isReadonlyPortfolioPolicy(value) {
|
|
|
87
89
|
automation.dailyWindow === "AMERICA_NEW_YORK_CALENDAR_DAY" &&
|
|
88
90
|
(value.updatedAt === undefined || typeof value.updatedAt === "string"));
|
|
89
91
|
}
|
|
92
|
+
const AUTOMATION_POLICY_KEYS = ["automatedApproval", "automationAcknowledged"];
|
|
93
|
+
/**
|
|
94
|
+
* An authored policy carries stock eligibility and nothing else. Automated
|
|
95
|
+
* trading is enabled only by the owner in the NexusTrade UI, so a policy that
|
|
96
|
+
* names it is refused here rather than sent.
|
|
97
|
+
*/
|
|
98
|
+
function parseAuthoredPolicy(value) {
|
|
99
|
+
if (AUTOMATION_POLICY_KEYS.some((key) => key in value)) {
|
|
100
|
+
throw new TypeError("Automated trading can only be changed by the portfolio owner in the NexusTrade UI; " +
|
|
101
|
+
"an authored policy may set only stockEligibility.");
|
|
102
|
+
}
|
|
103
|
+
const unknownKeys = Object.keys(value).filter((key) => key !== "stockEligibility");
|
|
104
|
+
if (unknownKeys.length || !isJsonObject(value.stockEligibility)) {
|
|
105
|
+
throw new TypeError("An authored policy must be { stockEligibility: {...} } and nothing else.");
|
|
106
|
+
}
|
|
107
|
+
return { stockEligibility: value.stockEligibility };
|
|
108
|
+
}
|
|
109
|
+
/** The authorable fields of a fetched policy's eligibility, for a copy. */
|
|
110
|
+
function authorableEligibility(stock) {
|
|
111
|
+
return {
|
|
112
|
+
minimumMarketCapUsd: stock.minimumMarketCapUsd,
|
|
113
|
+
maximumMarketCapUsd: stock.maximumMarketCapUsd,
|
|
114
|
+
industryFilter: {
|
|
115
|
+
mode: stock.industryFilter.mode,
|
|
116
|
+
match: stock.industryFilter.match,
|
|
117
|
+
industries: [...stock.industryFilter.industries],
|
|
118
|
+
},
|
|
119
|
+
missingMarketCapBehavior: stock.missingMarketCapBehavior,
|
|
120
|
+
shareClassBehavior: stock.shareClassBehavior,
|
|
121
|
+
};
|
|
122
|
+
}
|
|
90
123
|
function encodePathSegment(value) {
|
|
91
124
|
return encodeURIComponent(value);
|
|
92
125
|
}
|
|
@@ -108,11 +141,27 @@ class PortfolioHandle {
|
|
|
108
141
|
createdAt;
|
|
109
142
|
updatedAt;
|
|
110
143
|
brokerage;
|
|
111
|
-
/** Server
|
|
144
|
+
/** Server snapshot of a fetched portfolio. Only its stock eligibility is ever sent back. */
|
|
112
145
|
#policy;
|
|
146
|
+
#authoredPolicy;
|
|
113
147
|
get policy() {
|
|
114
148
|
return this.#policy;
|
|
115
149
|
}
|
|
150
|
+
/** Stock eligibility this handle will submit; automated trading is never submitted. */
|
|
151
|
+
get authoredPolicy() {
|
|
152
|
+
if (this.#authoredPolicy)
|
|
153
|
+
return this.#authoredPolicy;
|
|
154
|
+
return this.#policy
|
|
155
|
+
? { stockEligibility: authorableEligibility(this.#policy.stockEligibility) }
|
|
156
|
+
: undefined;
|
|
157
|
+
}
|
|
158
|
+
/** Replace the authored stock eligibility. Omitted fields take the server defaults. */
|
|
159
|
+
setStockEligibility(stockEligibility) {
|
|
160
|
+
this.#authoredPolicy = parseAuthoredPolicy({
|
|
161
|
+
stockEligibility: stockEligibility,
|
|
162
|
+
});
|
|
163
|
+
return this;
|
|
164
|
+
}
|
|
116
165
|
#transport;
|
|
117
166
|
constructor(data, options = {}) {
|
|
118
167
|
const record = { ...data };
|
|
@@ -158,6 +207,9 @@ class PortfolioHandle {
|
|
|
158
207
|
if (isReadonlyPortfolioPolicy(record.policy)) {
|
|
159
208
|
this.#policy = record.policy;
|
|
160
209
|
}
|
|
210
|
+
else if (isJsonObject(record.policy)) {
|
|
211
|
+
this.#authoredPolicy = parseAuthoredPolicy(record.policy);
|
|
212
|
+
}
|
|
161
213
|
for (const [key, value] of Object.entries(record)) {
|
|
162
214
|
if (key === "name" ||
|
|
163
215
|
key === "initialValue" ||
|
|
@@ -225,6 +277,9 @@ class PortfolioHandle {
|
|
|
225
277
|
body.updatedAt = this.updatedAt;
|
|
226
278
|
if (this.brokerage !== undefined)
|
|
227
279
|
body.brokerage = this.brokerage;
|
|
280
|
+
const authored = this.authoredPolicy;
|
|
281
|
+
if (authored)
|
|
282
|
+
body.policy = authored;
|
|
228
283
|
return body;
|
|
229
284
|
}
|
|
230
285
|
async #resolveTransport(transport) {
|
package/dist/esm/client.d.ts
CHANGED
|
@@ -236,7 +236,7 @@ export interface CustomIndicatorInput {
|
|
|
236
236
|
description?: string;
|
|
237
237
|
scope?: "global" | "asset";
|
|
238
238
|
pointKind?: "observation" | "period_aggregate" | "disclosed";
|
|
239
|
-
aggregatePeriod?: "1d" | "1w" | "1mo" | "1q";
|
|
239
|
+
aggregatePeriod?: "1min" | "1d" | "1w" | "1mo" | "1q";
|
|
240
240
|
points?: ReadonlyArray<CustomIndicatorPointInput>;
|
|
241
241
|
}
|
|
242
242
|
type IndicatorPointKind = NonNullable<CustomIndicatorInput["pointKind"]>;
|
package/dist/esm/client.js
CHANGED
|
@@ -645,6 +645,29 @@ function pointKindPoints(points, pointKind, aggregatePeriod) {
|
|
|
645
645
|
}
|
|
646
646
|
return row;
|
|
647
647
|
}
|
|
648
|
+
if (aggregatePeriod === "1min") {
|
|
649
|
+
// One completed bar: timestamp is the bar open, available at bar close.
|
|
650
|
+
if (eventDay ||
|
|
651
|
+
!eventTime ||
|
|
652
|
+
eventTime.getUTCSeconds() !== 0 ||
|
|
653
|
+
eventTime.getUTCMilliseconds() !== 0) {
|
|
654
|
+
throw new Error(`Point ${index + 1}: 1min timestamp must be the bar-open instant with an explicit UTC offset and no seconds.`);
|
|
655
|
+
}
|
|
656
|
+
const barClose = new Date(eventTime.getTime() + 60_000);
|
|
657
|
+
if (row.availableAt === undefined) {
|
|
658
|
+
row.availableAt = barClose.toISOString();
|
|
659
|
+
}
|
|
660
|
+
else {
|
|
661
|
+
const explicit = availableDay ? addUtcDays(availableDay, 1) : availableTime;
|
|
662
|
+
if (!explicit || explicit.getTime() < barClose.getTime()) {
|
|
663
|
+
throw new Error(`Point ${index + 1}: availableAt precedes the 1min bar close.`);
|
|
664
|
+
}
|
|
665
|
+
if (availableDay) {
|
|
666
|
+
row.availableAt = utcMidnight(explicit);
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
return row;
|
|
670
|
+
}
|
|
648
671
|
if (!eventTime) {
|
|
649
672
|
throw new Error(`Point ${index + 1}: aggregate timestamp must be date-only or include an explicit UTC offset.`);
|
|
650
673
|
}
|
|
@@ -439,6 +439,29 @@ export interface Strategy {
|
|
|
439
439
|
/** Omitted means Market. Limit always requires an explicit price policy. */
|
|
440
440
|
orderExecution?: StrategyOrderExecutionPolicy;
|
|
441
441
|
}
|
|
442
|
+
export interface AuthoredIndustryFilter {
|
|
443
|
+
mode: "ALL" | "INCLUDE_ONLY";
|
|
444
|
+
match: "ANY" | "ALL";
|
|
445
|
+
industries: readonly string[];
|
|
446
|
+
}
|
|
447
|
+
/**
|
|
448
|
+
* Which stocks the portfolio's dynamic universes may select. Omitted fields keep
|
|
449
|
+
* the default: minimumMarketCapUsd 1_000_000_000, no maximum, every industry,
|
|
450
|
+
* missing caps EXCLUDE, one share class per company.
|
|
451
|
+
*/
|
|
452
|
+
export interface AuthoredStockEligibility {
|
|
453
|
+
minimumMarketCapUsd?: number;
|
|
454
|
+
maximumMarketCapUsd?: number | null;
|
|
455
|
+
industryFilter?: AuthoredIndustryFilter;
|
|
456
|
+
/** INCLUDE keeps names with no known market cap (most ETFs). */
|
|
457
|
+
missingMarketCapBehavior?: "EXCLUDE" | "INCLUDE";
|
|
458
|
+
/** ALL_CLASSES lets a pairs book hold both GOOG and GOOGL. */
|
|
459
|
+
shareClassBehavior?: "ONE_PER_COMPANY" | "ALL_CLASSES";
|
|
460
|
+
}
|
|
461
|
+
/** Automated trading is never authored: only the owner enables it, in the NexusTrade UI. */
|
|
462
|
+
export interface AuthoredPortfolioPolicy {
|
|
463
|
+
stockEligibility: AuthoredStockEligibility;
|
|
464
|
+
}
|
|
442
465
|
export interface Portfolio {
|
|
443
466
|
name: string;
|
|
444
467
|
initialValue?: number;
|
|
@@ -449,6 +472,7 @@ export interface Portfolio {
|
|
|
449
472
|
supportsFractionalShares?: boolean;
|
|
450
473
|
supportsCrypto?: boolean;
|
|
451
474
|
alertsEnabled?: boolean;
|
|
475
|
+
policy?: AuthoredPortfolioPolicy;
|
|
452
476
|
}
|
|
453
477
|
export type AssetType = "Stock" | "Cryptocurrency" | "Option" | "Other";
|
|
454
478
|
export type Interval = "Day" | "Hour" | "Minute";
|
|
@@ -673,6 +697,7 @@ export declare const portfolio: (name: string, strategies: Strategy[], options?:
|
|
|
673
697
|
supportsFractionalShares?: boolean;
|
|
674
698
|
supportsCrypto?: boolean;
|
|
675
699
|
alertsEnabled?: boolean;
|
|
700
|
+
policy?: AuthoredPortfolioPolicy;
|
|
676
701
|
}) => PortfolioHandle;
|
|
677
702
|
/**
|
|
678
703
|
* AbsoluteValue indicator.
|
|
@@ -1105,6 +1130,16 @@ export declare function MinimumPrice(asset: AssetArg, length?: number, interval?
|
|
|
1105
1130
|
* Minus indicator.
|
|
1106
1131
|
*/
|
|
1107
1132
|
export declare function Minus(left: Indicator, right: Indicator): Indicator;
|
|
1133
|
+
/**
|
|
1134
|
+
* MinuteBarHigh indicator.
|
|
1135
|
+
* @param asset Ticker name (ex. SPY, BTC)
|
|
1136
|
+
*/
|
|
1137
|
+
export declare function MinuteBarHigh(asset: AssetArg): Indicator;
|
|
1138
|
+
/**
|
|
1139
|
+
* MinuteBarLow indicator.
|
|
1140
|
+
* @param asset Ticker name (ex. SPY, BTC)
|
|
1141
|
+
*/
|
|
1142
|
+
export declare function MinuteBarLow(asset: AssetArg): Indicator;
|
|
1108
1143
|
/**
|
|
1109
1144
|
* MinutesAfterOpen indicator.
|
|
1110
1145
|
*/
|
|
@@ -1095,6 +1095,24 @@ export function Minus(left, right) {
|
|
|
1095
1095
|
d.indicators = [left, right];
|
|
1096
1096
|
return d;
|
|
1097
1097
|
}
|
|
1098
|
+
/**
|
|
1099
|
+
* MinuteBarHigh indicator.
|
|
1100
|
+
* @param asset Ticker name (ex. SPY, BTC)
|
|
1101
|
+
*/
|
|
1102
|
+
export function MinuteBarHigh(asset) {
|
|
1103
|
+
const d = { type: "MinuteBarHigh" };
|
|
1104
|
+
setAsset(d, "targetAsset", asset);
|
|
1105
|
+
return d;
|
|
1106
|
+
}
|
|
1107
|
+
/**
|
|
1108
|
+
* MinuteBarLow indicator.
|
|
1109
|
+
* @param asset Ticker name (ex. SPY, BTC)
|
|
1110
|
+
*/
|
|
1111
|
+
export function MinuteBarLow(asset) {
|
|
1112
|
+
const d = { type: "MinuteBarLow" };
|
|
1113
|
+
setAsset(d, "targetAsset", asset);
|
|
1114
|
+
return d;
|
|
1115
|
+
}
|
|
1098
1116
|
/**
|
|
1099
1117
|
* MinutesAfterOpen indicator.
|
|
1100
1118
|
*/
|
package/dist/esm/portfolio.d.ts
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* import this module without a cycle through `client.ts`.
|
|
10
10
|
*/
|
|
11
11
|
import { type JsonObject, type Transport } from "./client.ts";
|
|
12
|
-
import type { Portfolio, Strategy } from "./generated/ntSdk.generated.js";
|
|
12
|
+
import type { AuthoredPortfolioPolicy, AuthoredStockEligibility, Portfolio, Strategy } from "./generated/ntSdk.generated.js";
|
|
13
13
|
export type PortfolioType = "paper" | "live" | "chat";
|
|
14
14
|
export type DeployOutcome = "minted" | "reactivated" | "already_active" | "seed_recovered";
|
|
15
15
|
export interface DeployResult {
|
|
@@ -45,6 +45,8 @@ export interface ReadonlyPortfolioPolicy {
|
|
|
45
45
|
};
|
|
46
46
|
/** INCLUDE keeps names with no known market cap (ETFs, unsized filers); the politician copy bots use it. */
|
|
47
47
|
readonly missingMarketCapBehavior: "EXCLUDE" | "INCLUDE";
|
|
48
|
+
/** ONE_PER_COMPANY keeps one share class per company in a selection; ALL_CLASSES allows pairs such as GOOG/GOOGL. */
|
|
49
|
+
readonly shareClassBehavior: "ONE_PER_COMPANY" | "ALL_CLASSES";
|
|
48
50
|
readonly missingIndustryBehavior: "EXCLUDE_WHEN_FILTER_SET";
|
|
49
51
|
readonly appliesTo: "DYNAMIC_STOCK_UNIVERSES";
|
|
50
52
|
};
|
|
@@ -76,6 +78,10 @@ export declare class PortfolioHandle implements Portfolio {
|
|
|
76
78
|
updatedAt?: string;
|
|
77
79
|
brokerage?: string;
|
|
78
80
|
get policy(): ReadonlyPortfolioPolicy | undefined;
|
|
81
|
+
/** Stock eligibility this handle will submit; automated trading is never submitted. */
|
|
82
|
+
get authoredPolicy(): AuthoredPortfolioPolicy | undefined;
|
|
83
|
+
/** Replace the authored stock eligibility. Omitted fields take the server defaults. */
|
|
84
|
+
setStockEligibility(stockEligibility: AuthoredStockEligibility): this;
|
|
79
85
|
constructor(data: Portfolio | JsonObject, options?: PortfolioHandleOptions);
|
|
80
86
|
static from(data: Portfolio | JsonObject, options?: PortfolioHandleOptions): PortfolioHandle;
|
|
81
87
|
/** Omit `id` — class fields would otherwise serialize as `"id": null`. */
|
package/dist/esm/portfolio.js
CHANGED
|
@@ -39,6 +39,8 @@ function isReadonlyPortfolioPolicy(value) {
|
|
|
39
39
|
isStringArray(industry.industries) &&
|
|
40
40
|
(stock.missingMarketCapBehavior === "EXCLUDE" ||
|
|
41
41
|
stock.missingMarketCapBehavior === "INCLUDE") &&
|
|
42
|
+
(stock.shareClassBehavior === "ONE_PER_COMPANY" ||
|
|
43
|
+
stock.shareClassBehavior === "ALL_CLASSES") &&
|
|
42
44
|
stock.missingIndustryBehavior === "EXCLUDE_WHEN_FILTER_SET" &&
|
|
43
45
|
stock.appliesTo === "DYNAMIC_STOCK_UNIVERSES" &&
|
|
44
46
|
typeof automation.enabled === "boolean" &&
|
|
@@ -50,6 +52,37 @@ function isReadonlyPortfolioPolicy(value) {
|
|
|
50
52
|
automation.dailyWindow === "AMERICA_NEW_YORK_CALENDAR_DAY" &&
|
|
51
53
|
(value.updatedAt === undefined || typeof value.updatedAt === "string"));
|
|
52
54
|
}
|
|
55
|
+
const AUTOMATION_POLICY_KEYS = ["automatedApproval", "automationAcknowledged"];
|
|
56
|
+
/**
|
|
57
|
+
* An authored policy carries stock eligibility and nothing else. Automated
|
|
58
|
+
* trading is enabled only by the owner in the NexusTrade UI, so a policy that
|
|
59
|
+
* names it is refused here rather than sent.
|
|
60
|
+
*/
|
|
61
|
+
function parseAuthoredPolicy(value) {
|
|
62
|
+
if (AUTOMATION_POLICY_KEYS.some((key) => key in value)) {
|
|
63
|
+
throw new TypeError("Automated trading can only be changed by the portfolio owner in the NexusTrade UI; " +
|
|
64
|
+
"an authored policy may set only stockEligibility.");
|
|
65
|
+
}
|
|
66
|
+
const unknownKeys = Object.keys(value).filter((key) => key !== "stockEligibility");
|
|
67
|
+
if (unknownKeys.length || !isJsonObject(value.stockEligibility)) {
|
|
68
|
+
throw new TypeError("An authored policy must be { stockEligibility: {...} } and nothing else.");
|
|
69
|
+
}
|
|
70
|
+
return { stockEligibility: value.stockEligibility };
|
|
71
|
+
}
|
|
72
|
+
/** The authorable fields of a fetched policy's eligibility, for a copy. */
|
|
73
|
+
function authorableEligibility(stock) {
|
|
74
|
+
return {
|
|
75
|
+
minimumMarketCapUsd: stock.minimumMarketCapUsd,
|
|
76
|
+
maximumMarketCapUsd: stock.maximumMarketCapUsd,
|
|
77
|
+
industryFilter: {
|
|
78
|
+
mode: stock.industryFilter.mode,
|
|
79
|
+
match: stock.industryFilter.match,
|
|
80
|
+
industries: [...stock.industryFilter.industries],
|
|
81
|
+
},
|
|
82
|
+
missingMarketCapBehavior: stock.missingMarketCapBehavior,
|
|
83
|
+
shareClassBehavior: stock.shareClassBehavior,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
53
86
|
function encodePathSegment(value) {
|
|
54
87
|
return encodeURIComponent(value);
|
|
55
88
|
}
|
|
@@ -71,11 +104,27 @@ export class PortfolioHandle {
|
|
|
71
104
|
createdAt;
|
|
72
105
|
updatedAt;
|
|
73
106
|
brokerage;
|
|
74
|
-
/** Server
|
|
107
|
+
/** Server snapshot of a fetched portfolio. Only its stock eligibility is ever sent back. */
|
|
75
108
|
#policy;
|
|
109
|
+
#authoredPolicy;
|
|
76
110
|
get policy() {
|
|
77
111
|
return this.#policy;
|
|
78
112
|
}
|
|
113
|
+
/** Stock eligibility this handle will submit; automated trading is never submitted. */
|
|
114
|
+
get authoredPolicy() {
|
|
115
|
+
if (this.#authoredPolicy)
|
|
116
|
+
return this.#authoredPolicy;
|
|
117
|
+
return this.#policy
|
|
118
|
+
? { stockEligibility: authorableEligibility(this.#policy.stockEligibility) }
|
|
119
|
+
: undefined;
|
|
120
|
+
}
|
|
121
|
+
/** Replace the authored stock eligibility. Omitted fields take the server defaults. */
|
|
122
|
+
setStockEligibility(stockEligibility) {
|
|
123
|
+
this.#authoredPolicy = parseAuthoredPolicy({
|
|
124
|
+
stockEligibility: stockEligibility,
|
|
125
|
+
});
|
|
126
|
+
return this;
|
|
127
|
+
}
|
|
79
128
|
#transport;
|
|
80
129
|
constructor(data, options = {}) {
|
|
81
130
|
const record = { ...data };
|
|
@@ -121,6 +170,9 @@ export class PortfolioHandle {
|
|
|
121
170
|
if (isReadonlyPortfolioPolicy(record.policy)) {
|
|
122
171
|
this.#policy = record.policy;
|
|
123
172
|
}
|
|
173
|
+
else if (isJsonObject(record.policy)) {
|
|
174
|
+
this.#authoredPolicy = parseAuthoredPolicy(record.policy);
|
|
175
|
+
}
|
|
124
176
|
for (const [key, value] of Object.entries(record)) {
|
|
125
177
|
if (key === "name" ||
|
|
126
178
|
key === "initialValue" ||
|
|
@@ -188,6 +240,9 @@ export class PortfolioHandle {
|
|
|
188
240
|
body.updatedAt = this.updatedAt;
|
|
189
241
|
if (this.brokerage !== undefined)
|
|
190
242
|
body.brokerage = this.brokerage;
|
|
243
|
+
const authored = this.authoredPolicy;
|
|
244
|
+
if (authored)
|
|
245
|
+
body.policy = authored;
|
|
191
246
|
return body;
|
|
192
247
|
}
|
|
193
248
|
async #resolveTransport(transport) {
|