nexustrade 1.1.0 → 1.2.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/AGENTS.md +20 -1
- package/README.md +235 -137
- package/dist/cjs/client.js +275 -9
- package/dist/cjs/generated/ntSdk.generated.js +51 -0
- package/dist/esm/client.d.ts +49 -0
- package/dist/esm/client.js +274 -8
- package/dist/esm/generated/ntSdk.generated.d.ts +51 -4
- package/dist/esm/generated/ntSdk.generated.js +47 -0
- package/package.json +1 -1
package/dist/cjs/client.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* pass an API key/base URL, or set NEXUSTRADE_API_KEY / NEXUSTRADE_API_BASE_URL.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.NexusTradeClient = exports.HttpTransport = exports.NexusTradeApiError = exports.CONNECT_POLL_INTERVAL_SECONDS = exports.DEFAULT_CONNECT_TIMEOUT_SECONDS = exports.POLL_BACKOFF_FACTOR = exports.MAX_POLL_INTERVAL_SECONDS = exports.DEFAULT_POLL_INTERVAL_SECONDS = exports.DEFAULT_POLL_TIMEOUT_SECONDS = exports.NO_HTTP_STATUS = void 0;
|
|
9
|
+
exports.NexusTradeClient = exports.HttpTransport = exports.NexusTradeApiError = exports.UPLOAD_PUT_JITTER_SECONDS = exports.UPLOAD_PUT_MAX_BACKOFF_SECONDS = exports.UPLOAD_PUT_INITIAL_BACKOFF_SECONDS = exports.MAX_UPLOAD_PUT_ATTEMPTS = exports.CONNECT_POLL_INTERVAL_SECONDS = exports.DEFAULT_CONNECT_TIMEOUT_SECONDS = exports.POLL_BACKOFF_FACTOR = exports.MAX_POLL_INTERVAL_SECONDS = exports.DEFAULT_POLL_INTERVAL_SECONDS = exports.DEFAULT_POLL_TIMEOUT_SECONDS = exports.NO_HTTP_STATUS = void 0;
|
|
10
10
|
exports.waitForOperation = waitForOperation;
|
|
11
11
|
exports.clientTransport = clientTransport;
|
|
12
12
|
exports.createCustomIndicator = createCustomIndicator;
|
|
@@ -72,6 +72,14 @@ function stdoutIsInteractive() {
|
|
|
72
72
|
// Point batches larger than this are uploaded rather than sent inline.
|
|
73
73
|
const MAX_INLINE_POINT_BYTES = 512 * 1024;
|
|
74
74
|
const MAX_UPLOAD_BYTES = 100 * 1024 * 1024;
|
|
75
|
+
// A presigned PUT crosses the open internet with no API-side retry behind it, so
|
|
76
|
+
// the client owns transient recovery. Jittered (unlike the poll backoff) because
|
|
77
|
+
// every client retrying a storage blip on the same schedule is the blip.
|
|
78
|
+
// checkSdkClientParity.ts asserts these match the Python SDK.
|
|
79
|
+
exports.MAX_UPLOAD_PUT_ATTEMPTS = 5;
|
|
80
|
+
exports.UPLOAD_PUT_INITIAL_BACKOFF_SECONDS = 0.5;
|
|
81
|
+
exports.UPLOAD_PUT_MAX_BACKOFF_SECONDS = 8.0;
|
|
82
|
+
exports.UPLOAD_PUT_JITTER_SECONDS = 0.25;
|
|
75
83
|
const POINT_FIELDS = {
|
|
76
84
|
timestamp: "timestamp",
|
|
77
85
|
value: "value",
|
|
@@ -99,6 +107,22 @@ class NexusTradeApiError extends Error {
|
|
|
99
107
|
}
|
|
100
108
|
}
|
|
101
109
|
exports.NexusTradeApiError = NexusTradeApiError;
|
|
110
|
+
function isRetryableUploadHttpStatus(status) {
|
|
111
|
+
return status === 408 || status === 429 || status >= 500;
|
|
112
|
+
}
|
|
113
|
+
/** Only a transport fault or a storage-side transient earns another PUT. */
|
|
114
|
+
function isRetryableUploadError(error) {
|
|
115
|
+
if (!(error instanceof NexusTradeApiError)) {
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
if (error.code === "transport_error") {
|
|
119
|
+
return true;
|
|
120
|
+
}
|
|
121
|
+
if (error.code === "upload_failed" && error.status !== exports.NO_HTTP_STATUS) {
|
|
122
|
+
return isRetryableUploadHttpStatus(error.status);
|
|
123
|
+
}
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
102
126
|
function origin(url) {
|
|
103
127
|
const parsed = new URL(url);
|
|
104
128
|
const scheme = parsed.protocol.replace(":", "").toLowerCase();
|
|
@@ -114,7 +138,7 @@ function sameOrigin(left, right) {
|
|
|
114
138
|
return a.scheme === b.scheme && a.host === b.host && a.port === b.port;
|
|
115
139
|
}
|
|
116
140
|
function supportsBinary(transport) {
|
|
117
|
-
return
|
|
141
|
+
return typeof transport.requestBytes === "function";
|
|
118
142
|
}
|
|
119
143
|
function supportsUpload(transport) {
|
|
120
144
|
return typeof transport.putBytes === "function";
|
|
@@ -200,7 +224,9 @@ function decodeJsonObject(bytes, status) {
|
|
|
200
224
|
catch {
|
|
201
225
|
throw new NexusTradeApiError(status, "invalid_response", "NexusTrade returned invalid JSON.");
|
|
202
226
|
}
|
|
203
|
-
if (typeof decoded !== "object" ||
|
|
227
|
+
if (typeof decoded !== "object" ||
|
|
228
|
+
decoded === null ||
|
|
229
|
+
Array.isArray(decoded)) {
|
|
204
230
|
throw new NexusTradeApiError(status, "invalid_response", "NexusTrade returned a non-object JSON response.");
|
|
205
231
|
}
|
|
206
232
|
return decoded;
|
|
@@ -227,6 +253,23 @@ class HttpTransport {
|
|
|
227
253
|
}
|
|
228
254
|
/** PUT a payload to a presigned storage URL. Sends no credential. */
|
|
229
255
|
async putBytes(url, data, options) {
|
|
256
|
+
let delaySeconds = exports.UPLOAD_PUT_INITIAL_BACKOFF_SECONDS;
|
|
257
|
+
for (let attempt = 0; attempt < exports.MAX_UPLOAD_PUT_ATTEMPTS; attempt++) {
|
|
258
|
+
try {
|
|
259
|
+
await this.#putBytesOnce(url, data, options);
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
catch (error) {
|
|
263
|
+
if (attempt >= exports.MAX_UPLOAD_PUT_ATTEMPTS - 1 ||
|
|
264
|
+
!isRetryableUploadError(error)) {
|
|
265
|
+
throw error;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
delaySeconds = Math.min(delaySeconds * 2, exports.UPLOAD_PUT_MAX_BACKOFF_SECONDS);
|
|
269
|
+
await sleep((delaySeconds + Math.random() * exports.UPLOAD_PUT_JITTER_SECONDS) * 1000);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
async #putBytesOnce(url, data, options) {
|
|
230
273
|
let parsed;
|
|
231
274
|
try {
|
|
232
275
|
parsed = new URL(url);
|
|
@@ -420,6 +463,129 @@ function customIndicatorPoints(points) {
|
|
|
420
463
|
}
|
|
421
464
|
return points.map(customIndicatorPoint);
|
|
422
465
|
}
|
|
466
|
+
function dateOnly(value) {
|
|
467
|
+
if (typeof value !== "string" || !/^\d{4}-\d{2}-\d{2}$/.test(value)) {
|
|
468
|
+
return undefined;
|
|
469
|
+
}
|
|
470
|
+
const parsed = new Date(`${value}T00:00:00.000Z`);
|
|
471
|
+
return Number.isNaN(parsed.getTime()) ||
|
|
472
|
+
parsed.toISOString().slice(0, 10) !== value
|
|
473
|
+
? undefined
|
|
474
|
+
: parsed;
|
|
475
|
+
}
|
|
476
|
+
function utcMidnight(day) {
|
|
477
|
+
return `${day.toISOString().slice(0, 10)}T00:00:00.000Z`;
|
|
478
|
+
}
|
|
479
|
+
function utcDateTime(value) {
|
|
480
|
+
const day = dateOnly(value);
|
|
481
|
+
if (day)
|
|
482
|
+
return day;
|
|
483
|
+
if (typeof value !== "string")
|
|
484
|
+
return undefined;
|
|
485
|
+
const hasExplicitZone = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(?::\d{2}(?:\.\d{1,9})?)?(?:Z|[+-]\d{2}:\d{2})$/i.test(value);
|
|
486
|
+
if (!hasExplicitZone)
|
|
487
|
+
return undefined;
|
|
488
|
+
const parsed = new Date(value);
|
|
489
|
+
return Number.isNaN(parsed.getTime()) ? undefined : parsed;
|
|
490
|
+
}
|
|
491
|
+
function addUtcDays(day, days) {
|
|
492
|
+
return new Date(Date.UTC(day.getUTCFullYear(), day.getUTCMonth(), day.getUTCDate() + days));
|
|
493
|
+
}
|
|
494
|
+
function pointKindPoints(points, pointKind, aggregatePeriod) {
|
|
495
|
+
if (!pointKind) {
|
|
496
|
+
if (aggregatePeriod) {
|
|
497
|
+
throw new Error("aggregatePeriod requires pointKind period_aggregate.");
|
|
498
|
+
}
|
|
499
|
+
return points;
|
|
500
|
+
}
|
|
501
|
+
if (pointKind !== "period_aggregate" && aggregatePeriod) {
|
|
502
|
+
throw new Error("aggregatePeriod is only valid for period_aggregate.");
|
|
503
|
+
}
|
|
504
|
+
if (pointKind === "period_aggregate" && !aggregatePeriod) {
|
|
505
|
+
throw new Error("period_aggregate requires aggregatePeriod.");
|
|
506
|
+
}
|
|
507
|
+
return points.map((point, index) => {
|
|
508
|
+
const row = { ...point };
|
|
509
|
+
const eventDay = dateOnly(row.timestamp);
|
|
510
|
+
const availableDay = dateOnly(row.availableAt);
|
|
511
|
+
const eventTime = utcDateTime(row.timestamp);
|
|
512
|
+
const availableTime = utcDateTime(row.availableAt);
|
|
513
|
+
if (pointKind === "observation") {
|
|
514
|
+
if (row.availableAt === undefined) {
|
|
515
|
+
row.availableAt = eventDay ? utcMidnight(eventDay) : row.timestamp;
|
|
516
|
+
}
|
|
517
|
+
else if (eventDay && availableDay?.getTime() === eventDay.getTime()) {
|
|
518
|
+
row.availableAt = utcMidnight(eventDay);
|
|
519
|
+
}
|
|
520
|
+
else if (availableDay) {
|
|
521
|
+
row.availableAt = utcMidnight(addUtcDays(availableDay, 1));
|
|
522
|
+
}
|
|
523
|
+
if (eventTime &&
|
|
524
|
+
availableTime &&
|
|
525
|
+
availableTime.toISOString().slice(0, 10) >
|
|
526
|
+
eventTime.toISOString().slice(0, 10)) {
|
|
527
|
+
throw new Error(`Point ${index + 1}: observation availableAt is after the event date.`);
|
|
528
|
+
}
|
|
529
|
+
return row;
|
|
530
|
+
}
|
|
531
|
+
if (pointKind === "disclosed") {
|
|
532
|
+
if (row.availableAt === undefined) {
|
|
533
|
+
throw new Error(`Point ${index + 1}: disclosed pointKind requires availableAt.`);
|
|
534
|
+
}
|
|
535
|
+
if (availableDay) {
|
|
536
|
+
row.availableAt = utcMidnight(addUtcDays(availableDay, 1));
|
|
537
|
+
}
|
|
538
|
+
return row;
|
|
539
|
+
}
|
|
540
|
+
if (!eventTime) {
|
|
541
|
+
throw new Error(`Point ${index + 1}: aggregate timestamp must be date-only or include an explicit UTC offset.`);
|
|
542
|
+
}
|
|
543
|
+
if (eventTime.getUTCHours() !== 0 ||
|
|
544
|
+
eventTime.getUTCMinutes() !== 0 ||
|
|
545
|
+
eventTime.getUTCSeconds() !== 0 ||
|
|
546
|
+
eventTime.getUTCMilliseconds() !== 0) {
|
|
547
|
+
throw new Error(`Point ${index + 1}: aggregate timestamp must be UTC midnight.`);
|
|
548
|
+
}
|
|
549
|
+
let periodEnd;
|
|
550
|
+
if (aggregatePeriod === "1d") {
|
|
551
|
+
periodEnd = addUtcDays(eventTime, 1);
|
|
552
|
+
}
|
|
553
|
+
else if (aggregatePeriod === "1w") {
|
|
554
|
+
if (eventTime.getUTCDay() !== 1) {
|
|
555
|
+
throw new Error(`Point ${index + 1}: 1w timestamp must be a Monday.`);
|
|
556
|
+
}
|
|
557
|
+
periodEnd = addUtcDays(eventTime, 7);
|
|
558
|
+
}
|
|
559
|
+
else if (aggregatePeriod === "1mo") {
|
|
560
|
+
if (eventTime.getUTCDate() !== 1) {
|
|
561
|
+
throw new Error(`Point ${index + 1}: 1mo timestamp must be month start.`);
|
|
562
|
+
}
|
|
563
|
+
periodEnd = new Date(Date.UTC(eventTime.getUTCFullYear(), eventTime.getUTCMonth() + 1, 1));
|
|
564
|
+
}
|
|
565
|
+
else {
|
|
566
|
+
if (eventTime.getUTCDate() !== 1 ||
|
|
567
|
+
![0, 3, 6, 9].includes(eventTime.getUTCMonth())) {
|
|
568
|
+
throw new Error(`Point ${index + 1}: 1q timestamp must be quarter start.`);
|
|
569
|
+
}
|
|
570
|
+
periodEnd = new Date(Date.UTC(eventTime.getUTCFullYear(), eventTime.getUTCMonth() + 3, 1));
|
|
571
|
+
}
|
|
572
|
+
const derived = utcMidnight(periodEnd);
|
|
573
|
+
if (row.availableAt === undefined) {
|
|
574
|
+
row.availableAt = derived;
|
|
575
|
+
}
|
|
576
|
+
else if (availableDay) {
|
|
577
|
+
const explicit = utcMidnight(addUtcDays(availableDay, 1));
|
|
578
|
+
if (explicit < derived) {
|
|
579
|
+
throw new Error(`Point ${index + 1}: availableAt precedes the aggregate close.`);
|
|
580
|
+
}
|
|
581
|
+
row.availableAt = explicit;
|
|
582
|
+
}
|
|
583
|
+
else if (availableTime && availableTime.getTime() < periodEnd.getTime()) {
|
|
584
|
+
throw new Error(`Point ${index + 1}: availableAt precedes the aggregate close.`);
|
|
585
|
+
}
|
|
586
|
+
return row;
|
|
587
|
+
});
|
|
588
|
+
}
|
|
423
589
|
function pointsJsonl(points) {
|
|
424
590
|
return new TextEncoder().encode(points.map((point) => `${JSON.stringify(point)}\n`).join(""));
|
|
425
591
|
}
|
|
@@ -606,21 +772,25 @@ class NexusTradeClient {
|
|
|
606
772
|
* than creating a second one.
|
|
607
773
|
*/
|
|
608
774
|
async createCustomIndicator(indicator, options) {
|
|
609
|
-
const { name, description, scope, points, ...rest } = indicator;
|
|
775
|
+
const { name, description, scope, pointKind, aggregatePeriod, points, ...rest } = indicator;
|
|
610
776
|
if (typeof name !== "string" || !name.trim()) {
|
|
611
777
|
throw new Error("createCustomIndicator requires a name.");
|
|
612
778
|
}
|
|
613
779
|
const unknown = Object.keys(rest);
|
|
614
780
|
if (unknown.length > 0) {
|
|
615
781
|
throw new Error(`Unknown custom indicator field(s): ${unknown.sort().join(", ")}. ` +
|
|
616
|
-
"Expected name, description, scope, and points.");
|
|
782
|
+
"Expected name, description, scope, pointKind, aggregatePeriod, and points.");
|
|
617
783
|
}
|
|
618
|
-
const normalized = points ? customIndicatorPoints(points) : [];
|
|
784
|
+
const normalized = pointKindPoints(points ? customIndicatorPoints(points) : [], pointKind, aggregatePeriod);
|
|
619
785
|
const body = { name: name.trim() };
|
|
620
786
|
if (description !== undefined)
|
|
621
787
|
body.description = description;
|
|
622
788
|
if (scope !== undefined)
|
|
623
789
|
body.scope = scope;
|
|
790
|
+
if (pointKind !== undefined)
|
|
791
|
+
body.pointKind = pointKind;
|
|
792
|
+
if (aggregatePeriod !== undefined)
|
|
793
|
+
body.aggregatePeriod = aggregatePeriod;
|
|
624
794
|
const inline = normalized.length > 0 &&
|
|
625
795
|
inlinePointBytes(normalized) <= MAX_INLINE_POINT_BYTES;
|
|
626
796
|
if (inline)
|
|
@@ -671,12 +841,21 @@ class NexusTradeClient {
|
|
|
671
841
|
* uploaded depending on how large it is.
|
|
672
842
|
*/
|
|
673
843
|
async appendCustomIndicatorPoints(customIndicatorId, points, options) {
|
|
674
|
-
const normalized = customIndicatorPoints(points);
|
|
844
|
+
const normalized = pointKindPoints(customIndicatorPoints(points), options.pointKind, options.aggregatePeriod);
|
|
675
845
|
if (normalized.length === 0) {
|
|
676
846
|
throw new Error("appendCustomIndicatorPoints needs at least one point.");
|
|
677
847
|
}
|
|
678
848
|
if (inlinePointBytes(normalized) <= MAX_INLINE_POINT_BYTES) {
|
|
679
|
-
const response = await this.transport.request("POST", `custom-indicators/${encodePathSegment(customIndicatorId)}/points`, {
|
|
849
|
+
const response = await this.transport.request("POST", `custom-indicators/${encodePathSegment(customIndicatorId)}/points`, {
|
|
850
|
+
body: {
|
|
851
|
+
points: normalized,
|
|
852
|
+
...(options.pointKind ? { pointKind: options.pointKind } : {}),
|
|
853
|
+
...(options.aggregatePeriod
|
|
854
|
+
? { aggregatePeriod: options.aggregatePeriod }
|
|
855
|
+
: {}),
|
|
856
|
+
},
|
|
857
|
+
idempotencyKey: options.idempotencyKey,
|
|
858
|
+
});
|
|
680
859
|
const indicator = response.indicator;
|
|
681
860
|
if (!isJsonObject(indicator)) {
|
|
682
861
|
throw new NexusTradeApiError(exports.NO_HTTP_STATUS, "invalid_response", "Custom indicator response is missing indicator.");
|
|
@@ -689,6 +868,43 @@ class NexusTradeClient {
|
|
|
689
868
|
upload,
|
|
690
869
|
};
|
|
691
870
|
}
|
|
871
|
+
/** Replace the complete series while retaining the same CustomIndicator id. */
|
|
872
|
+
async replaceCustomIndicatorPoints(customIndicatorId, points, options) {
|
|
873
|
+
const normalized = pointKindPoints(customIndicatorPoints(points), options.pointKind, options.aggregatePeriod);
|
|
874
|
+
if (normalized.length === 0) {
|
|
875
|
+
throw new Error("replaceCustomIndicatorPoints needs at least one point.");
|
|
876
|
+
}
|
|
877
|
+
if (inlinePointBytes(normalized) <= MAX_INLINE_POINT_BYTES) {
|
|
878
|
+
return customIndicatorOf(await this.transport.request("PUT", `custom-indicators/${encodePathSegment(customIndicatorId)}/points`, {
|
|
879
|
+
body: {
|
|
880
|
+
points: normalized,
|
|
881
|
+
allowShrink: options.allowShrink === true,
|
|
882
|
+
...(options.pointKind ? { pointKind: options.pointKind } : {}),
|
|
883
|
+
...(options.aggregatePeriod
|
|
884
|
+
? { aggregatePeriod: options.aggregatePeriod }
|
|
885
|
+
: {}),
|
|
886
|
+
},
|
|
887
|
+
idempotencyKey: options.idempotencyKey,
|
|
888
|
+
}));
|
|
889
|
+
}
|
|
890
|
+
const upload = await this.uploadCustomIndicatorPoints(customIndicatorId, normalized, options.idempotencyKey, { mode: "replace", allowShrink: options.allowShrink === true });
|
|
891
|
+
return {
|
|
892
|
+
...(await this.getCustomIndicator(customIndicatorId)),
|
|
893
|
+
upload,
|
|
894
|
+
};
|
|
895
|
+
}
|
|
896
|
+
/** Soft-archive a CustomIndicator. Pass confirm when active portfolios use it. */
|
|
897
|
+
async archiveCustomIndicator(customIndicatorId, options = {}) {
|
|
898
|
+
const response = await this.transport.request("DELETE", `custom-indicators/${encodePathSegment(customIndicatorId)}`, { body: { confirm: options.confirm === true } });
|
|
899
|
+
if (!isJsonObject(response.archive)) {
|
|
900
|
+
throw new NexusTradeApiError(exports.NO_HTTP_STATUS, "invalid_response", "Custom indicator archive response is missing archive details.");
|
|
901
|
+
}
|
|
902
|
+
return response.archive;
|
|
903
|
+
}
|
|
904
|
+
/** Restore a soft-archived CustomIndicator. */
|
|
905
|
+
async restoreCustomIndicator(customIndicatorId) {
|
|
906
|
+
return customIndicatorOf(await this.transport.request("POST", `custom-indicators/${encodePathSegment(customIndicatorId)}/restore`, { body: {} }));
|
|
907
|
+
}
|
|
692
908
|
/**
|
|
693
909
|
* Open an upload slot and return a presigned `uploadUrl` to PUT to.
|
|
694
910
|
*
|
|
@@ -711,6 +927,10 @@ class NexusTradeClient {
|
|
|
711
927
|
body.contentType = options.contentType;
|
|
712
928
|
if (options.sizeBytes !== undefined)
|
|
713
929
|
body.sizeBytes = options.sizeBytes;
|
|
930
|
+
if (options.mode !== undefined)
|
|
931
|
+
body.mode = options.mode;
|
|
932
|
+
if (options.allowShrink !== undefined)
|
|
933
|
+
body.allowShrink = options.allowShrink;
|
|
714
934
|
const response = await this.transport.request("POST", `custom-indicators/${encodePathSegment(customIndicatorId)}/uploads`, { body, idempotencyKey: options.idempotencyKey });
|
|
715
935
|
const ticket = response.ticket;
|
|
716
936
|
if (!isJsonObject(ticket) || !ticket.jobId) {
|
|
@@ -732,7 +952,7 @@ class NexusTradeClient {
|
|
|
732
952
|
async waitForCustomIndicatorUpload(customIndicatorId, jobId, options = {}) {
|
|
733
953
|
return waitForOperation((pendingId) => this.getCustomIndicatorUpload(customIndicatorId, pendingId), jobId, options);
|
|
734
954
|
}
|
|
735
|
-
async uploadCustomIndicatorPoints(customIndicatorId, points, idempotencyKey) {
|
|
955
|
+
async uploadCustomIndicatorPoints(customIndicatorId, points, idempotencyKey, options = {}) {
|
|
736
956
|
const payload = pointsJsonl(points);
|
|
737
957
|
if (payload.length > MAX_UPLOAD_BYTES) {
|
|
738
958
|
throw new Error(`${points.length} points serialize to ` +
|
|
@@ -747,6 +967,8 @@ class NexusTradeClient {
|
|
|
747
967
|
format: "jsonl",
|
|
748
968
|
sizeBytes: payload.length,
|
|
749
969
|
idempotencyKey,
|
|
970
|
+
mode: options.mode,
|
|
971
|
+
allowShrink: options.allowShrink,
|
|
750
972
|
});
|
|
751
973
|
const jobId = String(ticket.jobId);
|
|
752
974
|
// No upload URL means this batch already reached the server on an earlier
|
|
@@ -949,6 +1171,50 @@ class NexusTradeClient {
|
|
|
949
1171
|
async cancelLakeQuery(queryId) {
|
|
950
1172
|
return operationOf(await this.transport.request("POST", `lake/queries/${encodePathSegment(queryId)}/cancel`));
|
|
951
1173
|
}
|
|
1174
|
+
/**
|
|
1175
|
+
* Submit a natural-language stock screen. Returns immediately; poll it.
|
|
1176
|
+
*
|
|
1177
|
+
* `returnQuery` keeps the generated SQL, engine and catalog version on the
|
|
1178
|
+
* result. It defaults on: the SQL is the audit trail, and without it the rows
|
|
1179
|
+
* are a number nobody can re-derive. It is returned on failure regardless,
|
|
1180
|
+
* because a rejected query is the most useful thing to read.
|
|
1181
|
+
*/
|
|
1182
|
+
async createNlScreen(question, options = {}) {
|
|
1183
|
+
return operationOf(await this.transport.request("POST", "nl/screens", {
|
|
1184
|
+
body: {
|
|
1185
|
+
question,
|
|
1186
|
+
returnQuery: options.returnQuery ?? true,
|
|
1187
|
+
},
|
|
1188
|
+
}));
|
|
1189
|
+
}
|
|
1190
|
+
async getNlScreen(screenId) {
|
|
1191
|
+
return operationOf(await this.transport.request("GET", `nl/screens/${encodePathSegment(screenId)}`));
|
|
1192
|
+
}
|
|
1193
|
+
async cancelNlScreen(screenId) {
|
|
1194
|
+
return operationOf(await this.transport.request("POST", `nl/screens/${encodePathSegment(screenId)}/cancel`));
|
|
1195
|
+
}
|
|
1196
|
+
/** Block until a screen is terminal. See `waitForOperation`. */
|
|
1197
|
+
async waitForNlScreen(screenId, options = {}) {
|
|
1198
|
+
return waitForOperation((id) => this.getNlScreen(id), screenId, options);
|
|
1199
|
+
}
|
|
1200
|
+
/**
|
|
1201
|
+
* Submit a natural-language lake ask. Returns immediately; poll it.
|
|
1202
|
+
*/
|
|
1203
|
+
async createLakeAsk(question) {
|
|
1204
|
+
return operationOf(await this.transport.request("POST", "lake/ask", {
|
|
1205
|
+
body: { question },
|
|
1206
|
+
}));
|
|
1207
|
+
}
|
|
1208
|
+
async getLakeAsk(askId) {
|
|
1209
|
+
return operationOf(await this.transport.request("GET", `lake/ask/${encodePathSegment(askId)}`));
|
|
1210
|
+
}
|
|
1211
|
+
async cancelLakeAsk(askId) {
|
|
1212
|
+
return operationOf(await this.transport.request("POST", `lake/ask/${encodePathSegment(askId)}/cancel`));
|
|
1213
|
+
}
|
|
1214
|
+
/** Block until a lake ask is terminal. See `waitForOperation`. */
|
|
1215
|
+
async waitForLakeAsk(askId, options = {}) {
|
|
1216
|
+
return waitForOperation((id) => this.getLakeAsk(id), askId, options);
|
|
1217
|
+
}
|
|
952
1218
|
async getLakeQueryManifest(queryId) {
|
|
953
1219
|
return operationOf(await this.transport.request("GET", `lake/queries/${encodePathSegment(queryId)}/manifest`));
|
|
954
1220
|
}
|
|
@@ -37,6 +37,7 @@ exports.Fundamental = Fundamental;
|
|
|
37
37
|
exports.GapPercentage = GapPercentage;
|
|
38
38
|
exports.GapSize = GapSize;
|
|
39
39
|
exports.HighOfDay = HighOfDay;
|
|
40
|
+
exports.ImpliedVolatility = ImpliedVolatility;
|
|
40
41
|
exports.Index = Index;
|
|
41
42
|
exports.IndicatorAtMinutesAfterOpen = IndicatorAtMinutesAfterOpen;
|
|
42
43
|
exports.IndicatorExponentialMovingAverage = IndicatorExponentialMovingAverage;
|
|
@@ -51,6 +52,9 @@ exports.IsAssetType = IsAssetType;
|
|
|
51
52
|
exports.IsIndexMember = IsIndexMember;
|
|
52
53
|
exports.IsIndustry = IsIndustry;
|
|
53
54
|
exports.IsNotAsset = IsNotAsset;
|
|
55
|
+
exports.IVHVRatio = IVHVRatio;
|
|
56
|
+
exports.IVPercentile = IVPercentile;
|
|
57
|
+
exports.IVRank = IVRank;
|
|
54
58
|
exports.LastOrderPrice = LastOrderPrice;
|
|
55
59
|
exports.Log = Log;
|
|
56
60
|
exports.LowOfDay = LowOfDay;
|
|
@@ -316,6 +320,7 @@ const leg = (config) => {
|
|
|
316
320
|
expirationRange: config.expirationRange,
|
|
317
321
|
ratio: config.ratio,
|
|
318
322
|
greekFilter: config.greekFilter,
|
|
323
|
+
liquidityFilter: config.liquidityFilter,
|
|
319
324
|
});
|
|
320
325
|
};
|
|
321
326
|
exports.leg = leg;
|
|
@@ -689,6 +694,17 @@ function HighOfDay(asset) {
|
|
|
689
694
|
setAsset(d, "targetAsset", asset);
|
|
690
695
|
return d;
|
|
691
696
|
}
|
|
697
|
+
/**
|
|
698
|
+
* ImpliedVolatility indicator.
|
|
699
|
+
* @param asset Ticker name (ex. SPY, BTC)
|
|
700
|
+
* @param dte Target constant-maturity tenor in calendar days (e.g. 30)
|
|
701
|
+
*/
|
|
702
|
+
function ImpliedVolatility(asset, dte = 30) {
|
|
703
|
+
const d = { type: "ImpliedVolatility" };
|
|
704
|
+
setAsset(d, "targetAsset", asset);
|
|
705
|
+
d["dte"] = dte;
|
|
706
|
+
return d;
|
|
707
|
+
}
|
|
692
708
|
/**
|
|
693
709
|
* Index indicator.
|
|
694
710
|
* @param metric Ticker key matching hydrated index price data (add more in BigQuery + rehydrate as needed)
|
|
@@ -836,6 +852,41 @@ function IsNotAsset(matchAsset, asset) {
|
|
|
836
852
|
setAsset(d, "targetAsset", asset);
|
|
837
853
|
return d;
|
|
838
854
|
}
|
|
855
|
+
/**
|
|
856
|
+
* IVHVRatio indicator.
|
|
857
|
+
* @param asset Ticker name (ex. SPY, BTC)
|
|
858
|
+
* @param hvWindow Trading days of log-return history for realized volatility
|
|
859
|
+
*/
|
|
860
|
+
function IVHVRatio(asset, hvWindow = 20) {
|
|
861
|
+
const d = { type: "IVHVRatio" };
|
|
862
|
+
setAsset(d, "targetAsset", asset);
|
|
863
|
+
d["hvWindow"] = hvWindow;
|
|
864
|
+
return d;
|
|
865
|
+
}
|
|
866
|
+
/**
|
|
867
|
+
* IVPercentile indicator.
|
|
868
|
+
* @param asset Ticker name (ex. SPY, BTC)
|
|
869
|
+
* @param length Length of time
|
|
870
|
+
* @param interval Unit of time
|
|
871
|
+
*/
|
|
872
|
+
function IVPercentile(asset, length = 252, interval = "Day") {
|
|
873
|
+
const d = { type: "IVPercentile" };
|
|
874
|
+
setAsset(d, "targetAsset", asset);
|
|
875
|
+
d.window = { length: length, interval: interval };
|
|
876
|
+
return d;
|
|
877
|
+
}
|
|
878
|
+
/**
|
|
879
|
+
* IVRank indicator.
|
|
880
|
+
* @param asset Ticker name (ex. SPY, BTC)
|
|
881
|
+
* @param length Length of time
|
|
882
|
+
* @param interval Unit of time
|
|
883
|
+
*/
|
|
884
|
+
function IVRank(asset, length = 252, interval = "Day") {
|
|
885
|
+
const d = { type: "IVRank" };
|
|
886
|
+
setAsset(d, "targetAsset", asset);
|
|
887
|
+
d.window = { length: length, interval: interval };
|
|
888
|
+
return d;
|
|
889
|
+
}
|
|
839
890
|
/**
|
|
840
891
|
* LastOrderPrice indicator.
|
|
841
892
|
* @param asset Ticker name (ex. SPY, BTC)
|
package/dist/esm/client.d.ts
CHANGED
|
@@ -43,6 +43,10 @@ export declare const MAX_POLL_INTERVAL_SECONDS = 15;
|
|
|
43
43
|
export declare const POLL_BACKOFF_FACTOR = 1.5;
|
|
44
44
|
export declare const DEFAULT_CONNECT_TIMEOUT_SECONDS = 300;
|
|
45
45
|
export declare const CONNECT_POLL_INTERVAL_SECONDS = 3;
|
|
46
|
+
export declare const MAX_UPLOAD_PUT_ATTEMPTS = 5;
|
|
47
|
+
export declare const UPLOAD_PUT_INITIAL_BACKOFF_SECONDS = 0.5;
|
|
48
|
+
export declare const UPLOAD_PUT_MAX_BACKOFF_SECONDS = 8;
|
|
49
|
+
export declare const UPLOAD_PUT_JITTER_SECONDS = 0.25;
|
|
46
50
|
export declare class NexusTradeApiError extends Error {
|
|
47
51
|
readonly status: number;
|
|
48
52
|
readonly code: string;
|
|
@@ -135,8 +139,12 @@ export interface CustomIndicatorInput {
|
|
|
135
139
|
name: string;
|
|
136
140
|
description?: string;
|
|
137
141
|
scope?: "global" | "asset";
|
|
142
|
+
pointKind?: "observation" | "period_aggregate" | "disclosed";
|
|
143
|
+
aggregatePeriod?: "1d" | "1w" | "1mo" | "1q";
|
|
138
144
|
points?: ReadonlyArray<CustomIndicatorPointInput>;
|
|
139
145
|
}
|
|
146
|
+
type IndicatorPointKind = NonNullable<CustomIndicatorInput["pointKind"]>;
|
|
147
|
+
type IndicatorAggregatePeriod = NonNullable<CustomIndicatorInput["aggregatePeriod"]>;
|
|
140
148
|
export declare function waitForOperation(fetch: (operationId: string) => Promise<JsonObject>, operationId: string, options?: WaitOptions): Promise<JsonObject>;
|
|
141
149
|
export declare class NexusTradeClient {
|
|
142
150
|
private readonly transport;
|
|
@@ -204,7 +212,22 @@ export declare class NexusTradeClient {
|
|
|
204
212
|
*/
|
|
205
213
|
appendCustomIndicatorPoints(customIndicatorId: string, points: ReadonlyArray<CustomIndicatorPointInput>, options: {
|
|
206
214
|
idempotencyKey: string;
|
|
215
|
+
pointKind?: IndicatorPointKind;
|
|
216
|
+
aggregatePeriod?: IndicatorAggregatePeriod;
|
|
207
217
|
}): Promise<JsonObject>;
|
|
218
|
+
/** Replace the complete series while retaining the same CustomIndicator id. */
|
|
219
|
+
replaceCustomIndicatorPoints(customIndicatorId: string, points: ReadonlyArray<CustomIndicatorPointInput>, options: {
|
|
220
|
+
idempotencyKey: string;
|
|
221
|
+
allowShrink?: boolean;
|
|
222
|
+
pointKind?: IndicatorPointKind;
|
|
223
|
+
aggregatePeriod?: IndicatorAggregatePeriod;
|
|
224
|
+
}): Promise<JsonObject>;
|
|
225
|
+
/** Soft-archive a CustomIndicator. Pass confirm when active portfolios use it. */
|
|
226
|
+
archiveCustomIndicator(customIndicatorId: string, options?: {
|
|
227
|
+
confirm?: boolean;
|
|
228
|
+
}): Promise<JsonObject>;
|
|
229
|
+
/** Restore a soft-archived CustomIndicator. */
|
|
230
|
+
restoreCustomIndicator(customIndicatorId: string): Promise<JsonObject>;
|
|
208
231
|
/**
|
|
209
232
|
* Open an upload slot and return a presigned `uploadUrl` to PUT to.
|
|
210
233
|
*
|
|
@@ -224,6 +247,8 @@ export declare class NexusTradeClient {
|
|
|
224
247
|
format?: "csv" | "json" | "jsonl";
|
|
225
248
|
contentType?: string;
|
|
226
249
|
sizeBytes?: number;
|
|
250
|
+
mode?: "append" | "replace";
|
|
251
|
+
allowShrink?: boolean;
|
|
227
252
|
}): Promise<JsonObject>;
|
|
228
253
|
/** Start validation of uploaded bytes and return the operation. */
|
|
229
254
|
completeCustomIndicatorUpload(customIndicatorId: string, jobId: string): Promise<JsonObject>;
|
|
@@ -321,6 +346,29 @@ export declare class NexusTradeClient {
|
|
|
321
346
|
}): Promise<JsonObject>;
|
|
322
347
|
getLakeQuery(queryId: string): Promise<JsonObject>;
|
|
323
348
|
cancelLakeQuery(queryId: string): Promise<JsonObject>;
|
|
349
|
+
/**
|
|
350
|
+
* Submit a natural-language stock screen. Returns immediately; poll it.
|
|
351
|
+
*
|
|
352
|
+
* `returnQuery` keeps the generated SQL, engine and catalog version on the
|
|
353
|
+
* result. It defaults on: the SQL is the audit trail, and without it the rows
|
|
354
|
+
* are a number nobody can re-derive. It is returned on failure regardless,
|
|
355
|
+
* because a rejected query is the most useful thing to read.
|
|
356
|
+
*/
|
|
357
|
+
createNlScreen(question: string, options?: {
|
|
358
|
+
returnQuery?: boolean;
|
|
359
|
+
}): Promise<JsonObject>;
|
|
360
|
+
getNlScreen(screenId: string): Promise<JsonObject>;
|
|
361
|
+
cancelNlScreen(screenId: string): Promise<JsonObject>;
|
|
362
|
+
/** Block until a screen is terminal. See `waitForOperation`. */
|
|
363
|
+
waitForNlScreen(screenId: string, options?: WaitOptions): Promise<JsonObject>;
|
|
364
|
+
/**
|
|
365
|
+
* Submit a natural-language lake ask. Returns immediately; poll it.
|
|
366
|
+
*/
|
|
367
|
+
createLakeAsk(question: string): Promise<JsonObject>;
|
|
368
|
+
getLakeAsk(askId: string): Promise<JsonObject>;
|
|
369
|
+
cancelLakeAsk(askId: string): Promise<JsonObject>;
|
|
370
|
+
/** Block until a lake ask is terminal. See `waitForOperation`. */
|
|
371
|
+
waitForLakeAsk(askId: string, options?: WaitOptions): Promise<JsonObject>;
|
|
324
372
|
getLakeQueryManifest(queryId: string): Promise<JsonObject>;
|
|
325
373
|
getLakeCatalog(): Promise<JsonObject[]>;
|
|
326
374
|
describeLakeTable(table: string): Promise<JsonObject>;
|
|
@@ -353,3 +401,4 @@ export declare function createPortfolio(portfolio: JsonObject, options: {
|
|
|
353
401
|
idempotencyKey: string;
|
|
354
402
|
client?: NexusTradeClient;
|
|
355
403
|
}): Promise<JsonObject>;
|
|
404
|
+
export {};
|