nexustrade 1.9.10 → 1.11.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.
@@ -393,6 +393,32 @@ export interface CloseOptionAction {
393
393
  quantity?: CloseQuantity;
394
394
  }
395
395
  export type Action = BuyOrSellAction | DepositOrWithdrawAction | AlertAction | LaunchAgentAction | DynamicRebalanceAction | RebalanceOptionAction | OpenOptionAction | CloseOptionAction;
396
+ export type StrategyLimitWorkingTime = {
397
+ type: "Day";
398
+ } | {
399
+ type: "Minutes";
400
+ minutes: number;
401
+ };
402
+ export type StrategyLimitPricePolicy = {
403
+ type: "QuoteRelative";
404
+ reference: "Current";
405
+ } | {
406
+ type: "UnitPrice";
407
+ amount: number;
408
+ } | {
409
+ type: "MaximumNetDebit";
410
+ amount: number;
411
+ } | {
412
+ type: "MinimumNetCredit";
413
+ amount: number;
414
+ };
415
+ export type StrategyOrderExecutionPolicy = {
416
+ type: "Market";
417
+ } | {
418
+ type: "Limit";
419
+ price: StrategyLimitPricePolicy;
420
+ workingTime?: StrategyLimitWorkingTime;
421
+ };
396
422
  /**
397
423
  * `automaticOrderApproval` is deliberately absent. It is system-managed and always
398
424
  * false for agent-created strategies, and placing it on an action fails validation —
@@ -403,10 +429,14 @@ export interface Strategy {
403
429
  condition: StrategyCondition;
404
430
  action: Action;
405
431
  active?: boolean;
432
+ /** Omitted means Market. Limit always requires an explicit price policy. */
433
+ orderExecution?: StrategyOrderExecutionPolicy;
406
434
  }
407
435
  export interface Portfolio {
408
436
  name: string;
409
437
  initialValue?: number;
438
+ cash?: number;
439
+ buyingPower?: number;
410
440
  strategies: Strategy[];
411
441
  main?: boolean;
412
442
  supportsFractionalShares?: boolean;
@@ -462,6 +492,24 @@ export declare const fewerThan: (count: number, ...conditions: Condition[]) => C
462
492
  export declare const exactly: (count: number, ...conditions: Condition[]) => Condition;
463
493
  /** Multi with an explicit Comparator (same wire shape as YAML Multi). */
464
494
  export declare const multi: (count: number, comparison: Comparator, ...conditions: Condition[]) => Condition;
495
+ /**
496
+ * Sequence. `andThen(30, "Minute", A, B)` is true at tick t when B is true at t
497
+ * and A was true at some STRICTLY EARLIER tick in the preceding 30 minutes.
498
+ *
499
+ * Simultaneous A and B does not fire — that is `and`. The window applies per
500
+ * transition, so with three or more steps each one must occur within the window
501
+ * of the step before it. Nesting is legal and means something different:
502
+ * `andThen(W, andThen(W, A, B), C)` is not `andThen(W, A, B, C)`.
503
+ *
504
+ * `interval` is REQUIRED and has no default. An omitted interval would fall
505
+ * back to Day and silently kill an intraday setup.
506
+ *
507
+ * Named `andThen` rather than `then`: a module namespace with a callable
508
+ * `then` export is assimilated as a thenable, so `await import("nexustrade")`
509
+ * would call it with resolve/reject and never settle. Emits wire type "Then",
510
+ * the same way atLeast/atMost/exactly emit "Multi".
511
+ */
512
+ export declare const andThen: (length: number, interval: Interval, ...conditions: Condition[]) => Condition;
465
513
  /** Always-true gate for strategies whose cadence lives in the pipeline. */
466
514
  export declare const always: () => Condition;
467
515
  export declare const meanVarianceAllocation: (config?: Partial<Omit<MeanVarianceAllocationPolicy, "type">>) => MeanVarianceAllocationPolicy;
@@ -582,8 +630,19 @@ export declare const closeOption: (config?: {
582
630
  triggers?: CloseOptionTrigger[];
583
631
  quantity?: CloseQuantity;
584
632
  }) => CloseOptionAction;
633
+ export declare const limitOrder: (config: {
634
+ price: StrategyLimitPricePolicy;
635
+ workingTime?: StrategyLimitWorkingTime;
636
+ }) => StrategyOrderExecutionPolicy;
637
+ export declare const currentLimit: () => StrategyLimitPricePolicy;
638
+ export declare const unitPriceLimit: (amount: number) => StrategyLimitPricePolicy;
639
+ export declare const maximumNetDebit: (amount: number) => StrategyLimitPricePolicy;
640
+ export declare const minimumNetCredit: (amount: number) => StrategyLimitPricePolicy;
641
+ export declare const goodForDay: () => StrategyLimitWorkingTime;
642
+ export declare const goodForMinutes: (minutes: number) => StrategyLimitWorkingTime;
585
643
  export declare const strategy: (name: string, condition: StrategyCondition, action: Action, options?: {
586
644
  active?: boolean;
645
+ orderExecution?: StrategyOrderExecutionPolicy;
587
646
  }) => Strategy;
588
647
  /**
589
648
  * Session / clock flatten — condition carries the gate (MinutesAfterOpen, Day, …).
@@ -799,6 +858,13 @@ export declare function ImpliedVolatility(asset: AssetArg, dte?: number): Indica
799
858
  * @param metric Ticker key matching hydrated index price data (add more in BigQuery + rehydrate as needed)
800
859
  */
801
860
  export declare function Index(metric?: "VIX" | "SPX" | "NDX" | "DJI" | "RUT" | "SKEW" | "VVIX" | "USDBROAD" | "TNX"): Indicator;
861
+ /**
862
+ * IndicatorAtEntry indicator.
863
+ * @param asset Ticker name (ex. SPY, BTC)
864
+ * @param side The side of the fill the value is anchored to
865
+ * @param orderStatus Matches order events with this status
866
+ */
867
+ export declare function IndicatorAtEntry(operand: Indicator, asset: AssetArg, side: Side, orderStatus?: OrderStatus): Indicator;
802
868
  /**
803
869
  * IndicatorAtMinutesAfterOpen indicator.
804
870
  * @param minutesAfterOpen The number of minutes after market open to capture the indicator value
@@ -1386,6 +1452,12 @@ export declare const walkForward: (portfolio: Portfolio, config: WalkForwardConf
1386
1452
  /** Submit a genetic optimization over the portfolio's tunable genes. */
1387
1453
  export declare const optimization: (portfolio: Portfolio, config: OptimizationConfig) => JobRequest;
1388
1454
  export type SweepSortDirection = "Highest" | "Lowest";
1455
+ /**
1456
+ * Which scalar inside an addressed condition node a parametric gene varies.
1457
+ * "Lhs"/"Rhs" name the two indicators of a comparison; "Node" names the node's
1458
+ * own number (a Then chain's window, a Multi's threshold).
1459
+ */
1460
+ export type ConditionNodeSlot = "Lhs" | "Rhs" | "Node";
1389
1461
  /** One authored sweep gene. Opaque to callers — built via the gene* builders. */
1390
1462
  export interface Gene {
1391
1463
  field: string;
@@ -1407,6 +1479,10 @@ export declare const geneExitCondition: (strategyIndex: number, values: {
1407
1479
  }[]) => Gene;
1408
1480
  /** Sweep EntryCooldownDays (Strategy scope) over a value set. */
1409
1481
  export declare const geneEntryCooldownDays: (strategyIndex: number, values: number[]) => Gene;
1482
+ /** Sweep ConditionWindowLength (Strategy scope) over a value set. */
1483
+ export declare const geneConditionWindowLength: (strategyIndex: number, path: number[], slot: ConditionNodeSlot, values: number[]) => Gene;
1484
+ /** Sweep ConditionThreshold (Strategy scope) over a value set. */
1485
+ export declare const geneConditionThreshold: (strategyIndex: number, path: number[], slot: ConditionNodeSlot, values: number[]) => Gene;
1410
1486
  /** Sweep RankSignal (Action scope) over a value set. */
1411
1487
  export declare const geneRankSignal: (strategyIndex: number, values: {
1412
1488
  label: string;
@@ -127,6 +127,24 @@ export const fewerThan = (count, ...conditions) => ({ type: "Multi", comparison:
127
127
  export const exactly = (count, ...conditions) => ({ type: "Multi", comparison: "equal", value: count, conditions });
128
128
  /** Multi with an explicit Comparator (same wire shape as YAML Multi). */
129
129
  export const multi = (count, comparison, ...conditions) => ({ type: "Multi", comparison, value: count, conditions });
130
+ /**
131
+ * Sequence. `andThen(30, "Minute", A, B)` is true at tick t when B is true at t
132
+ * and A was true at some STRICTLY EARLIER tick in the preceding 30 minutes.
133
+ *
134
+ * Simultaneous A and B does not fire — that is `and`. The window applies per
135
+ * transition, so with three or more steps each one must occur within the window
136
+ * of the step before it. Nesting is legal and means something different:
137
+ * `andThen(W, andThen(W, A, B), C)` is not `andThen(W, A, B, C)`.
138
+ *
139
+ * `interval` is REQUIRED and has no default. An omitted interval would fall
140
+ * back to Day and silently kill an intraday setup.
141
+ *
142
+ * Named `andThen` rather than `then`: a module namespace with a callable
143
+ * `then` export is assimilated as a thenable, so `await import("nexustrade")`
144
+ * would call it with resolve/reject and never settle. Emits wire type "Then",
145
+ * the same way atLeast/atMost/exactly emit "Multi".
146
+ */
147
+ export const andThen = (length, interval, ...conditions) => ({ type: "Then", conditions, window: { length, interval } });
130
148
  /** Always-true gate for strategies whose cadence lives in the pipeline. */
131
149
  export const always = () => compare(Value(1), Value(0), "greaterThan");
132
150
  export const meanVarianceAllocation = (config = {}) => ({
@@ -246,15 +264,53 @@ export const dteTrigger = (bounds) => compact({ type: "dte", ...bounds });
246
264
  export const daysHeldTrigger = (bounds) => compact({ type: "daysHeld", ...bounds });
247
265
  export const greeksTrigger = (bounds) => compact({ type: "greeks", ...bounds });
248
266
  export const closeOption = (config = {}) => compact({ type: "CloseOption", ...config });
267
+ export const limitOrder = (config) => compact({ type: "Limit", ...config });
268
+ export const currentLimit = () => ({
269
+ type: "QuoteRelative",
270
+ reference: "Current",
271
+ });
272
+ export const unitPriceLimit = (amount) => ({
273
+ type: "UnitPrice",
274
+ amount,
275
+ });
276
+ export const maximumNetDebit = (amount) => ({
277
+ type: "MaximumNetDebit",
278
+ amount,
279
+ });
280
+ export const minimumNetCredit = (amount) => ({
281
+ type: "MinimumNetCredit",
282
+ amount,
283
+ });
284
+ export const goodForDay = () => ({ type: "Day" });
285
+ export const goodForMinutes = (minutes) => ({
286
+ type: "Minutes",
287
+ minutes,
288
+ });
249
289
  // ---- assembly ----
250
- export const strategy = (name, condition, action, options = {}) => compact({ name, condition, action, ...options });
290
+ export const strategy = (name, condition, action, options = {}) => compact({
291
+ name,
292
+ condition,
293
+ action,
294
+ ...options,
295
+ orderExecution: options.orderExecution ?? { type: "Market" },
296
+ });
251
297
  /**
252
298
  * Session / clock flatten — condition carries the gate (MinutesAfterOpen, Day, …).
253
299
  * Never pairs with always(); PnL/DTE/daysHeld exits use closeOption({ triggers }).
254
300
  * Book-level only — CandidateCondition is rejected (same as strategy when).
255
301
  */
256
302
  export const sessionFlatten = (condition, config = {}, name = "Session flatten") => strategy(name, condition, closeOption({ ...config }));
257
- export const portfolio = (name, strategies, options = {}) => new PortfolioHandle(compact({ name, initialValue: 10000, ...options, strategies }));
303
+ export const portfolio = (name, strategies, options = {}) => {
304
+ const initialValue = options.initialValue ?? 10000;
305
+ return new PortfolioHandle(compact({
306
+ name,
307
+ initialValue,
308
+ cash: initialValue,
309
+ buyingPower: initialValue,
310
+ ...options,
311
+ strategies,
312
+ }));
313
+ };
258
314
  // ---- generated indicator builders ----
259
315
  /**
260
316
  * AbsoluteValue indicator.
@@ -607,6 +663,20 @@ export function Index(metric = "VIX") {
607
663
  d["metric"] = metric;
608
664
  return d;
609
665
  }
666
+ /**
667
+ * IndicatorAtEntry indicator.
668
+ * @param asset Ticker name (ex. SPY, BTC)
669
+ * @param side The side of the fill the value is anchored to
670
+ * @param orderStatus Matches order events with this status
671
+ */
672
+ export function IndicatorAtEntry(operand, asset, side, orderStatus = "Filled") {
673
+ const d = { type: "IndicatorAtEntry" };
674
+ setAsset(d, "targetAsset", asset);
675
+ d["side"] = side;
676
+ d["orderStatus"] = orderStatus;
677
+ d.indicators = [operand];
678
+ return d;
679
+ }
610
680
  /**
611
681
  * IndicatorAtMinutesAfterOpen indicator.
612
682
  * @param minutesAfterOpen The number of minutes after market open to capture the indicator value
@@ -1490,6 +1560,20 @@ export const geneEntryCooldownDays = (strategyIndex, values) => ({
1490
1560
  target: { scope: "Strategy", field: "EntryCooldownDays", strategyIndex },
1491
1561
  values: values,
1492
1562
  });
1563
+ /** Sweep ConditionWindowLength (Strategy scope) over a value set. */
1564
+ export const geneConditionWindowLength = (strategyIndex, path, slot, values) => ({
1565
+ field: "ConditionWindowLength",
1566
+ scope: "Strategy",
1567
+ target: { scope: "Strategy", field: "ConditionWindowLength", strategyIndex, path, slot },
1568
+ values: values,
1569
+ });
1570
+ /** Sweep ConditionThreshold (Strategy scope) over a value set. */
1571
+ export const geneConditionThreshold = (strategyIndex, path, slot, values) => ({
1572
+ field: "ConditionThreshold",
1573
+ scope: "Strategy",
1574
+ target: { scope: "Strategy", field: "ConditionThreshold", strategyIndex, path, slot },
1575
+ values: values,
1576
+ });
1493
1577
  /** Sweep RankSignal (Action scope) over a value set. */
1494
1578
  export const geneRankSignal = (strategyIndex, values) => ({
1495
1579
  field: "RankSignal",
@@ -1,7 +1,7 @@
1
1
  export { AgentRun } from "./agent.js";
2
2
  export type { AgentEvent, AgentRunOptions } from "./agent.js";
3
- export { HttpTransport, NexusTradeApiError, NexusTradeClient, createCustomIndicator, createPortfolio, waitForOperation, } from "./client.js";
4
- export type { CustomIndicatorInput, CustomIndicatorPointInput, HttpTransportOptions, JsonObject, JsonValue, ListPortfoliosOptions, NexusTradeClientOptions, RequestOptions, Transport, UploadTransport, WaitOptions, } from "./client.js";
3
+ export { HttpTransport, NexusTradeApiError, NexusTradeClient, NexusTradeWorkspaceSessionExpiredError, createCustomIndicator, createPortfolio, waitForOperation, } from "./client.js";
4
+ export type { BacktestCollateralStatistics, CustomIndicatorInput, CustomIndicatorPointInput, HttpTransportOptions, JsonObject, JsonValue, ListPortfoliosOptions, NexusTradeClientOptions, RequestOptions, Transport, UploadTransport, WaitOptions, WorkspaceSessionTransport, } from "./client.js";
5
5
  export { PortfolioHandle, portfolioHandleFromWire, } from "./portfolio.js";
6
6
  export type { DeployOutcome, DeployResult, PortfolioHandleOptions, PortfolioListResult, PortfolioType, ReadonlyPortfolioPolicy, } from "./portfolio.js";
7
7
  export * from "./generated/ntSdk.generated.js";
package/dist/esm/index.js CHANGED
@@ -1,4 +1,4 @@
1
1
  export { AgentRun } from "./agent.js";
2
- export { HttpTransport, NexusTradeApiError, NexusTradeClient, createCustomIndicator, createPortfolio, waitForOperation, } from "./client.js";
2
+ export { HttpTransport, NexusTradeApiError, NexusTradeClient, NexusTradeWorkspaceSessionExpiredError, createCustomIndicator, createPortfolio, waitForOperation, } from "./client.js";
3
3
  export { PortfolioHandle, portfolioHandleFromWire, } from "./portfolio.js";
4
4
  export * from "./generated/ntSdk.generated.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nexustrade",
3
- "version": "1.9.10",
3
+ "version": "1.11.0",
4
4
  "description": "Typed TypeScript SDK for NexusTrade portfolio authoring, backtesting, and optimization",
5
5
  "license": "MIT",
6
6
  "author": "Starks Technology",