nexustrade 5.1.0 → 5.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/README.md +33 -3
- package/dist/cjs/client.js +8 -2
- package/dist/cjs/portfolio.js +3 -0
- package/dist/esm/client.d.ts +3 -1
- package/dist/esm/client.js +8 -2
- package/dist/esm/portfolio.d.ts +2 -0
- package/dist/esm/portfolio.js +3 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -119,6 +119,27 @@ Backtest operations may include `warnings: string[]` immediately after
|
|
|
119
119
|
submission and again in the terminal `result`. Treat them as material caveats;
|
|
120
120
|
they do not change a successful operation into a failure.
|
|
121
121
|
|
|
122
|
+
### Benchmark
|
|
123
|
+
|
|
124
|
+
A terminal `result` also carries the benchmark the run was compared against:
|
|
125
|
+
`result.baselineSymbol` and `result.baselineStatistics`, the buy-and-hold
|
|
126
|
+
benchmark's statistics over the same window (for example
|
|
127
|
+
`baselineStatistics.percentChange`). Choose the benchmark with
|
|
128
|
+
`backtest(book, { ..., baselineAsset: { type: "Stock", symbol: "QQQ" } })`, or
|
|
129
|
+
`{ type: "Cryptocurrency", symbol: "BTC-USD" }`. `baselineSymbol` is the older
|
|
130
|
+
Stock-only shorthand; pass one or the other, never both. When both are
|
|
131
|
+
omitted, the single traded stock or option underlying is the benchmark,
|
|
132
|
+
otherwise SPY.
|
|
133
|
+
|
|
134
|
+
Changed in 5.2.0: an omitted baseline used to be SPY for every API backtest.
|
|
135
|
+
It is now inferred exactly as the MCP `backtest_portfolio` tool infers it, and
|
|
136
|
+
an explicit baseline symbol is uppercased. Earlier results were not rerun. A
|
|
137
|
+
new run of the same book can therefore report a different benchmark, so pass
|
|
138
|
+
the baseline explicitly where an earlier comparison must hold.
|
|
139
|
+
A cached single-name spec that omitted the baseline therefore runs once more
|
|
140
|
+
after upgrading, because its benchmark is now part of the run's identity. The
|
|
141
|
+
portfolio handle accepts the same typed benchmark: `PortfolioHandle.backtest({ baselineAsset })`.
|
|
142
|
+
|
|
122
143
|
### Collateral at risk
|
|
123
144
|
|
|
124
145
|
A terminal operation's `result.statistics` answers how much capital the run had
|
|
@@ -898,6 +919,7 @@ is missing here, so this list cannot drift from the code.
|
|
|
898
919
|
| `new NexusTradeClient({ apiKey, baseUrl })` | Explicit credentials |
|
|
899
920
|
| `new NexusTradeClient()` | Lazy anonymous workspace with strict limits |
|
|
900
921
|
| `NexusTradeClient.fromEnvironment()` | Read them from the environment or `.env` |
|
|
922
|
+
| `new NexusTradeClient({ requestTimeoutSeconds })` | Per-request HTTP timeout (default 30); also accepted by `fromEnvironment` |
|
|
901
923
|
| `exportWorkspaceSession()` | Export an anonymous workspace for later use |
|
|
902
924
|
| `importWorkspaceSession(token)` | Resume an existing anonymous workspace |
|
|
903
925
|
|
|
@@ -1025,9 +1047,17 @@ check on an otherwise-successful reply.
|
|
|
1025
1047
|
|
|
1026
1048
|
## Timeouts
|
|
1027
1049
|
|
|
1028
|
-
`new
|
|
1029
|
-
deadline for one request.
|
|
1030
|
-
|
|
1050
|
+
`new NexusTradeClient({ requestTimeoutSeconds })` (default 30) sets the HTTP
|
|
1051
|
+
transport's total wall-clock deadline for one request. Raise it for large
|
|
1052
|
+
`createBacktests` batches:
|
|
1053
|
+
|
|
1054
|
+
```ts
|
|
1055
|
+
const client = NexusTradeClient.fromEnvironment({ requestTimeoutSeconds: 120 });
|
|
1056
|
+
```
|
|
1057
|
+
|
|
1058
|
+
It is separate from the `timeoutSeconds` wait option, which bounds how long a
|
|
1059
|
+
poll waits. Neither bounds how long a _job_ takes. A custom `transport`
|
|
1060
|
+
configures its own timeout, so passing both throws.
|
|
1031
1061
|
|
|
1032
1062
|
## Scope
|
|
1033
1063
|
|
package/dist/cjs/client.js
CHANGED
|
@@ -510,6 +510,7 @@ const BACKTEST_ARG_NAMES = [
|
|
|
510
510
|
["start_date", "startDate"],
|
|
511
511
|
["end_date", "endDate"],
|
|
512
512
|
["baseline_symbol", "baseline"],
|
|
513
|
+
["baseline_asset", "baselineAsset"],
|
|
513
514
|
["interval", "interval"],
|
|
514
515
|
["initial_value", "initialValue"],
|
|
515
516
|
["generate_events", "generateEvents"],
|
|
@@ -788,6 +789,10 @@ class NexusTradeClient {
|
|
|
788
789
|
transport;
|
|
789
790
|
constructor(options = {}) {
|
|
790
791
|
if (options.transport) {
|
|
792
|
+
if (options.requestTimeoutSeconds !== undefined) {
|
|
793
|
+
throw new Error("requestTimeoutSeconds applies only to the built-in HTTP transport; " +
|
|
794
|
+
"configure a custom transport directly.");
|
|
795
|
+
}
|
|
791
796
|
this.transport = options.transport;
|
|
792
797
|
return;
|
|
793
798
|
}
|
|
@@ -801,10 +806,11 @@ class NexusTradeClient {
|
|
|
801
806
|
apiKey,
|
|
802
807
|
baseUrl: baseUrl ?? exports.DEFAULT_API_BASE_URL,
|
|
803
808
|
workspaceSession: options.workspaceSession,
|
|
809
|
+
timeoutSeconds: options.requestTimeoutSeconds,
|
|
804
810
|
});
|
|
805
811
|
}
|
|
806
|
-
static fromEnvironment() {
|
|
807
|
-
return new NexusTradeClient();
|
|
812
|
+
static fromEnvironment(options = {}) {
|
|
813
|
+
return new NexusTradeClient(options);
|
|
808
814
|
}
|
|
809
815
|
/** Return the anonymous workspace token after the first API call bootstraps it. */
|
|
810
816
|
exportWorkspaceSession() {
|
package/dist/cjs/portfolio.js
CHANGED
|
@@ -377,6 +377,9 @@ class PortfolioHandle {
|
|
|
377
377
|
};
|
|
378
378
|
if (options.baseline !== undefined)
|
|
379
379
|
input.baseline = options.baseline;
|
|
380
|
+
if (options.baselineAsset !== undefined) {
|
|
381
|
+
input.baselineAsset = options.baselineAsset;
|
|
382
|
+
}
|
|
380
383
|
if (options.interval !== undefined)
|
|
381
384
|
input.interval = options.interval;
|
|
382
385
|
if (options.initialValue !== undefined) {
|
package/dist/esm/client.d.ts
CHANGED
|
@@ -176,6 +176,8 @@ export interface NexusTradeClientOptions {
|
|
|
176
176
|
baseUrl?: string;
|
|
177
177
|
workspaceSession?: string;
|
|
178
178
|
transport?: Transport;
|
|
179
|
+
/** Per-request HTTP timeout for the built-in transport (default 30). */
|
|
180
|
+
requestTimeoutSeconds?: number;
|
|
179
181
|
}
|
|
180
182
|
export interface WaitOptions {
|
|
181
183
|
timeoutSeconds?: number;
|
|
@@ -241,7 +243,7 @@ export declare function waitForOperation(fetch: (operationId: string) => Promise
|
|
|
241
243
|
export declare class NexusTradeClient {
|
|
242
244
|
private readonly transport;
|
|
243
245
|
constructor(options?: NexusTradeClientOptions);
|
|
244
|
-
static fromEnvironment(): NexusTradeClient;
|
|
246
|
+
static fromEnvironment(options?: Pick<NexusTradeClientOptions, "requestTimeoutSeconds">): NexusTradeClient;
|
|
245
247
|
/** Return the anonymous workspace token after the first API call bootstraps it. */
|
|
246
248
|
exportWorkspaceSession(): string | undefined;
|
|
247
249
|
/** Resume an existing anonymous workspace without creating a replacement. */
|
package/dist/esm/client.js
CHANGED
|
@@ -500,6 +500,7 @@ const BACKTEST_ARG_NAMES = [
|
|
|
500
500
|
["start_date", "startDate"],
|
|
501
501
|
["end_date", "endDate"],
|
|
502
502
|
["baseline_symbol", "baseline"],
|
|
503
|
+
["baseline_asset", "baselineAsset"],
|
|
503
504
|
["interval", "interval"],
|
|
504
505
|
["initial_value", "initialValue"],
|
|
505
506
|
["generate_events", "generateEvents"],
|
|
@@ -778,6 +779,10 @@ export class NexusTradeClient {
|
|
|
778
779
|
transport;
|
|
779
780
|
constructor(options = {}) {
|
|
780
781
|
if (options.transport) {
|
|
782
|
+
if (options.requestTimeoutSeconds !== undefined) {
|
|
783
|
+
throw new Error("requestTimeoutSeconds applies only to the built-in HTTP transport; " +
|
|
784
|
+
"configure a custom transport directly.");
|
|
785
|
+
}
|
|
781
786
|
this.transport = options.transport;
|
|
782
787
|
return;
|
|
783
788
|
}
|
|
@@ -791,10 +796,11 @@ export class NexusTradeClient {
|
|
|
791
796
|
apiKey,
|
|
792
797
|
baseUrl: baseUrl ?? DEFAULT_API_BASE_URL,
|
|
793
798
|
workspaceSession: options.workspaceSession,
|
|
799
|
+
timeoutSeconds: options.requestTimeoutSeconds,
|
|
794
800
|
});
|
|
795
801
|
}
|
|
796
|
-
static fromEnvironment() {
|
|
797
|
-
return new NexusTradeClient();
|
|
802
|
+
static fromEnvironment(options = {}) {
|
|
803
|
+
return new NexusTradeClient(options);
|
|
798
804
|
}
|
|
799
805
|
/** Return the anonymous workspace token after the first API call bootstraps it. */
|
|
800
806
|
exportWorkspaceSession() {
|
package/dist/esm/portfolio.d.ts
CHANGED
|
@@ -110,6 +110,8 @@ export declare class PortfolioHandle implements Portfolio {
|
|
|
110
110
|
endDate: string;
|
|
111
111
|
idempotencyKey: string;
|
|
112
112
|
baseline?: string;
|
|
113
|
+
/** Typed benchmark `{ type, symbol, name? }`; never with `baseline`. */
|
|
114
|
+
baselineAsset?: JsonObject;
|
|
113
115
|
interval?: string;
|
|
114
116
|
initialValue?: number;
|
|
115
117
|
generateEvents?: boolean;
|
package/dist/esm/portfolio.js
CHANGED
|
@@ -340,6 +340,9 @@ export class PortfolioHandle {
|
|
|
340
340
|
};
|
|
341
341
|
if (options.baseline !== undefined)
|
|
342
342
|
input.baseline = options.baseline;
|
|
343
|
+
if (options.baselineAsset !== undefined) {
|
|
344
|
+
input.baselineAsset = options.baselineAsset;
|
|
345
|
+
}
|
|
343
346
|
if (options.interval !== undefined)
|
|
344
347
|
input.interval = options.interval;
|
|
345
348
|
if (options.initialValue !== undefined) {
|
package/package.json
CHANGED