stock-bot/test/fixtures/native-replay.ts

117 lines
3.8 KiB
TypeScript

import type { ReplayConfig } from '../../apps/stock/orchestrator/src/contracts/native-replay';
import { createDatasetV2 } from '../../apps/stock/orchestrator/src/data/historical-dataset-v2';
/** Retained synthetic sessions, raw executable bars, explicit availability. */
export function nativeReplayFixture(barsPerAsset = 3, assets = 1, owners = ['A']) {
const start = Date.parse('2024-01-01T09:00:00Z'),
minute = 60000,
day = 86400000;
const at = (step: number) => start + Math.floor(step / 600) * day + (step % 600) * minute;
const end = at(barsPerAsset - 1) + minute;
const instruments = Array.from({ length: assets }, (_, i) => `X${i}.US`);
const calendar = {
id: 'fixture-calendar',
venue: 'TEST',
timeZone: 'UTC',
revision: '1',
source: 'synthetic',
startDate: '2024-01-01',
endDate: new Date(end + day).toISOString().slice(0, 10),
sessions: Array.from({ length: Math.ceil(barsPerAsset / 600) }, (_, i) => ({
date: new Date(start + i * day).toISOString().slice(0, 10),
open: start + i * day,
close: start + i * day + 600 * minute,
})),
};
const dataset = createDatasetV2({
metadata: {
calendars: [calendar],
series: instruments.map(instrumentId => ({
id: `${instrumentId}:1m`,
instrumentId,
interval: '1m',
calendarId: calendar.id,
venue: calendar.venue,
source: { provider: 'synthetic', revision: 'f07-v1' },
timestamp: 'interval-start',
availability: 'explicit',
adjustment: 'raw',
})),
executionSeries: instruments.map(instrumentId => ({
instrumentId,
seriesId: `${instrumentId}:1m`,
})),
bounds: { warmupStart: start, tradeStart: start + minute, tradeEnd: end },
universe: {
selection: 'point-in-time',
asOf: start,
revision: '1',
instrumentIds: instruments,
},
corporateActions: instruments.map(instrumentId => ({
instrumentId,
status: 'action-free',
start,
end,
revision: '1',
actions: [],
})),
},
bars: instruments.flatMap(instrumentId =>
Array.from({ length: barsPerAsset }, (_, step) => ({
seriesId: `${instrumentId}:1m`,
timestamp: at(step),
availableAt: at(step) + minute,
sourceSequence: step,
open: 10 + (step % 20) * 2,
high: 11 + (step % 20) * 2,
low: 10 + (step % 20) * 2,
close: 11 + (step % 20) * 2,
volume: 1000,
}))
),
});
const config: ReplayConfig = {
matching: {
risk: {
ledger: {
version: 1,
sessionId: 'f07-fixture',
accountId: 'research-only',
baseCurrency: 'USD',
reserveOwnerId: 'reserve',
ownerIds: owners,
initialCapital: '10000',
riskSession: {
calendarId: 'account',
calendarRevision: '1',
sessionId: 'risk',
startsAt: start,
},
},
feeRate: '0.01',
maxOrderQuantity: '1000000',
maxPositionQuantity: '1000000',
maxSymbolExposure: '1000000',
maxGrossExposure: '1000000',
maxDailyLoss: '1000000',
maxDrawdownAmount: '1000000',
maxMarkAgeMs: day * 2,
},
owners: owners.map(ownerId => ({ ownerId, mode: 'Target' })),
series: instruments.map(instrumentId => ({
instrumentId,
seriesId: `${instrumentId}:1m`,
mode: 'Open',
})),
halfSpreadRate: '0',
slippageRate: '0',
latencyMs: 0,
},
participation_rate: '1',
cadence: owners.map(owner_id => ({ owner_id, series_ids: instruments.map(id => `${id}:1m`) })),
allow_exploratory: false,
risk_boundaries: [],
};
return { dataset, config, start, minute, instruments };
}