import { hedgeCalculator } from './hedgeCalculator' import { tradeRouter } from './router' import { HedgeRequest, ExecutionPlan, ExecutionResult } from './types' export class HedgingExecutor { async execute(req: HedgeRequest): Promise { // 1) 计算对冲决策 const decision = hedgeCalculator.decide(req) if (!decision.shouldHedge) { return { success: true, executedQuantity: 0, executedPrice: 0, orderId: undefined, txHash: undefined } } const side: 'buy' | 'sell' = decision.hedgeQuantity > 0 ? 'buy' : 'sell' const absQty = Math.abs(decision.hedgeQuantity) // 2) 路由报价(根据 method) const quote = decision.method === 'spot' ? await tradeRouter.quoteSpot(req.symbol, absQty) : await tradeRouter.quotePerp(req.symbol, absQty) // 3) 滑点检查(占位:总是通过)。实际应根据 req.config.thresholds.maxSlippage 与 quote 对比 // 4) 生成执行计划 const plan: ExecutionPlan = { method: decision.method, symbol: req.symbol, quantity: absQty, side, quote, } // 5) 执行 const result = await tradeRouter.execute(plan) return result as ExecutionResult } } export const hedgingExecutor = new HedgingExecutor()