/** * TradingEngine — composes Portfolio + RiskEngine + ExchangeClient into the * single surface the Franklin capabilities call into. * * Responsibilities: * - Pre-trade risk check (refuse the order if it would breach caps). * - Route the order to the Exchange (mock or real adapter). * - Apply the resulting Fill to the Portfolio. * * The engine holds no state itself beyond the injected dependencies; that * keeps the class easy to unit-test and lets us swap the ExchangeClient for * a real adapter without touching capability plumbing. */ import type { ExchangeClient } from './mock-exchange.js'; import type { Portfolio } from './portfolio.js'; import type { RiskEngine } from './risk.js'; export interface OpenPositionRequest { symbol: string; qty: number; priceUsd: number; } export interface CloseRequest { symbol: string; qty?: number; } export type Outcome = { status: 'filled'; fill: { symbol: string; qty: number; priceUsd: number; feeUsd: number; }; } | { status: 'blocked'; reason: string; } | { status: 'noop'; reason: string; }; export interface TradingEngineDeps { portfolio: Portfolio; risk: RiskEngine; exchange: ExchangeClient; } export declare class TradingEngine { private deps; constructor(deps: TradingEngineDeps); openPosition(req: OpenPositionRequest): Promise; closePosition(req: CloseRequest): Promise; }