@qtsurfer/sdk 0.7.0 → 0.8.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 +245 -10
- package/dist/index.d.ts +780 -7
- package/dist/index.js +516 -65
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/auth/session.ts +86 -2
- package/src/client.ts +153 -3
- package/src/errors.ts +4 -2
- package/src/index.ts +33 -0
- package/src/internal/polling.ts +142 -0
- package/src/internal/preparation.ts +121 -0
- package/src/internal/requestError.ts +36 -0
- package/src/workflows/backtest.ts +46 -167
- package/src/workflows/catalog.ts +74 -0
- package/src/workflows/strategies.ts +118 -0
- package/src/workflows/sweep.ts +861 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ResultMap, AuthTokenResponse } from '@qtsurfer/api-client';
|
|
1
|
+
import { ResultMap, Exchange as Exchange$1, InstrumentDetail as InstrumentDetail$1, StrategyState as StrategyState$1, SweepProgress as SweepProgress$1, ExecuteSweepAccepted, ExecuteSweepResult, SweepSensitivity as SweepSensitivity$1, SweepHeatmap as SweepHeatmap$1, SweepHeatmapCell as SweepHeatmapCell$1, SweepMarginal as SweepMarginal$1, SweepMarginalPoint as SweepMarginalPoint$1, SweepRunRow as SweepRunRow$1, WalkForwardFold as WalkForwardFold$1, WalkForwardResult as WalkForwardResult$1, AuthTokenResponse } from '@qtsurfer/api-client';
|
|
2
2
|
|
|
3
3
|
interface BacktestRequest {
|
|
4
4
|
/** Strategy source code (Java) */
|
|
@@ -48,9 +48,619 @@ interface BacktestOptions {
|
|
|
48
48
|
timeoutMs?: number;
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
+
/**
|
|
52
|
+
* One exchange the platform serves. Alias for api-client's `Exchange`:
|
|
53
|
+
* `id` (what every other call takes as `exchangeId`), `name`, and an
|
|
54
|
+
* optional `description`.
|
|
55
|
+
*/
|
|
56
|
+
type Exchange = Exchange$1;
|
|
57
|
+
/**
|
|
58
|
+
* One instrument on an exchange. Alias for api-client's `InstrumentDetail`:
|
|
59
|
+
* `id` / `base` / `quote`, plus optional `coverage` (the date windows for
|
|
60
|
+
* which tickers and klines actually exist, per data type), `lastPrice` and
|
|
61
|
+
* `volume24h`.
|
|
62
|
+
*
|
|
63
|
+
* `coverage` is what tells you whether a backtest range is downloadable at
|
|
64
|
+
* all; it is optional, and absent means the platform did not report one, not
|
|
65
|
+
* that there is no data.
|
|
66
|
+
*/
|
|
67
|
+
type InstrumentDetail = InstrumentDetail$1;
|
|
68
|
+
/**
|
|
69
|
+
* A market segment of an exchange. `'spot'` is the default segment served
|
|
70
|
+
* when {@link QTSurfer.instruments} is called without one.
|
|
71
|
+
*/
|
|
72
|
+
type InstrumentSegment = 'spot' | 'futures';
|
|
73
|
+
|
|
51
74
|
/** Wire format for hourly tickers/klines downloads. */
|
|
52
75
|
type DownloadFormat = 'lastra' | 'parquet';
|
|
53
76
|
|
|
77
|
+
/**
|
|
78
|
+
* Everything the platform records about a registered strategy. Alias for
|
|
79
|
+
* api-client's `StrategyState`.
|
|
80
|
+
*
|
|
81
|
+
* `validation` is the verdict and is one of:
|
|
82
|
+
*
|
|
83
|
+
* - `'not_validated'` — registered, never checked.
|
|
84
|
+
* - `'pending'` — a check was asked for and has not answered yet.
|
|
85
|
+
* - `'passed'` — the class loaded and survived its first event.
|
|
86
|
+
* - `'failed'` — it did not; `detail` says how.
|
|
87
|
+
*
|
|
88
|
+
* **`'passed'` is a floor, not a guarantee.** It means the compiled class
|
|
89
|
+
* could be instantiated and got through the first event of a short synthetic
|
|
90
|
+
* run — not the caller's instrument, not the caller's window, and not the
|
|
91
|
+
* rest of the run. It says nothing about whether the strategy is correct,
|
|
92
|
+
* profitable, or safe to run at scale. `dryRunIncomplete` marks a check that
|
|
93
|
+
* ran out of its budget, which makes a `'passed'` verdict a lower floor
|
|
94
|
+
* still, and makes an empty `notices` list no longer a clean bill of health.
|
|
95
|
+
*
|
|
96
|
+
* A verdict describes the bytecode that existed when it was recorded:
|
|
97
|
+
* `compiledAt` newer than `validatedAt` means the strategy was recompiled
|
|
98
|
+
* afterwards and the verdict no longer describes what would run.
|
|
99
|
+
*/
|
|
100
|
+
type StrategyState = StrategyState$1;
|
|
101
|
+
/**
|
|
102
|
+
* Outcome of {@link QTSurfer.validateStrategy} — the SDK's rendering of the
|
|
103
|
+
* two answers that operation has, which the response body alone cannot tell
|
|
104
|
+
* apart.
|
|
105
|
+
*
|
|
106
|
+
* - `queued: false` — a verdict already existed for the current compilation
|
|
107
|
+
* and comes back in `state` unchanged; nothing new was queued. This is
|
|
108
|
+
* **not** the same as "terminal": a check queued by an earlier call can
|
|
109
|
+
* still be running, so read `state.validation` rather than treating
|
|
110
|
+
* `queued: false` as "there is an answer".
|
|
111
|
+
* - `queued: true` — a check was just queued. Nothing is known yet; poll
|
|
112
|
+
* {@link QTSurfer.strategy} until `validation` leaves `'pending'`.
|
|
113
|
+
*/
|
|
114
|
+
type StrategyValidation = {
|
|
115
|
+
queued: false;
|
|
116
|
+
strategyId: string;
|
|
117
|
+
state: StrategyState;
|
|
118
|
+
} | {
|
|
119
|
+
queued: true;
|
|
120
|
+
strategyId: string;
|
|
121
|
+
state?: undefined;
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* The metric a sweep optimizes, and the one its leaderboard and its
|
|
126
|
+
* sensitivity surfaces are read against.
|
|
127
|
+
*
|
|
128
|
+
* One vocabulary throughout: the objective a {@link SweepRequest} is submitted
|
|
129
|
+
* with is the objective the leaderboard is ranked by, and the one
|
|
130
|
+
* {@link Sweep.sensitivity} aggregates unless a different one is asked for.
|
|
131
|
+
*
|
|
132
|
+
* - `'sharpe'` — risk-adjusted return; the platform default when a request names none.
|
|
133
|
+
* - `'sortino'` — downside-risk-adjusted return.
|
|
134
|
+
* - `'pnl'` — absolute net profit and loss.
|
|
135
|
+
* - `'maxdd'` — maximum drawdown.
|
|
136
|
+
*/
|
|
137
|
+
type SweepObjective = 'sharpe' | 'sortino' | 'pnl' | 'maxdd';
|
|
138
|
+
/**
|
|
139
|
+
* How the parameter grid is turned into the list of vectors that actually run.
|
|
140
|
+
*
|
|
141
|
+
* - `'grid'` — every combination of every axis value. The platform default;
|
|
142
|
+
* cost is the product of the axis sizes.
|
|
143
|
+
* - `'random'` — uniformly random draws from the grid, capped at
|
|
144
|
+
* {@link SweepRequest.samples}.
|
|
145
|
+
* - `'lhs'` — Latin hypercube draws, which spread the sample more evenly than
|
|
146
|
+
* uniform random.
|
|
147
|
+
*
|
|
148
|
+
* `samples` is required by `'random'` and `'lhs'` and ignored by `'grid'`.
|
|
149
|
+
*/
|
|
150
|
+
type SweepSampler = 'grid' | 'random' | 'lhs';
|
|
151
|
+
/**
|
|
152
|
+
* How the ranked leaderboard is ordered.
|
|
153
|
+
*
|
|
154
|
+
* The **platform default is `'plateau'`**, so the order a sweep answers with is
|
|
155
|
+
* *not* raw objective order unless you ask for it. A plateau score is the
|
|
156
|
+
* objective of the worst run in a point's immediate neighbourhood, so a point
|
|
157
|
+
* only ranks well when the region around it does too — which exists because
|
|
158
|
+
* the highest raw score is very often a spike that does not survive the
|
|
159
|
+
* parameters moving slightly.
|
|
160
|
+
*
|
|
161
|
+
* **What you request is not always what you get.** Read `ranking` on the
|
|
162
|
+
* result to find out which ordering was actually applied: a sweep with no
|
|
163
|
+
* stored parameter grid has no neighbourhood to score against and falls back
|
|
164
|
+
* to `'raw'`, and a walk-forward sweep is always `'raw'` because its
|
|
165
|
+
* leaderboard is one out-of-sample row per fold rather than a grid.
|
|
166
|
+
*
|
|
167
|
+
* This applies to the ranked view only. Alongside `order: 'natural'` it is
|
|
168
|
+
* **ignored** — that view is always ordered by `runIx`.
|
|
169
|
+
*/
|
|
170
|
+
type SweepRanking = 'plateau' | 'raw';
|
|
171
|
+
/**
|
|
172
|
+
* Which view of a sweep's rows to read: the display leaderboard, or every row
|
|
173
|
+
* in a stable order.
|
|
174
|
+
*
|
|
175
|
+
* - `'ranked'` — the platform default. Sorted, and capped at a display limit;
|
|
176
|
+
* `truncated` on the result is `true` when the cap actually bit, in which
|
|
177
|
+
* case rows exist that this view does not carry. This is the view
|
|
178
|
+
* {@link SweepRanking} applies to.
|
|
179
|
+
* - `'natural'` — every available row, untruncated, in deterministic `runIx`
|
|
180
|
+
* order. The view to read when materialising durable trial rows rather than
|
|
181
|
+
* showing a top-N, and the only way to reach rows the ranked view dropped —
|
|
182
|
+
* {@link Sweep.results} reads it off an existing sweep without re-running it.
|
|
183
|
+
* {@link SweepRanking} is **ignored** here and the response reports `'raw'`;
|
|
184
|
+
* rank, plateau score and neighbour count belong to the ranked view and are
|
|
185
|
+
* not part of this one.
|
|
186
|
+
*/
|
|
187
|
+
type SweepOrder = 'ranked' | 'natural';
|
|
188
|
+
/**
|
|
189
|
+
* Sweep lifecycle as observed by the SDK, readable off {@link Sweep.state}.
|
|
190
|
+
*
|
|
191
|
+
* - `'executing'` — submitted and being polled.
|
|
192
|
+
* - `'completed'` — finished. The platform's own status may still be `'PARTIAL'`.
|
|
193
|
+
* - `'failed'` — the poll itself failed: transport, HTTP, or a stage timeout.
|
|
194
|
+
* - `'canceled'` — the sweep was aborted and the platform reported it cancelled.
|
|
195
|
+
*/
|
|
196
|
+
type SweepState = 'executing' | 'completed' | 'failed' | 'canceled';
|
|
197
|
+
/**
|
|
198
|
+
* One strategy property and the values a sweep should try for it: either a
|
|
199
|
+
* numeric range walked in fixed steps, or an explicit list.
|
|
200
|
+
*
|
|
201
|
+
* ```ts
|
|
202
|
+
* const params: Record<string, ParamAxis> = {
|
|
203
|
+
* rsiPeriod: { from: 7, to: 28, step: 1 },
|
|
204
|
+
* useTrendFilter: { values: [true, false] },
|
|
205
|
+
* };
|
|
206
|
+
* ```
|
|
207
|
+
*
|
|
208
|
+
* The two shapes are mutually exclusive on the wire, and mixing them is a
|
|
209
|
+
* request the platform rejects rather than reconciles. A list entry is a number
|
|
210
|
+
* or a boolean — the axis of a boolean flag is `{ values: [true, false] }`, not
|
|
211
|
+
* a range.
|
|
212
|
+
*/
|
|
213
|
+
type ParamAxis = {
|
|
214
|
+
/** First value. */
|
|
215
|
+
from: number;
|
|
216
|
+
/** Last value the walk may reach. */
|
|
217
|
+
to: number;
|
|
218
|
+
/** Increment; must be greater than zero. */
|
|
219
|
+
step: number;
|
|
220
|
+
} | {
|
|
221
|
+
/** The values to try; at least one. */
|
|
222
|
+
values: Array<number | boolean>;
|
|
223
|
+
};
|
|
224
|
+
/**
|
|
225
|
+
* Opt a sweep into walk-forward validation.
|
|
226
|
+
*
|
|
227
|
+
* Attaching this changes what the sweep does, not just how much of it runs.
|
|
228
|
+
* Instead of scoring every parameter vector once over the whole range, the data
|
|
229
|
+
* is cut into sequential folds; each fold optimizes the whole grid on its own
|
|
230
|
+
* window and then scores only its winner on the window immediately after — data
|
|
231
|
+
* that winner was never chosen on. The question it answers is not "which
|
|
232
|
+
* parameters won" but "does re-optimizing this periodically actually work".
|
|
233
|
+
*
|
|
234
|
+
* Omit it and nothing about the sweep changes, including the shape of the
|
|
235
|
+
* response.
|
|
236
|
+
*
|
|
237
|
+
* **It costs folds × grid.** Four folds over a 500-point grid is roughly 2000
|
|
238
|
+
* backtests where the plain sweep is 500, which is why it is opt-in. The
|
|
239
|
+
* platform rejects the request outright when that product exceeds its sweep
|
|
240
|
+
* budget.
|
|
241
|
+
*
|
|
242
|
+
* **It is a different sweep, not a variant of one.** Two requests that differ
|
|
243
|
+
* only in this block do not deduplicate against each other.
|
|
244
|
+
*
|
|
245
|
+
* The answer arrives as `walkForward` on the {@link SweepResult} — see
|
|
246
|
+
* {@link Sweep.result} for how to read it.
|
|
247
|
+
*/
|
|
248
|
+
interface SweepWalkForward {
|
|
249
|
+
/**
|
|
250
|
+
* How many sequential optimize-then-score windows to run. Two is the floor
|
|
251
|
+
* and the reason is structural rather than a tuning preference: parameter
|
|
252
|
+
* drift is measured between consecutive fold winners, and a single fold has
|
|
253
|
+
* no consecutive pair, so it would report the strongest possible stability
|
|
254
|
+
* having measured nothing. The ceiling is a platform setting; exceeding it is
|
|
255
|
+
* rejected.
|
|
256
|
+
*/
|
|
257
|
+
folds: number;
|
|
258
|
+
/**
|
|
259
|
+
* Share of each fold's window spent optimizing, the rest being where its
|
|
260
|
+
* winner is scored. Omit to take the platform default. Lower values leave
|
|
261
|
+
* more data to score on and, on short sessions, are what let the requested
|
|
262
|
+
* fold count tile the data at all. Must be within 10..90.
|
|
263
|
+
*/
|
|
264
|
+
inSamplePct?: number;
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* What the platform answered when it accepted the sweep, exactly as it sent it
|
|
268
|
+
* — see {@link Sweep.accepted} for the three fields that make it worth reading
|
|
269
|
+
* before any result exists.
|
|
270
|
+
*/
|
|
271
|
+
type SweepAccepted = ExecuteSweepAccepted;
|
|
272
|
+
/**
|
|
273
|
+
* A sweep snapshot: status, progress, and the rows available for the selected
|
|
274
|
+
* view. Resolved by {@link Sweep.result}, which is also where the semantics of
|
|
275
|
+
* every field are documented.
|
|
276
|
+
*/
|
|
277
|
+
type SweepResult = ExecuteSweepResult;
|
|
278
|
+
/**
|
|
279
|
+
* The platform's own progress record for a running sweep, carried on
|
|
280
|
+
* {@link SweepProgressEvent.snapshot}. Distinct from the event that wraps it:
|
|
281
|
+
* this is what the server reported, the event is what the SDK emitted.
|
|
282
|
+
*
|
|
283
|
+
* Two of its fields are easy to add together by mistake. `aborted` counts
|
|
284
|
+
* individual runs that executed and aborted — a row-level count. `failedShards`
|
|
285
|
+
* counts whole units of work (shards, or folds on a walk-forward sweep) that
|
|
286
|
+
* failed and will not be retried, having never reported anything. A shard that
|
|
287
|
+
* dies before producing a single row leaves `aborted` at zero, which is exactly
|
|
288
|
+
* why the second count exists; **summing them double-counts nothing and
|
|
289
|
+
* describes nothing**.
|
|
290
|
+
*
|
|
291
|
+
* `retrying` is not a failure count either — those units failed on something
|
|
292
|
+
* transient and are queued to be attempted again, so a sweep with a non-zero
|
|
293
|
+
* value there is still expected to finish.
|
|
294
|
+
*
|
|
295
|
+
* `etaSeconds` is **omitted, never zero** when it cannot be computed: a sweep
|
|
296
|
+
* with nothing finished has no observed rate to extrapolate from, and a zero
|
|
297
|
+
* would read as "about to finish". When present it runs conservative — it
|
|
298
|
+
* excludes queue wait entirely, and a sweep that spent part of its life being
|
|
299
|
+
* retried will have diluted the rate it is derived from.
|
|
300
|
+
*/
|
|
301
|
+
type SweepProgress = SweepProgress$1;
|
|
302
|
+
/** One trial on a sweep's leaderboard. See {@link Sweep.result} for how to read it. */
|
|
303
|
+
type SweepRunRow = SweepRunRow$1;
|
|
304
|
+
/**
|
|
305
|
+
* Sensitivity aggregates over a sweep's stored rows, returned by
|
|
306
|
+
* {@link Sweep.sensitivity}. Marginals are always complete; the pair surfaces
|
|
307
|
+
* may be capped, in which case `heatmapsTruncated` is `true`.
|
|
308
|
+
*/
|
|
309
|
+
type SweepSensitivity = SweepSensitivity$1;
|
|
310
|
+
/** One axis, with every other axis collapsed away. */
|
|
311
|
+
type SweepMarginal = SweepMarginal$1;
|
|
312
|
+
/** How the objective behaved at one value of one axis. */
|
|
313
|
+
type SweepMarginalPoint = SweepMarginalPoint$1;
|
|
314
|
+
/** The surface for one pair of axes, with all others collapsed away. */
|
|
315
|
+
type SweepHeatmap = SweepHeatmap$1;
|
|
316
|
+
/** One cell of a {@link SweepHeatmap}. */
|
|
317
|
+
type SweepHeatmapCell = SweepHeatmapCell$1;
|
|
318
|
+
/**
|
|
319
|
+
* The walk-forward section of a {@link SweepResult}, present exactly when the
|
|
320
|
+
* sweep was submitted with {@link SweepWalkForward}.
|
|
321
|
+
*
|
|
322
|
+
* **`paramDrift` absent is not zero.** The field is omitted whenever the figure
|
|
323
|
+
* could not be computed — fewer than two folds finished, or no stored grid to
|
|
324
|
+
* place the winners on — and zero is itself a meaningful reading there (winners
|
|
325
|
+
* that never moved), so a placeholder would be indistinguishable from perfect
|
|
326
|
+
* stability.
|
|
327
|
+
*/
|
|
328
|
+
type WalkForwardResult = WalkForwardResult$1;
|
|
329
|
+
/**
|
|
330
|
+
* What one fold concluded. The out-of-sample row is the answer; the in-sample
|
|
331
|
+
* figure is only there to be compared against it, since any grid produces a
|
|
332
|
+
* flattering in-sample winner — that is what optimizing does. The gap between
|
|
333
|
+
* them is the whole reading.
|
|
334
|
+
*/
|
|
335
|
+
type WalkForwardFold = WalkForwardFold$1;
|
|
336
|
+
/**
|
|
337
|
+
* A parameter sweep over one instrument and one window: the same strategy run
|
|
338
|
+
* once per parameter vector, scored and ranked against a single objective.
|
|
339
|
+
*
|
|
340
|
+
* ```ts
|
|
341
|
+
* const request: SweepRequest = {
|
|
342
|
+
* strategy: source,
|
|
343
|
+
* exchangeId: 'binance',
|
|
344
|
+
* instrument: 'BTC/USDT',
|
|
345
|
+
* from: '2026-01-01T00:00:00Z',
|
|
346
|
+
* to: '2026-02-01T00:00:00Z',
|
|
347
|
+
* params: {
|
|
348
|
+
* rsiPeriod: { from: 7, to: 28, step: 1 },
|
|
349
|
+
* useTrendFilter: { values: [true, false] },
|
|
350
|
+
* },
|
|
351
|
+
* objective: 'sharpe',
|
|
352
|
+
* };
|
|
353
|
+
* ```
|
|
354
|
+
*/
|
|
355
|
+
interface SweepRequest {
|
|
356
|
+
/** Strategy source code (Java), compiled once and reused by every trial. */
|
|
357
|
+
strategy: string;
|
|
358
|
+
/** Exchange id, e.g. `binance`. */
|
|
359
|
+
exchangeId: string;
|
|
360
|
+
/** Instrument symbol, e.g. `BTC/USDT`. */
|
|
361
|
+
instrument: string;
|
|
362
|
+
/** Range start (ISO-8601, ISO DATE, or BASIC ISO DATE). */
|
|
363
|
+
from: string;
|
|
364
|
+
/** Range end (same formats as `from`; must be later than `from`). */
|
|
365
|
+
to: string;
|
|
366
|
+
/** The grid: one {@link ParamAxis} per strategy property to vary. At least one. */
|
|
367
|
+
params: Record<string, ParamAxis>;
|
|
368
|
+
/**
|
|
369
|
+
* How the grid becomes the list of vectors actually run. Omit to keep the
|
|
370
|
+
* platform default, the full cross product.
|
|
371
|
+
*/
|
|
372
|
+
sampler?: SweepSampler;
|
|
373
|
+
/**
|
|
374
|
+
* How many vectors to draw for `'random'` and `'lhs'`; ignored by `'grid'`.
|
|
375
|
+
*/
|
|
376
|
+
samples?: number;
|
|
377
|
+
/**
|
|
378
|
+
* Reproducibility seed. Omit to let the platform generate one and report it
|
|
379
|
+
* back on {@link Sweep.accepted}, so a randomly sampled sweep can be replayed
|
|
380
|
+
* exactly by submitting the same seed again.
|
|
381
|
+
*/
|
|
382
|
+
seed?: number;
|
|
383
|
+
/**
|
|
384
|
+
* The metric to optimize and rank by; omit to keep the platform default
|
|
385
|
+
* (`'sharpe'`). It is also what {@link Sweep.sensitivity} aggregates unless
|
|
386
|
+
* told otherwise.
|
|
387
|
+
*/
|
|
388
|
+
objective?: SweepObjective;
|
|
389
|
+
/**
|
|
390
|
+
* Opt into walk-forward validation, which changes both what runs and the
|
|
391
|
+
* shape of the answer. Omit to run an ordinary sweep.
|
|
392
|
+
*/
|
|
393
|
+
walkForward?: SweepWalkForward;
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* Emitted at stage transitions and after each poll of a running sweep.
|
|
397
|
+
*
|
|
398
|
+
* The `snapshot` is where the detail lives — see {@link SweepProgress}, whose
|
|
399
|
+
* counts measure different things and must not be added together.
|
|
400
|
+
*/
|
|
401
|
+
interface SweepProgressEvent {
|
|
402
|
+
/** Current workflow stage. */
|
|
403
|
+
stage: BacktestStage;
|
|
404
|
+
/**
|
|
405
|
+
* 0-100, computed from the runs finished out of the runs expected (`done` /
|
|
406
|
+
* `total` on the snapshot, both run-level counts — not the shard counts,
|
|
407
|
+
* which partition units of work rather than runs). Absent on stage
|
|
408
|
+
* transitions before the first poll.
|
|
409
|
+
*/
|
|
410
|
+
percent?: number;
|
|
411
|
+
/**
|
|
412
|
+
* Fraction (0-1) of the requested window that actually holds data, as
|
|
413
|
+
* reported once preparation completes. Present only on the final `preparing`
|
|
414
|
+
* event. Worth reading on a sweep in particular: a thinly covered window is
|
|
415
|
+
* about to be scored once per parameter vector.
|
|
416
|
+
*/
|
|
417
|
+
coverageRatio?: number;
|
|
418
|
+
/**
|
|
419
|
+
* The platform's progress record for the sweep. Present only on `executing`
|
|
420
|
+
* events.
|
|
421
|
+
*/
|
|
422
|
+
snapshot?: SweepProgress;
|
|
423
|
+
}
|
|
424
|
+
/** Tuning knobs for a {@link QTSurfer.sweep} invocation. */
|
|
425
|
+
interface SweepOptions {
|
|
426
|
+
/**
|
|
427
|
+
* Ask the platform to stop the sweep between parameter vectors.
|
|
428
|
+
*
|
|
429
|
+
* **Aborting does not reject {@link Sweep.result}** — it resolves with
|
|
430
|
+
* whatever was scored before the stop. That is a deliberate divergence from
|
|
431
|
+
* `backtest()`, which rejects with `QTSCanceledError` when its run is
|
|
432
|
+
* aborted; see {@link Sweep.result} for why. Aborting *before* the platform
|
|
433
|
+
* has accepted the sweep — during compile, prepare or submission — rejects
|
|
434
|
+
* the {@link QTSurfer.sweep} call itself with `QTSCanceledError`, since there
|
|
435
|
+
* is no sweep yet and so no rows to keep.
|
|
436
|
+
*/
|
|
437
|
+
signal?: AbortSignal;
|
|
438
|
+
/** Called on stage transitions and after each poll with updated progress. */
|
|
439
|
+
onProgress?: (p: SweepProgressEvent) => void;
|
|
440
|
+
/**
|
|
441
|
+
* Initial interval between polls. Default 2000ms, backed off up to
|
|
442
|
+
* `maxPollIntervalMs`. Longer than a single backtest's, because a sweep is
|
|
443
|
+
* many backtests and its leaderboard changes on the timescale of shards
|
|
444
|
+
* finishing rather than ticks.
|
|
445
|
+
*/
|
|
446
|
+
pollIntervalMs?: number;
|
|
447
|
+
/** Upper bound for exponential backoff. Default 15000ms. */
|
|
448
|
+
maxPollIntervalMs?: number;
|
|
449
|
+
/**
|
|
450
|
+
* Per-stage timeout. Default none. A sweep is many backtests, so the execute
|
|
451
|
+
* stage legitimately outlasts anything a single run would take.
|
|
452
|
+
*/
|
|
453
|
+
timeoutMs?: number;
|
|
454
|
+
/**
|
|
455
|
+
* How to order the leaderboard the poll reads. Omit to send no preference and
|
|
456
|
+
* take the platform default, which is `'plateau'` — so leaving this unset
|
|
457
|
+
* does **not** give you raw objective order. What was actually applied is
|
|
458
|
+
* reported on the result. **Ignored entirely when `order` is `'natural'`**,
|
|
459
|
+
* which is always ordered by `runIx`; the platform accepts both and answers
|
|
460
|
+
* with the ordering it applied.
|
|
461
|
+
*/
|
|
462
|
+
ranking?: SweepRanking;
|
|
463
|
+
/**
|
|
464
|
+
* Which view of the rows the background poll reads. Omit to take the platform
|
|
465
|
+
* default, `'ranked'` — the sorted, display-capped leaderboard. `'natural'`
|
|
466
|
+
* returns every available row untruncated.
|
|
467
|
+
*
|
|
468
|
+
* This only decides what {@link Sweep.result} resolves with. Reading the same
|
|
469
|
+
* sweep another way afterwards — to reach the rows a `truncated` ranked view
|
|
470
|
+
* dropped, say — is {@link Sweep.results}, which re-reads rather than
|
|
471
|
+
* re-running.
|
|
472
|
+
*/
|
|
473
|
+
order?: SweepOrder;
|
|
474
|
+
}
|
|
475
|
+
/**
|
|
476
|
+
* Handle for a running parameter sweep, returned by {@link QTSurfer.sweep} once
|
|
477
|
+
* the platform has accepted it. The leaderboard keeps being polled in the
|
|
478
|
+
* background.
|
|
479
|
+
*/
|
|
480
|
+
interface Sweep {
|
|
481
|
+
/** Server-side sweep identifier. */
|
|
482
|
+
readonly sweepId: string;
|
|
483
|
+
/**
|
|
484
|
+
* The prepared dataset every trial ran against — the prepare jobId the
|
|
485
|
+
* workflow resolved before submitting, which is also what addresses this
|
|
486
|
+
* sweep on the wire.
|
|
487
|
+
*
|
|
488
|
+
* This is the value the workflow prepared with, not the acceptance echo of
|
|
489
|
+
* it. {@link Sweep.accepted} carries the echo, unmodified, for anyone who
|
|
490
|
+
* wants to compare the two.
|
|
491
|
+
*/
|
|
492
|
+
readonly requestId: string;
|
|
493
|
+
/** The compiled strategy every trial shares. */
|
|
494
|
+
readonly strategyId: string;
|
|
495
|
+
/**
|
|
496
|
+
* What acceptance already answered, before a single trial has run, exactly as
|
|
497
|
+
* the platform sent it.
|
|
498
|
+
*
|
|
499
|
+
* Three of its fields are the reason this is exposed rather than folded away:
|
|
500
|
+
*
|
|
501
|
+
* - `seed` — the effective seed, generated platform-side when the request
|
|
502
|
+
* omitted one. Submitting it again is what makes a randomly sampled sweep
|
|
503
|
+
* replayable.
|
|
504
|
+
* - `queued` — `false` means an identical sweep already existed and nothing
|
|
505
|
+
* new was enqueued. The handle is still valid and still resolves; it is
|
|
506
|
+
* just reading a sweep this call did not start.
|
|
507
|
+
* - `walkForward` — present exactly when this is a walk-forward sweep. It is
|
|
508
|
+
* the discriminator, and it is available here immediately, so code watching
|
|
509
|
+
* progress can branch on the answer's shape without waiting for
|
|
510
|
+
* {@link Sweep.result}.
|
|
511
|
+
*/
|
|
512
|
+
readonly accepted: SweepAccepted;
|
|
513
|
+
/**
|
|
514
|
+
* Local snapshot of the sweep lifecycle; reading it does not contact the
|
|
515
|
+
* server.
|
|
516
|
+
*/
|
|
517
|
+
readonly state: SweepState;
|
|
518
|
+
/**
|
|
519
|
+
* Resolves with the final leaderboard once the sweep stops advancing.
|
|
520
|
+
*
|
|
521
|
+
* **This resolves on every terminal status, cancellation included** —
|
|
522
|
+
* `'COMPLETED'`, `'PARTIAL'` and `'CANCELLED'` all hand back the result
|
|
523
|
+
* rather than raising. That is a deliberate divergence from `backtest()`,
|
|
524
|
+
* which rejects with `QTSCanceledError` when its run is aborted: cancelling a
|
|
525
|
+
* sweep is documented as leaving completed rows readable, and throwing them
|
|
526
|
+
* away would lose the only reason to cancel a sweep late rather than early.
|
|
527
|
+
* Read `status` to find out which of the three you got. The promise rejects
|
|
528
|
+
* only for transport failures, HTTP errors, and stage timeouts.
|
|
529
|
+
*
|
|
530
|
+
* `'PARTIAL'` means at least one unit of work died and its runs are simply
|
|
531
|
+
* missing. There is no failed status for a sweep as a whole, so a sweep whose
|
|
532
|
+
* every shard died is `'PARTIAL'` with an empty leaderboard — check
|
|
533
|
+
* `leaderboardSize` before reading anything into a top row.
|
|
534
|
+
*
|
|
535
|
+
* ### Reading the leaderboard
|
|
536
|
+
*
|
|
537
|
+
* **The default order is not the raw objective order.** It is plateau order,
|
|
538
|
+
* and `ranking` on the result says which was actually applied — not always
|
|
539
|
+
* the one requested, because a sweep with no stored parameter grid cannot be
|
|
540
|
+
* plateau-ranked and falls back to raw. See {@link SweepRanking}.
|
|
541
|
+
*
|
|
542
|
+
* **The default view is capped.** When `truncated` is `true`, rows exist that
|
|
543
|
+
* the leaderboard does not carry — `leaderboardSize` counts what is
|
|
544
|
+
* available. {@link Sweep.results} with `order: 'natural'` is what returns
|
|
545
|
+
* all of them, in `runIx` order and with no ranking applied. That is a
|
|
546
|
+
* re-read of this same sweep, not a second one.
|
|
547
|
+
*
|
|
548
|
+
* **`plateauScore` and `neighbourCount` are read together.** A neighbour
|
|
549
|
+
* count of `0` means the point had no neighbours in the grid to compare
|
|
550
|
+
* against, so its plateau score is unevidenced rather than confirmed — on its
|
|
551
|
+
* own it is indistinguishable from a genuinely robust one.
|
|
552
|
+
*
|
|
553
|
+
* **`deflatedSharpe`** is the probability that a row's Sharpe reflects real
|
|
554
|
+
* edge rather than the best draw from however many vectors were tried. Around
|
|
555
|
+
* 0.95 and up it survives the multiple-testing correction; near 0.5 or below
|
|
556
|
+
* it is not distinguishable from the best of a pile of coin flips. It is
|
|
557
|
+
* absent on aborted runs, and on sweeps with too few trials to establish any
|
|
558
|
+
* dispersion to deflate against.
|
|
559
|
+
*
|
|
560
|
+
* **`pbo`** is the probability of backtest overfitting for the sweep as a
|
|
561
|
+
* whole: how often the configuration that won in-sample lands below median
|
|
562
|
+
* out-of-sample. Above roughly 0.5 the sweep is selecting noise, and that
|
|
563
|
+
* verdict is about the search, not about any one row — a high value
|
|
564
|
+
* discredits the top row however good it looks. It is computed once the last
|
|
565
|
+
* unit of work finishes, so it is absent while the sweep is still running and
|
|
566
|
+
* on sweeps too small for the statistic to mean anything.
|
|
567
|
+
*
|
|
568
|
+
* ### A walk-forward sweep answers in a different shape
|
|
569
|
+
*
|
|
570
|
+
* `walkForward` is the discriminator, and it appears as soon as the sweep is
|
|
571
|
+
* accepted — before any fold has finished — so it is safe to branch on while
|
|
572
|
+
* polling (it is also on {@link Sweep.accepted}). When it is present, the
|
|
573
|
+
* leaderboard is one row per *completed fold*: that fold's winner as it
|
|
574
|
+
* scored out-of-sample, with **`runIx` carrying the fold index rather than a
|
|
575
|
+
* position in the grid**. No plateau score, deflated Sharpe or PBO figure is
|
|
576
|
+
* reported for one — the out-of-sample numbers are already the honest
|
|
577
|
+
* measurement. See {@link WalkForwardResult} for why an absent `paramDrift`
|
|
578
|
+
* is not a zero.
|
|
579
|
+
*
|
|
580
|
+
* ### An empty leaderboard is not always an empty answer
|
|
581
|
+
*
|
|
582
|
+
* A sweep can finish having scored nothing, because every shard failed before
|
|
583
|
+
* producing a row. When that happens `failReason` carries the cause reported
|
|
584
|
+
* by the *first* shard to fail — typically something the whole grid would have
|
|
585
|
+
* hit, such as a strategy that could not be loaded. Read it before concluding
|
|
586
|
+
* that a sweep with no rows simply found nothing: those are different
|
|
587
|
+
* outcomes and the leaderboard alone cannot tell them apart. Only the first
|
|
588
|
+
* failure is recorded, so where several shards failed for different reasons
|
|
589
|
+
* this names one of them rather than summarising all — pair it with
|
|
590
|
+
* `progress.failedShards` for the count.
|
|
591
|
+
*/
|
|
592
|
+
readonly result: Promise<SweepResult>;
|
|
593
|
+
/**
|
|
594
|
+
* Re-read this sweep's rows under a different view.
|
|
595
|
+
*
|
|
596
|
+
* **This is a read, not a re-run.** It compiles nothing, prepares nothing and
|
|
597
|
+
* submits nothing: the same sweep is asked for its rows again with different
|
|
598
|
+
* query parameters, so no second sweep is created and nothing is enqueued.
|
|
599
|
+
* The view a {@link SweepOptions} chose applies to the background poll behind
|
|
600
|
+
* {@link Sweep.result}; this is how to look at the same sweep another way
|
|
601
|
+
* afterwards.
|
|
602
|
+
*
|
|
603
|
+
* **It is the route to rows the ranked view dropped.** When `truncated` is
|
|
604
|
+
* `true` on a result, rows exist that the leaderboard does not carry;
|
|
605
|
+
* `order: 'natural'` returns every available row untruncated, in
|
|
606
|
+
* deterministic `runIx` order.
|
|
607
|
+
*
|
|
608
|
+
* **`ranking` is ignored when `order` is `'natural'`** — that view is always
|
|
609
|
+
* ordered by `runIx`, and the response reports `'raw'`. The platform accepts
|
|
610
|
+
* both rather than rejecting the pair, and answers with the ordering it
|
|
611
|
+
* actually applied.
|
|
612
|
+
*
|
|
613
|
+
* Readable while the sweep is still running, in which case it returns the
|
|
614
|
+
* rows finished so far — exactly like {@link Sweep.sensitivity}. Like every
|
|
615
|
+
* handle-scoped call, it does not take part in an
|
|
616
|
+
* {@link AuthenticatedClient}'s refresh-on-401 policy.
|
|
617
|
+
*
|
|
618
|
+
* @param view which view to read; an absent property takes the platform
|
|
619
|
+
* default (`order: 'ranked'`, `ranking: 'plateau'`)
|
|
620
|
+
* @throws QTSError on any non-2xx response, with the HTTP status on `status`.
|
|
621
|
+
*/
|
|
622
|
+
results(view?: {
|
|
623
|
+
order?: SweepOrder;
|
|
624
|
+
ranking?: SweepRanking;
|
|
625
|
+
}): Promise<SweepResult>;
|
|
626
|
+
/**
|
|
627
|
+
* How the objective moves as each parameter moves — the question a
|
|
628
|
+
* leaderboard cannot answer. A leaderboard says which point won; a sweep can
|
|
629
|
+
* spend its whole budget on an axis that never moved the objective at all,
|
|
630
|
+
* and the top rows hide that completely.
|
|
631
|
+
*
|
|
632
|
+
* A *marginal* takes one axis and collapses every other one: for each value
|
|
633
|
+
* of that axis it aggregates every run that used it, whatever the rest of the
|
|
634
|
+
* parameters were. A flat marginal means the axis did not matter over the
|
|
635
|
+
* range swept. `best`, `mean` and `worst` are all reported because them
|
|
636
|
+
* disagreeing is the signal — a value with a high best and a poor mean only
|
|
637
|
+
* works in specific company, which is an interaction, and a single number
|
|
638
|
+
* would hide it. A *heatmap* does the same over a pair of axes, where that
|
|
639
|
+
* interaction is visible directly.
|
|
640
|
+
*
|
|
641
|
+
* **Check `heatmapsTruncated`.** Marginals are always complete; the pair
|
|
642
|
+
* surfaces are quadratic in the axis count and may be capped to stay inside
|
|
643
|
+
* the response budget. When the flag is `true`, at least one pair was left
|
|
644
|
+
* out, so the list you have is not the full set of interactions. This method
|
|
645
|
+
* hands back the whole {@link SweepSensitivity} rather than just its surfaces
|
|
646
|
+
* precisely so that flag cannot be lost on the way out.
|
|
647
|
+
*
|
|
648
|
+
* Readable while the sweep is still running, in which case the aggregates
|
|
649
|
+
* describe the runs finished so far and `rowsAnalysed` says how many that
|
|
650
|
+
* was. Aborted runs are excluded throughout: a run that threw measured
|
|
651
|
+
* nothing, and counting it as a bad outcome would invent evidence against a
|
|
652
|
+
* parameter value that was never really tested.
|
|
653
|
+
*
|
|
654
|
+
* Like every handle-scoped call, this does not take part in an
|
|
655
|
+
* {@link AuthenticatedClient}'s refresh-on-401 policy.
|
|
656
|
+
*
|
|
657
|
+
* @param objective which metric to aggregate; omit to use the objective the
|
|
658
|
+
* sweep was submitted with
|
|
659
|
+
* @throws QTSError on any non-2xx response, with the HTTP status on `status`.
|
|
660
|
+
*/
|
|
661
|
+
sensitivity(objective?: SweepObjective): Promise<SweepSensitivity>;
|
|
662
|
+
}
|
|
663
|
+
|
|
54
664
|
/** Configuration for {@link QTSurfer}. */
|
|
55
665
|
interface QTSurferOptions {
|
|
56
666
|
/** Base URL of the QTSurfer API, e.g. `https://api.qtsurfer.com/v1`. */
|
|
@@ -79,7 +689,9 @@ interface DownloadHourArgs {
|
|
|
79
689
|
}
|
|
80
690
|
/**
|
|
81
691
|
* Thin, stateless wrapper over `@qtsurfer/api-client` that exposes the SDK's
|
|
82
|
-
* workflow methods (`backtest`, `tickers`, `klines`)
|
|
692
|
+
* workflow methods (`backtest`, `sweep`, `tickers`, `klines`), the platform catalog
|
|
693
|
+
* (`exchanges`, `instruments`) and the strategy surface (`validateStrategy`,
|
|
694
|
+
* `strategy`). Constructing an
|
|
83
695
|
* instance reconfigures the underlying api-client singleton, so avoid
|
|
84
696
|
* holding two `QTSurfer`s with different `baseUrl`s or tokens alive in the
|
|
85
697
|
* same process — they will race. Prefer the `authenticate()` helper over
|
|
@@ -94,6 +706,45 @@ declare class QTSurfer {
|
|
|
94
706
|
* stage-by-stage error and retry semantics.
|
|
95
707
|
*/
|
|
96
708
|
backtest(req: BacktestRequest, opts?: BacktestOptions): Promise<BacktestResult>;
|
|
709
|
+
/**
|
|
710
|
+
* Run the full compile → prepare → executeSweep pipeline and resolve once the
|
|
711
|
+
* platform has accepted the sweep, handing back a {@link Sweep} that keeps
|
|
712
|
+
* polling the leaderboard in the background.
|
|
713
|
+
*
|
|
714
|
+
* The whole sweep is one call because the execute-sweep endpoint is addressed
|
|
715
|
+
* by the id of an already-prepared dataset: exposing the stages separately
|
|
716
|
+
* would hand dataset lifecycle to the caller and buy nothing. Preparing is
|
|
717
|
+
* idempotent, so sweeping the same window twice prepares it once.
|
|
718
|
+
*
|
|
719
|
+
* The returned promise rejects with {@link QTSStrategyCompileError} if
|
|
720
|
+
* compilation fails, {@link QTSPreparationError} if data preparation fails,
|
|
721
|
+
* {@link QTSExecutionError} if the platform rejects the sweep — an expanded
|
|
722
|
+
* grid over the server limit, or a walk-forward request whose fold count
|
|
723
|
+
* multiplies past the sweep budget, both answer `400` — {@link QTSTimeoutError}
|
|
724
|
+
* if a stage exceeds `timeoutMs`, or {@link QTSCanceledError} if the caller's
|
|
725
|
+
* signal fires before the sweep is accepted. A plain {@link QTSError} means
|
|
726
|
+
* the request itself is malformed (an empty grid, a non-positive `step`, a
|
|
727
|
+
* walk-forward block with fewer than two folds) and never reached the network.
|
|
728
|
+
*
|
|
729
|
+
* What the sweep *found* arrives through {@link Sweep.result}, which is also
|
|
730
|
+
* where the semantics of the leaderboard are documented. Acceptance already
|
|
731
|
+
* answers three things worth reading before any result exists — the effective
|
|
732
|
+
* seed, whether this submission enqueued anything, and whether this is a
|
|
733
|
+
* walk-forward sweep — see {@link Sweep.accepted}.
|
|
734
|
+
*
|
|
735
|
+
* ```ts
|
|
736
|
+
* const handle = await qts.sweep({
|
|
737
|
+
* strategy: source,
|
|
738
|
+
* exchangeId: 'binance',
|
|
739
|
+
* instrument: 'BTC/USDT',
|
|
740
|
+
* from: '2026-01-01T00:00:00Z',
|
|
741
|
+
* to: '2026-02-01T00:00:00Z',
|
|
742
|
+
* params: { rsiPeriod: { from: 7, to: 28, step: 1 } },
|
|
743
|
+
* });
|
|
744
|
+
* const leaderboard = await handle.result;
|
|
745
|
+
* ```
|
|
746
|
+
*/
|
|
747
|
+
sweep(req: SweepRequest, opts?: SweepOptions): Promise<Sweep>;
|
|
97
748
|
/**
|
|
98
749
|
* Download one hour of raw tickers for an instrument as a {@link Blob}.
|
|
99
750
|
* Defaults to Lastra; pass `{ format: 'parquet' }` for Parquet.
|
|
@@ -101,14 +752,89 @@ declare class QTSurfer {
|
|
|
101
752
|
tickers(args: DownloadHourArgs): Promise<Blob>;
|
|
102
753
|
/** Download one hour of klines for an instrument as a {@link Blob}. */
|
|
103
754
|
klines(args: DownloadHourArgs): Promise<Blob>;
|
|
755
|
+
/**
|
|
756
|
+
* List the exchanges the platform serves. Each `id` is what every other
|
|
757
|
+
* method takes as `exchangeId`.
|
|
758
|
+
*
|
|
759
|
+
* @throws QTSError on any non-2xx response, with the HTTP status on
|
|
760
|
+
* `status`.
|
|
761
|
+
*/
|
|
762
|
+
exchanges(): Promise<Exchange[]>;
|
|
763
|
+
/**
|
|
764
|
+
* List an exchange's instruments, each with the per-data-type `coverage`
|
|
765
|
+
* that says which date windows are actually downloadable.
|
|
766
|
+
*
|
|
767
|
+
* Omitting `segment` asks for the exchange's **default** segment, which is
|
|
768
|
+
* `'spot'` today. The API answers with a HAL envelope that this method
|
|
769
|
+
* unwraps to the instrument array, so the envelope's `meta.segment`,
|
|
770
|
+
* `meta.updatedAt` and segment-discovery `_links` do not reach you: if you
|
|
771
|
+
* need certainty about which segment you are looking at, pass `segment`
|
|
772
|
+
* explicitly rather than relying on the default.
|
|
773
|
+
*
|
|
774
|
+
* @param exchangeId exchange identifier, e.g. `binance`
|
|
775
|
+
* @throws QTSError on any non-2xx response, with the HTTP status on
|
|
776
|
+
* `status`.
|
|
777
|
+
*/
|
|
778
|
+
instruments(exchangeId: string, segment?: InstrumentSegment): Promise<InstrumentDetail[]>;
|
|
779
|
+
/**
|
|
780
|
+
* Ask the platform to check that a registered strategy can actually run:
|
|
781
|
+
* it instantiates the compiled class and drives it through a bounded
|
|
782
|
+
* synthetic series, so a wiring fault surfaces here instead of at the first
|
|
783
|
+
* backtest.
|
|
784
|
+
*
|
|
785
|
+
* **Idempotent, and two-outcome.** `queued: false` means a verdict already
|
|
786
|
+
* existed for the current compilation and came back unchanged in `state` —
|
|
787
|
+
* nothing was queued. `queued: true` means a check was just started, and is
|
|
788
|
+
* **not** terminal: poll {@link QTSurfer.strategy} until `validation`
|
|
789
|
+
* leaves `'pending'`. The discriminant reports whether work was *started*,
|
|
790
|
+
* not whether a verdict *exists*, because a `queued: false` answer can
|
|
791
|
+
* itself carry `validation: 'pending'` from a check an earlier call queued;
|
|
792
|
+
* `state.validation` is what tells you that.
|
|
793
|
+
*
|
|
794
|
+
* **Poll with a deadline of your own.** `'pending'` is not guaranteed to
|
|
795
|
+
* resolve — a queued check can go unreported for far longer than one takes,
|
|
796
|
+
* which the platform eventually flags as `validationStalled`. Nothing about
|
|
797
|
+
* the strategy is disproved when that happens, but a caller that waits for
|
|
798
|
+
* a terminal verdict without a timeout can wait forever. This SDK ships no
|
|
799
|
+
* polling helper for that reason: the timeout is the caller's policy.
|
|
800
|
+
*
|
|
801
|
+
* Whatever the verdict, it is a floor rather than a guarantee — see
|
|
802
|
+
* {@link StrategyState}.
|
|
803
|
+
*
|
|
804
|
+
* @param strategyId the id returned when the strategy was compiled
|
|
805
|
+
* @throws QTSError on any non-2xx response; a `404` (carried on `status`)
|
|
806
|
+
* means no such registered strategy for this caller.
|
|
807
|
+
*/
|
|
808
|
+
validateStrategy(strategyId: string): Promise<StrategyValidation>;
|
|
809
|
+
/**
|
|
810
|
+
* Read everything the platform records about a strategy: whether it is
|
|
811
|
+
* registered at all, its validation verdict, the market data its compiled
|
|
812
|
+
* class requires, and any engine notices the check raised. This is what to
|
|
813
|
+
* poll after {@link QTSurfer.validateStrategy} returns `queued: true`, and
|
|
814
|
+
* the only place a verdict is read from.
|
|
815
|
+
*
|
|
816
|
+
* Check `compiledAt` against `validatedAt` before trusting a verdict: the
|
|
817
|
+
* strategy may have been recompiled since it was recorded, in which case
|
|
818
|
+
* the verdict describes bytecode that is no longer what would run.
|
|
819
|
+
* See {@link StrategyState} for why even a fresh `'passed'` is a floor
|
|
820
|
+
* rather than a guarantee.
|
|
821
|
+
*
|
|
822
|
+
* @param strategyId the id returned when the strategy was compiled
|
|
823
|
+
* @throws QTSError on any non-2xx response. A `404` (carried on `status`)
|
|
824
|
+
* means exactly one thing — no such registered strategy for this caller.
|
|
825
|
+
* It is never a stale or expired answer.
|
|
826
|
+
*/
|
|
827
|
+
strategy(strategyId: string): Promise<StrategyState>;
|
|
104
828
|
}
|
|
105
829
|
|
|
106
830
|
/**
|
|
107
831
|
* Base class for every error the SDK throws. Catch this to handle all SDK
|
|
108
832
|
* failures generically, or catch a specific subclass below to tell which
|
|
109
833
|
* stage failed. `status` is only set when the throw site had an HTTP status
|
|
110
|
-
* to attach
|
|
111
|
-
*
|
|
834
|
+
* to attach: {@link QTSDownloadError} always carries one, and so does the
|
|
835
|
+
* plain `QTSError` thrown by the single-request calls (`exchanges`,
|
|
836
|
+
* `instruments`, `validateStrategy`, `strategy`). The workflow-stage errors
|
|
837
|
+
* carry `cause` instead and encode retryability in their message.
|
|
112
838
|
*/
|
|
113
839
|
declare class QTSError extends Error {
|
|
114
840
|
readonly cause?: unknown | undefined;
|
|
@@ -259,21 +985,68 @@ declare class AuthenticatedClient {
|
|
|
259
985
|
* triggering a refresh.
|
|
260
986
|
*/
|
|
261
987
|
backtest(req: BacktestRequest, opts?: BacktestOptions): Promise<BacktestResult>;
|
|
988
|
+
/**
|
|
989
|
+
* Run the full compile → prepare → executeSweep pipeline and resolve once the
|
|
990
|
+
* platform has accepted the sweep, handing back a {@link Sweep} that keeps
|
|
991
|
+
* polling the leaderboard in the background. See {@link QTSurfer.sweep} for
|
|
992
|
+
* why the sweep is one call rather than composable stages, and
|
|
993
|
+
* {@link Sweep.result} for how to read what it found.
|
|
994
|
+
*
|
|
995
|
+
* The currently cached token is sent (minting one first if none is cached),
|
|
996
|
+
* but as with `backtest()` a `401` here is **not** auto-retried: the
|
|
997
|
+
* underlying stage errors carry no HTTP status, so a token that expires
|
|
998
|
+
* mid-pipeline surfaces as `QTSPreparationError`/`QTSExecutionError` rather
|
|
999
|
+
* than triggering a refresh.
|
|
1000
|
+
*
|
|
1001
|
+
* The background leaderboard poll and {@link Sweep.sensitivity} sit outside
|
|
1002
|
+
* the policy for a second, independent reason: both run after this promise
|
|
1003
|
+
* has already resolved, so a token that expires while a sweep is in flight
|
|
1004
|
+
* surfaces on {@link Sweep.result} whatever the stage errors carry.
|
|
1005
|
+
*/
|
|
1006
|
+
sweep(req: SweepRequest, opts?: SweepOptions): Promise<Sweep>;
|
|
262
1007
|
/** Download one hour of raw tickers. Refreshes the token once on `401` before retrying. */
|
|
263
1008
|
tickers(args: DownloadHourArgs): Promise<Blob>;
|
|
264
1009
|
/** Download one hour of klines. Refreshes the token once on `401` before retrying. */
|
|
265
1010
|
klines(args: DownloadHourArgs): Promise<Blob>;
|
|
1011
|
+
/**
|
|
1012
|
+
* List the exchanges the platform serves. Refreshes the token once on `401`
|
|
1013
|
+
* before retrying.
|
|
1014
|
+
*/
|
|
1015
|
+
exchanges(): Promise<Exchange[]>;
|
|
1016
|
+
/**
|
|
1017
|
+
* List an exchange's instruments, optionally for a specific segment.
|
|
1018
|
+
* Refreshes the token once on `401` before retrying. See
|
|
1019
|
+
* {@link QTSurfer.instruments} for what the unwrapped HAL envelope leaves
|
|
1020
|
+
* out.
|
|
1021
|
+
*/
|
|
1022
|
+
instruments(exchangeId: string, segment?: InstrumentSegment): Promise<InstrumentDetail[]>;
|
|
1023
|
+
/**
|
|
1024
|
+
* Ask the platform to check that a registered strategy can actually run.
|
|
1025
|
+
* Refreshes the token once on `401` before retrying. Two-outcome — see
|
|
1026
|
+
* {@link QTSurfer.validateStrategy}; `queued: true` is not terminal and
|
|
1027
|
+
* must be followed by polling {@link AuthenticatedClient.strategy} under a
|
|
1028
|
+
* deadline of your own.
|
|
1029
|
+
*/
|
|
1030
|
+
validateStrategy(strategyId: string): Promise<StrategyValidation>;
|
|
1031
|
+
/**
|
|
1032
|
+
* Read a strategy's recorded state, including its validation verdict.
|
|
1033
|
+
* Refreshes the token once on `401` before retrying. See
|
|
1034
|
+
* {@link StrategyState} for why a `'passed'` verdict is a floor rather than
|
|
1035
|
+
* a guarantee.
|
|
1036
|
+
*/
|
|
1037
|
+
strategy(strategyId: string): Promise<StrategyState>;
|
|
266
1038
|
}
|
|
267
1039
|
/**
|
|
268
1040
|
* Exchange a long-lived API key for an authenticated session.
|
|
269
1041
|
*
|
|
270
1042
|
* If `apikey` is omitted, the SDK reads `QTSURFER_APIKEY` from the
|
|
271
1043
|
* environment. The returned {@link AuthenticatedClient} caches the JWT,
|
|
272
|
-
* refreshes it on 401, and exposes the same
|
|
273
|
-
*
|
|
1044
|
+
* refreshes it on 401, and exposes the same surface as `QTSurfer`
|
|
1045
|
+
* (`backtest`, `sweep`, `tickers`, `klines`, `exchanges`, `instruments`,
|
|
1046
|
+
* `validateStrategy`, `strategy`).
|
|
274
1047
|
*
|
|
275
1048
|
* @throws {QTSAuthError} if no apikey is supplied or available in env.
|
|
276
1049
|
*/
|
|
277
1050
|
declare function authenticate(apikey?: string, opts?: AuthOptions): Promise<AuthenticatedClient>;
|
|
278
1051
|
|
|
279
|
-
export { type AuthOptions, AuthenticatedClient, type BacktestOptions, type BacktestProgress, type BacktestRequest, type BacktestResult, type BacktestStage, type DownloadFormat, type DownloadHourArgs, InMemoryTokenStore, QTSAuthError, QTSCanceledError, QTSDownloadError, QTSError, QTSExecutionError, QTSPreparationError, QTSStrategyCompileError, QTSTimeoutError, QTSurfer, type QTSurferOptions, type TokenStore, authenticate };
|
|
1052
|
+
export { type AuthOptions, AuthenticatedClient, type BacktestOptions, type BacktestProgress, type BacktestRequest, type BacktestResult, type BacktestStage, type DownloadFormat, type DownloadHourArgs, type Exchange, InMemoryTokenStore, type InstrumentDetail, type InstrumentSegment, type ParamAxis, QTSAuthError, QTSCanceledError, QTSDownloadError, QTSError, QTSExecutionError, QTSPreparationError, QTSStrategyCompileError, QTSTimeoutError, QTSurfer, type QTSurferOptions, type StrategyState, type StrategyValidation, type Sweep, type SweepAccepted, type SweepHeatmap, type SweepHeatmapCell, type SweepMarginal, type SweepMarginalPoint, type SweepObjective, type SweepOptions, type SweepOrder, type SweepProgress, type SweepProgressEvent, type SweepRanking, type SweepRequest, type SweepResult, type SweepRunRow, type SweepSampler, type SweepSensitivity, type SweepState, type SweepWalkForward, type TokenStore, type WalkForwardFold, type WalkForwardResult, authenticate };
|