@qtsurfer/sdk 0.1.1 → 0.1.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
@@ -35,7 +35,7 @@ const result = await qts.backtest(
35
35
  {
36
36
  strategy: readFileSync('./MyStrategy.java', 'utf8'),
37
37
  exchangeId: 'binance',
38
- instrument: 'BTCUSDT',
38
+ instrument: 'BTC/USDT',
39
39
  from: '2024-01-01',
40
40
  to: '2024-12-31',
41
41
  storeSignals: true,
package/dist/index.d.ts CHANGED
@@ -1,4 +1,67 @@
1
- export { QTSurfer, type QTSurferOptions } from './client';
2
- export { QTSError, QTSStrategyCompileError, QTSPreparationError, QTSExecutionError, QTSTimeoutError, QTSCanceledError, } from './errors';
3
- export type { BacktestRequest, BacktestResult, BacktestProgress, BacktestStage, BacktestOptions, } from './workflows/backtest';
4
- //# sourceMappingURL=index.d.ts.map
1
+ import { ResultMap } from '@qtsurfer/api-client';
2
+
3
+ interface BacktestRequest {
4
+ /** Strategy source code (Java) */
5
+ strategy: string;
6
+ /** Exchange id, e.g. `binance` */
7
+ exchangeId: string;
8
+ /** Instrument symbol, e.g. `BTC/USDT` */
9
+ instrument: string;
10
+ /** Date range start (ISO-8601, ISO DATE or BASIC ISO DATE) */
11
+ from: string;
12
+ /** Date range end (same formats as `from`) */
13
+ to: string;
14
+ /** When true, the worker uploads emitted signals to object storage. */
15
+ storeSignals?: boolean;
16
+ }
17
+ type BacktestResult = ResultMap;
18
+ type BacktestStage = 'compiling' | 'preparing' | 'executing';
19
+ interface BacktestProgress {
20
+ stage: BacktestStage;
21
+ /** 0-100 when size is known. Undefined during stage start. */
22
+ percent?: number;
23
+ }
24
+ interface BacktestOptions {
25
+ /** Abort the workflow. Cancels the current poll and calls `cancelExecution` server-side if execution has started. */
26
+ signal?: AbortSignal;
27
+ /** Called on stage transitions and after each poll with updated progress. */
28
+ onProgress?: (p: BacktestProgress) => void;
29
+ /** Initial interval between polls. Default 500ms, backed off up to `maxPollIntervalMs`. */
30
+ pollIntervalMs?: number;
31
+ /** Upper bound for exponential backoff. Default 5000ms. */
32
+ maxPollIntervalMs?: number;
33
+ /** Per-stage timeout. Default none. */
34
+ timeoutMs?: number;
35
+ }
36
+
37
+ interface QTSurferOptions {
38
+ baseUrl: string;
39
+ token?: string;
40
+ fetch?: typeof fetch;
41
+ }
42
+ declare class QTSurfer {
43
+ constructor(options: QTSurferOptions);
44
+ backtest(req: BacktestRequest, opts?: BacktestOptions): Promise<BacktestResult>;
45
+ }
46
+
47
+ declare class QTSError extends Error {
48
+ readonly cause?: unknown | undefined;
49
+ constructor(message: string, cause?: unknown | undefined);
50
+ }
51
+ declare class QTSStrategyCompileError extends QTSError {
52
+ constructor(message: string, cause?: unknown);
53
+ }
54
+ declare class QTSPreparationError extends QTSError {
55
+ constructor(message: string, cause?: unknown);
56
+ }
57
+ declare class QTSExecutionError extends QTSError {
58
+ constructor(message: string, cause?: unknown);
59
+ }
60
+ declare class QTSTimeoutError extends QTSError {
61
+ constructor(message: string, cause?: unknown);
62
+ }
63
+ declare class QTSCanceledError extends QTSError {
64
+ constructor(message: string, cause?: unknown);
65
+ }
66
+
67
+ export { type BacktestOptions, type BacktestProgress, type BacktestRequest, type BacktestResult, type BacktestStage, QTSCanceledError, QTSError, QTSExecutionError, QTSPreparationError, QTSStrategyCompileError, QTSTimeoutError, QTSurfer, type QTSurferOptions };
package/dist/index.js CHANGED
@@ -1,3 +1,268 @@
1
- export { QTSurfer } from './client';
2
- export { QTSError, QTSStrategyCompileError, QTSPreparationError, QTSExecutionError, QTSTimeoutError, QTSCanceledError, } from './errors';
1
+ // src/client.ts
2
+ import { client as apiClient } from "@qtsurfer/api-client";
3
+
4
+ // src/workflows/backtest.ts
5
+ import {
6
+ cancelExecution,
7
+ executeBacktesting,
8
+ getExecutionResult,
9
+ getPreparationStatus,
10
+ getStrategyStatus,
11
+ postStrategy,
12
+ prepareBacktesting
13
+ } from "@qtsurfer/api-client";
14
+ import {
15
+ ExponentialBackoff,
16
+ TaskCancelledError,
17
+ TimeoutStrategy,
18
+ handleWhenResult,
19
+ retry,
20
+ timeout,
21
+ wrap
22
+ } from "cockatiel";
23
+
24
+ // src/errors.ts
25
+ var QTSError = class extends Error {
26
+ constructor(message, cause) {
27
+ super(message);
28
+ this.cause = cause;
29
+ this.name = "QTSError";
30
+ }
31
+ cause;
32
+ };
33
+ var QTSStrategyCompileError = class extends QTSError {
34
+ constructor(message, cause) {
35
+ super(message, cause);
36
+ this.name = "QTSStrategyCompileError";
37
+ }
38
+ };
39
+ var QTSPreparationError = class extends QTSError {
40
+ constructor(message, cause) {
41
+ super(message, cause);
42
+ this.name = "QTSPreparationError";
43
+ }
44
+ };
45
+ var QTSExecutionError = class extends QTSError {
46
+ constructor(message, cause) {
47
+ super(message, cause);
48
+ this.name = "QTSExecutionError";
49
+ }
50
+ };
51
+ var QTSTimeoutError = class extends QTSError {
52
+ constructor(message, cause) {
53
+ super(message, cause);
54
+ this.name = "QTSTimeoutError";
55
+ }
56
+ };
57
+ var QTSCanceledError = class extends QTSError {
58
+ constructor(message, cause) {
59
+ super(message, cause);
60
+ this.name = "QTSCanceledError";
61
+ }
62
+ };
63
+
64
+ // src/workflows/backtest.ts
65
+ var TICKER = "ticker";
66
+ function normalizeStatus(raw) {
67
+ const value = typeof raw === "string" ? raw.toLowerCase() : "";
68
+ if (value === "completed") return "completed";
69
+ if (value === "failed") return "failed";
70
+ if (value === "aborted" || value === "cancelled" || value === "canceled") {
71
+ return "aborted";
72
+ }
73
+ return "in-progress";
74
+ }
75
+ async function backtest(req, opts = {}) {
76
+ const policy = buildStagePolicy(opts);
77
+ opts.onProgress?.({ stage: "compiling" });
78
+ const strategyId = await compileStrategy(req.strategy, policy, opts);
79
+ opts.onProgress?.({ stage: "preparing" });
80
+ const prepareJobId = await prepareData(req, policy, opts);
81
+ opts.onProgress?.({ stage: "executing" });
82
+ return executeStrategy(req, prepareJobId, strategyId, policy, opts);
83
+ }
84
+ function buildStagePolicy(opts) {
85
+ const retryPolicy = retry(
86
+ handleWhenResult((r) => {
87
+ const status = r?.status;
88
+ return normalizeStatus(status) === "in-progress";
89
+ }),
90
+ {
91
+ maxAttempts: Number.MAX_SAFE_INTEGER,
92
+ backoff: new ExponentialBackoff({
93
+ initialDelay: opts.pollIntervalMs ?? 500,
94
+ maxDelay: opts.maxPollIntervalMs ?? 5e3
95
+ })
96
+ }
97
+ );
98
+ return opts.timeoutMs ? wrap(timeout(opts.timeoutMs, TimeoutStrategy.Cooperative), retryPolicy) : retryPolicy;
99
+ }
100
+ async function compileStrategy(source, policy, opts) {
101
+ const { data, error } = await postStrategy({
102
+ body: source,
103
+ headers: { "X-Compile-Async": true },
104
+ ...opts.signal ? { signal: opts.signal } : {}
105
+ });
106
+ if (error) throw new QTSStrategyCompileError("Strategy submission failed", error);
107
+ if (!data) throw new QTSStrategyCompileError("Empty response from strategy endpoint");
108
+ if ("strategyId" in data && data.strategyId) {
109
+ return data.strategyId;
110
+ }
111
+ if (!("jobId" in data) || !data.jobId) {
112
+ throw new QTSStrategyCompileError("Missing jobId/strategyId in compile response");
113
+ }
114
+ const compileJobId = data.jobId;
115
+ const status = await runStage(
116
+ policy,
117
+ opts,
118
+ async ({ signal }) => {
119
+ const res = await getStrategyStatus({ path: { strategyId: compileJobId }, signal });
120
+ if (res.error) throw new QTSStrategyCompileError("Compile status request failed", res.error);
121
+ if (!res.data) throw new QTSStrategyCompileError("Empty compile status response");
122
+ return res.data;
123
+ }
124
+ );
125
+ const norm = normalizeStatus(status.status);
126
+ if (norm === "failed") {
127
+ throw new QTSStrategyCompileError(status.statusDetail ?? "Strategy compilation failed");
128
+ }
129
+ if (norm === "aborted") {
130
+ throw new QTSCanceledError("Strategy compilation aborted");
131
+ }
132
+ if (!status.strategyId) {
133
+ throw new QTSStrategyCompileError("Compile completed without a strategyId");
134
+ }
135
+ return status.strategyId;
136
+ }
137
+ async function prepareData(req, policy, opts) {
138
+ const { data, error } = await prepareBacktesting({
139
+ path: { exchangeId: req.exchangeId, type: TICKER },
140
+ body: { instrument: req.instrument, from: req.from, to: req.to },
141
+ ...opts.signal ? { signal: opts.signal } : {}
142
+ });
143
+ if (error) throw new QTSPreparationError("Prepare submission failed", error);
144
+ if (!data?.jobId) throw new QTSPreparationError("Missing jobId in prepare response");
145
+ const prepareJobId = data.jobId;
146
+ const state = await runStage(
147
+ policy,
148
+ opts,
149
+ async ({ signal }) => {
150
+ const res = await getPreparationStatus({
151
+ path: { exchangeId: req.exchangeId, type: TICKER, jobId: prepareJobId },
152
+ signal
153
+ });
154
+ if (res.error) throw new QTSPreparationError("Preparation status request failed", res.error);
155
+ if (!res.data) throw new QTSPreparationError("Empty preparation status response");
156
+ return res.data;
157
+ },
158
+ (r) => {
159
+ if (r.size > 0) {
160
+ opts.onProgress?.({ stage: "preparing", percent: r.completed / r.size * 100 });
161
+ }
162
+ }
163
+ );
164
+ const prepNorm = normalizeStatus(state.status);
165
+ if (prepNorm === "failed") {
166
+ throw new QTSPreparationError(state.statusDetail ?? "Data preparation failed");
167
+ }
168
+ if (prepNorm === "aborted") {
169
+ throw new QTSCanceledError("Data preparation aborted");
170
+ }
171
+ return prepareJobId;
172
+ }
173
+ async function executeStrategy(req, prepareJobId, strategyId, policy, opts) {
174
+ const { data, error } = await executeBacktesting({
175
+ path: { exchangeId: req.exchangeId, type: TICKER },
176
+ body: {
177
+ prepareJobId,
178
+ strategyId,
179
+ ...req.storeSignals !== void 0 ? { storeSignals: req.storeSignals } : {}
180
+ },
181
+ ...opts.signal ? { signal: opts.signal } : {}
182
+ });
183
+ if (error) throw new QTSExecutionError("Execute submission failed", error);
184
+ if (!data?.jobId) throw new QTSExecutionError("Missing jobId in execute response");
185
+ const executeJobId = data.jobId;
186
+ try {
187
+ const finalResult = await runStage(
188
+ policy,
189
+ opts,
190
+ async ({ signal }) => {
191
+ const res = await getExecutionResult({
192
+ path: { exchangeId: req.exchangeId, type: TICKER, jobId: executeJobId },
193
+ signal
194
+ });
195
+ if (res.error) throw new QTSExecutionError("Execution result request failed", res.error);
196
+ if (!res.data) throw new QTSExecutionError("Empty execution result response");
197
+ return { ...res.data.state, __result: res.data.results };
198
+ },
199
+ (r) => {
200
+ if (r.size > 0) {
201
+ opts.onProgress?.({ stage: "executing", percent: r.completed / r.size * 100 });
202
+ }
203
+ }
204
+ );
205
+ const execNorm = normalizeStatus(finalResult.status);
206
+ if (execNorm === "failed") {
207
+ throw new QTSExecutionError(finalResult.statusDetail ?? "Execution failed");
208
+ }
209
+ if (execNorm === "aborted") {
210
+ throw new QTSCanceledError("Execution aborted");
211
+ }
212
+ return finalResult.__result;
213
+ } catch (err) {
214
+ if (err instanceof QTSCanceledError) {
215
+ await cancelExecution({
216
+ path: { exchangeId: req.exchangeId, type: TICKER, jobId: executeJobId }
217
+ }).catch(() => void 0);
218
+ }
219
+ throw err;
220
+ }
221
+ }
222
+ async function runStage(policy, opts, fetchFn, onEachAttempt) {
223
+ try {
224
+ return await policy.execute(async (ctx) => {
225
+ if (opts.signal?.aborted) throw new QTSCanceledError("Workflow aborted");
226
+ const result = await fetchFn(ctx);
227
+ onEachAttempt?.(result);
228
+ if (opts.signal?.aborted) throw new QTSCanceledError("Workflow aborted");
229
+ return result;
230
+ }, opts.signal);
231
+ } catch (err) {
232
+ if (err instanceof QTSCanceledError) throw err;
233
+ if (err instanceof TaskCancelledError) {
234
+ if (opts.signal?.aborted) throw new QTSCanceledError("Workflow aborted", err);
235
+ throw new QTSTimeoutError(`Stage exceeded ${opts.timeoutMs}ms`, err);
236
+ }
237
+ if (opts.signal?.aborted) throw new QTSCanceledError("Workflow aborted", err);
238
+ throw err;
239
+ }
240
+ }
241
+
242
+ // src/client.ts
243
+ var QTSurfer = class {
244
+ constructor(options) {
245
+ apiClient.setConfig({
246
+ baseUrl: options.baseUrl,
247
+ ...options.token ? { headers: { Authorization: `Bearer ${options.token}` } } : {},
248
+ ...options.fetch ? { fetch: options.fetch } : {}
249
+ });
250
+ }
251
+ backtest(req, opts) {
252
+ return backtest(req, opts);
253
+ }
254
+ // Future surface:
255
+ // strategies: { compile, status, list }
256
+ // instruments: { list, get } with TTL cache
257
+ // jobs: { cancel, stream, result }
258
+ };
259
+ export {
260
+ QTSCanceledError,
261
+ QTSError,
262
+ QTSExecutionError,
263
+ QTSPreparationError,
264
+ QTSStrategyCompileError,
265
+ QTSTimeoutError,
266
+ QTSurfer
267
+ };
3
268
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAwB,MAAM,UAAU,CAAC;AAC1D,OAAO,EACL,QAAQ,EACR,uBAAuB,EACvB,mBAAmB,EACnB,iBAAiB,EACjB,eAAe,EACf,gBAAgB,GACjB,MAAM,UAAU,CAAC"}
1
+ {"version":3,"sources":["../src/client.ts","../src/workflows/backtest.ts","../src/errors.ts"],"sourcesContent":["import { client as apiClient } from '@qtsurfer/api-client';\nimport {\n backtest,\n type BacktestOptions,\n type BacktestRequest,\n type BacktestResult,\n} from './workflows/backtest';\n\nexport interface QTSurferOptions {\n baseUrl: string;\n token?: string;\n fetch?: typeof fetch;\n}\n\nexport class QTSurfer {\n constructor(options: QTSurferOptions) {\n apiClient.setConfig({\n baseUrl: options.baseUrl,\n ...(options.token\n ? { headers: { Authorization: `Bearer ${options.token}` } }\n : {}),\n ...(options.fetch ? { fetch: options.fetch } : {}),\n });\n }\n\n backtest(req: BacktestRequest, opts?: BacktestOptions): Promise<BacktestResult> {\n return backtest(req, opts);\n }\n\n // Future surface:\n // strategies: { compile, status, list }\n // instruments: { list, get } with TTL cache\n // jobs: { cancel, stream, result }\n}\n","import {\n cancelExecution,\n executeBacktesting,\n getExecutionResult,\n getPreparationStatus,\n getStrategyStatus,\n postStrategy,\n prepareBacktesting,\n type DataSourceType,\n type ResultMap,\n} from '@qtsurfer/api-client';\nimport {\n ExponentialBackoff,\n TaskCancelledError,\n TimeoutStrategy,\n handleWhenResult,\n retry,\n timeout,\n wrap,\n type IPolicy,\n type ICancellationContext,\n} from 'cockatiel';\nimport {\n QTSCanceledError,\n QTSExecutionError,\n QTSPreparationError,\n QTSStrategyCompileError,\n QTSTimeoutError,\n} from '../errors';\n\nexport interface BacktestRequest {\n /** Strategy source code (Java) */\n strategy: string;\n /** Exchange id, e.g. `binance` */\n exchangeId: string;\n /** Instrument symbol, e.g. `BTC/USDT` */\n instrument: string;\n /** Date range start (ISO-8601, ISO DATE or BASIC ISO DATE) */\n from: string;\n /** Date range end (same formats as `from`) */\n to: string;\n /** When true, the worker uploads emitted signals to object storage. */\n storeSignals?: boolean;\n}\n\nexport type BacktestResult = ResultMap;\n\nexport type BacktestStage = 'compiling' | 'preparing' | 'executing';\n\nexport interface BacktestProgress {\n stage: BacktestStage;\n /** 0-100 when size is known. Undefined during stage start. */\n percent?: number;\n}\n\nexport interface BacktestOptions {\n /** Abort the workflow. Cancels the current poll and calls `cancelExecution` server-side if execution has started. */\n signal?: AbortSignal;\n /** Called on stage transitions and after each poll with updated progress. */\n onProgress?: (p: BacktestProgress) => void;\n /** Initial interval between polls. Default 500ms, backed off up to `maxPollIntervalMs`. */\n pollIntervalMs?: number;\n /** Upper bound for exponential backoff. Default 5000ms. */\n maxPollIntervalMs?: number;\n /** Per-stage timeout. Default none. */\n timeoutMs?: number;\n}\n\nconst TICKER: DataSourceType = 'ticker';\n\ntype JobStatus = 'New' | 'Started' | 'Completed' | 'Aborted' | 'Failed';\n\n/**\n * Normalize the backend job status to a stable lowercase form so we can\n * reason about it regardless of OpenAPI spec drift (the live API sometimes\n * returns lowercase values like `queued` / `completed` / `failed`).\n */\ntype NormalizedStatus = 'in-progress' | 'completed' | 'failed' | 'aborted';\n\nfunction normalizeStatus(raw: unknown): NormalizedStatus {\n const value = typeof raw === 'string' ? raw.toLowerCase() : '';\n if (value === 'completed') return 'completed';\n if (value === 'failed') return 'failed';\n if (value === 'aborted' || value === 'cancelled' || value === 'canceled') {\n return 'aborted';\n }\n // new / started / queued / running / anything else → still running\n return 'in-progress';\n}\n\nexport async function backtest(\n req: BacktestRequest,\n opts: BacktestOptions = {},\n): Promise<BacktestResult> {\n const policy = buildStagePolicy(opts);\n\n // 1. Compile strategy (async mode)\n opts.onProgress?.({ stage: 'compiling' });\n const strategyId = await compileStrategy(req.strategy, policy, opts);\n\n // 2. Prepare data\n opts.onProgress?.({ stage: 'preparing' });\n const prepareJobId = await prepareData(req, policy, opts);\n\n // 3. Execute\n opts.onProgress?.({ stage: 'executing' });\n return executeStrategy(req, prepareJobId, strategyId, policy, opts);\n}\n\nfunction buildStagePolicy(opts: BacktestOptions): IPolicy<ICancellationContext, never> {\n const retryPolicy = retry(\n handleWhenResult((r) => {\n const status = (r as { status?: unknown } | undefined)?.status;\n return normalizeStatus(status) === 'in-progress';\n }),\n {\n maxAttempts: Number.MAX_SAFE_INTEGER,\n backoff: new ExponentialBackoff({\n initialDelay: opts.pollIntervalMs ?? 500,\n maxDelay: opts.maxPollIntervalMs ?? 5000,\n }),\n },\n );\n\n return opts.timeoutMs\n ? wrap(timeout(opts.timeoutMs, TimeoutStrategy.Cooperative), retryPolicy)\n : retryPolicy;\n}\n\nasync function compileStrategy(\n source: string,\n policy: IPolicy<ICancellationContext, never>,\n opts: BacktestOptions,\n): Promise<string> {\n const { data, error } = await postStrategy({\n body: source,\n headers: { 'X-Compile-Async': true },\n ...(opts.signal ? { signal: opts.signal } : {}),\n });\n if (error) throw new QTSStrategyCompileError('Strategy submission failed', error);\n if (!data) throw new QTSStrategyCompileError('Empty response from strategy endpoint');\n\n // Sync mode returns { strategyId }; async mode returns { jobId }.\n if ('strategyId' in data && data.strategyId) {\n return data.strategyId;\n }\n if (!('jobId' in data) || !data.jobId) {\n throw new QTSStrategyCompileError('Missing jobId/strategyId in compile response');\n }\n\n const compileJobId = data.jobId;\n const status = await runStage(\n policy,\n opts,\n async ({ signal }) => {\n const res = await getStrategyStatus({ path: { strategyId: compileJobId }, signal });\n if (res.error) throw new QTSStrategyCompileError('Compile status request failed', res.error);\n if (!res.data) throw new QTSStrategyCompileError('Empty compile status response');\n return res.data;\n },\n );\n\n const norm = normalizeStatus(status.status);\n if (norm === 'failed') {\n throw new QTSStrategyCompileError(status.statusDetail ?? 'Strategy compilation failed');\n }\n if (norm === 'aborted') {\n throw new QTSCanceledError('Strategy compilation aborted');\n }\n if (!status.strategyId) {\n throw new QTSStrategyCompileError('Compile completed without a strategyId');\n }\n return status.strategyId;\n}\n\nasync function prepareData(\n req: BacktestRequest,\n policy: IPolicy<ICancellationContext, never>,\n opts: BacktestOptions,\n): Promise<string> {\n const { data, error } = await prepareBacktesting({\n path: { exchangeId: req.exchangeId, type: TICKER },\n body: { instrument: req.instrument, from: req.from, to: req.to },\n ...(opts.signal ? { signal: opts.signal } : {}),\n });\n if (error) throw new QTSPreparationError('Prepare submission failed', error);\n if (!data?.jobId) throw new QTSPreparationError('Missing jobId in prepare response');\n\n const prepareJobId = data.jobId;\n const state = await runStage(\n policy,\n opts,\n async ({ signal }) => {\n const res = await getPreparationStatus({\n path: { exchangeId: req.exchangeId, type: TICKER, jobId: prepareJobId },\n signal,\n });\n if (res.error) throw new QTSPreparationError('Preparation status request failed', res.error);\n if (!res.data) throw new QTSPreparationError('Empty preparation status response');\n return res.data;\n },\n (r) => {\n if (r.size > 0) {\n opts.onProgress?.({ stage: 'preparing', percent: (r.completed / r.size) * 100 });\n }\n },\n );\n\n const prepNorm = normalizeStatus(state.status);\n if (prepNorm === 'failed') {\n throw new QTSPreparationError(state.statusDetail ?? 'Data preparation failed');\n }\n if (prepNorm === 'aborted') {\n throw new QTSCanceledError('Data preparation aborted');\n }\n return prepareJobId;\n}\n\nasync function executeStrategy(\n req: BacktestRequest,\n prepareJobId: string,\n strategyId: string,\n policy: IPolicy<ICancellationContext, never>,\n opts: BacktestOptions,\n): Promise<BacktestResult> {\n const { data, error } = await executeBacktesting({\n path: { exchangeId: req.exchangeId, type: TICKER },\n body: {\n prepareJobId,\n strategyId,\n ...(req.storeSignals !== undefined ? { storeSignals: req.storeSignals } : {}),\n },\n ...(opts.signal ? { signal: opts.signal } : {}),\n });\n if (error) throw new QTSExecutionError('Execute submission failed', error);\n if (!data?.jobId) throw new QTSExecutionError('Missing jobId in execute response');\n\n const executeJobId = data.jobId;\n\n try {\n const finalResult = await runStage(\n policy,\n opts,\n async ({ signal }) => {\n const res = await getExecutionResult({\n path: { exchangeId: req.exchangeId, type: TICKER, jobId: executeJobId },\n signal,\n });\n if (res.error) throw new QTSExecutionError('Execution result request failed', res.error);\n if (!res.data) throw new QTSExecutionError('Empty execution result response');\n return { ...res.data.state, __result: res.data.results };\n },\n (r) => {\n if (r.size > 0) {\n opts.onProgress?.({ stage: 'executing', percent: (r.completed / r.size) * 100 });\n }\n },\n );\n\n const execNorm = normalizeStatus(finalResult.status);\n if (execNorm === 'failed') {\n throw new QTSExecutionError(finalResult.statusDetail ?? 'Execution failed');\n }\n if (execNorm === 'aborted') {\n throw new QTSCanceledError('Execution aborted');\n }\n return finalResult.__result;\n } catch (err) {\n if (err instanceof QTSCanceledError) {\n await cancelExecution({\n path: { exchangeId: req.exchangeId, type: TICKER, jobId: executeJobId },\n }).catch(() => undefined);\n }\n throw err;\n }\n}\n\nasync function runStage<T extends { status: JobStatus }>(\n policy: IPolicy<ICancellationContext, never>,\n opts: BacktestOptions,\n fetchFn: (ctx: ICancellationContext) => Promise<T>,\n onEachAttempt?: (r: T) => void,\n): Promise<T> {\n try {\n return await policy.execute(async (ctx) => {\n if (opts.signal?.aborted) throw new QTSCanceledError('Workflow aborted');\n const result = await fetchFn(ctx);\n onEachAttempt?.(result);\n if (opts.signal?.aborted) throw new QTSCanceledError('Workflow aborted');\n return result;\n }, opts.signal);\n } catch (err) {\n if (err instanceof QTSCanceledError) throw err;\n if (err instanceof TaskCancelledError) {\n if (opts.signal?.aborted) throw new QTSCanceledError('Workflow aborted', err);\n throw new QTSTimeoutError(`Stage exceeded ${opts.timeoutMs}ms`, err);\n }\n if (opts.signal?.aborted) throw new QTSCanceledError('Workflow aborted', err);\n throw err;\n }\n}\n","export class QTSError extends Error {\n constructor(message: string, readonly cause?: unknown) {\n super(message);\n this.name = 'QTSError';\n }\n}\n\nexport class QTSStrategyCompileError extends QTSError {\n constructor(message: string, cause?: unknown) {\n super(message, cause);\n this.name = 'QTSStrategyCompileError';\n }\n}\n\nexport class QTSPreparationError extends QTSError {\n constructor(message: string, cause?: unknown) {\n super(message, cause);\n this.name = 'QTSPreparationError';\n }\n}\n\nexport class QTSExecutionError extends QTSError {\n constructor(message: string, cause?: unknown) {\n super(message, cause);\n this.name = 'QTSExecutionError';\n }\n}\n\nexport class QTSTimeoutError extends QTSError {\n constructor(message: string, cause?: unknown) {\n super(message, cause);\n this.name = 'QTSTimeoutError';\n }\n}\n\nexport class QTSCanceledError extends QTSError {\n constructor(message: string, cause?: unknown) {\n super(message, cause);\n this.name = 'QTSCanceledError';\n }\n}\n"],"mappings":";AAAA,SAAS,UAAU,iBAAiB;;;ACApC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAGK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAGK;;;ACrBA,IAAM,WAAN,cAAuB,MAAM;AAAA,EAClC,YAAY,SAA0B,OAAiB;AACrD,UAAM,OAAO;AADuB;AAEpC,SAAK,OAAO;AAAA,EACd;AAAA,EAHsC;AAIxC;AAEO,IAAM,0BAAN,cAAsC,SAAS;AAAA,EACpD,YAAY,SAAiB,OAAiB;AAC5C,UAAM,SAAS,KAAK;AACpB,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,sBAAN,cAAkC,SAAS;AAAA,EAChD,YAAY,SAAiB,OAAiB;AAC5C,UAAM,SAAS,KAAK;AACpB,SAAK,OAAO;AAAA,EACd;AACF;AA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CAAC;AAAA,EACH;AAAA,EAEA,SAAS,KAAsB,MAAiD;AAC9E,WAAO,SAAS,KAAK,IAAI;AAAA,EAC3B;AAAA;AAAA;AAAA;AAAA;AAMF;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qtsurfer/sdk",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Opinionated TypeScript SDK for QTSurfer: workflow orchestration, domain objects, normalized errors",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -18,8 +18,11 @@
18
18
  "LICENSE"
19
19
  ],
20
20
  "scripts": {
21
- "build": "tsc",
22
- "lint": "tsc --noEmit",
21
+ "build": "tsup",
22
+ "lint": "tsc --noEmit -p tsconfig.test.json",
23
+ "test": "vitest run",
24
+ "test:watch": "vitest",
25
+ "test:integration": "vitest run --config vitest.integration.config.ts",
23
26
  "prepublishOnly": "npm run build"
24
27
  },
25
28
  "repository": {
@@ -44,11 +47,15 @@
44
47
  "access": "public"
45
48
  },
46
49
  "dependencies": {
47
- "@qtsurfer/api-client": "^0.1.0",
50
+ "@qtsurfer/api-client": "^0.1.1",
48
51
  "cockatiel": "^3.2.1"
49
52
  },
50
53
  "devDependencies": {
51
- "typescript": "^5.8.0"
54
+ "@types/node": "^25.6.0",
55
+ "@vitest/coverage-v8": "^4.1.4",
56
+ "tsup": "^8.5.1",
57
+ "typescript": "^5.8.0",
58
+ "vitest": "^4.1.4"
52
59
  },
53
60
  "engines": {
54
61
  "node": ">=20"
@@ -33,7 +33,7 @@ export interface BacktestRequest {
33
33
  strategy: string;
34
34
  /** Exchange id, e.g. `binance` */
35
35
  exchangeId: string;
36
- /** Instrument symbol, e.g. `BTCUSDT` */
36
+ /** Instrument symbol, e.g. `BTC/USDT` */
37
37
  instrument: string;
38
38
  /** Date range start (ISO-8601, ISO DATE or BASIC ISO DATE) */
39
39
  from: string;
@@ -70,6 +70,24 @@ const TICKER: DataSourceType = 'ticker';
70
70
 
71
71
  type JobStatus = 'New' | 'Started' | 'Completed' | 'Aborted' | 'Failed';
72
72
 
73
+ /**
74
+ * Normalize the backend job status to a stable lowercase form so we can
75
+ * reason about it regardless of OpenAPI spec drift (the live API sometimes
76
+ * returns lowercase values like `queued` / `completed` / `failed`).
77
+ */
78
+ type NormalizedStatus = 'in-progress' | 'completed' | 'failed' | 'aborted';
79
+
80
+ function normalizeStatus(raw: unknown): NormalizedStatus {
81
+ const value = typeof raw === 'string' ? raw.toLowerCase() : '';
82
+ if (value === 'completed') return 'completed';
83
+ if (value === 'failed') return 'failed';
84
+ if (value === 'aborted' || value === 'cancelled' || value === 'canceled') {
85
+ return 'aborted';
86
+ }
87
+ // new / started / queued / running / anything else → still running
88
+ return 'in-progress';
89
+ }
90
+
73
91
  export async function backtest(
74
92
  req: BacktestRequest,
75
93
  opts: BacktestOptions = {},
@@ -92,8 +110,8 @@ export async function backtest(
92
110
  function buildStagePolicy(opts: BacktestOptions): IPolicy<ICancellationContext, never> {
93
111
  const retryPolicy = retry(
94
112
  handleWhenResult((r) => {
95
- const status = (r as { status?: JobStatus } | undefined)?.status;
96
- return status === 'New' || status === 'Started';
113
+ const status = (r as { status?: unknown } | undefined)?.status;
114
+ return normalizeStatus(status) === 'in-progress';
97
115
  }),
98
116
  {
99
117
  maxAttempts: Number.MAX_SAFE_INTEGER,
@@ -142,10 +160,11 @@ async function compileStrategy(
142
160
  },
143
161
  );
144
162
 
145
- if (status.status === 'Failed') {
163
+ const norm = normalizeStatus(status.status);
164
+ if (norm === 'failed') {
146
165
  throw new QTSStrategyCompileError(status.statusDetail ?? 'Strategy compilation failed');
147
166
  }
148
- if (status.status === 'Aborted') {
167
+ if (norm === 'aborted') {
149
168
  throw new QTSCanceledError('Strategy compilation aborted');
150
169
  }
151
170
  if (!status.strategyId) {
@@ -187,10 +206,11 @@ async function prepareData(
187
206
  },
188
207
  );
189
208
 
190
- if (state.status === 'Failed') {
209
+ const prepNorm = normalizeStatus(state.status);
210
+ if (prepNorm === 'failed') {
191
211
  throw new QTSPreparationError(state.statusDetail ?? 'Data preparation failed');
192
212
  }
193
- if (state.status === 'Aborted') {
213
+ if (prepNorm === 'aborted') {
194
214
  throw new QTSCanceledError('Data preparation aborted');
195
215
  }
196
216
  return prepareJobId;
@@ -237,10 +257,11 @@ async function executeStrategy(
237
257
  },
238
258
  );
239
259
 
240
- if (finalResult.status === 'Failed') {
260
+ const execNorm = normalizeStatus(finalResult.status);
261
+ if (execNorm === 'failed') {
241
262
  throw new QTSExecutionError(finalResult.statusDetail ?? 'Execution failed');
242
263
  }
243
- if (finalResult.status === 'Aborted') {
264
+ if (execNorm === 'aborted') {
244
265
  throw new QTSCanceledError('Execution aborted');
245
266
  }
246
267
  return finalResult.__result;
@@ -262,15 +283,19 @@ async function runStage<T extends { status: JobStatus }>(
262
283
  ): Promise<T> {
263
284
  try {
264
285
  return await policy.execute(async (ctx) => {
286
+ if (opts.signal?.aborted) throw new QTSCanceledError('Workflow aborted');
265
287
  const result = await fetchFn(ctx);
266
288
  onEachAttempt?.(result);
289
+ if (opts.signal?.aborted) throw new QTSCanceledError('Workflow aborted');
267
290
  return result;
268
291
  }, opts.signal);
269
292
  } catch (err) {
293
+ if (err instanceof QTSCanceledError) throw err;
270
294
  if (err instanceof TaskCancelledError) {
271
295
  if (opts.signal?.aborted) throw new QTSCanceledError('Workflow aborted', err);
272
296
  throw new QTSTimeoutError(`Stage exceeded ${opts.timeoutMs}ms`, err);
273
297
  }
298
+ if (opts.signal?.aborted) throw new QTSCanceledError('Workflow aborted', err);
274
299
  throw err;
275
300
  }
276
301
  }
package/dist/client.d.ts DELETED
@@ -1,11 +0,0 @@
1
- import { type BacktestOptions, type BacktestRequest, type BacktestResult } from './workflows/backtest';
2
- export interface QTSurferOptions {
3
- baseUrl: string;
4
- token?: string;
5
- fetch?: typeof fetch;
6
- }
7
- export declare class QTSurfer {
8
- constructor(options: QTSurferOptions);
9
- backtest(req: BacktestRequest, opts?: BacktestOptions): Promise<BacktestResult>;
10
- }
11
- //# sourceMappingURL=client.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,eAAe,EACpB,KAAK,eAAe,EACpB,KAAK,cAAc,EACpB,MAAM,sBAAsB,CAAC;AAE9B,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;CACtB;AAED,qBAAa,QAAQ;gBACP,OAAO,EAAE,eAAe;IAUpC,QAAQ,CAAC,GAAG,EAAE,eAAe,EAAE,IAAI,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC,cAAc,CAAC;CAQhF"}
package/dist/client.js DELETED
@@ -1,17 +0,0 @@
1
- import { client as apiClient } from '@qtsurfer/api-client';
2
- import { backtest, } from './workflows/backtest';
3
- export class QTSurfer {
4
- constructor(options) {
5
- apiClient.setConfig({
6
- baseUrl: options.baseUrl,
7
- ...(options.token
8
- ? { headers: { Authorization: `Bearer ${options.token}` } }
9
- : {}),
10
- ...(options.fetch ? { fetch: options.fetch } : {}),
11
- });
12
- }
13
- backtest(req, opts) {
14
- return backtest(req, opts);
15
- }
16
- }
17
- //# sourceMappingURL=client.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EACL,QAAQ,GAIT,MAAM,sBAAsB,CAAC;AAQ9B,MAAM,OAAO,QAAQ;IACnB,YAAY,OAAwB;QAClC,SAAS,CAAC,SAAS,CAAC;YAClB,OAAO,EAAE,OAAO,CAAC,OAAO;YACxB,GAAG,CAAC,OAAO,CAAC,KAAK;gBACf,CAAC,CAAC,EAAE,OAAO,EAAE,EAAE,aAAa,EAAE,UAAU,OAAO,CAAC,KAAK,EAAE,EAAE,EAAE;gBAC3D,CAAC,CAAC,EAAE,CAAC;YACP,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SACnD,CAAC,CAAC;IACL,CAAC;IAED,QAAQ,CAAC,GAAoB,EAAE,IAAsB;QACnD,OAAO,QAAQ,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;IAC7B,CAAC;CAMF"}
package/dist/errors.d.ts DELETED
@@ -1,20 +0,0 @@
1
- export declare class QTSError extends Error {
2
- readonly cause?: unknown | undefined;
3
- constructor(message: string, cause?: unknown | undefined);
4
- }
5
- export declare class QTSStrategyCompileError extends QTSError {
6
- constructor(message: string, cause?: unknown);
7
- }
8
- export declare class QTSPreparationError extends QTSError {
9
- constructor(message: string, cause?: unknown);
10
- }
11
- export declare class QTSExecutionError extends QTSError {
12
- constructor(message: string, cause?: unknown);
13
- }
14
- export declare class QTSTimeoutError extends QTSError {
15
- constructor(message: string, cause?: unknown);
16
- }
17
- export declare class QTSCanceledError extends QTSError {
18
- constructor(message: string, cause?: unknown);
19
- }
20
- //# sourceMappingURL=errors.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,QAAS,SAAQ,KAAK;IACJ,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO;gBAAzC,OAAO,EAAE,MAAM,EAAW,KAAK,CAAC,EAAE,OAAO,YAAA;CAItD;AAED,qBAAa,uBAAwB,SAAQ,QAAQ;gBACvC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO;CAI7C;AAED,qBAAa,mBAAoB,SAAQ,QAAQ;gBACnC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO;CAI7C;AAED,qBAAa,iBAAkB,SAAQ,QAAQ;gBACjC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO;CAI7C;AAED,qBAAa,eAAgB,SAAQ,QAAQ;gBAC/B,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO;CAI7C;AAED,qBAAa,gBAAiB,SAAQ,QAAQ;gBAChC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO;CAI7C"}
package/dist/errors.js DELETED
@@ -1,39 +0,0 @@
1
- export class QTSError extends Error {
2
- cause;
3
- constructor(message, cause) {
4
- super(message);
5
- this.cause = cause;
6
- this.name = 'QTSError';
7
- }
8
- }
9
- export class QTSStrategyCompileError extends QTSError {
10
- constructor(message, cause) {
11
- super(message, cause);
12
- this.name = 'QTSStrategyCompileError';
13
- }
14
- }
15
- export class QTSPreparationError extends QTSError {
16
- constructor(message, cause) {
17
- super(message, cause);
18
- this.name = 'QTSPreparationError';
19
- }
20
- }
21
- export class QTSExecutionError extends QTSError {
22
- constructor(message, cause) {
23
- super(message, cause);
24
- this.name = 'QTSExecutionError';
25
- }
26
- }
27
- export class QTSTimeoutError extends QTSError {
28
- constructor(message, cause) {
29
- super(message, cause);
30
- this.name = 'QTSTimeoutError';
31
- }
32
- }
33
- export class QTSCanceledError extends QTSError {
34
- constructor(message, cause) {
35
- super(message, cause);
36
- this.name = 'QTSCanceledError';
37
- }
38
- }
39
- //# sourceMappingURL=errors.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,QAAS,SAAQ,KAAK;IACK;IAAtC,YAAY,OAAe,EAAW,KAAe;QACnD,KAAK,CAAC,OAAO,CAAC,CAAC;QADqB,UAAK,GAAL,KAAK,CAAU;QAEnD,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC;IACzB,CAAC;CACF;AAED,MAAM,OAAO,uBAAwB,SAAQ,QAAQ;IACnD,YAAY,OAAe,EAAE,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{ type ResultMap } from '@qtsurfer/api-client';
2
- export interface BacktestRequest {
3
- /** Strategy source code (Java) */
4
- strategy: string;
5
- /** Exchange id, e.g. `binance` */
6
- exchangeId: string;
7
- /** Instrument symbol, e.g. `BTCUSDT` */
8
- instrument: string;
9
- /** Date range start (ISO-8601, ISO DATE or BASIC ISO DATE) */
10
- from: string;
11
- /** Date range end (same formats as `from`) */
12
- to: string;
13
- /** When true, the worker uploads emitted signals to object storage. */
14
- storeSignals?: boolean;
15
- }
16
- export type BacktestResult = ResultMap;
17
- export type BacktestStage = 'compiling' | 'preparing' | 'executing';
18
- export interface BacktestProgress {
19
- stage: BacktestStage;
20
- /** 0-100 when size is known. Undefined during stage start. */
21
- percent?: number;
22
- }
23
- export interface BacktestOptions {
24
- /** Abort the workflow. Cancels the current poll and calls `cancelExecution` server-side if execution has started. */
25
- signal?: AbortSignal;
26
- /** Called on stage transitions and after each poll with updated progress. */
27
- onProgress?: (p: BacktestProgress) => void;
28
- /** Initial interval between polls. Default 500ms, backed off up to `maxPollIntervalMs`. */
29
- pollIntervalMs?: number;
30
- /** Upper bound for exponential backoff. Default 5000ms. */
31
- maxPollIntervalMs?: number;
32
- /** Per-stage timeout. Default none. */
33
- timeoutMs?: number;
34
- }
35
- export declare function backtest(req: BacktestRequest, opts?: BacktestOptions): Promise<BacktestResult>;
36
- //# sourceMappingURL=backtest.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"backtest.d.ts","sourceRoot":"","sources":["../../src/workflows/backtest.ts"],"names":[],"mappings":"AAAA,OAAO,EASL,KAAK,SAAS,EACf,MAAM,sBAAsB,CAAC;AAoB9B,MAAM,WAAW,eAAe;IAC9B,kCAAkC;IAClC,QAAQ,EAAE,MAAM,CAAC;IACjB,kCAAkC;IAClC,UAAU,EAAE,MAAM,CAAC;IACnB,wCAAwC;IACxC,UAAU,EAAE,MAAM,CAAC;IACnB,8DAA8D;IAC9D,IAAI,EAAE,MAAM,CAAC;IACb,8CAA8C;IAC9C,EAAE,EAAE,MAAM,CAAC;IACX,uEAAuE;IACvE,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB;AAED,MAAM,MAAM,cAAc,GAAG,SAAS,CAAC;AAEvC,MAAM,MAAM,aAAa,GAAG,WAAW,GAAG,WAAW,GAAG,WAAW,CAAC;AAEpE,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,aAAa,CAAC;IACrB,8DAA8D;IAC9D,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,eAAe;IAC9B,qHAAqH;IACrH,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,6EAA6E;IAC7E,UAAU,CAAC,EAAE,CAAC,CAAC,EAAE,gBAAgB,KAAK,IAAI,CAAC;IAC3C,2FAA2F;IAC3F,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,2DAA2D;IAC3D,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,uCAAuC;IACvC,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAMD,wBAAsB,QAAQ,CAC5B,GAAG,EAAE,eAAe,EACpB,IAAI,GAAE,eAAoB,GACzB,OAAO,CAAC,cAAc,CAAC,CAczB"}
@@ -1,168 +0,0 @@
1
- import { cancelExecution, executeBacktesting, getExecutionResult, getPreparationStatus, getStrategyStatus, postStrategy, prepareBacktesting, } from '@qtsurfer/api-client';
2
- import { ExponentialBackoff, TaskCancelledError, TimeoutStrategy, handleWhenResult, retry, timeout, wrap, } from 'cockatiel';
3
- import { QTSCanceledError, QTSExecutionError, QTSPreparationError, QTSStrategyCompileError, QTSTimeoutError, } from '../errors';
4
- const TICKER = 'ticker';
5
- export async function backtest(req, opts = {}) {
6
- const policy = buildStagePolicy(opts);
7
- // 1. Compile strategy (async mode)
8
- opts.onProgress?.({ stage: 'compiling' });
9
- const strategyId = await compileStrategy(req.strategy, policy, opts);
10
- // 2. Prepare data
11
- opts.onProgress?.({ stage: 'preparing' });
12
- const prepareJobId = await prepareData(req, policy, opts);
13
- // 3. Execute
14
- opts.onProgress?.({ stage: 'executing' });
15
- return executeStrategy(req, prepareJobId, strategyId, policy, opts);
16
- }
17
- function buildStagePolicy(opts) {
18
- const retryPolicy = retry(handleWhenResult((r) => {
19
- const status = r?.status;
20
- return status === 'New' || status === 'Started';
21
- }), {
22
- maxAttempts: Number.MAX_SAFE_INTEGER,
23
- backoff: new ExponentialBackoff({
24
- initialDelay: opts.pollIntervalMs ?? 500,
25
- maxDelay: opts.maxPollIntervalMs ?? 5000,
26
- }),
27
- });
28
- return opts.timeoutMs
29
- ? wrap(timeout(opts.timeoutMs, TimeoutStrategy.Cooperative), retryPolicy)
30
- : retryPolicy;
31
- }
32
- async function compileStrategy(source, policy, opts) {
33
- const { data, error } = await postStrategy({
34
- body: source,
35
- headers: { 'X-Compile-Async': true },
36
- ...(opts.signal ? { signal: opts.signal } : {}),
37
- });
38
- if (error)
39
- throw new QTSStrategyCompileError('Strategy submission failed', error);
40
- if (!data)
41
- throw new QTSStrategyCompileError('Empty response from strategy endpoint');
42
- // Sync mode returns { strategyId }; async mode returns { jobId }.
43
- if ('strategyId' in data && data.strategyId) {
44
- return data.strategyId;
45
- }
46
- if (!('jobId' in data) || !data.jobId) {
47
- throw new QTSStrategyCompileError('Missing jobId/strategyId in compile response');
48
- }
49
- const compileJobId = data.jobId;
50
- const status = await runStage(policy, opts, async ({ signal }) => {
51
- const res = await getStrategyStatus({ path: { strategyId: compileJobId }, signal });
52
- if (res.error)
53
- throw new QTSStrategyCompileError('Compile status request failed', res.error);
54
- if (!res.data)
55
- throw new QTSStrategyCompileError('Empty compile status response');
56
- return res.data;
57
- });
58
- if (status.status === 'Failed') {
59
- throw new QTSStrategyCompileError(status.statusDetail ?? 'Strategy compilation failed');
60
- }
61
- if (status.status === 'Aborted') {
62
- throw new QTSCanceledError('Strategy compilation aborted');
63
- }
64
- if (!status.strategyId) {
65
- throw new QTSStrategyCompileError('Compile completed without a strategyId');
66
- }
67
- return status.strategyId;
68
- }
69
- async function prepareData(req, policy, opts) {
70
- const { data, error } = await prepareBacktesting({
71
- path: { exchangeId: req.exchangeId, type: TICKER },
72
- body: { instrument: req.instrument, from: req.from, to: req.to },
73
- ...(opts.signal ? { signal: opts.signal } : {}),
74
- });
75
- if (error)
76
- throw new QTSPreparationError('Prepare submission failed', error);
77
- if (!data?.jobId)
78
- throw new QTSPreparationError('Missing jobId in prepare response');
79
- const prepareJobId = data.jobId;
80
- const state = await runStage(policy, opts, async ({ signal }) => {
81
- const res = await getPreparationStatus({
82
- path: { exchangeId: req.exchangeId, type: TICKER, jobId: prepareJobId },
83
- signal,
84
- });
85
- if (res.error)
86
- throw new QTSPreparationError('Preparation status request failed', res.error);
87
- if (!res.data)
88
- throw new QTSPreparationError('Empty preparation status response');
89
- return res.data;
90
- }, (r) => {
91
- if (r.size > 0) {
92
- opts.onProgress?.({ stage: 'preparing', percent: (r.completed / r.size) * 100 });
93
- }
94
- });
95
- if (state.status === 'Failed') {
96
- throw new QTSPreparationError(state.statusDetail ?? 'Data preparation failed');
97
- }
98
- if (state.status === 'Aborted') {
99
- throw new QTSCanceledError('Data preparation aborted');
100
- }
101
- return prepareJobId;
102
- }
103
- async function executeStrategy(req, prepareJobId, strategyId, policy, opts) {
104
- const { data, error } = await executeBacktesting({
105
- path: { exchangeId: req.exchangeId, type: TICKER },
106
- body: {
107
- prepareJobId,
108
- strategyId,
109
- ...(req.storeSignals !== undefined ? { storeSignals: req.storeSignals } : {}),
110
- },
111
- ...(opts.signal ? { signal: opts.signal } : {}),
112
- });
113
- if (error)
114
- throw new QTSExecutionError('Execute submission failed', error);
115
- if (!data?.jobId)
116
- throw new QTSExecutionError('Missing jobId in execute response');
117
- const executeJobId = data.jobId;
118
- try {
119
- const finalResult = await runStage(policy, opts, async ({ signal }) => {
120
- const res = await getExecutionResult({
121
- path: { exchangeId: req.exchangeId, type: TICKER, jobId: executeJobId },
122
- signal,
123
- });
124
- if (res.error)
125
- throw new QTSExecutionError('Execution result request failed', res.error);
126
- if (!res.data)
127
- throw new QTSExecutionError('Empty execution result response');
128
- return { ...res.data.state, __result: res.data.results };
129
- }, (r) => {
130
- if (r.size > 0) {
131
- opts.onProgress?.({ stage: 'executing', percent: (r.completed / r.size) * 100 });
132
- }
133
- });
134
- if (finalResult.status === 'Failed') {
135
- throw new QTSExecutionError(finalResult.statusDetail ?? 'Execution failed');
136
- }
137
- if (finalResult.status === 'Aborted') {
138
- throw new QTSCanceledError('Execution aborted');
139
- }
140
- return finalResult.__result;
141
- }
142
- catch (err) {
143
- if (err instanceof QTSCanceledError) {
144
- await cancelExecution({
145
- path: { exchangeId: req.exchangeId, type: TICKER, jobId: executeJobId },
146
- }).catch(() => undefined);
147
- }
148
- throw err;
149
- }
150
- }
151
- async function runStage(policy, opts, fetchFn, onEachAttempt) {
152
- try {
153
- return await policy.execute(async (ctx) => {
154
- const result = await fetchFn(ctx);
155
- onEachAttempt?.(result);
156
- return result;
157
- }, opts.signal);
158
- }
159
- catch (err) {
160
- if (err instanceof TaskCancelledError) {
161
- if (opts.signal?.aborted)
162
- throw new QTSCanceledError('Workflow aborted', err);
163
- throw new QTSTimeoutError(`Stage exceeded ${opts.timeoutMs}ms`, err);
164
- }
165
- throw err;
166
- }
167
- }
168
- //# sourceMappingURL=backtest.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"backtest.js","sourceRoot":"","sources":["../../src/workflows/backtest.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,kBAAkB,EAClB,kBAAkB,EAClB,oBAAoB,EACpB,iBAAiB,EACjB,YAAY,EACZ,kBAAkB,GAGnB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,kBAAkB,EAClB,kBAAkB,EAClB,eAAe,EACf,gBAAgB,EAChB,KAAK,EACL,OAAO,EACP,IAAI,GAGL,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,mBAAmB,EACnB,uBAAuB,EACvB,eAAe,GAChB,MAAM,WA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