feat(paper): gate canonical execution on durable feed readiness
This commit is contained in:
parent
c01e96e4dd
commit
75abae2cfc
24 changed files with 3720 additions and 66 deletions
|
|
@ -1,5 +1,7 @@
|
|||
import { ServiceContainerBuilder } from '@stock-bot/di';
|
||||
import type { StockAppConfig } from '@stock-bot/stock-config';
|
||||
import { paperConfigurationSchema } from './contracts/paper-runtime';
|
||||
import { validatePaperConfiguration } from './paper/feed';
|
||||
import {
|
||||
assertSupportedComposition,
|
||||
registerOrchestratorServices,
|
||||
|
|
@ -12,11 +14,30 @@ export async function createContainer(
|
|||
config: StockAppConfig,
|
||||
options: { role?: OrchestratorRole } = {}
|
||||
) {
|
||||
const role = options.role === undefined ? 'paper' : options.role;
|
||||
const settings = config.services?.orchestrator;
|
||||
if (settings?.defaultMode === 'live') {
|
||||
throw new Error('Live trading is disabled: no real broker adapter exists');
|
||||
}
|
||||
const role =
|
||||
options.role === undefined
|
||||
? settings?.defaultMode === 'backtest'
|
||||
? 'research-only'
|
||||
: 'paper'
|
||||
: options.role;
|
||||
const configuredEngine = config.services?.orchestrator?.backtesting?.useRustEngine;
|
||||
const useRustEngine = configuredEngine === undefined ? true : configuredEngine;
|
||||
// Fail before opening connections as well as before registering runtime services.
|
||||
assertSupportedComposition(role, useRustEngine);
|
||||
if (settings?.canonicalPaper !== undefined && role !== 'paper') {
|
||||
throw new Error('Canonical paper configuration requires a paper composition');
|
||||
}
|
||||
const canonicalPaper =
|
||||
settings?.canonicalPaper === undefined
|
||||
? undefined
|
||||
: validatePaperConfiguration(paperConfigurationSchema.parse(settings.canonicalPaper));
|
||||
if (canonicalPaper && !config.database?.postgres?.enabled) {
|
||||
throw new Error('Canonical paper requires durable PostgreSQL custody');
|
||||
}
|
||||
const container = await new ServiceContainerBuilder()
|
||||
.withConfig(config)
|
||||
.withOptions({
|
||||
|
|
@ -35,6 +56,8 @@ export async function createContainer(
|
|||
allowSyntheticData: config.services?.orchestrator?.backtesting?.allowSyntheticData ?? false,
|
||||
syntheticSeed: config.services?.orchestrator?.backtesting?.syntheticSeed ?? 42,
|
||||
nativeExecutionTimeoutMs: config.services?.orchestrator?.backtesting?.executionTimeoutMs,
|
||||
canonicalPaper,
|
||||
paperTradingCapital: settings?.paperTradingCapital,
|
||||
});
|
||||
return container.resolve('serviceContainer') as OrchestratorServices;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue