nexustrade 5.2.2 → 5.3.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 +134 -1
- package/dist/cjs/client.js +97 -0
- package/dist/cjs/congress.js +29 -0
- package/dist/esm/client.d.ts +60 -1
- package/dist/esm/client.js +97 -0
- package/dist/esm/congress.d.ts +390 -0
- package/dist/esm/congress.js +26 -0
- package/dist/esm/index.d.ts +2 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -771,6 +771,120 @@ Branch on `result.outcome`, not on status alone:
|
|
|
771
771
|
|
|
772
772
|
This method spends LLM credits.
|
|
773
773
|
|
|
774
|
+
## Congressional trades
|
|
775
|
+
|
|
776
|
+
House and Senate stock disclosures (STOCK Act periodic transaction reports) are
|
|
777
|
+
readable as data, separately from the `PoliticalTrades` strategy indicators.
|
|
778
|
+
The client calls NexusTrade's REST API at `/api/political-disclosures`, on the
|
|
779
|
+
same host as the SDK routes.
|
|
780
|
+
|
|
781
|
+
Seven reads work with no API key and no workspace, so a bare client is enough:
|
|
782
|
+
|
|
783
|
+
```ts
|
|
784
|
+
import { NexusTradeClient } from "nexustrade";
|
|
785
|
+
|
|
786
|
+
const client = new NexusTradeClient(); // no API key needed for these reads
|
|
787
|
+
|
|
788
|
+
const page = await client.listCongressionalTrades({
|
|
789
|
+
ticker: "NVDA",
|
|
790
|
+
fromDate: "2026-01-01",
|
|
791
|
+
limit: 5,
|
|
792
|
+
});
|
|
793
|
+
for (const trade of page.data.trades) {
|
|
794
|
+
console.log(
|
|
795
|
+
trade.availableAt, // public from here: the date to trade from
|
|
796
|
+
trade.filerName,
|
|
797
|
+
trade.action,
|
|
798
|
+
trade.ticker,
|
|
799
|
+
trade.amountBracket
|
|
800
|
+
);
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
// Next page: the same filters plus the cursor.
|
|
804
|
+
if (page.data.nextCursor) {
|
|
805
|
+
await client.listCongressionalTrades({
|
|
806
|
+
ticker: "NVDA",
|
|
807
|
+
fromDate: "2026-01-01",
|
|
808
|
+
limit: 5,
|
|
809
|
+
cursor: page.data.nextCursor,
|
|
810
|
+
});
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
const pelosi = await client.getPolitician("nancy-pelosi");
|
|
814
|
+
console.log(pelosi.data.politician.displayName, pelosi.data.profile.summary);
|
|
815
|
+
|
|
816
|
+
const board = await client.getCongressionalLeaderboard({ limit: 5 });
|
|
817
|
+
console.log(board.best.map((row) => [row.displayName, row.excessReturn]));
|
|
818
|
+
|
|
819
|
+
const slowest = await client.listCongressionalFilingLatency({ limit: 5 });
|
|
820
|
+
console.log(slowest.data.map((row) => [row.displayName, row.medianDaysToPublic]));
|
|
821
|
+
```
|
|
822
|
+
|
|
823
|
+
**Trade from `availableAt`.** Each trade carries `transactionDate` (when the
|
|
824
|
+
member traded) and `availableAt` (when the disclosure became public). The gap is
|
|
825
|
+
usually weeks. A backtest or signal that acts on `transactionDate` uses
|
|
826
|
+
information nobody outside Congress had, so every date filter here
|
|
827
|
+
(`fromDate`, `toDate`, `asOf`) is compared against a public date, never the trade
|
|
828
|
+
date. `fromDate`, `toDate` and `sort` use `firstAvailableAt`, the day the first
|
|
829
|
+
version of a disclosure became public. It equals `availableAt` unless the
|
|
830
|
+
disclosure was later amended.
|
|
831
|
+
|
|
832
|
+
Filters, all optional: `q` (free text; a phrase naming exactly one member
|
|
833
|
+
resolves to that member), `filerKey` (Bioguide ID such as `P000197`), `ticker`,
|
|
834
|
+
`chamber` (`house`, `senate`, `all`), `action` (`purchase`, `sale`, `exchange`,
|
|
835
|
+
`unmarked`, `all`), `instrument` (`equity`, `option`, `fund`, `bond`, `other`,
|
|
836
|
+
`all`), `sort` (`newest`, `oldest`), `fromDate` / `toDate` (`YYYY-MM-DD`), `asOf` (ISO
|
|
837
|
+
timestamp; reads the record as it was publicly known then), `cursor` and
|
|
838
|
+
`limit` (1 to 100, default 25). `toDate` defaults to the day of `asOf`, which
|
|
839
|
+
defaults to the dataset's last update (`dataUpdatedAt`), and `fromDate` defaults
|
|
840
|
+
to 29 days before `toDate`, so with no dates the feed covers the 30 days ending
|
|
841
|
+
on the last update day. `instrument` defaults to `equity`. Amounts are the disclosed brackets (`amountLow`,
|
|
842
|
+
`amountHigh`), never exact figures.
|
|
843
|
+
|
|
844
|
+
Each method takes the filters its route reads. The summary takes no `sort`,
|
|
845
|
+
`cursor` or `limit`. The filer, filing latency and volume lists take `limit`
|
|
846
|
+
but no `sort` or `cursor`. The member records (`getPolitician`,
|
|
847
|
+
`getCongressionalFiler`) take `ticker`, `action`, `instrument`, `sort`, the
|
|
848
|
+
dates, `cursor` and `limit`; with neither date they cover the whole record,
|
|
849
|
+
2012-01-01 to today, and `instrument` defaults to `all`.
|
|
850
|
+
|
|
851
|
+
Every read except the leaderboard and the copy bot returns an envelope:
|
|
852
|
+
`data`, plus `snapshotId`, `asOf`, `dataUpdatedAt`, `stale`, `cache`,
|
|
853
|
+
`coverage` and the applied `filters`.
|
|
854
|
+
|
|
855
|
+
The detail and coverage reads need an API key with the `read` scope. Without
|
|
856
|
+
one they raise `NexusTradeApiError` with status 401. The client sends its key
|
|
857
|
+
on every read when it holds one, so a key that is supplied must be valid and
|
|
858
|
+
have the `read` scope even on the calls that need no key.
|
|
859
|
+
|
|
860
|
+
```ts
|
|
861
|
+
const authed = new NexusTradeClient({ apiKey: process.env.NEXUSTRADE_API_KEY });
|
|
862
|
+
|
|
863
|
+
const detail = await authed.getCongressionalTrade("house:20035831:0");
|
|
864
|
+
console.log(detail.data.current, detail.data.history.length);
|
|
865
|
+
|
|
866
|
+
const coverage = await authed.getCongressionalCoverage();
|
|
867
|
+
console.log(coverage.data.events, coverage.data.latestAvailableAt);
|
|
868
|
+
```
|
|
869
|
+
|
|
870
|
+
| Method | Endpoint | API key |
|
|
871
|
+
| --- | --- | --- |
|
|
872
|
+
| `listCongressionalTrades` | `GET /trades` | No |
|
|
873
|
+
| `getCongressionalTradeSummary` | `GET /summary` | No |
|
|
874
|
+
| `getCongressionalLeaderboard` | `GET /leaderboard` | No |
|
|
875
|
+
| `listCongressionalFilingLatency` | `GET /filer-latency` | No |
|
|
876
|
+
| `listCongressionalTradeVolume` | `GET /filer-volume` | No |
|
|
877
|
+
| `getPolitician` | `GET /politicians/:id` | No |
|
|
878
|
+
| `getPoliticianBot` | `GET /politicians/:id/bot` | No |
|
|
879
|
+
| `listCongressionalFilers` | `GET /filers` | Yes |
|
|
880
|
+
| `getCongressionalFiler` | `GET /filers/:filerKey` | Yes |
|
|
881
|
+
| `getCongressionalTrade` | `GET /trades/:eventId` | Yes |
|
|
882
|
+
| `getCongressionalFiling` | `GET /filings/:chamber/:docId` | Yes |
|
|
883
|
+
| `getCongressionalCoverage` | `GET /coverage` | Yes |
|
|
884
|
+
|
|
885
|
+
`getPoliticianBot` returns a `sharedPortfolioId` you can pass to
|
|
886
|
+
`forkPublicPortfolio` to copy that member's bot into your workspace.
|
|
887
|
+
|
|
774
888
|
## Managed watchlist universes
|
|
775
889
|
|
|
776
890
|
`nt.updateWatchlist({watchlistKey, memberId, instrument, amountBasis, chamber, output})`
|
|
@@ -923,6 +1037,23 @@ is missing here, so this list cannot drift from the code.
|
|
|
923
1037
|
| `exportWorkspaceSession()` | Export an anonymous workspace for later use |
|
|
924
1038
|
| `importWorkspaceSession(token)` | Resume an existing anonymous workspace |
|
|
925
1039
|
|
|
1040
|
+
**Congressional trades**
|
|
1041
|
+
|
|
1042
|
+
| Method | Purpose |
|
|
1043
|
+
| --- | --- |
|
|
1044
|
+
| `listCongressionalTrades({ ticker, fromDate, cursor, … })` | Disclosed trades, newest first (no API key) |
|
|
1045
|
+
| `getCongressionalTradeSummary({ … })` | Purchase and sale totals over the same filters (no API key) |
|
|
1046
|
+
| `getCongressionalLeaderboard({ limit })` | Members ranked by their copy bot against SPY (no API key) |
|
|
1047
|
+
| `listCongressionalFilingLatency({ … })` | Days from trade to public disclosure per member (no API key) |
|
|
1048
|
+
| `listCongressionalTradeVolume({ … })` | Disclosed dollar volume per member (no API key) |
|
|
1049
|
+
| `getPolitician(id, { … })` | One member's profile and trading record (no API key) |
|
|
1050
|
+
| `getPoliticianBot(id)` | A member's copy bot and cached backtest (no API key) |
|
|
1051
|
+
| `listCongressionalFilers({ … })` | Members with matching disclosures (API key) |
|
|
1052
|
+
| `getCongressionalFiler(filerKey, { … })` | One member's record by Bioguide ID (API key) |
|
|
1053
|
+
| `getCongressionalTrade(eventId, { asOf })` | One disclosure with its amendment history (API key) |
|
|
1054
|
+
| `getCongressionalFiling(chamber, docId)` | One source filing and its trades (API key) |
|
|
1055
|
+
| `getCongressionalCoverage()` | How much of the public record the dataset holds (API key) |
|
|
1056
|
+
|
|
926
1057
|
**PortfolioHandle** — returned by the `portfolio(...)` builder and by
|
|
927
1058
|
`getPortfolio` / `listPortfolios`.
|
|
928
1059
|
|
|
@@ -1063,7 +1194,9 @@ configures its own timeout, so passing both throws.
|
|
|
1063
1194
|
|
|
1064
1195
|
Portfolio drafting, backtesting, optimization, walk-forward studies, and the
|
|
1065
1196
|
natural-language screener, versioned under `/api/v1/nexustrade`. Market data is
|
|
1066
|
-
available only through the natural-language screener.
|
|
1197
|
+
available only through the natural-language screener. Congressional trade
|
|
1198
|
+
disclosures are the exception: they are read from `/api/political-disclosures`
|
|
1199
|
+
(see [Congressional trades](#congressional-trades)).
|
|
1067
1200
|
The full surface requires a registered API key; anonymous workspaces are limited
|
|
1068
1201
|
to portfolio authoring/forking, backtests, and programmatic agent/chat calls.
|
|
1069
1202
|
Creating a live deployment remains outside this surface.
|
package/dist/cjs/client.js
CHANGED
|
@@ -12,6 +12,7 @@ exports.clientTransport = clientTransport;
|
|
|
12
12
|
exports.createCustomIndicator = createCustomIndicator;
|
|
13
13
|
exports.createPortfolio = createPortfolio;
|
|
14
14
|
const agent_ts_1 = require("./agent.js");
|
|
15
|
+
const congress_ts_1 = require("./congress.js");
|
|
15
16
|
const env_ts_1 = require("./env.js");
|
|
16
17
|
const portfolio_ts_1 = require("./portfolio.js");
|
|
17
18
|
/** Boundary adapter: builder output is JSON by construction. */
|
|
@@ -162,6 +163,15 @@ function sameOrigin(left, right) {
|
|
|
162
163
|
function supportsUpload(transport) {
|
|
163
164
|
return typeof transport.putBytes === "function";
|
|
164
165
|
}
|
|
166
|
+
function supportsPublicApi(transport) {
|
|
167
|
+
return typeof transport.getPublicApi === "function";
|
|
168
|
+
}
|
|
169
|
+
async function readPublicApi(transport, path) {
|
|
170
|
+
if (!supportsPublicApi(transport)) {
|
|
171
|
+
throw new NexusTradeApiError(exports.NO_HTTP_STATUS, "unsupported_transport", "Congressional trade reads require HttpTransport.getPublicApi.");
|
|
172
|
+
}
|
|
173
|
+
return (await transport.getPublicApi(path));
|
|
174
|
+
}
|
|
165
175
|
function assertValidApiKey(apiKey) {
|
|
166
176
|
const invalid = typeof apiKey !== "string" ||
|
|
167
177
|
apiKey.length === 0 ||
|
|
@@ -274,6 +284,10 @@ async function apiErrorFromResponse(response) {
|
|
|
274
284
|
if (body.message)
|
|
275
285
|
message = String(body.message);
|
|
276
286
|
}
|
|
287
|
+
else if (typeof decoded.message === "string" && decoded.message) {
|
|
288
|
+
// Public REST routes answer `{ message }` with no error envelope.
|
|
289
|
+
message = decoded.message;
|
|
290
|
+
}
|
|
277
291
|
}
|
|
278
292
|
catch {
|
|
279
293
|
// Non-JSON error bodies keep the transport-level code/message.
|
|
@@ -290,6 +304,9 @@ function workspaceSessionUrl(baseUrl) {
|
|
|
290
304
|
parsed.hash = "";
|
|
291
305
|
return parsed.toString();
|
|
292
306
|
}
|
|
307
|
+
function publicApiUrl(baseUrl, path) {
|
|
308
|
+
return `${new URL(baseUrl).origin}/api/${path.replace(/^\/+/, "")}`;
|
|
309
|
+
}
|
|
293
310
|
function supportsWorkspaceSession(transport) {
|
|
294
311
|
const candidate = transport;
|
|
295
312
|
return (typeof candidate.exportWorkspaceSession === "function" &&
|
|
@@ -450,6 +467,16 @@ class HttpTransport {
|
|
|
450
467
|
if (options.idempotencyKey !== undefined) {
|
|
451
468
|
headers["Idempotency-Key"] = options.idempotencyKey;
|
|
452
469
|
}
|
|
470
|
+
return this.#send(method, url, headers, payload);
|
|
471
|
+
}
|
|
472
|
+
async getPublicApi(path) {
|
|
473
|
+
const headers = { Accept: "application/json" };
|
|
474
|
+
if (this.#apiKey !== undefined) {
|
|
475
|
+
headers.Authorization = `Bearer ${this.#apiKey}`;
|
|
476
|
+
}
|
|
477
|
+
return this.#send("GET", publicApiUrl(this.#baseUrl, path), headers);
|
|
478
|
+
}
|
|
479
|
+
async #send(method, url, headers, payload) {
|
|
453
480
|
const controller = new AbortController();
|
|
454
481
|
const timer = setTimeout(() => controller.abort(), this.#timeoutSeconds * 1000);
|
|
455
482
|
try {
|
|
@@ -1431,6 +1458,76 @@ class NexusTradeClient {
|
|
|
1431
1458
|
async waitForNlScreen(screenId, options = {}) {
|
|
1432
1459
|
return waitForOperation((id) => this.getNlScreen(id), screenId, options);
|
|
1433
1460
|
}
|
|
1461
|
+
/**
|
|
1462
|
+
* Congressional trade disclosures, newest first. No API key required.
|
|
1463
|
+
*
|
|
1464
|
+
* Defaults to equities first made public in the 30 days ending on the
|
|
1465
|
+
* dataset's last update day. `fromDate` and `toDate` filter on
|
|
1466
|
+
* `firstAvailableAt`. Trade from `availableAt`, when the disclosure became
|
|
1467
|
+
* public, never `transactionDate`.
|
|
1468
|
+
*/
|
|
1469
|
+
async listCongressionalTrades(options = {}) {
|
|
1470
|
+
return readPublicApi(this.transport, `political-disclosures/trades${encodeQuery((0, congress_ts_1.congressionalQueryParams)(options))}`);
|
|
1471
|
+
}
|
|
1472
|
+
/** Purchase and sale totals over the same filters as the feed. No API key required. */
|
|
1473
|
+
async getCongressionalTradeSummary(filters = {}) {
|
|
1474
|
+
return readPublicApi(this.transport, `political-disclosures/summary${encodeQuery((0, congress_ts_1.congressionalQueryParams)(filters))}`);
|
|
1475
|
+
}
|
|
1476
|
+
/** Members ranked by their copy bot's cached backtest against SPY. No API key required. */
|
|
1477
|
+
async getCongressionalLeaderboard(options = {}) {
|
|
1478
|
+
return readPublicApi(this.transport, `political-disclosures/leaderboard${encodeQuery({
|
|
1479
|
+
limit: options.limit === undefined ? undefined : String(options.limit),
|
|
1480
|
+
})}`);
|
|
1481
|
+
}
|
|
1482
|
+
/** Days from trade to public disclosure per member, slowest first. No API key required. */
|
|
1483
|
+
async listCongressionalFilingLatency(filters = {}) {
|
|
1484
|
+
return readPublicApi(this.transport, `political-disclosures/filer-latency${encodeQuery((0, congress_ts_1.congressionalQueryParams)(filters))}`);
|
|
1485
|
+
}
|
|
1486
|
+
/** Disclosed dollar volume per member, largest first. No API key required. */
|
|
1487
|
+
async listCongressionalTradeVolume(filters = {}) {
|
|
1488
|
+
return readPublicApi(this.transport, `political-disclosures/filer-volume${encodeQuery((0, congress_ts_1.congressionalQueryParams)(filters))}`);
|
|
1489
|
+
}
|
|
1490
|
+
/**
|
|
1491
|
+
* One member's profile and whole trading record. No API key required.
|
|
1492
|
+
*
|
|
1493
|
+
* `id` is a Bioguide ID (`"P000197"`) or a page slug (`"nancy-pelosi"`).
|
|
1494
|
+
* With neither date the record runs from 2012-01-01 to today, and
|
|
1495
|
+
* `instrument` defaults to `"all"`.
|
|
1496
|
+
*/
|
|
1497
|
+
async getPolitician(id, options = {}) {
|
|
1498
|
+
return readPublicApi(this.transport, `political-disclosures/politicians/${encodePathSegment(id)}${encodeQuery((0, congress_ts_1.congressionalQueryParams)(options))}`);
|
|
1499
|
+
}
|
|
1500
|
+
/** A member's copy bot and its cached backtest. No API key required. */
|
|
1501
|
+
async getPoliticianBot(id) {
|
|
1502
|
+
return readPublicApi(this.transport, `political-disclosures/politicians/${encodePathSegment(id)}/bot`);
|
|
1503
|
+
}
|
|
1504
|
+
/** Members with disclosures matching the filters. Requires an API key. */
|
|
1505
|
+
async listCongressionalFilers(filters = {}) {
|
|
1506
|
+
return readPublicApi(this.transport, `political-disclosures/filers${encodeQuery((0, congress_ts_1.congressionalQueryParams)(filters))}`);
|
|
1507
|
+
}
|
|
1508
|
+
/**
|
|
1509
|
+
* One member's summary, activity and trades by Bioguide ID. Requires an API key.
|
|
1510
|
+
*
|
|
1511
|
+
* With neither date the record runs from 2012-01-01 to today, and
|
|
1512
|
+
* `instrument` defaults to `"all"`.
|
|
1513
|
+
*/
|
|
1514
|
+
async getCongressionalFiler(filerKey, options = {}) {
|
|
1515
|
+
return readPublicApi(this.transport, `political-disclosures/filers/${encodePathSegment(filerKey)}${encodeQuery((0, congress_ts_1.congressionalQueryParams)(options))}`);
|
|
1516
|
+
}
|
|
1517
|
+
/** One disclosure with its amendment history. Requires an API key. */
|
|
1518
|
+
async getCongressionalTrade(eventId, options = {}) {
|
|
1519
|
+
return readPublicApi(this.transport, `political-disclosures/trades/${encodePathSegment(eventId)}${encodeQuery({
|
|
1520
|
+
asOf: options.asOf,
|
|
1521
|
+
})}`);
|
|
1522
|
+
}
|
|
1523
|
+
/** One source filing and every trade it disclosed. Requires an API key. */
|
|
1524
|
+
async getCongressionalFiling(chamber, docId) {
|
|
1525
|
+
return readPublicApi(this.transport, `political-disclosures/filings/${encodePathSegment(chamber)}/${encodePathSegment(docId)}`);
|
|
1526
|
+
}
|
|
1527
|
+
/** How much of the public record the dataset holds. Requires an API key. */
|
|
1528
|
+
async getCongressionalCoverage() {
|
|
1529
|
+
return readPublicApi(this.transport, "political-disclosures/coverage");
|
|
1530
|
+
}
|
|
1434
1531
|
/** Resolve once a backtest is terminal. See `waitForOperation`. */
|
|
1435
1532
|
async waitForBacktest(backtestId, options = {}) {
|
|
1436
1533
|
return waitForOperation((id) => this.getBacktest(id), backtestId, options);
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Congressional (STOCK Act) disclosure types for the public REST API at
|
|
4
|
+
* `/api/political-disclosures`.
|
|
5
|
+
*
|
|
6
|
+
* `availableAt` is when a disclosure became public. It is the only date a
|
|
7
|
+
* strategy may act on: `transactionDate` is when the member traded, typically
|
|
8
|
+
* weeks before anyone outside Congress could know. Date filters and `sort` use
|
|
9
|
+
* `firstAvailableAt`, when the first version of a disclosure became public.
|
|
10
|
+
*/
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.congressionalQueryParams = congressionalQueryParams;
|
|
13
|
+
/** Query pairs in one fixed order, so both SDKs put the same bytes on the wire. */
|
|
14
|
+
function congressionalQueryParams(options) {
|
|
15
|
+
return {
|
|
16
|
+
q: options.q,
|
|
17
|
+
filerKey: options.filerKey,
|
|
18
|
+
ticker: options.ticker,
|
|
19
|
+
chamber: options.chamber,
|
|
20
|
+
action: options.action,
|
|
21
|
+
instrument: options.instrument,
|
|
22
|
+
sort: options.sort,
|
|
23
|
+
from: options.fromDate,
|
|
24
|
+
to: options.toDate,
|
|
25
|
+
asOf: options.asOf,
|
|
26
|
+
cursor: options.cursor,
|
|
27
|
+
limit: options.limit === undefined ? undefined : String(options.limit),
|
|
28
|
+
};
|
|
29
|
+
}
|
package/dist/esm/client.d.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* pass an API key/base URL, or set NEXUSTRADE_API_KEY / NEXUSTRADE_API_BASE_URL.
|
|
6
6
|
*/
|
|
7
7
|
import { AgentRun } from "./agent.ts";
|
|
8
|
+
import { type CongressChamber, type CongressionalCoverage, type CongressionalEnvelope, type CongressionalFiler, type CongressionalFilerDetail, type CongressionalFilerListOptions, type CongressionalFilerVolume, type CongressionalFiling, type CongressionalFilingLatency, type CongressionalLeaderboard, type CongressionalMemberRecordOptions, type CongressionalTradeDetail, type CongressionalTradeFilters, type CongressionalTradePage, type CongressionalTradeSummary, type ListCongressionalTradesOptions, type PoliticianBot, type PoliticianProfile } from "./congress.ts";
|
|
8
9
|
import type { JobRequest, OrderStatus, Portfolio, Strategy } from "./generated/ntSdk.generated.js";
|
|
9
10
|
import { PortfolioHandle, type DeployResult, type PortfolioListResult } from "./portfolio.ts";
|
|
10
11
|
export type JsonValue = string | number | boolean | null | JsonValue[] | {
|
|
@@ -149,6 +150,17 @@ export interface UploadTransport extends Transport {
|
|
|
149
150
|
contentType: string;
|
|
150
151
|
}): Promise<void>;
|
|
151
152
|
}
|
|
153
|
+
/**
|
|
154
|
+
* Transports that can read NexusTrade's public REST API.
|
|
155
|
+
*
|
|
156
|
+
* Those routes are served at `/api/<path>` on the API origin, beside the
|
|
157
|
+
* versioned SDK routes rather than under them. `path` is relative to `/api/`.
|
|
158
|
+
* An API key is sent when the transport holds one; an anonymous workspace
|
|
159
|
+
* session is never sent, because these routes do not read it.
|
|
160
|
+
*/
|
|
161
|
+
export interface PublicApiTransport extends Transport {
|
|
162
|
+
getPublicApi(path: string): Promise<JsonObject>;
|
|
163
|
+
}
|
|
152
164
|
export interface HttpTransportOptions {
|
|
153
165
|
apiKey?: string;
|
|
154
166
|
baseUrl: string;
|
|
@@ -159,7 +171,7 @@ export interface WorkspaceSessionTransport extends Transport {
|
|
|
159
171
|
exportWorkspaceSession(): string | undefined;
|
|
160
172
|
importWorkspaceSession(workspaceSession: string): void;
|
|
161
173
|
}
|
|
162
|
-
export declare class HttpTransport implements Transport, UploadTransport, WorkspaceSessionTransport {
|
|
174
|
+
export declare class HttpTransport implements Transport, UploadTransport, WorkspaceSessionTransport, PublicApiTransport {
|
|
163
175
|
#private;
|
|
164
176
|
constructor(options: HttpTransportOptions);
|
|
165
177
|
get baseUrl(): string;
|
|
@@ -170,6 +182,7 @@ export declare class HttpTransport implements Transport, UploadTransport, Worksp
|
|
|
170
182
|
contentType: string;
|
|
171
183
|
}): Promise<void>;
|
|
172
184
|
request(method: string, path: string, options?: RequestOptions): Promise<JsonObject>;
|
|
185
|
+
getPublicApi(path: string): Promise<JsonObject>;
|
|
173
186
|
}
|
|
174
187
|
export interface NexusTradeClientOptions {
|
|
175
188
|
apiKey?: string;
|
|
@@ -476,6 +489,52 @@ export declare class NexusTradeClient {
|
|
|
476
489
|
cancelNlScreen(screenId: string): Promise<JsonObject>;
|
|
477
490
|
/** Block until a screen is terminal. See `waitForOperation`. */
|
|
478
491
|
waitForNlScreen(screenId: string, options?: WaitOptions): Promise<JsonObject>;
|
|
492
|
+
/**
|
|
493
|
+
* Congressional trade disclosures, newest first. No API key required.
|
|
494
|
+
*
|
|
495
|
+
* Defaults to equities first made public in the 30 days ending on the
|
|
496
|
+
* dataset's last update day. `fromDate` and `toDate` filter on
|
|
497
|
+
* `firstAvailableAt`. Trade from `availableAt`, when the disclosure became
|
|
498
|
+
* public, never `transactionDate`.
|
|
499
|
+
*/
|
|
500
|
+
listCongressionalTrades(options?: ListCongressionalTradesOptions): Promise<CongressionalEnvelope<CongressionalTradePage>>;
|
|
501
|
+
/** Purchase and sale totals over the same filters as the feed. No API key required. */
|
|
502
|
+
getCongressionalTradeSummary(filters?: CongressionalTradeFilters): Promise<CongressionalEnvelope<CongressionalTradeSummary>>;
|
|
503
|
+
/** Members ranked by their copy bot's cached backtest against SPY. No API key required. */
|
|
504
|
+
getCongressionalLeaderboard(options?: {
|
|
505
|
+
limit?: number;
|
|
506
|
+
}): Promise<CongressionalLeaderboard>;
|
|
507
|
+
/** Days from trade to public disclosure per member, slowest first. No API key required. */
|
|
508
|
+
listCongressionalFilingLatency(filters?: CongressionalFilerListOptions): Promise<CongressionalEnvelope<CongressionalFilingLatency[]>>;
|
|
509
|
+
/** Disclosed dollar volume per member, largest first. No API key required. */
|
|
510
|
+
listCongressionalTradeVolume(filters?: CongressionalFilerListOptions): Promise<CongressionalEnvelope<CongressionalFilerVolume[]>>;
|
|
511
|
+
/**
|
|
512
|
+
* One member's profile and whole trading record. No API key required.
|
|
513
|
+
*
|
|
514
|
+
* `id` is a Bioguide ID (`"P000197"`) or a page slug (`"nancy-pelosi"`).
|
|
515
|
+
* With neither date the record runs from 2012-01-01 to today, and
|
|
516
|
+
* `instrument` defaults to `"all"`.
|
|
517
|
+
*/
|
|
518
|
+
getPolitician(id: string, options?: CongressionalMemberRecordOptions): Promise<CongressionalEnvelope<PoliticianProfile>>;
|
|
519
|
+
/** A member's copy bot and its cached backtest. No API key required. */
|
|
520
|
+
getPoliticianBot(id: string): Promise<PoliticianBot>;
|
|
521
|
+
/** Members with disclosures matching the filters. Requires an API key. */
|
|
522
|
+
listCongressionalFilers(filters?: CongressionalFilerListOptions): Promise<CongressionalEnvelope<CongressionalFiler[]>>;
|
|
523
|
+
/**
|
|
524
|
+
* One member's summary, activity and trades by Bioguide ID. Requires an API key.
|
|
525
|
+
*
|
|
526
|
+
* With neither date the record runs from 2012-01-01 to today, and
|
|
527
|
+
* `instrument` defaults to `"all"`.
|
|
528
|
+
*/
|
|
529
|
+
getCongressionalFiler(filerKey: string, options?: CongressionalMemberRecordOptions): Promise<CongressionalEnvelope<CongressionalFilerDetail>>;
|
|
530
|
+
/** One disclosure with its amendment history. Requires an API key. */
|
|
531
|
+
getCongressionalTrade(eventId: string, options?: {
|
|
532
|
+
asOf?: string;
|
|
533
|
+
}): Promise<CongressionalEnvelope<CongressionalTradeDetail>>;
|
|
534
|
+
/** One source filing and every trade it disclosed. Requires an API key. */
|
|
535
|
+
getCongressionalFiling(chamber: CongressChamber, docId: string): Promise<CongressionalEnvelope<CongressionalFiling>>;
|
|
536
|
+
/** How much of the public record the dataset holds. Requires an API key. */
|
|
537
|
+
getCongressionalCoverage(): Promise<CongressionalEnvelope<CongressionalCoverage>>;
|
|
479
538
|
/** Resolve once a backtest is terminal. See `waitForOperation`. */
|
|
480
539
|
waitForBacktest(backtestId: string, options?: WaitOptions): Promise<JsonObject>;
|
|
481
540
|
/** Resolve once an optimization is terminal. See `waitForOperation`. */
|
package/dist/esm/client.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* pass an API key/base URL, or set NEXUSTRADE_API_KEY / NEXUSTRADE_API_BASE_URL.
|
|
6
6
|
*/
|
|
7
7
|
import { AgentRun } from "./agent.js";
|
|
8
|
+
import { congressionalQueryParams, } from "./congress.js";
|
|
8
9
|
import { LazyDotenv, environmentValue } from "./env.js";
|
|
9
10
|
import { portfolioHandleFromWire, } from "./portfolio.js";
|
|
10
11
|
/** Boundary adapter: builder output is JSON by construction. */
|
|
@@ -153,6 +154,15 @@ function sameOrigin(left, right) {
|
|
|
153
154
|
function supportsUpload(transport) {
|
|
154
155
|
return typeof transport.putBytes === "function";
|
|
155
156
|
}
|
|
157
|
+
function supportsPublicApi(transport) {
|
|
158
|
+
return typeof transport.getPublicApi === "function";
|
|
159
|
+
}
|
|
160
|
+
async function readPublicApi(transport, path) {
|
|
161
|
+
if (!supportsPublicApi(transport)) {
|
|
162
|
+
throw new NexusTradeApiError(NO_HTTP_STATUS, "unsupported_transport", "Congressional trade reads require HttpTransport.getPublicApi.");
|
|
163
|
+
}
|
|
164
|
+
return (await transport.getPublicApi(path));
|
|
165
|
+
}
|
|
156
166
|
function assertValidApiKey(apiKey) {
|
|
157
167
|
const invalid = typeof apiKey !== "string" ||
|
|
158
168
|
apiKey.length === 0 ||
|
|
@@ -265,6 +275,10 @@ async function apiErrorFromResponse(response) {
|
|
|
265
275
|
if (body.message)
|
|
266
276
|
message = String(body.message);
|
|
267
277
|
}
|
|
278
|
+
else if (typeof decoded.message === "string" && decoded.message) {
|
|
279
|
+
// Public REST routes answer `{ message }` with no error envelope.
|
|
280
|
+
message = decoded.message;
|
|
281
|
+
}
|
|
268
282
|
}
|
|
269
283
|
catch {
|
|
270
284
|
// Non-JSON error bodies keep the transport-level code/message.
|
|
@@ -281,6 +295,9 @@ function workspaceSessionUrl(baseUrl) {
|
|
|
281
295
|
parsed.hash = "";
|
|
282
296
|
return parsed.toString();
|
|
283
297
|
}
|
|
298
|
+
function publicApiUrl(baseUrl, path) {
|
|
299
|
+
return `${new URL(baseUrl).origin}/api/${path.replace(/^\/+/, "")}`;
|
|
300
|
+
}
|
|
284
301
|
function supportsWorkspaceSession(transport) {
|
|
285
302
|
const candidate = transport;
|
|
286
303
|
return (typeof candidate.exportWorkspaceSession === "function" &&
|
|
@@ -441,6 +458,16 @@ export class HttpTransport {
|
|
|
441
458
|
if (options.idempotencyKey !== undefined) {
|
|
442
459
|
headers["Idempotency-Key"] = options.idempotencyKey;
|
|
443
460
|
}
|
|
461
|
+
return this.#send(method, url, headers, payload);
|
|
462
|
+
}
|
|
463
|
+
async getPublicApi(path) {
|
|
464
|
+
const headers = { Accept: "application/json" };
|
|
465
|
+
if (this.#apiKey !== undefined) {
|
|
466
|
+
headers.Authorization = `Bearer ${this.#apiKey}`;
|
|
467
|
+
}
|
|
468
|
+
return this.#send("GET", publicApiUrl(this.#baseUrl, path), headers);
|
|
469
|
+
}
|
|
470
|
+
async #send(method, url, headers, payload) {
|
|
444
471
|
const controller = new AbortController();
|
|
445
472
|
const timer = setTimeout(() => controller.abort(), this.#timeoutSeconds * 1000);
|
|
446
473
|
try {
|
|
@@ -1421,6 +1448,76 @@ export class NexusTradeClient {
|
|
|
1421
1448
|
async waitForNlScreen(screenId, options = {}) {
|
|
1422
1449
|
return waitForOperation((id) => this.getNlScreen(id), screenId, options);
|
|
1423
1450
|
}
|
|
1451
|
+
/**
|
|
1452
|
+
* Congressional trade disclosures, newest first. No API key required.
|
|
1453
|
+
*
|
|
1454
|
+
* Defaults to equities first made public in the 30 days ending on the
|
|
1455
|
+
* dataset's last update day. `fromDate` and `toDate` filter on
|
|
1456
|
+
* `firstAvailableAt`. Trade from `availableAt`, when the disclosure became
|
|
1457
|
+
* public, never `transactionDate`.
|
|
1458
|
+
*/
|
|
1459
|
+
async listCongressionalTrades(options = {}) {
|
|
1460
|
+
return readPublicApi(this.transport, `political-disclosures/trades${encodeQuery(congressionalQueryParams(options))}`);
|
|
1461
|
+
}
|
|
1462
|
+
/** Purchase and sale totals over the same filters as the feed. No API key required. */
|
|
1463
|
+
async getCongressionalTradeSummary(filters = {}) {
|
|
1464
|
+
return readPublicApi(this.transport, `political-disclosures/summary${encodeQuery(congressionalQueryParams(filters))}`);
|
|
1465
|
+
}
|
|
1466
|
+
/** Members ranked by their copy bot's cached backtest against SPY. No API key required. */
|
|
1467
|
+
async getCongressionalLeaderboard(options = {}) {
|
|
1468
|
+
return readPublicApi(this.transport, `political-disclosures/leaderboard${encodeQuery({
|
|
1469
|
+
limit: options.limit === undefined ? undefined : String(options.limit),
|
|
1470
|
+
})}`);
|
|
1471
|
+
}
|
|
1472
|
+
/** Days from trade to public disclosure per member, slowest first. No API key required. */
|
|
1473
|
+
async listCongressionalFilingLatency(filters = {}) {
|
|
1474
|
+
return readPublicApi(this.transport, `political-disclosures/filer-latency${encodeQuery(congressionalQueryParams(filters))}`);
|
|
1475
|
+
}
|
|
1476
|
+
/** Disclosed dollar volume per member, largest first. No API key required. */
|
|
1477
|
+
async listCongressionalTradeVolume(filters = {}) {
|
|
1478
|
+
return readPublicApi(this.transport, `political-disclosures/filer-volume${encodeQuery(congressionalQueryParams(filters))}`);
|
|
1479
|
+
}
|
|
1480
|
+
/**
|
|
1481
|
+
* One member's profile and whole trading record. No API key required.
|
|
1482
|
+
*
|
|
1483
|
+
* `id` is a Bioguide ID (`"P000197"`) or a page slug (`"nancy-pelosi"`).
|
|
1484
|
+
* With neither date the record runs from 2012-01-01 to today, and
|
|
1485
|
+
* `instrument` defaults to `"all"`.
|
|
1486
|
+
*/
|
|
1487
|
+
async getPolitician(id, options = {}) {
|
|
1488
|
+
return readPublicApi(this.transport, `political-disclosures/politicians/${encodePathSegment(id)}${encodeQuery(congressionalQueryParams(options))}`);
|
|
1489
|
+
}
|
|
1490
|
+
/** A member's copy bot and its cached backtest. No API key required. */
|
|
1491
|
+
async getPoliticianBot(id) {
|
|
1492
|
+
return readPublicApi(this.transport, `political-disclosures/politicians/${encodePathSegment(id)}/bot`);
|
|
1493
|
+
}
|
|
1494
|
+
/** Members with disclosures matching the filters. Requires an API key. */
|
|
1495
|
+
async listCongressionalFilers(filters = {}) {
|
|
1496
|
+
return readPublicApi(this.transport, `political-disclosures/filers${encodeQuery(congressionalQueryParams(filters))}`);
|
|
1497
|
+
}
|
|
1498
|
+
/**
|
|
1499
|
+
* One member's summary, activity and trades by Bioguide ID. Requires an API key.
|
|
1500
|
+
*
|
|
1501
|
+
* With neither date the record runs from 2012-01-01 to today, and
|
|
1502
|
+
* `instrument` defaults to `"all"`.
|
|
1503
|
+
*/
|
|
1504
|
+
async getCongressionalFiler(filerKey, options = {}) {
|
|
1505
|
+
return readPublicApi(this.transport, `political-disclosures/filers/${encodePathSegment(filerKey)}${encodeQuery(congressionalQueryParams(options))}`);
|
|
1506
|
+
}
|
|
1507
|
+
/** One disclosure with its amendment history. Requires an API key. */
|
|
1508
|
+
async getCongressionalTrade(eventId, options = {}) {
|
|
1509
|
+
return readPublicApi(this.transport, `political-disclosures/trades/${encodePathSegment(eventId)}${encodeQuery({
|
|
1510
|
+
asOf: options.asOf,
|
|
1511
|
+
})}`);
|
|
1512
|
+
}
|
|
1513
|
+
/** One source filing and every trade it disclosed. Requires an API key. */
|
|
1514
|
+
async getCongressionalFiling(chamber, docId) {
|
|
1515
|
+
return readPublicApi(this.transport, `political-disclosures/filings/${encodePathSegment(chamber)}/${encodePathSegment(docId)}`);
|
|
1516
|
+
}
|
|
1517
|
+
/** How much of the public record the dataset holds. Requires an API key. */
|
|
1518
|
+
async getCongressionalCoverage() {
|
|
1519
|
+
return readPublicApi(this.transport, "political-disclosures/coverage");
|
|
1520
|
+
}
|
|
1424
1521
|
/** Resolve once a backtest is terminal. See `waitForOperation`. */
|
|
1425
1522
|
async waitForBacktest(backtestId, options = {}) {
|
|
1426
1523
|
return waitForOperation((id) => this.getBacktest(id), backtestId, options);
|
|
@@ -0,0 +1,390 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Congressional (STOCK Act) disclosure types for the public REST API at
|
|
3
|
+
* `/api/political-disclosures`.
|
|
4
|
+
*
|
|
5
|
+
* `availableAt` is when a disclosure became public. It is the only date a
|
|
6
|
+
* strategy may act on: `transactionDate` is when the member traded, typically
|
|
7
|
+
* weeks before anyone outside Congress could know. Date filters and `sort` use
|
|
8
|
+
* `firstAvailableAt`, when the first version of a disclosure became public.
|
|
9
|
+
*/
|
|
10
|
+
export type CongressChamber = "house" | "senate";
|
|
11
|
+
export type CongressAction = "purchase" | "sale" | "exchange" | "unmarked";
|
|
12
|
+
export type CongressInstrument = "equity" | "option" | "fund" | "bond" | "other";
|
|
13
|
+
export type CongressOwner = "self" | "spouse" | "dependent_child" | "joint" | "not_indicated";
|
|
14
|
+
export type CongressParty = "Democrat" | "Republican" | "Independent" | "Other";
|
|
15
|
+
export type CongressParseMethod = "text" | "scan" | "html" | "paper";
|
|
16
|
+
export type CongressSort = "newest" | "oldest";
|
|
17
|
+
/**
|
|
18
|
+
* Filters shared by the trade feed and its aggregates.
|
|
19
|
+
*
|
|
20
|
+
* `toDate` defaults to the day of `asOf`, which defaults to the dataset's last
|
|
21
|
+
* update. With no `fromDate` the window is the 30 days ending at `toDate`.
|
|
22
|
+
* `instrument` defaults to `"equity"`; pass `"all"` to include options, funds
|
|
23
|
+
* and bonds.
|
|
24
|
+
*/
|
|
25
|
+
export interface CongressionalTradeFilters {
|
|
26
|
+
/** Free-text search. A phrase naming exactly one member resolves to that member. */
|
|
27
|
+
q?: string;
|
|
28
|
+
/** Bioguide ID, for example `"P000197"`. */
|
|
29
|
+
filerKey?: string;
|
|
30
|
+
ticker?: string;
|
|
31
|
+
chamber?: CongressChamber | "all";
|
|
32
|
+
action?: CongressAction | "all";
|
|
33
|
+
instrument?: CongressInstrument | "all";
|
|
34
|
+
/** `YYYY-MM-DD`, compared against the day of `firstAvailableAt`. Sent as `from`. */
|
|
35
|
+
fromDate?: string;
|
|
36
|
+
/** `YYYY-MM-DD`, compared against the day of `firstAvailableAt`. Sent as `to`. */
|
|
37
|
+
toDate?: string;
|
|
38
|
+
/** ISO timestamp. Reads the record as it was publicly known at that instant. */
|
|
39
|
+
asOf?: string;
|
|
40
|
+
}
|
|
41
|
+
/** The trade feed: the shared filters plus ordering and paging. */
|
|
42
|
+
export interface ListCongressionalTradesOptions extends CongressionalTradeFilters {
|
|
43
|
+
/** Orders by `firstAvailableAt`. Default `"newest"`. */
|
|
44
|
+
sort?: CongressSort;
|
|
45
|
+
/** `nextCursor` from the previous page, sent with the same filters. */
|
|
46
|
+
cursor?: string;
|
|
47
|
+
/** 1 to 100. Default 25. */
|
|
48
|
+
limit?: number;
|
|
49
|
+
}
|
|
50
|
+
/** The per-member lists (filers, filing latency, volume). Each has a fixed order. */
|
|
51
|
+
export interface CongressionalFilerListOptions extends CongressionalTradeFilters {
|
|
52
|
+
/** 1 to 100. Default 25. */
|
|
53
|
+
limit?: number;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* One member's record, for `getPolitician` and `getCongressionalFiler`.
|
|
57
|
+
*
|
|
58
|
+
* With neither date the record runs from 2012-01-01 to today. With only one,
|
|
59
|
+
* the other takes the feed default. `instrument` defaults to `"all"`.
|
|
60
|
+
*/
|
|
61
|
+
export interface CongressionalMemberRecordOptions {
|
|
62
|
+
ticker?: string;
|
|
63
|
+
action?: CongressAction | "all";
|
|
64
|
+
instrument?: CongressInstrument | "all";
|
|
65
|
+
/** Orders the trades by `firstAvailableAt`. Default `"newest"`. */
|
|
66
|
+
sort?: CongressSort;
|
|
67
|
+
/** `YYYY-MM-DD`, compared against the day of `firstAvailableAt`. Sent as `from`. */
|
|
68
|
+
fromDate?: string;
|
|
69
|
+
/** `YYYY-MM-DD`, compared against the day of `firstAvailableAt`. Sent as `to`. */
|
|
70
|
+
toDate?: string;
|
|
71
|
+
/** ISO timestamp. Reads the record as it was publicly known at that instant. */
|
|
72
|
+
asOf?: string;
|
|
73
|
+
/** `recentTradesNextCursor` from the previous page, sent with the same filters. */
|
|
74
|
+
cursor?: string;
|
|
75
|
+
/** Trades per page, 1 to 100. Default 25. */
|
|
76
|
+
limit?: number;
|
|
77
|
+
}
|
|
78
|
+
/** The filters the server applied, defaults included. */
|
|
79
|
+
export interface CongressionalAppliedFilters {
|
|
80
|
+
q: string | null;
|
|
81
|
+
filerKey: string | null;
|
|
82
|
+
ticker: string | null;
|
|
83
|
+
chamber: CongressChamber | "all";
|
|
84
|
+
action: CongressAction | "all";
|
|
85
|
+
instrument: CongressInstrument | "all";
|
|
86
|
+
sort: CongressSort;
|
|
87
|
+
from: string;
|
|
88
|
+
to: string;
|
|
89
|
+
asOf: string;
|
|
90
|
+
cursor: string | null;
|
|
91
|
+
limit: number;
|
|
92
|
+
}
|
|
93
|
+
export interface CongressionalCoverage {
|
|
94
|
+
filings: number;
|
|
95
|
+
events: number;
|
|
96
|
+
failedFilings: number;
|
|
97
|
+
latestAvailableAt: string | null;
|
|
98
|
+
latestProcessedAt: string | null;
|
|
99
|
+
byChamber: Record<CongressChamber, {
|
|
100
|
+
filings: number | null;
|
|
101
|
+
latestFilingDate: string | null;
|
|
102
|
+
}>;
|
|
103
|
+
}
|
|
104
|
+
/** Every disclosure read except the leaderboard and the copy bot. */
|
|
105
|
+
export interface CongressionalEnvelope<T> {
|
|
106
|
+
data: T;
|
|
107
|
+
snapshotId: string;
|
|
108
|
+
asOf: string;
|
|
109
|
+
dataUpdatedAt: string;
|
|
110
|
+
stale: boolean;
|
|
111
|
+
cache: "hit" | "miss" | "stale";
|
|
112
|
+
coverage: CongressionalCoverage | null;
|
|
113
|
+
filters: CongressionalAppliedFilters | null;
|
|
114
|
+
}
|
|
115
|
+
export interface CongressionalTrade {
|
|
116
|
+
/** `<chamber>:<docId>:<rowIndex>`, for example `"house:20035831:0"`. */
|
|
117
|
+
eventId: string;
|
|
118
|
+
version: number;
|
|
119
|
+
filerKey: string;
|
|
120
|
+
filerName: string;
|
|
121
|
+
chamber: CongressChamber;
|
|
122
|
+
owner: CongressOwner;
|
|
123
|
+
action: CongressAction;
|
|
124
|
+
partialSale: boolean;
|
|
125
|
+
instrument: CongressInstrument;
|
|
126
|
+
/** When the member traded. Not public knowledge on this date. */
|
|
127
|
+
transactionDate: string | null;
|
|
128
|
+
filingDate: string;
|
|
129
|
+
/** When the first version became public. `from`, `to` and `sort` use this. */
|
|
130
|
+
firstAvailableAt: string;
|
|
131
|
+
/** When this version became public. The date to trade from. */
|
|
132
|
+
availableAt: string;
|
|
133
|
+
supersededAt: string | null;
|
|
134
|
+
ticker: string | null;
|
|
135
|
+
assetDescription: string;
|
|
136
|
+
assetTypeCode: string | null;
|
|
137
|
+
assetTypeLabel: string | null;
|
|
138
|
+
/** Disclosures report a bracket, never an amount. */
|
|
139
|
+
amountBracket: string | null;
|
|
140
|
+
amountLow: number | null;
|
|
141
|
+
amountHigh: number | null;
|
|
142
|
+
tickerResolutionStatus: string | null;
|
|
143
|
+
sourceDocId: string;
|
|
144
|
+
sourceRowIndex: number;
|
|
145
|
+
sourceUrl: string;
|
|
146
|
+
/** `"scan"` and `"paper"` rows were read from an image. */
|
|
147
|
+
sourceParseMethod: CongressParseMethod | null;
|
|
148
|
+
}
|
|
149
|
+
export interface CongressMemberBadge {
|
|
150
|
+
party: CongressParty | null;
|
|
151
|
+
state: string | null;
|
|
152
|
+
slug: string;
|
|
153
|
+
}
|
|
154
|
+
export interface CongressionalTradePage {
|
|
155
|
+
trades: CongressionalTrade[];
|
|
156
|
+
/** Pass as `cursor` with the same filters; null on the last page. */
|
|
157
|
+
nextCursor: string | null;
|
|
158
|
+
/** `filerKey` to badge, for the members on this page. */
|
|
159
|
+
members?: Record<string, CongressMemberBadge>;
|
|
160
|
+
}
|
|
161
|
+
export interface CongressionalVolumeRank {
|
|
162
|
+
ticker: string;
|
|
163
|
+
events: number;
|
|
164
|
+
amountLow: number | null;
|
|
165
|
+
amountHigh: number | null;
|
|
166
|
+
}
|
|
167
|
+
export interface CongressionalTradeSummary {
|
|
168
|
+
purchaseEvents: number;
|
|
169
|
+
saleEvents: number;
|
|
170
|
+
otherEvents: number;
|
|
171
|
+
activeFilers: number;
|
|
172
|
+
disclosedEvents: number;
|
|
173
|
+
purchaseAmountLow: number | null;
|
|
174
|
+
purchaseAmountHigh: number | null;
|
|
175
|
+
purchaseMissingLow: number;
|
|
176
|
+
purchaseMissingHigh: number;
|
|
177
|
+
saleAmountLow: number | null;
|
|
178
|
+
saleAmountHigh: number | null;
|
|
179
|
+
saleMissingLow: number;
|
|
180
|
+
saleMissingHigh: number;
|
|
181
|
+
netAmountLow: number | null;
|
|
182
|
+
netAmountHigh: number | null;
|
|
183
|
+
unresolvedTickerEvents: number;
|
|
184
|
+
mostPurchased: Array<{
|
|
185
|
+
ticker: string;
|
|
186
|
+
events: number;
|
|
187
|
+
}>;
|
|
188
|
+
mostPurchasedByVolume?: CongressionalVolumeRank[];
|
|
189
|
+
}
|
|
190
|
+
export interface CongressionalFiler {
|
|
191
|
+
filerKey: string;
|
|
192
|
+
displayName: string;
|
|
193
|
+
chamber: CongressChamber;
|
|
194
|
+
disclosureEvents: number;
|
|
195
|
+
purchaseEvents: number;
|
|
196
|
+
saleEvents: number;
|
|
197
|
+
latestDisclosureAt: string | null;
|
|
198
|
+
identityStatus: "member";
|
|
199
|
+
}
|
|
200
|
+
export interface CongressionalFilerYearActivity {
|
|
201
|
+
year: number;
|
|
202
|
+
purchases: number;
|
|
203
|
+
sales: number;
|
|
204
|
+
purchaseMidpoint: number | null;
|
|
205
|
+
saleMidpoint: number | null;
|
|
206
|
+
}
|
|
207
|
+
export interface CongressionalFilerActivity {
|
|
208
|
+
byYear: CongressionalFilerYearActivity[];
|
|
209
|
+
firstPublicAt: string | null;
|
|
210
|
+
lastPublicAt: string | null;
|
|
211
|
+
filings: number;
|
|
212
|
+
/** Filings carrying a trade made public more than 45 days after it. */
|
|
213
|
+
lateFilings: number;
|
|
214
|
+
}
|
|
215
|
+
export interface CongressionalFilerDetail {
|
|
216
|
+
filer: CongressionalFiler;
|
|
217
|
+
summary: CongressionalTradeSummary;
|
|
218
|
+
recentTrades: CongressionalTrade[];
|
|
219
|
+
recentTradesNextCursor: string | null;
|
|
220
|
+
activity: CongressionalFilerActivity;
|
|
221
|
+
}
|
|
222
|
+
/** How long one member's disclosures take to become public. */
|
|
223
|
+
export interface CongressionalFilingLatency {
|
|
224
|
+
filerKey: string;
|
|
225
|
+
displayName: string;
|
|
226
|
+
transactions: number;
|
|
227
|
+
filings: number;
|
|
228
|
+
medianDaysToPublic: number | null;
|
|
229
|
+
p95DaysToPublic: number | null;
|
|
230
|
+
transactionsOverFortyFiveDays: number;
|
|
231
|
+
filingsOverFortyFiveDays: number;
|
|
232
|
+
}
|
|
233
|
+
/** One member's disclosed dollars, as sums of bracket bounds. */
|
|
234
|
+
export interface CongressionalFilerVolume {
|
|
235
|
+
filerKey: string;
|
|
236
|
+
displayName: string;
|
|
237
|
+
transactions: number;
|
|
238
|
+
purchaseTransactions: number;
|
|
239
|
+
saleTransactions: number;
|
|
240
|
+
filings: number;
|
|
241
|
+
volumeLow: number;
|
|
242
|
+
/** Null when any bracket is open-ended. */
|
|
243
|
+
volumeHigh: number | null;
|
|
244
|
+
volumeMidpoint: number;
|
|
245
|
+
openEndedTransactions: number;
|
|
246
|
+
party?: CongressParty | null;
|
|
247
|
+
state?: string | null;
|
|
248
|
+
slug?: string | null;
|
|
249
|
+
}
|
|
250
|
+
export interface CongressCommitteeAssignment {
|
|
251
|
+
id: string;
|
|
252
|
+
name: string;
|
|
253
|
+
title: string | null;
|
|
254
|
+
}
|
|
255
|
+
export interface Politician {
|
|
256
|
+
/** Bioguide ID. */
|
|
257
|
+
memberId: string;
|
|
258
|
+
slug: string;
|
|
259
|
+
displayName: string;
|
|
260
|
+
party: CongressParty | null;
|
|
261
|
+
committees: CongressCommitteeAssignment[];
|
|
262
|
+
imageUrl: string | null;
|
|
263
|
+
chamber: CongressChamber | null;
|
|
264
|
+
state: string | null;
|
|
265
|
+
district: number | null;
|
|
266
|
+
firstTookOffice: string | null;
|
|
267
|
+
lastServedEnd: string | null;
|
|
268
|
+
}
|
|
269
|
+
export interface PoliticianProfile {
|
|
270
|
+
politician: Politician;
|
|
271
|
+
profile: CongressionalFilerDetail;
|
|
272
|
+
}
|
|
273
|
+
export interface PoliticianBotStatistics {
|
|
274
|
+
totalReturn: number;
|
|
275
|
+
cagr: number | null;
|
|
276
|
+
fiveYearEquivalent: number | null;
|
|
277
|
+
spyTotalReturn: number | null;
|
|
278
|
+
spyCagr: number | null;
|
|
279
|
+
spyFiveYearEquivalent: number | null;
|
|
280
|
+
sharpe: number | null;
|
|
281
|
+
sortino: number | null;
|
|
282
|
+
maxDrawdown: number | null;
|
|
283
|
+
closedTrades: number | null;
|
|
284
|
+
fees: number | null;
|
|
285
|
+
medianDeployment: number | null;
|
|
286
|
+
distinctNames: number | null;
|
|
287
|
+
}
|
|
288
|
+
export interface PoliticianBotCurvePoint {
|
|
289
|
+
date: string;
|
|
290
|
+
value: number;
|
|
291
|
+
performanceValue?: number;
|
|
292
|
+
spy: number | null;
|
|
293
|
+
}
|
|
294
|
+
/** A member's copy bot: a cached engine backtest of following their disclosures. */
|
|
295
|
+
export interface PoliticianBot {
|
|
296
|
+
status: "ready" | "stale" | "computing" | "ineligible";
|
|
297
|
+
memberId: string;
|
|
298
|
+
displayName: string | null;
|
|
299
|
+
purchaseCount: number | null;
|
|
300
|
+
minPurchases: number;
|
|
301
|
+
profileId: string | null;
|
|
302
|
+
/** Pass to `forkPublicPortfolio` to copy the bot into your workspace. */
|
|
303
|
+
sharedPortfolioId: string | null;
|
|
304
|
+
windowStart: string | null;
|
|
305
|
+
windowEnd: string | null;
|
|
306
|
+
refreshedAt: string | null;
|
|
307
|
+
refreshRequestedAt: string | null;
|
|
308
|
+
refreshPending: boolean;
|
|
309
|
+
initialValue: number;
|
|
310
|
+
statistics: PoliticianBotStatistics | null;
|
|
311
|
+
curve: PoliticianBotCurvePoint[];
|
|
312
|
+
mixed: boolean;
|
|
313
|
+
}
|
|
314
|
+
export interface CongressionalLeaderboardRow {
|
|
315
|
+
memberId: string;
|
|
316
|
+
displayName: string;
|
|
317
|
+
slug: string | null;
|
|
318
|
+
party: CongressParty | null;
|
|
319
|
+
chamber: CongressChamber | null;
|
|
320
|
+
state: string | null;
|
|
321
|
+
windowStart: string;
|
|
322
|
+
windowEnd: string;
|
|
323
|
+
mixed: boolean;
|
|
324
|
+
totalReturn: number;
|
|
325
|
+
spyTotalReturn: number;
|
|
326
|
+
/** `totalReturn` minus `spyTotalReturn`. */
|
|
327
|
+
excessReturn: number;
|
|
328
|
+
/** `(1 + cagr)^5 - 1`, the ranking basis. */
|
|
329
|
+
fiveYearEquivalent: number | null;
|
|
330
|
+
sharpe: number | null;
|
|
331
|
+
maxDrawdown: number | null;
|
|
332
|
+
purchaseCount: number;
|
|
333
|
+
imageUrl: string | null;
|
|
334
|
+
lastServedEnd: string | null;
|
|
335
|
+
spark: {
|
|
336
|
+
bot: number[];
|
|
337
|
+
spy: Array<number | null>;
|
|
338
|
+
} | null;
|
|
339
|
+
}
|
|
340
|
+
export interface CongressionalLeaderboard {
|
|
341
|
+
/** Members whose copy bot beat SPY, best first. */
|
|
342
|
+
best: CongressionalLeaderboardRow[];
|
|
343
|
+
featured: {
|
|
344
|
+
memberId: string;
|
|
345
|
+
initialValue: number;
|
|
346
|
+
windowEnd: string;
|
|
347
|
+
curve: PoliticianBotCurvePoint[];
|
|
348
|
+
} | null;
|
|
349
|
+
/** Members whose copy bot trailed SPY, worst first. */
|
|
350
|
+
worst: CongressionalLeaderboardRow[];
|
|
351
|
+
byParty: Array<{
|
|
352
|
+
party: CongressParty | "Unknown";
|
|
353
|
+
members: number;
|
|
354
|
+
meanExcessReturn: number;
|
|
355
|
+
}>;
|
|
356
|
+
basis: {
|
|
357
|
+
rankedMembers: number;
|
|
358
|
+
beatSpy: number;
|
|
359
|
+
meanExcessReturn: number | null;
|
|
360
|
+
minPurchases: number;
|
|
361
|
+
minWindowDays: number;
|
|
362
|
+
benchmark: "SPY";
|
|
363
|
+
/** Starting capital of every ranked book. */
|
|
364
|
+
initialValue: number;
|
|
365
|
+
refreshedAt: string | null;
|
|
366
|
+
minPartyMembers: number;
|
|
367
|
+
};
|
|
368
|
+
}
|
|
369
|
+
export interface CongressionalTradeDetail {
|
|
370
|
+
current: CongressionalTrade;
|
|
371
|
+
/** Every version of the disclosure public as of the read, amendments included. */
|
|
372
|
+
history: CongressionalTrade[];
|
|
373
|
+
}
|
|
374
|
+
export interface CongressionalFiling {
|
|
375
|
+
chamber: CongressChamber;
|
|
376
|
+
docId: string;
|
|
377
|
+
filerKey: string | null;
|
|
378
|
+
filerName: string;
|
|
379
|
+
stateDistrict: string | null;
|
|
380
|
+
filingDate: string;
|
|
381
|
+
availableAt: string;
|
|
382
|
+
sourceUrl: string;
|
|
383
|
+
extractionStatus: "ok" | "failed" | "unsupported";
|
|
384
|
+
extractedRows: number;
|
|
385
|
+
amendedReportDate: string | null;
|
|
386
|
+
reportDate: string | null;
|
|
387
|
+
trades: CongressionalTrade[];
|
|
388
|
+
}
|
|
389
|
+
/** Query pairs in one fixed order, so both SDKs put the same bytes on the wire. */
|
|
390
|
+
export declare function congressionalQueryParams(options: ListCongressionalTradesOptions): Record<string, string | undefined>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Congressional (STOCK Act) disclosure types for the public REST API at
|
|
3
|
+
* `/api/political-disclosures`.
|
|
4
|
+
*
|
|
5
|
+
* `availableAt` is when a disclosure became public. It is the only date a
|
|
6
|
+
* strategy may act on: `transactionDate` is when the member traded, typically
|
|
7
|
+
* weeks before anyone outside Congress could know. Date filters and `sort` use
|
|
8
|
+
* `firstAvailableAt`, when the first version of a disclosure became public.
|
|
9
|
+
*/
|
|
10
|
+
/** Query pairs in one fixed order, so both SDKs put the same bytes on the wire. */
|
|
11
|
+
export function congressionalQueryParams(options) {
|
|
12
|
+
return {
|
|
13
|
+
q: options.q,
|
|
14
|
+
filerKey: options.filerKey,
|
|
15
|
+
ticker: options.ticker,
|
|
16
|
+
chamber: options.chamber,
|
|
17
|
+
action: options.action,
|
|
18
|
+
instrument: options.instrument,
|
|
19
|
+
sort: options.sort,
|
|
20
|
+
from: options.fromDate,
|
|
21
|
+
to: options.toDate,
|
|
22
|
+
asOf: options.asOf,
|
|
23
|
+
cursor: options.cursor,
|
|
24
|
+
limit: options.limit === undefined ? undefined : String(options.limit),
|
|
25
|
+
};
|
|
26
|
+
}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
export { AgentRun } from "./agent.js";
|
|
2
2
|
export type { AgentEvent, AgentRunOptions } from "./agent.js";
|
|
3
3
|
export { HttpTransport, NexusTradeApiError, NexusTradeClient, NexusTradeWorkspaceSessionExpiredError, createCustomIndicator, createPortfolio, waitForOperation, } from "./client.js";
|
|
4
|
-
export type {
|
|
4
|
+
export type { CongressAction, CongressChamber, CongressCommitteeAssignment, CongressInstrument, CongressMemberBadge, CongressOwner, CongressParseMethod, CongressParty, CongressSort, CongressionalAppliedFilters, CongressionalCoverage, CongressionalEnvelope, CongressionalFiler, CongressionalFilerActivity, CongressionalFilerDetail, CongressionalFilerListOptions, CongressionalFilerVolume, CongressionalFilerYearActivity, CongressionalFiling, CongressionalFilingLatency, CongressionalLeaderboard, CongressionalLeaderboardRow, CongressionalMemberRecordOptions, CongressionalTrade, CongressionalTradeDetail, CongressionalTradeFilters, CongressionalTradePage, CongressionalTradeSummary, CongressionalVolumeRank, ListCongressionalTradesOptions, Politician, PoliticianBot, PoliticianBotCurvePoint, PoliticianBotStatistics, PoliticianProfile, } from "./congress.js";
|
|
5
|
+
export type { AddStrategiesOperation, BacktestCollateralStatistics, CustomIndicatorInput, CustomIndicatorPointInput, HttpTransportOptions, JsonObject, JsonValue, ListOrdersOptions, ListPortfoliosOptions, NexusTradeClientOptions, PortfolioEditOperation, UpdatePortfolioOperation, PortfolioRenameOperation, PublicApiTransport, RemoveStrategiesOperation, ReplaceStrategiesOperation, ReplaceStrategyOperation, RequestOptions, Transport, UploadTransport, WaitOptions, WorkspaceSessionTransport, } from "./client.js";
|
|
5
6
|
export { PortfolioHandle, portfolioHandleFromWire, } from "./portfolio.js";
|
|
6
7
|
export type { DeployOutcome, DeployResult, PortfolioHandleOptions, PortfolioListResult, PortfolioType, ReadonlyPortfolioPolicy, } from "./portfolio.js";
|
|
7
8
|
export * from "./generated/ntSdk.generated.js";
|
package/package.json
CHANGED