nexustrade 0.3.0 → 0.4.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 +1 -1
- package/dist/cjs/client.js +10 -3
- package/dist/cjs/generated/ntSdk.generated.js +2 -6
- package/dist/esm/client.d.ts +7 -1
- package/dist/esm/client.js +10 -3
- package/dist/esm/generated/ntSdk.generated.d.ts +0 -2
- package/dist/esm/generated/ntSdk.generated.js +0 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -87,7 +87,7 @@ const book = nt.portfolio("Momentum", [
|
|
|
87
87
|
| **Portfolio state** | `PortfolioValue` `BuyingPower` `MaxDrawdown` `InitialValue` |
|
|
88
88
|
| **Fundamentals** | `Fundamental` `Economic` `DaysUntilEarnings` `IsIndexMember` `IsIndustry` |
|
|
89
89
|
| **Options** | `OptionDaysToExpiration` `OptionCollateral` `OptionUnrealizedPnL` `openOption` `closeOption` |
|
|
90
|
-
| **Actions** | `buy` `sell` `
|
|
90
|
+
| **Actions** | `buy` `sell` `alert` `dynamicRebalance` `rebalanceOption` |
|
|
91
91
|
| **Selection** | `filter` `selectTop` `selectPercentile` `universe` |
|
|
92
92
|
| **Logic** | `always` `atLeast` `atMost` `exactly` `fewerThan` `multi` `and` `or` |
|
|
93
93
|
|
package/dist/cjs/client.js
CHANGED
|
@@ -56,11 +56,18 @@ const TERMINAL_STATUSES = ["cancelled", "completed", "failed"];
|
|
|
56
56
|
class NexusTradeApiError extends Error {
|
|
57
57
|
status;
|
|
58
58
|
code;
|
|
59
|
-
|
|
59
|
+
/**
|
|
60
|
+
* Set for operation errors (timeout / failure). A timed-out job is still
|
|
61
|
+
* running, so the caller needs the id to resume waiting without resubmitting
|
|
62
|
+
* — reading it out of the message is not an interface.
|
|
63
|
+
*/
|
|
64
|
+
operationId;
|
|
65
|
+
constructor(status, code, message, operationId) {
|
|
60
66
|
super(`${code}: ${message}`);
|
|
61
67
|
this.name = "NexusTradeApiError";
|
|
62
68
|
this.status = status;
|
|
63
69
|
this.code = code;
|
|
70
|
+
this.operationId = operationId;
|
|
64
71
|
}
|
|
65
72
|
}
|
|
66
73
|
exports.NexusTradeApiError = NexusTradeApiError;
|
|
@@ -305,7 +312,7 @@ function operationFailure(operation, operationId, status) {
|
|
|
305
312
|
if (error.message)
|
|
306
313
|
message = String(error.message);
|
|
307
314
|
}
|
|
308
|
-
return new NexusTradeApiError(exports.NO_HTTP_STATUS, code, message);
|
|
315
|
+
return new NexusTradeApiError(exports.NO_HTTP_STATUS, code, message, operationId);
|
|
309
316
|
}
|
|
310
317
|
/**
|
|
311
318
|
* Poll `fetch(operationId)` until the operation reaches a terminal state.
|
|
@@ -345,7 +352,7 @@ async function waitForOperation(fetch, operationId, options = {}) {
|
|
|
345
352
|
if (remainingMs <= 0) {
|
|
346
353
|
throw new NexusTradeApiError(exports.NO_HTTP_STATUS, "operation_timeout", `Operation ${operationId} was still '${status || "unknown"}' after ` +
|
|
347
354
|
`${timeoutSeconds}s. It is still running — poll again with the ` +
|
|
348
|
-
"same id rather than resubmitting.");
|
|
355
|
+
"same id (error.operationId) rather than resubmitting.", operationId);
|
|
349
356
|
}
|
|
350
357
|
if (interval > 0) {
|
|
351
358
|
const delayMs = Math.min(interval * 1000, remainingMs);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.walkForward = exports.backtest = exports.SMA = exports.RSI = exports.PriceStdDev = exports.EMA = exports.BBand = exports.portfolio = exports.sessionFlatten = exports.strategy = exports.closeOption = exports.greeksTrigger = exports.daysHeldTrigger = exports.dteTrigger = exports.pnlTrigger = exports.rebalanceOption = exports.sleeve = exports.structureTemplate = exports.openOption = exports.againstParent = exports.optionsBuilder = exports.leg = exports.dynamicRebalance = exports.launchAgent = exports.alert = exports.
|
|
4
|
-
exports.geneUniversePipelineFilter = exports.geneSelectTopLimit = exports.geneDteBracket = exports.geneStrikeDistance = exports.geneOptionDelta = exports.geneStructureKind = exports.geneTakeProfitPct = exports.geneRollTriggerDte = exports.geneDeploymentPct = exports.geneTotalBudgetPct = exports.geneAllocationPct = exports.geneBuyingPowerPct = exports.geneRankSignal = exports.geneEntryCooldownDays = exports.geneExitCondition = exports.geneEntryCondition =
|
|
3
|
+
exports.geneSubject = exports.optimization = exports.walkForward = exports.backtest = exports.SMA = exports.RSI = exports.PriceStdDev = exports.EMA = exports.BBand = exports.portfolio = exports.sessionFlatten = exports.strategy = exports.closeOption = exports.greeksTrigger = exports.daysHeldTrigger = exports.dteTrigger = exports.pnlTrigger = exports.rebalanceOption = exports.sleeve = exports.structureTemplate = exports.openOption = exports.againstParent = exports.optionsBuilder = exports.leg = exports.dynamicRebalance = exports.launchAgent = exports.alert = exports.sell = exports.buy = exports.selectPercentile = exports.selectTop = exports.filter = exports.always = exports.multi = exports.exactly = exports.fewerThan = exports.atMost = exports.atLeast = exports.or = exports.and = exports.neq = exports.eq = exports.lte = exports.gte = exports.lt = exports.gt = exports.cryptoAsset = exports.stockAsset = exports.PORTFOLIO_WIDE = exports.CANDIDATE = void 0;
|
|
4
|
+
exports.geneUniversePipelineFilter = exports.geneSelectTopLimit = exports.geneDteBracket = exports.geneStrikeDistance = exports.geneOptionDelta = exports.geneStructureKind = exports.geneTakeProfitPct = exports.geneRollTriggerDte = exports.geneDeploymentPct = exports.geneTotalBudgetPct = exports.geneAllocationPct = exports.geneBuyingPowerPct = exports.geneRankSignal = exports.geneEntryCooldownDays = exports.geneExitCondition = exports.geneEntryCondition = void 0;
|
|
5
5
|
exports.universe = universe;
|
|
6
6
|
exports.AbsoluteValue = AbsoluteValue;
|
|
7
7
|
exports.AverageTrueRange = AverageTrueRange;
|
|
@@ -270,10 +270,6 @@ const buy = (target, amount, type = "percent of portfolio") => ({ type: "Buy", t
|
|
|
270
270
|
exports.buy = buy;
|
|
271
271
|
const sell = (target, amount, type = "percent of portfolio") => ({ type: "Sell", targetAsset: toAsset(target), amount: { type, amount } });
|
|
272
272
|
exports.sell = sell;
|
|
273
|
-
const deposit = (amount, type = "dollars") => ({ type: "Deposit", amount: { type, amount } });
|
|
274
|
-
exports.deposit = deposit;
|
|
275
|
-
const withdraw = (amount, type = "dollars") => ({ type: "Withdraw", amount: { type, amount } });
|
|
276
|
-
exports.withdraw = withdraw;
|
|
277
273
|
const alert = (message) => ({ type: "Alert", message });
|
|
278
274
|
exports.alert = alert;
|
|
279
275
|
const launchAgent = (config) => compact({ type: "LaunchAgent", ...config });
|
package/dist/esm/client.d.ts
CHANGED
|
@@ -45,7 +45,13 @@ export declare const POLL_BACKOFF_FACTOR = 1.5;
|
|
|
45
45
|
export declare class NexusTradeApiError extends Error {
|
|
46
46
|
readonly status: number;
|
|
47
47
|
readonly code: string;
|
|
48
|
-
|
|
48
|
+
/**
|
|
49
|
+
* Set for operation errors (timeout / failure). A timed-out job is still
|
|
50
|
+
* running, so the caller needs the id to resume waiting without resubmitting
|
|
51
|
+
* — reading it out of the message is not an interface.
|
|
52
|
+
*/
|
|
53
|
+
readonly operationId?: string;
|
|
54
|
+
constructor(status: number, code: string, message: string, operationId?: string);
|
|
49
55
|
}
|
|
50
56
|
export interface RequestOptions {
|
|
51
57
|
body?: JsonObject;
|
package/dist/esm/client.js
CHANGED
|
@@ -50,11 +50,18 @@ const TERMINAL_STATUSES = ["cancelled", "completed", "failed"];
|
|
|
50
50
|
export class NexusTradeApiError extends Error {
|
|
51
51
|
status;
|
|
52
52
|
code;
|
|
53
|
-
|
|
53
|
+
/**
|
|
54
|
+
* Set for operation errors (timeout / failure). A timed-out job is still
|
|
55
|
+
* running, so the caller needs the id to resume waiting without resubmitting
|
|
56
|
+
* — reading it out of the message is not an interface.
|
|
57
|
+
*/
|
|
58
|
+
operationId;
|
|
59
|
+
constructor(status, code, message, operationId) {
|
|
54
60
|
super(`${code}: ${message}`);
|
|
55
61
|
this.name = "NexusTradeApiError";
|
|
56
62
|
this.status = status;
|
|
57
63
|
this.code = code;
|
|
64
|
+
this.operationId = operationId;
|
|
58
65
|
}
|
|
59
66
|
}
|
|
60
67
|
function origin(url) {
|
|
@@ -297,7 +304,7 @@ function operationFailure(operation, operationId, status) {
|
|
|
297
304
|
if (error.message)
|
|
298
305
|
message = String(error.message);
|
|
299
306
|
}
|
|
300
|
-
return new NexusTradeApiError(NO_HTTP_STATUS, code, message);
|
|
307
|
+
return new NexusTradeApiError(NO_HTTP_STATUS, code, message, operationId);
|
|
301
308
|
}
|
|
302
309
|
/**
|
|
303
310
|
* Poll `fetch(operationId)` until the operation reaches a terminal state.
|
|
@@ -337,7 +344,7 @@ export async function waitForOperation(fetch, operationId, options = {}) {
|
|
|
337
344
|
if (remainingMs <= 0) {
|
|
338
345
|
throw new NexusTradeApiError(NO_HTTP_STATUS, "operation_timeout", `Operation ${operationId} was still '${status || "unknown"}' after ` +
|
|
339
346
|
`${timeoutSeconds}s. It is still running — poll again with the ` +
|
|
340
|
-
"same id rather than resubmitting.");
|
|
347
|
+
"same id (error.operationId) rather than resubmitting.", operationId);
|
|
341
348
|
}
|
|
342
349
|
if (interval > 0) {
|
|
343
350
|
const delayMs = Math.min(interval * 1000, remainingMs);
|
|
@@ -407,8 +407,6 @@ export declare function universe(source: "ALL_US_STOCKS" | "SP500" | "NASDAQ100"
|
|
|
407
407
|
export declare function universe(source: "SPECIFIC_ASSETS", assets: AssetArg[]): Universe;
|
|
408
408
|
export declare const buy: (target: AssetArg, amount: number, type?: AllocationType) => BuyOrSellAction;
|
|
409
409
|
export declare const sell: (target: AssetArg, amount: number, type?: AllocationType) => BuyOrSellAction;
|
|
410
|
-
export declare const deposit: (amount: number, type?: DepositWithdrawAllocationType) => DepositOrWithdrawAction;
|
|
411
|
-
export declare const withdraw: (amount: number, type?: DepositWithdrawAllocationType) => DepositOrWithdrawAction;
|
|
412
410
|
export declare const alert: (message: string) => AlertAction;
|
|
413
411
|
export declare const launchAgent: (config: {
|
|
414
412
|
planningModel: string;
|
|
@@ -141,8 +141,6 @@ export function universe(source, assets) {
|
|
|
141
141
|
// ---- equity + cash actions ----
|
|
142
142
|
export const buy = (target, amount, type = "percent of portfolio") => ({ type: "Buy", targetAsset: toAsset(target), amount: { type, amount } });
|
|
143
143
|
export const sell = (target, amount, type = "percent of portfolio") => ({ type: "Sell", targetAsset: toAsset(target), amount: { type, amount } });
|
|
144
|
-
export const deposit = (amount, type = "dollars") => ({ type: "Deposit", amount: { type, amount } });
|
|
145
|
-
export const withdraw = (amount, type = "dollars") => ({ type: "Withdraw", amount: { type, amount } });
|
|
146
144
|
export const alert = (message) => ({ type: "Alert", message });
|
|
147
145
|
export const launchAgent = (config) => compact({ type: "LaunchAgent", ...config });
|
|
148
146
|
export const dynamicRebalance = (config) => compact({ type: "DynamicRebalance", ...config });
|