feat(engine): expose canonical replay sessions through native workers
This commit is contained in:
parent
417a7bd21e
commit
e3635f23cf
26 changed files with 2693 additions and 33 deletions
|
|
@ -1,4 +1,5 @@
|
|||
import { BacktestEngine } from '@stock-bot/engine';
|
||||
import { executeReplayTrace } from './native-replay';
|
||||
import { resolveNativeStrategies } from './native-strategies';
|
||||
import { nativeWorkerRequestSchema, type NativeWorkerMessage } from './native-worker-protocol';
|
||||
|
||||
|
|
@ -15,7 +16,16 @@ function send(message: NativeWorkerMessage): Promise<void> {
|
|||
|
||||
process.once('message', async (input: unknown) => {
|
||||
try {
|
||||
const { config, data } = nativeWorkerRequestSchema.parse(input);
|
||||
const request = nativeWorkerRequestSchema.parse(input);
|
||||
if (request.type === 'runReplayTrace') {
|
||||
await send({ type: 'progress', progress: 0, message: 'Canonical replay trace started' });
|
||||
// One load and a local pull loop; no per-observation IPC. The supervisor
|
||||
// can still SIGKILL native work, exactly as for the legacy one-shot path.
|
||||
const { result } = executeReplayTrace(request);
|
||||
await send({ type: 'result', result: JSON.stringify(result) });
|
||||
return;
|
||||
}
|
||||
const { config, data } = request;
|
||||
const engine = new BacktestEngine({
|
||||
name: config.name ?? 'Backtest',
|
||||
strategy: config.strategy,
|
||||
|
|
@ -27,7 +37,9 @@ process.once('message', async (input: unknown) => {
|
|||
slippage: config.slippage ?? 0.0001,
|
||||
dataFrequency: config.dataFrequency,
|
||||
});
|
||||
if (config.riskLimits) {engine.updateRiskLimits(config.riskLimits);}
|
||||
if (config.riskLimits) {
|
||||
engine.updateRiskLimits(config.riskLimits);
|
||||
}
|
||||
for (const { strategy, name, id, parameters } of resolveNativeStrategies(config)) {
|
||||
engine.addNativeStrategy(strategy, name, id, parameters);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue