Centralize strategy contracts and share indicator calculations

This commit is contained in:
Boki 2026-10-21 15:50:39 -04:00
parent 366d39001b
commit 4207bf2c1c
25 changed files with 1323 additions and 477 deletions

View file

@ -539,13 +539,22 @@ describe('one backtest execution workflow', () => {
});
const workerUrl = new URL('../fixtures/native-backtest-worker.ts', import.meta.url);
const blockingConfig = { ...config, config: { ...config.config, fixtureBehavior: 'block' } };
const blockingConfig = { ...config, name: 'fixture:block' };
function workerReady(runner: BacktestRunner) {
return new Promise<{ pid: number; runId: string }>(resolve => {
runner.once('progress', (progress: { message: string; runId: string }) => {
return new Promise<{ pid: number; runId: string }>((resolve, reject) => {
const onError = (error: Error) => {
runner.off('progress', onProgress);
reject(error);
};
const onProgress = (progress: { message: string; runId: string }) => {
if (!progress.message.startsWith('Fixture worker ready:')) return;
runner.off('progress', onProgress);
runner.off('error', onError);
resolve({ pid: Number(progress.message.split(':')[1]), runId: progress.runId });
});
};
runner.once('error', onError);
runner.on('progress', onProgress);
});
}
@ -633,7 +642,7 @@ describe('isolated native backtest workers', () => {
});
const ready = workerReady(f.runner);
const failed = f.runner
.runBacktest({ ...config, config: { fixtureBehavior: behavior } })
.runBacktest({ ...config, name: `fixture:${behavior}` })
.catch(error => error);
const { pid } = await ready;
expect(String(await failed)).toContain(message);
@ -693,7 +702,7 @@ describe('isolated native backtest workers', () => {
const f = await fixture(false, { workerUrl });
const ready = workerReady(f.runner);
const cancelled = f.runner
.runBacktest({ ...config, config: { fixtureBehavior: 'result-then-block' } })
.runBacktest({ ...config, name: 'fixture:result-then-block' })
.catch(error => error);
const { pid, runId } = await ready;
await f.runner.stopBacktest(runId);
@ -827,10 +836,7 @@ describe('isolated native backtest workers', () => {
}
};
Object.defineProperty(api, 'wsHandler', { value: handler });
const definition = await api.createBacktest(
{ ...blockingConfig, name: config.name! },
{ autoStart: false }
);
const definition = await api.createBacktest(blockingConfig, { autoStart: false });
const ready = workerReady(f.runner);
const run = await api.createRun({ backtestId: definition.id, speedMultiplier: null });
const execution = f.runner.runQueued(run.id).catch(error => error);