nexustrade 1.24.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 +40 -2
- package/dist/cjs/portfolio.js +58 -2
- package/dist/esm/client.d.ts +1 -1
- package/dist/esm/client.js +23 -0
- package/dist/esm/generated/ntSdk.generated.d.ts +46 -2
- package/dist/esm/generated/ntSdk.generated.js +37 -2
- package/dist/esm/portfolio.d.ts +9 -2
- package/dist/esm/portfolio.js +58 -2
- 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
|
}
|
|
@@ -56,6 +56,7 @@ exports.IndicatorStandardDeviation = IndicatorStandardDeviation;
|
|
|
56
56
|
exports.IndicatorWindowAgo = IndicatorWindowAgo;
|
|
57
57
|
exports.InitialValue = InitialValue;
|
|
58
58
|
exports.InsiderTrades = InsiderTrades;
|
|
59
|
+
exports.InstitutionalHoldings = InstitutionalHoldings;
|
|
59
60
|
exports.IsAsset = IsAsset;
|
|
60
61
|
exports.IsAssetType = IsAssetType;
|
|
61
62
|
exports.IsIndexMember = IsIndexMember;
|
|
@@ -75,6 +76,8 @@ exports.MaximumPrice = MaximumPrice;
|
|
|
75
76
|
exports.Min = Min;
|
|
76
77
|
exports.MinimumPrice = MinimumPrice;
|
|
77
78
|
exports.Minus = Minus;
|
|
79
|
+
exports.MinuteBarHigh = MinuteBarHigh;
|
|
80
|
+
exports.MinuteBarLow = MinuteBarLow;
|
|
78
81
|
exports.MinutesAfterOpen = MinutesAfterOpen;
|
|
79
82
|
exports.MinutesSinceAgent = MinutesSinceAgent;
|
|
80
83
|
exports.MinutesSinceAlert = MinutesSinceAlert;
|
|
@@ -1061,6 +1064,21 @@ function InsiderTrades(asset, metric = "NetValue", role = "Any", windowDays = 90
|
|
|
1061
1064
|
d["windowDays"] = windowDays;
|
|
1062
1065
|
return d;
|
|
1063
1066
|
}
|
|
1067
|
+
/**
|
|
1068
|
+
* InstitutionalHoldings indicator.
|
|
1069
|
+
* @param asset Ticker name (ex. SPY, BTC)
|
|
1070
|
+
* @param manager Optional: a CIK such as 1067983, or part of a manager's name such as Renaissance Technologies. Leave empty for every manager. A CIK is exact; a name can match several firms
|
|
1071
|
+
* @param metric Managers holding, shares or value held, concentration, or the change since the previous quarter
|
|
1072
|
+
* @param windowDays Read a disclosed period only if its filing became public within this many trailing days
|
|
1073
|
+
*/
|
|
1074
|
+
function InstitutionalHoldings(asset, manager, metric = "HolderCount", windowDays = 180) {
|
|
1075
|
+
const d = { type: "InstitutionalHoldings" };
|
|
1076
|
+
setAsset(d, "targetAsset", asset);
|
|
1077
|
+
d["manager"] = manager;
|
|
1078
|
+
d["metric"] = metric;
|
|
1079
|
+
d["windowDays"] = windowDays;
|
|
1080
|
+
return d;
|
|
1081
|
+
}
|
|
1064
1082
|
/**
|
|
1065
1083
|
* IsAsset indicator.
|
|
1066
1084
|
* @param matchAsset The specific asset to compare against (ex. UPRO, GLD)
|
|
@@ -1271,6 +1289,24 @@ function Minus(left, right) {
|
|
|
1271
1289
|
d.indicators = [left, right];
|
|
1272
1290
|
return d;
|
|
1273
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
|
+
}
|
|
1274
1310
|
/**
|
|
1275
1311
|
* MinutesAfterOpen indicator.
|
|
1276
1312
|
*/
|
|
@@ -1628,13 +1664,14 @@ function Plus(left, right) {
|
|
|
1628
1664
|
* PoliticalTrades indicator.
|
|
1629
1665
|
* @param asset Pass CANDIDATE inside a rebalance pipeline to bind each stock.
|
|
1630
1666
|
* @param filer Member full or last name. Pass an empty string for all members.
|
|
1631
|
-
* @param metric Amount-range aggregate, event count,
|
|
1667
|
+
* @param metric Amount-range aggregate, event count, distinct purchasing members, or Held: 1 while the member still holds the asset (latest public disclosure is a purchase or partial sale), ignoring the window.
|
|
1632
1668
|
* @param windowDays Trailing calendar days measured from when each event became public.
|
|
1633
1669
|
* @param amountBasis Range endpoint used by amount metrics; LowerBound is conservative.
|
|
1634
1670
|
* @param instrument Equity excludes confirmed option disclosures; Option selects them explicitly.
|
|
1635
1671
|
* @param chamber Optional advanced cohort filter; named-member requests should normally use All.
|
|
1672
|
+
* @param memberId Bioguide id such as P000197. Matches exactly and overrides filer, because names collide.
|
|
1636
1673
|
*/
|
|
1637
|
-
function PoliticalTrades(asset, filer, metric = "BuyAmount", windowDays = 90, amountBasis = "LowerBound", instrument = "Equity", chamber = "All") {
|
|
1674
|
+
function PoliticalTrades(asset, filer, metric = "BuyAmount", windowDays = 90, amountBasis = "LowerBound", instrument = "Equity", chamber = "All", memberId = "") {
|
|
1638
1675
|
const d = { type: "PoliticalTrades" };
|
|
1639
1676
|
setAsset(d, "targetAsset", asset);
|
|
1640
1677
|
d["filer"] = filer;
|
|
@@ -1643,6 +1680,7 @@ function PoliticalTrades(asset, filer, metric = "BuyAmount", windowDays = 90, am
|
|
|
1643
1680
|
d["amountBasis"] = amountBasis;
|
|
1644
1681
|
d["instrument"] = instrument;
|
|
1645
1682
|
d["chamber"] = chamber;
|
|
1683
|
+
d["memberId"] = memberId;
|
|
1646
1684
|
return d;
|
|
1647
1685
|
}
|
|
1648
1686
|
/**
|
package/dist/cjs/portfolio.js
CHANGED
|
@@ -74,7 +74,10 @@ function isReadonlyPortfolioPolicy(value) {
|
|
|
74
74
|
(industry.mode === "ALL" || industry.mode === "INCLUDE_ONLY") &&
|
|
75
75
|
(industry.match === "ANY" || industry.match === "ALL") &&
|
|
76
76
|
isStringArray(industry.industries) &&
|
|
77
|
-
stock.missingMarketCapBehavior === "EXCLUDE"
|
|
77
|
+
(stock.missingMarketCapBehavior === "EXCLUDE" ||
|
|
78
|
+
stock.missingMarketCapBehavior === "INCLUDE") &&
|
|
79
|
+
(stock.shareClassBehavior === "ONE_PER_COMPANY" ||
|
|
80
|
+
stock.shareClassBehavior === "ALL_CLASSES") &&
|
|
78
81
|
stock.missingIndustryBehavior === "EXCLUDE_WHEN_FILTER_SET" &&
|
|
79
82
|
stock.appliesTo === "DYNAMIC_STOCK_UNIVERSES" &&
|
|
80
83
|
typeof automation.enabled === "boolean" &&
|
|
@@ -86,6 +89,37 @@ function isReadonlyPortfolioPolicy(value) {
|
|
|
86
89
|
automation.dailyWindow === "AMERICA_NEW_YORK_CALENDAR_DAY" &&
|
|
87
90
|
(value.updatedAt === undefined || typeof value.updatedAt === "string"));
|
|
88
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
|
+
}
|
|
89
123
|
function encodePathSegment(value) {
|
|
90
124
|
return encodeURIComponent(value);
|
|
91
125
|
}
|
|
@@ -107,11 +141,27 @@ class PortfolioHandle {
|
|
|
107
141
|
createdAt;
|
|
108
142
|
updatedAt;
|
|
109
143
|
brokerage;
|
|
110
|
-
/** Server
|
|
144
|
+
/** Server snapshot of a fetched portfolio. Only its stock eligibility is ever sent back. */
|
|
111
145
|
#policy;
|
|
146
|
+
#authoredPolicy;
|
|
112
147
|
get policy() {
|
|
113
148
|
return this.#policy;
|
|
114
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
|
+
}
|
|
115
165
|
#transport;
|
|
116
166
|
constructor(data, options = {}) {
|
|
117
167
|
const record = { ...data };
|
|
@@ -157,6 +207,9 @@ class PortfolioHandle {
|
|
|
157
207
|
if (isReadonlyPortfolioPolicy(record.policy)) {
|
|
158
208
|
this.#policy = record.policy;
|
|
159
209
|
}
|
|
210
|
+
else if (isJsonObject(record.policy)) {
|
|
211
|
+
this.#authoredPolicy = parseAuthoredPolicy(record.policy);
|
|
212
|
+
}
|
|
160
213
|
for (const [key, value] of Object.entries(record)) {
|
|
161
214
|
if (key === "name" ||
|
|
162
215
|
key === "initialValue" ||
|
|
@@ -224,6 +277,9 @@ class PortfolioHandle {
|
|
|
224
277
|
body.updatedAt = this.updatedAt;
|
|
225
278
|
if (this.brokerage !== undefined)
|
|
226
279
|
body.brokerage = this.brokerage;
|
|
280
|
+
const authored = this.authoredPolicy;
|
|
281
|
+
if (authored)
|
|
282
|
+
body.policy = authored;
|
|
227
283
|
return body;
|
|
228
284
|
}
|
|
229
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.
|
|
@@ -981,6 +1006,14 @@ export declare function InitialValue(): Indicator;
|
|
|
981
1006
|
* @param windowDays Count trades whose filings became public within this many trailing days
|
|
982
1007
|
*/
|
|
983
1008
|
export declare function InsiderTrades(asset: AssetArg, metric?: "NetValue" | "BuyValue" | "SellValue" | "NetShares" | "BuyCount" | "SellCount" | "DistinctBuyers", role?: "Any" | "Officer" | "Director" | "TenPercentOwner", windowDays?: number): Indicator;
|
|
1009
|
+
/**
|
|
1010
|
+
* InstitutionalHoldings indicator.
|
|
1011
|
+
* @param asset Ticker name (ex. SPY, BTC)
|
|
1012
|
+
* @param manager Optional: a CIK such as 1067983, or part of a manager's name such as Renaissance Technologies. Leave empty for every manager. A CIK is exact; a name can match several firms
|
|
1013
|
+
* @param metric Managers holding, shares or value held, concentration, or the change since the previous quarter
|
|
1014
|
+
* @param windowDays Read a disclosed period only if its filing became public within this many trailing days
|
|
1015
|
+
*/
|
|
1016
|
+
export declare function InstitutionalHoldings(asset: AssetArg, manager: string, metric?: "HolderCount" | "TotalShares" | "TotalValue" | "ConcentrationTop5" | "NetShareChange" | "NetHolderChange" | "NewHolders" | "ClosedHolders", windowDays?: number): Indicator;
|
|
984
1017
|
/**
|
|
985
1018
|
* IsAsset indicator.
|
|
986
1019
|
* @param matchAsset The specific asset to compare against (ex. UPRO, GLD)
|
|
@@ -1097,6 +1130,16 @@ export declare function MinimumPrice(asset: AssetArg, length?: number, interval?
|
|
|
1097
1130
|
* Minus indicator.
|
|
1098
1131
|
*/
|
|
1099
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;
|
|
1100
1143
|
/**
|
|
1101
1144
|
* MinutesAfterOpen indicator.
|
|
1102
1145
|
*/
|
|
@@ -1289,13 +1332,14 @@ export declare function Plus(left: Indicator, right: Indicator): Indicator;
|
|
|
1289
1332
|
* PoliticalTrades indicator.
|
|
1290
1333
|
* @param asset Pass CANDIDATE inside a rebalance pipeline to bind each stock.
|
|
1291
1334
|
* @param filer Member full or last name. Pass an empty string for all members.
|
|
1292
|
-
* @param metric Amount-range aggregate, event count,
|
|
1335
|
+
* @param metric Amount-range aggregate, event count, distinct purchasing members, or Held: 1 while the member still holds the asset (latest public disclosure is a purchase or partial sale), ignoring the window.
|
|
1293
1336
|
* @param windowDays Trailing calendar days measured from when each event became public.
|
|
1294
1337
|
* @param amountBasis Range endpoint used by amount metrics; LowerBound is conservative.
|
|
1295
1338
|
* @param instrument Equity excludes confirmed option disclosures; Option selects them explicitly.
|
|
1296
1339
|
* @param chamber Optional advanced cohort filter; named-member requests should normally use All.
|
|
1340
|
+
* @param memberId Bioguide id such as P000197. Matches exactly and overrides filer, because names collide.
|
|
1297
1341
|
*/
|
|
1298
|
-
export declare function PoliticalTrades(asset: AssetArg, filer: string, metric?: "NetAmount" | "BuyAmount" | "SellAmount" | "BuyCount" | "SellCount" | "DistinctBuyers", windowDays?: number, amountBasis?: "LowerBound" | "Midpoint" | "UpperBound", instrument?: "Equity" | "Option" | "All", chamber?: "All" | "House" | "Senate"): Indicator;
|
|
1342
|
+
export declare function PoliticalTrades(asset: AssetArg, filer: string, metric?: "NetAmount" | "BuyAmount" | "SellAmount" | "BuyCount" | "SellCount" | "DistinctBuyers" | "Held", windowDays?: number, amountBasis?: "LowerBound" | "Midpoint" | "UpperBound", instrument?: "Equity" | "Option" | "All", chamber?: "All" | "House" | "Senate", memberId?: string): Indicator;
|
|
1299
1343
|
/**
|
|
1300
1344
|
* PortfolioValue indicator.
|
|
1301
1345
|
*/
|
|
@@ -870,6 +870,21 @@ export function InsiderTrades(asset, metric = "NetValue", role = "Any", windowDa
|
|
|
870
870
|
d["windowDays"] = windowDays;
|
|
871
871
|
return d;
|
|
872
872
|
}
|
|
873
|
+
/**
|
|
874
|
+
* InstitutionalHoldings indicator.
|
|
875
|
+
* @param asset Ticker name (ex. SPY, BTC)
|
|
876
|
+
* @param manager Optional: a CIK such as 1067983, or part of a manager's name such as Renaissance Technologies. Leave empty for every manager. A CIK is exact; a name can match several firms
|
|
877
|
+
* @param metric Managers holding, shares or value held, concentration, or the change since the previous quarter
|
|
878
|
+
* @param windowDays Read a disclosed period only if its filing became public within this many trailing days
|
|
879
|
+
*/
|
|
880
|
+
export function InstitutionalHoldings(asset, manager, metric = "HolderCount", windowDays = 180) {
|
|
881
|
+
const d = { type: "InstitutionalHoldings" };
|
|
882
|
+
setAsset(d, "targetAsset", asset);
|
|
883
|
+
d["manager"] = manager;
|
|
884
|
+
d["metric"] = metric;
|
|
885
|
+
d["windowDays"] = windowDays;
|
|
886
|
+
return d;
|
|
887
|
+
}
|
|
873
888
|
/**
|
|
874
889
|
* IsAsset indicator.
|
|
875
890
|
* @param matchAsset The specific asset to compare against (ex. UPRO, GLD)
|
|
@@ -1080,6 +1095,24 @@ export function Minus(left, right) {
|
|
|
1080
1095
|
d.indicators = [left, right];
|
|
1081
1096
|
return d;
|
|
1082
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
|
+
}
|
|
1083
1116
|
/**
|
|
1084
1117
|
* MinutesAfterOpen indicator.
|
|
1085
1118
|
*/
|
|
@@ -1437,13 +1470,14 @@ export function Plus(left, right) {
|
|
|
1437
1470
|
* PoliticalTrades indicator.
|
|
1438
1471
|
* @param asset Pass CANDIDATE inside a rebalance pipeline to bind each stock.
|
|
1439
1472
|
* @param filer Member full or last name. Pass an empty string for all members.
|
|
1440
|
-
* @param metric Amount-range aggregate, event count,
|
|
1473
|
+
* @param metric Amount-range aggregate, event count, distinct purchasing members, or Held: 1 while the member still holds the asset (latest public disclosure is a purchase or partial sale), ignoring the window.
|
|
1441
1474
|
* @param windowDays Trailing calendar days measured from when each event became public.
|
|
1442
1475
|
* @param amountBasis Range endpoint used by amount metrics; LowerBound is conservative.
|
|
1443
1476
|
* @param instrument Equity excludes confirmed option disclosures; Option selects them explicitly.
|
|
1444
1477
|
* @param chamber Optional advanced cohort filter; named-member requests should normally use All.
|
|
1478
|
+
* @param memberId Bioguide id such as P000197. Matches exactly and overrides filer, because names collide.
|
|
1445
1479
|
*/
|
|
1446
|
-
export function PoliticalTrades(asset, filer, metric = "BuyAmount", windowDays = 90, amountBasis = "LowerBound", instrument = "Equity", chamber = "All") {
|
|
1480
|
+
export function PoliticalTrades(asset, filer, metric = "BuyAmount", windowDays = 90, amountBasis = "LowerBound", instrument = "Equity", chamber = "All", memberId = "") {
|
|
1447
1481
|
const d = { type: "PoliticalTrades" };
|
|
1448
1482
|
setAsset(d, "targetAsset", asset);
|
|
1449
1483
|
d["filer"] = filer;
|
|
@@ -1452,6 +1486,7 @@ export function PoliticalTrades(asset, filer, metric = "BuyAmount", windowDays =
|
|
|
1452
1486
|
d["amountBasis"] = amountBasis;
|
|
1453
1487
|
d["instrument"] = instrument;
|
|
1454
1488
|
d["chamber"] = chamber;
|
|
1489
|
+
d["memberId"] = memberId;
|
|
1455
1490
|
return d;
|
|
1456
1491
|
}
|
|
1457
1492
|
/**
|
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 {
|
|
@@ -43,7 +43,10 @@ export interface ReadonlyPortfolioPolicy {
|
|
|
43
43
|
readonly match: "ANY" | "ALL";
|
|
44
44
|
readonly industries: readonly string[];
|
|
45
45
|
};
|
|
46
|
-
|
|
46
|
+
/** INCLUDE keeps names with no known market cap (ETFs, unsized filers); the politician copy bots use it. */
|
|
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";
|
|
47
50
|
readonly missingIndustryBehavior: "EXCLUDE_WHEN_FILTER_SET";
|
|
48
51
|
readonly appliesTo: "DYNAMIC_STOCK_UNIVERSES";
|
|
49
52
|
};
|
|
@@ -75,6 +78,10 @@ export declare class PortfolioHandle implements Portfolio {
|
|
|
75
78
|
updatedAt?: string;
|
|
76
79
|
brokerage?: string;
|
|
77
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;
|
|
78
85
|
constructor(data: Portfolio | JsonObject, options?: PortfolioHandleOptions);
|
|
79
86
|
static from(data: Portfolio | JsonObject, options?: PortfolioHandleOptions): PortfolioHandle;
|
|
80
87
|
/** Omit `id` — class fields would otherwise serialize as `"id": null`. */
|
package/dist/esm/portfolio.js
CHANGED
|
@@ -37,7 +37,10 @@ function isReadonlyPortfolioPolicy(value) {
|
|
|
37
37
|
(industry.mode === "ALL" || industry.mode === "INCLUDE_ONLY") &&
|
|
38
38
|
(industry.match === "ANY" || industry.match === "ALL") &&
|
|
39
39
|
isStringArray(industry.industries) &&
|
|
40
|
-
stock.missingMarketCapBehavior === "EXCLUDE"
|
|
40
|
+
(stock.missingMarketCapBehavior === "EXCLUDE" ||
|
|
41
|
+
stock.missingMarketCapBehavior === "INCLUDE") &&
|
|
42
|
+
(stock.shareClassBehavior === "ONE_PER_COMPANY" ||
|
|
43
|
+
stock.shareClassBehavior === "ALL_CLASSES") &&
|
|
41
44
|
stock.missingIndustryBehavior === "EXCLUDE_WHEN_FILTER_SET" &&
|
|
42
45
|
stock.appliesTo === "DYNAMIC_STOCK_UNIVERSES" &&
|
|
43
46
|
typeof automation.enabled === "boolean" &&
|
|
@@ -49,6 +52,37 @@ function isReadonlyPortfolioPolicy(value) {
|
|
|
49
52
|
automation.dailyWindow === "AMERICA_NEW_YORK_CALENDAR_DAY" &&
|
|
50
53
|
(value.updatedAt === undefined || typeof value.updatedAt === "string"));
|
|
51
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
|
+
}
|
|
52
86
|
function encodePathSegment(value) {
|
|
53
87
|
return encodeURIComponent(value);
|
|
54
88
|
}
|
|
@@ -70,11 +104,27 @@ export class PortfolioHandle {
|
|
|
70
104
|
createdAt;
|
|
71
105
|
updatedAt;
|
|
72
106
|
brokerage;
|
|
73
|
-
/** Server
|
|
107
|
+
/** Server snapshot of a fetched portfolio. Only its stock eligibility is ever sent back. */
|
|
74
108
|
#policy;
|
|
109
|
+
#authoredPolicy;
|
|
75
110
|
get policy() {
|
|
76
111
|
return this.#policy;
|
|
77
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
|
+
}
|
|
78
128
|
#transport;
|
|
79
129
|
constructor(data, options = {}) {
|
|
80
130
|
const record = { ...data };
|
|
@@ -120,6 +170,9 @@ export class PortfolioHandle {
|
|
|
120
170
|
if (isReadonlyPortfolioPolicy(record.policy)) {
|
|
121
171
|
this.#policy = record.policy;
|
|
122
172
|
}
|
|
173
|
+
else if (isJsonObject(record.policy)) {
|
|
174
|
+
this.#authoredPolicy = parseAuthoredPolicy(record.policy);
|
|
175
|
+
}
|
|
123
176
|
for (const [key, value] of Object.entries(record)) {
|
|
124
177
|
if (key === "name" ||
|
|
125
178
|
key === "initialValue" ||
|
|
@@ -187,6 +240,9 @@ export class PortfolioHandle {
|
|
|
187
240
|
body.updatedAt = this.updatedAt;
|
|
188
241
|
if (this.brokerage !== undefined)
|
|
189
242
|
body.brokerage = this.brokerage;
|
|
243
|
+
const authored = this.authoredPolicy;
|
|
244
|
+
if (authored)
|
|
245
|
+
body.policy = authored;
|
|
190
246
|
return body;
|
|
191
247
|
}
|
|
192
248
|
async #resolveTransport(transport) {
|