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/esm/client.js
CHANGED
|
@@ -65,6 +65,14 @@ function stdoutIsInteractive() {
|
|
|
65
65
|
// Point batches larger than this are uploaded rather than sent inline.
|
|
66
66
|
const MAX_INLINE_POINT_BYTES = 512 * 1024;
|
|
67
67
|
const MAX_UPLOAD_BYTES = 100 * 1024 * 1024;
|
|
68
|
+
// A presigned PUT crosses the open internet with no API-side retry behind it, so
|
|
69
|
+
// the client owns transient recovery. Jittered (unlike the poll backoff) because
|
|
70
|
+
// every client retrying a storage blip on the same schedule is the blip.
|
|
71
|
+
// checkSdkClientParity.ts asserts these match the Python SDK.
|
|
72
|
+
export const MAX_UPLOAD_PUT_ATTEMPTS = 5;
|
|
73
|
+
export const UPLOAD_PUT_INITIAL_BACKOFF_SECONDS = 0.5;
|
|
74
|
+
export const UPLOAD_PUT_MAX_BACKOFF_SECONDS = 8.0;
|
|
75
|
+
export const UPLOAD_PUT_JITTER_SECONDS = 0.25;
|
|
68
76
|
const POINT_FIELDS = {
|
|
69
77
|
timestamp: "timestamp",
|
|
70
78
|
value: "value",
|
|
@@ -91,6 +99,22 @@ export class NexusTradeApiError extends Error {
|
|
|
91
99
|
this.operationId = operationId;
|
|
92
100
|
}
|
|
93
101
|
}
|
|
102
|
+
function isRetryableUploadHttpStatus(status) {
|
|
103
|
+
return status === 408 || status === 429 || status >= 500;
|
|
104
|
+
}
|
|
105
|
+
/** Only a transport fault or a storage-side transient earns another PUT. */
|
|
106
|
+
function isRetryableUploadError(error) {
|
|
107
|
+
if (!(error instanceof NexusTradeApiError)) {
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
if (error.code === "transport_error") {
|
|
111
|
+
return true;
|
|
112
|
+
}
|
|
113
|
+
if (error.code === "upload_failed" && error.status !== NO_HTTP_STATUS) {
|
|
114
|
+
return isRetryableUploadHttpStatus(error.status);
|
|
115
|
+
}
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
94
118
|
function origin(url) {
|
|
95
119
|
const parsed = new URL(url);
|
|
96
120
|
const scheme = parsed.protocol.replace(":", "").toLowerCase();
|
|
@@ -106,7 +130,7 @@ function sameOrigin(left, right) {
|
|
|
106
130
|
return a.scheme === b.scheme && a.host === b.host && a.port === b.port;
|
|
107
131
|
}
|
|
108
132
|
function supportsBinary(transport) {
|
|
109
|
-
return
|
|
133
|
+
return typeof transport.requestBytes === "function";
|
|
110
134
|
}
|
|
111
135
|
function supportsUpload(transport) {
|
|
112
136
|
return typeof transport.putBytes === "function";
|
|
@@ -192,7 +216,9 @@ function decodeJsonObject(bytes, status) {
|
|
|
192
216
|
catch {
|
|
193
217
|
throw new NexusTradeApiError(status, "invalid_response", "NexusTrade returned invalid JSON.");
|
|
194
218
|
}
|
|
195
|
-
if (typeof decoded !== "object" ||
|
|
219
|
+
if (typeof decoded !== "object" ||
|
|
220
|
+
decoded === null ||
|
|
221
|
+
Array.isArray(decoded)) {
|
|
196
222
|
throw new NexusTradeApiError(status, "invalid_response", "NexusTrade returned a non-object JSON response.");
|
|
197
223
|
}
|
|
198
224
|
return decoded;
|
|
@@ -219,6 +245,23 @@ export class HttpTransport {
|
|
|
219
245
|
}
|
|
220
246
|
/** PUT a payload to a presigned storage URL. Sends no credential. */
|
|
221
247
|
async putBytes(url, data, options) {
|
|
248
|
+
let delaySeconds = UPLOAD_PUT_INITIAL_BACKOFF_SECONDS;
|
|
249
|
+
for (let attempt = 0; attempt < MAX_UPLOAD_PUT_ATTEMPTS; attempt++) {
|
|
250
|
+
try {
|
|
251
|
+
await this.#putBytesOnce(url, data, options);
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
catch (error) {
|
|
255
|
+
if (attempt >= MAX_UPLOAD_PUT_ATTEMPTS - 1 ||
|
|
256
|
+
!isRetryableUploadError(error)) {
|
|
257
|
+
throw error;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
delaySeconds = Math.min(delaySeconds * 2, UPLOAD_PUT_MAX_BACKOFF_SECONDS);
|
|
261
|
+
await sleep((delaySeconds + Math.random() * UPLOAD_PUT_JITTER_SECONDS) * 1000);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
async #putBytesOnce(url, data, options) {
|
|
222
265
|
let parsed;
|
|
223
266
|
try {
|
|
224
267
|
parsed = new URL(url);
|
|
@@ -411,6 +454,129 @@ function customIndicatorPoints(points) {
|
|
|
411
454
|
}
|
|
412
455
|
return points.map(customIndicatorPoint);
|
|
413
456
|
}
|
|
457
|
+
function dateOnly(value) {
|
|
458
|
+
if (typeof value !== "string" || !/^\d{4}-\d{2}-\d{2}$/.test(value)) {
|
|
459
|
+
return undefined;
|
|
460
|
+
}
|
|
461
|
+
const parsed = new Date(`${value}T00:00:00.000Z`);
|
|
462
|
+
return Number.isNaN(parsed.getTime()) ||
|
|
463
|
+
parsed.toISOString().slice(0, 10) !== value
|
|
464
|
+
? undefined
|
|
465
|
+
: parsed;
|
|
466
|
+
}
|
|
467
|
+
function utcMidnight(day) {
|
|
468
|
+
return `${day.toISOString().slice(0, 10)}T00:00:00.000Z`;
|
|
469
|
+
}
|
|
470
|
+
function utcDateTime(value) {
|
|
471
|
+
const day = dateOnly(value);
|
|
472
|
+
if (day)
|
|
473
|
+
return day;
|
|
474
|
+
if (typeof value !== "string")
|
|
475
|
+
return undefined;
|
|
476
|
+
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);
|
|
477
|
+
if (!hasExplicitZone)
|
|
478
|
+
return undefined;
|
|
479
|
+
const parsed = new Date(value);
|
|
480
|
+
return Number.isNaN(parsed.getTime()) ? undefined : parsed;
|
|
481
|
+
}
|
|
482
|
+
function addUtcDays(day, days) {
|
|
483
|
+
return new Date(Date.UTC(day.getUTCFullYear(), day.getUTCMonth(), day.getUTCDate() + days));
|
|
484
|
+
}
|
|
485
|
+
function pointKindPoints(points, pointKind, aggregatePeriod) {
|
|
486
|
+
if (!pointKind) {
|
|
487
|
+
if (aggregatePeriod) {
|
|
488
|
+
throw new Error("aggregatePeriod requires pointKind period_aggregate.");
|
|
489
|
+
}
|
|
490
|
+
return points;
|
|
491
|
+
}
|
|
492
|
+
if (pointKind !== "period_aggregate" && aggregatePeriod) {
|
|
493
|
+
throw new Error("aggregatePeriod is only valid for period_aggregate.");
|
|
494
|
+
}
|
|
495
|
+
if (pointKind === "period_aggregate" && !aggregatePeriod) {
|
|
496
|
+
throw new Error("period_aggregate requires aggregatePeriod.");
|
|
497
|
+
}
|
|
498
|
+
return points.map((point, index) => {
|
|
499
|
+
const row = { ...point };
|
|
500
|
+
const eventDay = dateOnly(row.timestamp);
|
|
501
|
+
const availableDay = dateOnly(row.availableAt);
|
|
502
|
+
const eventTime = utcDateTime(row.timestamp);
|
|
503
|
+
const availableTime = utcDateTime(row.availableAt);
|
|
504
|
+
if (pointKind === "observation") {
|
|
505
|
+
if (row.availableAt === undefined) {
|
|
506
|
+
row.availableAt = eventDay ? utcMidnight(eventDay) : row.timestamp;
|
|
507
|
+
}
|
|
508
|
+
else if (eventDay && availableDay?.getTime() === eventDay.getTime()) {
|
|
509
|
+
row.availableAt = utcMidnight(eventDay);
|
|
510
|
+
}
|
|
511
|
+
else if (availableDay) {
|
|
512
|
+
row.availableAt = utcMidnight(addUtcDays(availableDay, 1));
|
|
513
|
+
}
|
|
514
|
+
if (eventTime &&
|
|
515
|
+
availableTime &&
|
|
516
|
+
availableTime.toISOString().slice(0, 10) >
|
|
517
|
+
eventTime.toISOString().slice(0, 10)) {
|
|
518
|
+
throw new Error(`Point ${index + 1}: observation availableAt is after the event date.`);
|
|
519
|
+
}
|
|
520
|
+
return row;
|
|
521
|
+
}
|
|
522
|
+
if (pointKind === "disclosed") {
|
|
523
|
+
if (row.availableAt === undefined) {
|
|
524
|
+
throw new Error(`Point ${index + 1}: disclosed pointKind requires availableAt.`);
|
|
525
|
+
}
|
|
526
|
+
if (availableDay) {
|
|
527
|
+
row.availableAt = utcMidnight(addUtcDays(availableDay, 1));
|
|
528
|
+
}
|
|
529
|
+
return row;
|
|
530
|
+
}
|
|
531
|
+
if (!eventTime) {
|
|
532
|
+
throw new Error(`Point ${index + 1}: aggregate timestamp must be date-only or include an explicit UTC offset.`);
|
|
533
|
+
}
|
|
534
|
+
if (eventTime.getUTCHours() !== 0 ||
|
|
535
|
+
eventTime.getUTCMinutes() !== 0 ||
|
|
536
|
+
eventTime.getUTCSeconds() !== 0 ||
|
|
537
|
+
eventTime.getUTCMilliseconds() !== 0) {
|
|
538
|
+
throw new Error(`Point ${index + 1}: aggregate timestamp must be UTC midnight.`);
|
|
539
|
+
}
|
|
540
|
+
let periodEnd;
|
|
541
|
+
if (aggregatePeriod === "1d") {
|
|
542
|
+
periodEnd = addUtcDays(eventTime, 1);
|
|
543
|
+
}
|
|
544
|
+
else if (aggregatePeriod === "1w") {
|
|
545
|
+
if (eventTime.getUTCDay() !== 1) {
|
|
546
|
+
throw new Error(`Point ${index + 1}: 1w timestamp must be a Monday.`);
|
|
547
|
+
}
|
|
548
|
+
periodEnd = addUtcDays(eventTime, 7);
|
|
549
|
+
}
|
|
550
|
+
else if (aggregatePeriod === "1mo") {
|
|
551
|
+
if (eventTime.getUTCDate() !== 1) {
|
|
552
|
+
throw new Error(`Point ${index + 1}: 1mo timestamp must be month start.`);
|
|
553
|
+
}
|
|
554
|
+
periodEnd = new Date(Date.UTC(eventTime.getUTCFullYear(), eventTime.getUTCMonth() + 1, 1));
|
|
555
|
+
}
|
|
556
|
+
else {
|
|
557
|
+
if (eventTime.getUTCDate() !== 1 ||
|
|
558
|
+
![0, 3, 6, 9].includes(eventTime.getUTCMonth())) {
|
|
559
|
+
throw new Error(`Point ${index + 1}: 1q timestamp must be quarter start.`);
|
|
560
|
+
}
|
|
561
|
+
periodEnd = new Date(Date.UTC(eventTime.getUTCFullYear(), eventTime.getUTCMonth() + 3, 1));
|
|
562
|
+
}
|
|
563
|
+
const derived = utcMidnight(periodEnd);
|
|
564
|
+
if (row.availableAt === undefined) {
|
|
565
|
+
row.availableAt = derived;
|
|
566
|
+
}
|
|
567
|
+
else if (availableDay) {
|
|
568
|
+
const explicit = utcMidnight(addUtcDays(availableDay, 1));
|
|
569
|
+
if (explicit < derived) {
|
|
570
|
+
throw new Error(`Point ${index + 1}: availableAt precedes the aggregate close.`);
|
|
571
|
+
}
|
|
572
|
+
row.availableAt = explicit;
|
|
573
|
+
}
|
|
574
|
+
else if (availableTime && availableTime.getTime() < periodEnd.getTime()) {
|
|
575
|
+
throw new Error(`Point ${index + 1}: availableAt precedes the aggregate close.`);
|
|
576
|
+
}
|
|
577
|
+
return row;
|
|
578
|
+
});
|
|
579
|
+
}
|
|
414
580
|
function pointsJsonl(points) {
|
|
415
581
|
return new TextEncoder().encode(points.map((point) => `${JSON.stringify(point)}\n`).join(""));
|
|
416
582
|
}
|
|
@@ -597,21 +763,25 @@ export class NexusTradeClient {
|
|
|
597
763
|
* than creating a second one.
|
|
598
764
|
*/
|
|
599
765
|
async createCustomIndicator(indicator, options) {
|
|
600
|
-
const { name, description, scope, points, ...rest } = indicator;
|
|
766
|
+
const { name, description, scope, pointKind, aggregatePeriod, points, ...rest } = indicator;
|
|
601
767
|
if (typeof name !== "string" || !name.trim()) {
|
|
602
768
|
throw new Error("createCustomIndicator requires a name.");
|
|
603
769
|
}
|
|
604
770
|
const unknown = Object.keys(rest);
|
|
605
771
|
if (unknown.length > 0) {
|
|
606
772
|
throw new Error(`Unknown custom indicator field(s): ${unknown.sort().join(", ")}. ` +
|
|
607
|
-
"Expected name, description, scope, and points.");
|
|
773
|
+
"Expected name, description, scope, pointKind, aggregatePeriod, and points.");
|
|
608
774
|
}
|
|
609
|
-
const normalized = points ? customIndicatorPoints(points) : [];
|
|
775
|
+
const normalized = pointKindPoints(points ? customIndicatorPoints(points) : [], pointKind, aggregatePeriod);
|
|
610
776
|
const body = { name: name.trim() };
|
|
611
777
|
if (description !== undefined)
|
|
612
778
|
body.description = description;
|
|
613
779
|
if (scope !== undefined)
|
|
614
780
|
body.scope = scope;
|
|
781
|
+
if (pointKind !== undefined)
|
|
782
|
+
body.pointKind = pointKind;
|
|
783
|
+
if (aggregatePeriod !== undefined)
|
|
784
|
+
body.aggregatePeriod = aggregatePeriod;
|
|
615
785
|
const inline = normalized.length > 0 &&
|
|
616
786
|
inlinePointBytes(normalized) <= MAX_INLINE_POINT_BYTES;
|
|
617
787
|
if (inline)
|
|
@@ -662,12 +832,21 @@ export class NexusTradeClient {
|
|
|
662
832
|
* uploaded depending on how large it is.
|
|
663
833
|
*/
|
|
664
834
|
async appendCustomIndicatorPoints(customIndicatorId, points, options) {
|
|
665
|
-
const normalized = customIndicatorPoints(points);
|
|
835
|
+
const normalized = pointKindPoints(customIndicatorPoints(points), options.pointKind, options.aggregatePeriod);
|
|
666
836
|
if (normalized.length === 0) {
|
|
667
837
|
throw new Error("appendCustomIndicatorPoints needs at least one point.");
|
|
668
838
|
}
|
|
669
839
|
if (inlinePointBytes(normalized) <= MAX_INLINE_POINT_BYTES) {
|
|
670
|
-
const response = await this.transport.request("POST", `custom-indicators/${encodePathSegment(customIndicatorId)}/points`, {
|
|
840
|
+
const response = await this.transport.request("POST", `custom-indicators/${encodePathSegment(customIndicatorId)}/points`, {
|
|
841
|
+
body: {
|
|
842
|
+
points: normalized,
|
|
843
|
+
...(options.pointKind ? { pointKind: options.pointKind } : {}),
|
|
844
|
+
...(options.aggregatePeriod
|
|
845
|
+
? { aggregatePeriod: options.aggregatePeriod }
|
|
846
|
+
: {}),
|
|
847
|
+
},
|
|
848
|
+
idempotencyKey: options.idempotencyKey,
|
|
849
|
+
});
|
|
671
850
|
const indicator = response.indicator;
|
|
672
851
|
if (!isJsonObject(indicator)) {
|
|
673
852
|
throw new NexusTradeApiError(NO_HTTP_STATUS, "invalid_response", "Custom indicator response is missing indicator.");
|
|
@@ -680,6 +859,43 @@ export class NexusTradeClient {
|
|
|
680
859
|
upload,
|
|
681
860
|
};
|
|
682
861
|
}
|
|
862
|
+
/** Replace the complete series while retaining the same CustomIndicator id. */
|
|
863
|
+
async replaceCustomIndicatorPoints(customIndicatorId, points, options) {
|
|
864
|
+
const normalized = pointKindPoints(customIndicatorPoints(points), options.pointKind, options.aggregatePeriod);
|
|
865
|
+
if (normalized.length === 0) {
|
|
866
|
+
throw new Error("replaceCustomIndicatorPoints needs at least one point.");
|
|
867
|
+
}
|
|
868
|
+
if (inlinePointBytes(normalized) <= MAX_INLINE_POINT_BYTES) {
|
|
869
|
+
return customIndicatorOf(await this.transport.request("PUT", `custom-indicators/${encodePathSegment(customIndicatorId)}/points`, {
|
|
870
|
+
body: {
|
|
871
|
+
points: normalized,
|
|
872
|
+
allowShrink: options.allowShrink === true,
|
|
873
|
+
...(options.pointKind ? { pointKind: options.pointKind } : {}),
|
|
874
|
+
...(options.aggregatePeriod
|
|
875
|
+
? { aggregatePeriod: options.aggregatePeriod }
|
|
876
|
+
: {}),
|
|
877
|
+
},
|
|
878
|
+
idempotencyKey: options.idempotencyKey,
|
|
879
|
+
}));
|
|
880
|
+
}
|
|
881
|
+
const upload = await this.uploadCustomIndicatorPoints(customIndicatorId, normalized, options.idempotencyKey, { mode: "replace", allowShrink: options.allowShrink === true });
|
|
882
|
+
return {
|
|
883
|
+
...(await this.getCustomIndicator(customIndicatorId)),
|
|
884
|
+
upload,
|
|
885
|
+
};
|
|
886
|
+
}
|
|
887
|
+
/** Soft-archive a CustomIndicator. Pass confirm when active portfolios use it. */
|
|
888
|
+
async archiveCustomIndicator(customIndicatorId, options = {}) {
|
|
889
|
+
const response = await this.transport.request("DELETE", `custom-indicators/${encodePathSegment(customIndicatorId)}`, { body: { confirm: options.confirm === true } });
|
|
890
|
+
if (!isJsonObject(response.archive)) {
|
|
891
|
+
throw new NexusTradeApiError(NO_HTTP_STATUS, "invalid_response", "Custom indicator archive response is missing archive details.");
|
|
892
|
+
}
|
|
893
|
+
return response.archive;
|
|
894
|
+
}
|
|
895
|
+
/** Restore a soft-archived CustomIndicator. */
|
|
896
|
+
async restoreCustomIndicator(customIndicatorId) {
|
|
897
|
+
return customIndicatorOf(await this.transport.request("POST", `custom-indicators/${encodePathSegment(customIndicatorId)}/restore`, { body: {} }));
|
|
898
|
+
}
|
|
683
899
|
/**
|
|
684
900
|
* Open an upload slot and return a presigned `uploadUrl` to PUT to.
|
|
685
901
|
*
|
|
@@ -702,6 +918,10 @@ export class NexusTradeClient {
|
|
|
702
918
|
body.contentType = options.contentType;
|
|
703
919
|
if (options.sizeBytes !== undefined)
|
|
704
920
|
body.sizeBytes = options.sizeBytes;
|
|
921
|
+
if (options.mode !== undefined)
|
|
922
|
+
body.mode = options.mode;
|
|
923
|
+
if (options.allowShrink !== undefined)
|
|
924
|
+
body.allowShrink = options.allowShrink;
|
|
705
925
|
const response = await this.transport.request("POST", `custom-indicators/${encodePathSegment(customIndicatorId)}/uploads`, { body, idempotencyKey: options.idempotencyKey });
|
|
706
926
|
const ticket = response.ticket;
|
|
707
927
|
if (!isJsonObject(ticket) || !ticket.jobId) {
|
|
@@ -723,7 +943,7 @@ export class NexusTradeClient {
|
|
|
723
943
|
async waitForCustomIndicatorUpload(customIndicatorId, jobId, options = {}) {
|
|
724
944
|
return waitForOperation((pendingId) => this.getCustomIndicatorUpload(customIndicatorId, pendingId), jobId, options);
|
|
725
945
|
}
|
|
726
|
-
async uploadCustomIndicatorPoints(customIndicatorId, points, idempotencyKey) {
|
|
946
|
+
async uploadCustomIndicatorPoints(customIndicatorId, points, idempotencyKey, options = {}) {
|
|
727
947
|
const payload = pointsJsonl(points);
|
|
728
948
|
if (payload.length > MAX_UPLOAD_BYTES) {
|
|
729
949
|
throw new Error(`${points.length} points serialize to ` +
|
|
@@ -738,6 +958,8 @@ export class NexusTradeClient {
|
|
|
738
958
|
format: "jsonl",
|
|
739
959
|
sizeBytes: payload.length,
|
|
740
960
|
idempotencyKey,
|
|
961
|
+
mode: options.mode,
|
|
962
|
+
allowShrink: options.allowShrink,
|
|
741
963
|
});
|
|
742
964
|
const jobId = String(ticket.jobId);
|
|
743
965
|
// No upload URL means this batch already reached the server on an earlier
|
|
@@ -940,6 +1162,50 @@ export class NexusTradeClient {
|
|
|
940
1162
|
async cancelLakeQuery(queryId) {
|
|
941
1163
|
return operationOf(await this.transport.request("POST", `lake/queries/${encodePathSegment(queryId)}/cancel`));
|
|
942
1164
|
}
|
|
1165
|
+
/**
|
|
1166
|
+
* Submit a natural-language stock screen. Returns immediately; poll it.
|
|
1167
|
+
*
|
|
1168
|
+
* `returnQuery` keeps the generated SQL, engine and catalog version on the
|
|
1169
|
+
* result. It defaults on: the SQL is the audit trail, and without it the rows
|
|
1170
|
+
* are a number nobody can re-derive. It is returned on failure regardless,
|
|
1171
|
+
* because a rejected query is the most useful thing to read.
|
|
1172
|
+
*/
|
|
1173
|
+
async createNlScreen(question, options = {}) {
|
|
1174
|
+
return operationOf(await this.transport.request("POST", "nl/screens", {
|
|
1175
|
+
body: {
|
|
1176
|
+
question,
|
|
1177
|
+
returnQuery: options.returnQuery ?? true,
|
|
1178
|
+
},
|
|
1179
|
+
}));
|
|
1180
|
+
}
|
|
1181
|
+
async getNlScreen(screenId) {
|
|
1182
|
+
return operationOf(await this.transport.request("GET", `nl/screens/${encodePathSegment(screenId)}`));
|
|
1183
|
+
}
|
|
1184
|
+
async cancelNlScreen(screenId) {
|
|
1185
|
+
return operationOf(await this.transport.request("POST", `nl/screens/${encodePathSegment(screenId)}/cancel`));
|
|
1186
|
+
}
|
|
1187
|
+
/** Block until a screen is terminal. See `waitForOperation`. */
|
|
1188
|
+
async waitForNlScreen(screenId, options = {}) {
|
|
1189
|
+
return waitForOperation((id) => this.getNlScreen(id), screenId, options);
|
|
1190
|
+
}
|
|
1191
|
+
/**
|
|
1192
|
+
* Submit a natural-language lake ask. Returns immediately; poll it.
|
|
1193
|
+
*/
|
|
1194
|
+
async createLakeAsk(question) {
|
|
1195
|
+
return operationOf(await this.transport.request("POST", "lake/ask", {
|
|
1196
|
+
body: { question },
|
|
1197
|
+
}));
|
|
1198
|
+
}
|
|
1199
|
+
async getLakeAsk(askId) {
|
|
1200
|
+
return operationOf(await this.transport.request("GET", `lake/ask/${encodePathSegment(askId)}`));
|
|
1201
|
+
}
|
|
1202
|
+
async cancelLakeAsk(askId) {
|
|
1203
|
+
return operationOf(await this.transport.request("POST", `lake/ask/${encodePathSegment(askId)}/cancel`));
|
|
1204
|
+
}
|
|
1205
|
+
/** Block until a lake ask is terminal. See `waitForOperation`. */
|
|
1206
|
+
async waitForLakeAsk(askId, options = {}) {
|
|
1207
|
+
return waitForOperation((id) => this.getLakeAsk(id), askId, options);
|
|
1208
|
+
}
|
|
943
1209
|
async getLakeQueryManifest(queryId) {
|
|
944
1210
|
return operationOf(await this.transport.request("GET", `lake/queries/${encodePathSegment(queryId)}/manifest`));
|
|
945
1211
|
}
|
|
@@ -131,6 +131,15 @@ export interface GreekFilter {
|
|
|
131
131
|
minRho?: number;
|
|
132
132
|
maxRho?: number;
|
|
133
133
|
}
|
|
134
|
+
/** Bid/ask constraints applied with `greekFilter` during resolution; a candidate must pass both. */
|
|
135
|
+
export interface LiquidityFilter {
|
|
136
|
+
/** Max (ask-bid)/mid. Preferred: $0.50 is 50% of a $1.00 contract, 1.7% of a $30.00 one. */
|
|
137
|
+
maxSpreadPct?: number;
|
|
138
|
+
/** Max ask-bid in dollars. When both bounds are set, both must pass. */
|
|
139
|
+
maxSpreadAbsolute?: number;
|
|
140
|
+
/** Minimum bid — excludes contracts you cannot sell into. */
|
|
141
|
+
minBid?: number;
|
|
142
|
+
}
|
|
134
143
|
export interface OptionsBuilderLeg {
|
|
135
144
|
optionType: OptionType;
|
|
136
145
|
direction: OptionDirection;
|
|
@@ -142,6 +151,7 @@ export interface OptionsBuilderLeg {
|
|
|
142
151
|
expirationRange?: ExpirationRange;
|
|
143
152
|
ratio?: number;
|
|
144
153
|
greekFilter?: GreekFilter;
|
|
154
|
+
liquidityFilter?: LiquidityFilter;
|
|
145
155
|
}
|
|
146
156
|
/** Shared fields for `leg(...)` (discriminated on distanceType). */
|
|
147
157
|
export type LegConfigBase = {
|
|
@@ -154,6 +164,7 @@ export type LegConfigBase = {
|
|
|
154
164
|
expirationRange?: ExpirationRange;
|
|
155
165
|
ratio?: number;
|
|
156
166
|
greekFilter?: GreekFilter;
|
|
167
|
+
liquidityFilter?: LiquidityFilter;
|
|
157
168
|
};
|
|
158
169
|
/** Percent/dollars strike — fallback optional. */
|
|
159
170
|
export type LegConfigPercentOrDollars = LegConfigBase & {
|
|
@@ -710,11 +721,17 @@ export declare function GapSize(asset: AssetArg): Indicator;
|
|
|
710
721
|
* @param asset Ticker name (ex. SPY, BTC)
|
|
711
722
|
*/
|
|
712
723
|
export declare function HighOfDay(asset: AssetArg): Indicator;
|
|
724
|
+
/**
|
|
725
|
+
* ImpliedVolatility indicator.
|
|
726
|
+
* @param asset Ticker name (ex. SPY, BTC)
|
|
727
|
+
* @param dte Target constant-maturity tenor in calendar days (e.g. 30)
|
|
728
|
+
*/
|
|
729
|
+
export declare function ImpliedVolatility(asset: AssetArg, dte?: number): Indicator;
|
|
713
730
|
/**
|
|
714
731
|
* Index indicator.
|
|
715
732
|
* @param metric Ticker key matching hydrated index price data (add more in BigQuery + rehydrate as needed)
|
|
716
733
|
*/
|
|
717
|
-
export declare function Index(metric?: "VIX" | "SPX" | "NDX" | "DJI" | "RUT" | "SKEW" | "VVIX" | "
|
|
734
|
+
export declare function Index(metric?: "VIX" | "SPX" | "NDX" | "DJI" | "RUT" | "SKEW" | "VVIX" | "USDBROAD" | "TNX"): Indicator;
|
|
718
735
|
/**
|
|
719
736
|
* IndicatorAtMinutesAfterOpen indicator.
|
|
720
737
|
* @param minutesAfterOpen The number of minutes after market open to capture the indicator value
|
|
@@ -790,6 +807,26 @@ export declare function IsIndustry(asset: AssetArg, industry: "technology" | "fi
|
|
|
790
807
|
* @param asset Ticker name (ex. SPY, BTC)
|
|
791
808
|
*/
|
|
792
809
|
export declare function IsNotAsset(matchAsset: AssetArg, asset: AssetArg): Indicator;
|
|
810
|
+
/**
|
|
811
|
+
* IVHVRatio indicator.
|
|
812
|
+
* @param asset Ticker name (ex. SPY, BTC)
|
|
813
|
+
* @param hvWindow Trading days of log-return history for realized volatility
|
|
814
|
+
*/
|
|
815
|
+
export declare function IVHVRatio(asset: AssetArg, hvWindow?: number): Indicator;
|
|
816
|
+
/**
|
|
817
|
+
* IVPercentile indicator.
|
|
818
|
+
* @param asset Ticker name (ex. SPY, BTC)
|
|
819
|
+
* @param length Length of time
|
|
820
|
+
* @param interval Unit of time
|
|
821
|
+
*/
|
|
822
|
+
export declare function IVPercentile(asset: AssetArg, length?: number, interval?: Interval): Indicator;
|
|
823
|
+
/**
|
|
824
|
+
* IVRank indicator.
|
|
825
|
+
* @param asset Ticker name (ex. SPY, BTC)
|
|
826
|
+
* @param length Length of time
|
|
827
|
+
* @param interval Unit of time
|
|
828
|
+
*/
|
|
829
|
+
export declare function IVRank(asset: AssetArg, length?: number, interval?: Interval): Indicator;
|
|
793
830
|
/**
|
|
794
831
|
* LastOrderPrice indicator.
|
|
795
832
|
* @param asset Ticker name (ex. SPY, BTC)
|
|
@@ -1287,13 +1324,20 @@ export interface Gene {
|
|
|
1287
1324
|
/** Sweep Subject (Portfolio scope) over a value set. */
|
|
1288
1325
|
export declare const geneSubject: (values: AssetArg[][]) => Gene;
|
|
1289
1326
|
/** Sweep EntryCondition (Strategy scope) over a value set. */
|
|
1290
|
-
export declare const geneEntryCondition: (strategyIndex: number, values:
|
|
1327
|
+
export declare const geneEntryCondition: (strategyIndex: number, values: {
|
|
1328
|
+
label: string;
|
|
1329
|
+
condition: Condition;
|
|
1330
|
+
}[]) => Gene;
|
|
1291
1331
|
/** Sweep ExitCondition (Strategy scope) over a value set. */
|
|
1292
|
-
export declare const geneExitCondition: (strategyIndex: number, values:
|
|
1332
|
+
export declare const geneExitCondition: (strategyIndex: number, values: {
|
|
1333
|
+
label: string;
|
|
1334
|
+
condition: Condition;
|
|
1335
|
+
}[]) => Gene;
|
|
1293
1336
|
/** Sweep EntryCooldownDays (Strategy scope) over a value set. */
|
|
1294
1337
|
export declare const geneEntryCooldownDays: (strategyIndex: number, values: number[]) => Gene;
|
|
1295
1338
|
/** Sweep RankSignal (Action scope) over a value set. */
|
|
1296
1339
|
export declare const geneRankSignal: (strategyIndex: number, values: {
|
|
1340
|
+
label: string;
|
|
1297
1341
|
indicator: Indicator;
|
|
1298
1342
|
direction: SweepSortDirection;
|
|
1299
1343
|
}[]) => Gene;
|
|
@@ -1323,5 +1367,8 @@ export declare const geneDteBracket: (strategyIndex: number, legIndex: number, v
|
|
|
1323
1367
|
/** Sweep SelectTopLimit (UniversePipeline scope) over a value set. */
|
|
1324
1368
|
export declare const geneSelectTopLimit: (strategyIndex: number, stageIndex: number, values: number[]) => Gene;
|
|
1325
1369
|
/** Sweep UniversePipelineFilter (UniversePipeline scope) over a value set. */
|
|
1326
|
-
export declare const geneUniversePipelineFilter: (strategyIndex: number, stageIndex: number, values:
|
|
1370
|
+
export declare const geneUniversePipelineFilter: (strategyIndex: number, stageIndex: number, values: {
|
|
1371
|
+
label: string;
|
|
1372
|
+
condition: Condition;
|
|
1373
|
+
}[]) => Gene;
|
|
1327
1374
|
export {};
|
|
@@ -184,6 +184,7 @@ export const leg = (config) => {
|
|
|
184
184
|
expirationRange: config.expirationRange,
|
|
185
185
|
ratio: config.ratio,
|
|
186
186
|
greekFilter: config.greekFilter,
|
|
187
|
+
liquidityFilter: config.liquidityFilter,
|
|
187
188
|
});
|
|
188
189
|
};
|
|
189
190
|
export const optionsBuilder = (config) => compact(config);
|
|
@@ -542,6 +543,17 @@ export function HighOfDay(asset) {
|
|
|
542
543
|
setAsset(d, "targetAsset", asset);
|
|
543
544
|
return d;
|
|
544
545
|
}
|
|
546
|
+
/**
|
|
547
|
+
* ImpliedVolatility indicator.
|
|
548
|
+
* @param asset Ticker name (ex. SPY, BTC)
|
|
549
|
+
* @param dte Target constant-maturity tenor in calendar days (e.g. 30)
|
|
550
|
+
*/
|
|
551
|
+
export function ImpliedVolatility(asset, dte = 30) {
|
|
552
|
+
const d = { type: "ImpliedVolatility" };
|
|
553
|
+
setAsset(d, "targetAsset", asset);
|
|
554
|
+
d["dte"] = dte;
|
|
555
|
+
return d;
|
|
556
|
+
}
|
|
545
557
|
/**
|
|
546
558
|
* Index indicator.
|
|
547
559
|
* @param metric Ticker key matching hydrated index price data (add more in BigQuery + rehydrate as needed)
|
|
@@ -689,6 +701,41 @@ export function IsNotAsset(matchAsset, asset) {
|
|
|
689
701
|
setAsset(d, "targetAsset", asset);
|
|
690
702
|
return d;
|
|
691
703
|
}
|
|
704
|
+
/**
|
|
705
|
+
* IVHVRatio indicator.
|
|
706
|
+
* @param asset Ticker name (ex. SPY, BTC)
|
|
707
|
+
* @param hvWindow Trading days of log-return history for realized volatility
|
|
708
|
+
*/
|
|
709
|
+
export function IVHVRatio(asset, hvWindow = 20) {
|
|
710
|
+
const d = { type: "IVHVRatio" };
|
|
711
|
+
setAsset(d, "targetAsset", asset);
|
|
712
|
+
d["hvWindow"] = hvWindow;
|
|
713
|
+
return d;
|
|
714
|
+
}
|
|
715
|
+
/**
|
|
716
|
+
* IVPercentile indicator.
|
|
717
|
+
* @param asset Ticker name (ex. SPY, BTC)
|
|
718
|
+
* @param length Length of time
|
|
719
|
+
* @param interval Unit of time
|
|
720
|
+
*/
|
|
721
|
+
export function IVPercentile(asset, length = 252, interval = "Day") {
|
|
722
|
+
const d = { type: "IVPercentile" };
|
|
723
|
+
setAsset(d, "targetAsset", asset);
|
|
724
|
+
d.window = { length: length, interval: interval };
|
|
725
|
+
return d;
|
|
726
|
+
}
|
|
727
|
+
/**
|
|
728
|
+
* IVRank indicator.
|
|
729
|
+
* @param asset Ticker name (ex. SPY, BTC)
|
|
730
|
+
* @param length Length of time
|
|
731
|
+
* @param interval Unit of time
|
|
732
|
+
*/
|
|
733
|
+
export function IVRank(asset, length = 252, interval = "Day") {
|
|
734
|
+
const d = { type: "IVRank" };
|
|
735
|
+
setAsset(d, "targetAsset", asset);
|
|
736
|
+
d.window = { length: length, interval: interval };
|
|
737
|
+
return d;
|
|
738
|
+
}
|
|
692
739
|
/**
|
|
693
740
|
* LastOrderPrice indicator.
|
|
694
741
|
* @param asset Ticker name (ex. SPY, BTC)
|