nexustrade 1.60.0 → 1.60.2

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 CHANGED
@@ -236,6 +236,11 @@ price target. Live option strategies must choose an explicit Limit policy.
236
236
 
237
237
  ### Option selection and execution limits
238
238
 
239
+ `strategy(..., { pendingOrderPolicy: "CancelConflictingBuys" })` enables backtest-only
240
+ exit priority over conflicting pending buys. Omission preserves waiting. Paper
241
+ and live deployment reject this opt-in because broker cancellation acknowledgements
242
+ are not implemented. The setting also accepts explicit `"Wait"`.
243
+
239
244
  Builders describe drafts. Typechecking does not prove that the engine can
240
245
  execute every requested rule; the API validates complete portfolios and their
241
246
  conditions.
@@ -336,6 +341,15 @@ const finished = await client.waitForBacktest(operation.id as string);
336
341
  A timeout throws `operation_timeout` and does **not** cancel the job — call the
337
342
  waiter again with the same id rather than resubmitting.
338
343
 
344
+ Transient network and HTTP 408/429/5xx polling failures retry the same operation
345
+ at most twice consecutively, within the wait deadline. Persistent failures keep
346
+ their original error code and operation ID; no new job is submitted.
347
+
348
+ Durable lake exports use a 900-second server budget by default (registered API
349
+ keys may request up to 1800 seconds). `waitForLakeQuery` defaults to 1200 seconds
350
+ to include queue time. Compute token budgets remain 90 seconds by default and
351
+ 180 seconds maximum. A client wait timeout does not extend the server budget.
352
+
339
353
  **Batches.** `createBacktests` submits many in one request and returns one
340
354
  operation each; `waitForBacktests(operations)` waits on all of them. Prefer it
341
355
  over a loop: one request, one idempotency key, one rate-limit slot.
@@ -747,8 +747,27 @@ async function waitForOperation(fetch, operationId, options = {}) {
747
747
  }
748
748
  const deadline = Date.now() + timeoutSeconds * 1000;
749
749
  let interval = Math.min(pollIntervalSeconds, maxPollIntervalSeconds);
750
+ let consecutiveErrors = 0;
750
751
  for (;;) {
751
- const operation = await fetch(operationId);
752
+ let operation;
753
+ try {
754
+ operation = await fetch(operationId);
755
+ }
756
+ catch (error) {
757
+ if (!(error instanceof NexusTradeApiError))
758
+ throw error;
759
+ consecutiveErrors += 1;
760
+ const transient = error.code === "transport_error" ||
761
+ error.status === 408 || error.status === 429 || error.status >= 500;
762
+ const remainingMs = deadline - Date.now();
763
+ if (!transient || consecutiveErrors >= 3 || remainingMs <= 0) {
764
+ throw new NexusTradeApiError(error.status, error.code, error.message, operationId);
765
+ }
766
+ await new Promise(resolve => setTimeout(resolve, Math.min(Math.max(1, interval) * 1000, remainingMs)));
767
+ interval = Math.min(Math.max(1, interval) * exports.POLL_BACKOFF_FACTOR, Math.max(1, maxPollIntervalSeconds));
768
+ continue;
769
+ }
770
+ consecutiveErrors = 0;
752
771
  const status = String(operation.status ?? "");
753
772
  if (TERMINAL_STATUSES.includes(status)) {
754
773
  if (raiseOnFailure && status !== "completed") {
@@ -1483,7 +1502,7 @@ class NexusTradeClient {
1483
1502
  }
1484
1503
  /** Resolve once a lake query is terminal. See `waitForOperation`. */
1485
1504
  async waitForLakeQuery(queryId, options = {}) {
1486
- return waitForOperation((id) => this.getLakeQuery(id), queryId, options);
1505
+ return waitForOperation((id) => this.getLakeQuery(id), queryId, { ...options, timeoutSeconds: options.timeoutSeconds ?? 1200 });
1487
1506
  }
1488
1507
  /** Resolve once a backtest is terminal. See `waitForOperation`. */
1489
1508
  async waitForBacktest(backtestId, options = {}) {
@@ -737,8 +737,27 @@ export async function waitForOperation(fetch, operationId, options = {}) {
737
737
  }
738
738
  const deadline = Date.now() + timeoutSeconds * 1000;
739
739
  let interval = Math.min(pollIntervalSeconds, maxPollIntervalSeconds);
740
+ let consecutiveErrors = 0;
740
741
  for (;;) {
741
- const operation = await fetch(operationId);
742
+ let operation;
743
+ try {
744
+ operation = await fetch(operationId);
745
+ }
746
+ catch (error) {
747
+ if (!(error instanceof NexusTradeApiError))
748
+ throw error;
749
+ consecutiveErrors += 1;
750
+ const transient = error.code === "transport_error" ||
751
+ error.status === 408 || error.status === 429 || error.status >= 500;
752
+ const remainingMs = deadline - Date.now();
753
+ if (!transient || consecutiveErrors >= 3 || remainingMs <= 0) {
754
+ throw new NexusTradeApiError(error.status, error.code, error.message, operationId);
755
+ }
756
+ await new Promise(resolve => setTimeout(resolve, Math.min(Math.max(1, interval) * 1000, remainingMs)));
757
+ interval = Math.min(Math.max(1, interval) * POLL_BACKOFF_FACTOR, Math.max(1, maxPollIntervalSeconds));
758
+ continue;
759
+ }
760
+ consecutiveErrors = 0;
742
761
  const status = String(operation.status ?? "");
743
762
  if (TERMINAL_STATUSES.includes(status)) {
744
763
  if (raiseOnFailure && status !== "completed") {
@@ -1473,7 +1492,7 @@ export class NexusTradeClient {
1473
1492
  }
1474
1493
  /** Resolve once a lake query is terminal. See `waitForOperation`. */
1475
1494
  async waitForLakeQuery(queryId, options = {}) {
1476
- return waitForOperation((id) => this.getLakeQuery(id), queryId, options);
1495
+ return waitForOperation((id) => this.getLakeQuery(id), queryId, { ...options, timeoutSeconds: options.timeoutSeconds ?? 1200 });
1477
1496
  }
1478
1497
  /** Resolve once a backtest is terminal. See `waitForOperation`. */
1479
1498
  async waitForBacktest(backtestId, options = {}) {
@@ -523,6 +523,8 @@ export interface Strategy {
523
523
  active?: boolean;
524
524
  /** Omitted means Market. Limit always requires an explicit price policy. */
525
525
  orderExecution?: StrategyOrderExecutionPolicy;
526
+ /** Backtest-only exit priority. CancelConflictingBuys cannot deploy to paper/live trading. */
527
+ pendingOrderPolicy?: "Wait" | "CancelConflictingBuys";
526
528
  }
527
529
  export interface AuthoredIndustryFilter {
528
530
  mode: "ALL" | "INCLUDE_ONLY";
@@ -821,6 +823,7 @@ export declare const goodForMinutes: (minutes: number) => StrategyLimitWorkingTi
821
823
  export declare const strategy: (name: string, condition: StrategyCondition, action: Action, options?: {
822
824
  active?: boolean;
823
825
  orderExecution?: StrategyOrderExecutionPolicy;
826
+ pendingOrderPolicy?: Strategy["pendingOrderPolicy"];
824
827
  }) => Strategy;
825
828
  /**
826
829
  * Session / clock flatten — condition carries the gate (MinutesAfterOpen, Day, …).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nexustrade",
3
- "version": "1.60.0",
3
+ "version": "1.60.2",
4
4
  "description": "Typed TypeScript SDK for NexusTrade portfolio authoring, backtesting, and optimization",
5
5
  "license": "MIT",
6
6
  "author": "Starks Technology",