# 数据模型:多平台 Delta 中性控制平面 ## 1. ExchangeAccount(交易账户) - **主键**:`accountId`(字符串,唯一) - **字段**: - `exchange`(字符串,枚举:pacifica/aster/binance/...) - `accountName`(字符串,展示用别名) - `publicKey`(字符串,经过加密存储) - `proxyProfile`(字符串,引用代理配置 ID) - `utilizationTargetMin`(小数,默认 0.5) - `utilizationTargetMax`(小数,默认 0.8) - `deltaThreshold`(小数,BTC 等值,默认 0.0005) - `maxPositionValue`(小数,账户允许的最大名义价值) - `stopLossConfigId`(字符串,引用止损模板) - `status`(枚举:active/paused/emergency) - `createdAt`、`updatedAt` - **关系**: - 关联多个 `ProxySession` - 与 `RiskEnvelope` 一对一关联 ## 2. MarketDataFeed(行情数据源) - **主键**:`feedId` - **字段**: - `exchange`(字符串) - `symbol`(字符串,如 BTC、ETH) - `wsEndpoint`(字符串) - `httpEndpoint`(字符串) - `wsLatencyP95`(毫秒,统计值) - `httpLatencyP95`(毫秒) - `freshnessThreshold`(毫秒,默认 2000) - `failoverDeadline`(毫秒,默认 10000) - `lastHeartbeat`(时间戳) - `status`(枚举:healthy/degraded/failing) - **关系**: - 与 `HedgeExecution` 订阅关系(间接) - 与 `SynthPriceSnapshot`(若合成行情)产生数据流 ## 3. StrategyModule(策略模块) - **主键**:`moduleId` - **字段**: - `name`(字符串) - `type`(枚举:market-making/funding-arbitrage/hedge-only/...) - `configSchema`(JSON Schema 描述) - `dryRunEnabled`(布尔,默认 true) - `maxConcurrentSignals`(整数) - `profitAfterFeeTarget`(小数,百分比) - `requiresSandbox`(布尔) - `status`(enable/disable) - **关系**: - 与多个 `ExchangeAccount` 建立分配记录 `AccountAllocation` - 生成 `OrderIntent` ## 4. RiskEnvelope(风险包络) - **主键**:`envelopeId` - **字段**: - `accountId`(外键,ExchangeAccount) - `maxDrawdownPercent`(小数) - `maxLeverage`(小数) - `deltaThreshold`(小数,默认继承账户级设定,可覆盖) - `slippageTolerance`(小数,百分比) - `emergencyStopLossSeconds`(整数,默认 30) - `createdAt`、`updatedAt` - **关系**: - 一对一关联 `ExchangeAccount` - 被 `HedgeExecution` 使用以验证阈值 ## 5. OrderIntent(订单意图) - **主键**:`intentId` - **字段**: - `moduleId`(外键,StrategyModule) - `accountId`(外键,ExchangeAccount) - `symbol`(字符串) - `side`(枚举:buy/sell) - `type`(枚举:limit/market/post-only/...) - `amount`(小数,base 数量) - `price`(小数,若限价) - `expectedProfitAfterFee`(小数,USD 等值) - `hedgePairIntentId`(字符串,可选,对冲配对) - `state`(pending/submitted/filled/cancelled/failed) - `createdAt`、`updatedAt` - **关系**: - 由 `StrategyModule` 创建 - `HedgeExecution` 会引用其结果并更新状态 ## 6. HedgeExecution(对冲执行记录) - **主键**:`executionId` - **字段**: - `primaryAccountId`、`hedgeAccountId`(外键,ExchangeAccount) - `deltaBefore`、`deltaAfter`(小数,BTC 等值) - `orders`(JSON 列表,含外部订单号、类型、价格、状态) - `triggerReason`(枚举:utilization/delta/failover/manual) - `durationMs`(整数) - `result`(枚举:success/partial/fail) - `createdAt` - **关系**: - 引用多个 `OrderIntent` - 依赖 `RiskEnvelope` 和 `MarketDataFeed` ## 7. ProxySession(代理会话) - **主键**:`sessionId` - **字段**: - `proxyProfile`(字符串) - `ip`、`port`、`auth`(凭证信息) - `accountIds`(数组,关联账户) - `lastRotation`(时间戳) - `status`(active/rotating/failed) - **关系**: - 与 `ExchangeAccount` 多对多(通过 accountIds) - 与 `OrderIntent`、`AccountSyncJob` 链接以记录调用来源 ## 8. AccountAllocation(账户分配关系) - **主键**:复合键(`moduleId`, `accountId`) - **字段**: - `weight`(小数,策略在账户内的权重) - `maxConcurrentOrders`(整数) - `sandboxMode`(布尔,表示是否仍在 Dry-run) - `createdAt`、`updatedAt` - **关系**: - 关联 `StrategyModule` 与 `ExchangeAccount` - 被分配时需校验 RiskEnvelope ## 9. SynthPriceSnapshot(合成价格快照) - **主键**:`snapshotId` - **字段**: - `symbol`(字符串) - `sourceFeeds`(数组,记录参与合成的 feedId) - `midPrice`、`bid`、`ask`(小数) - `timestamp`(时间戳) - `reason`(枚举:ws-failover/http-timeout/manual) - **关系**: - 由 `MarketDataFeed` 的回退逻辑生成 - 提供给 `OrderIntent` 作为价格依据 ## 10. MonitoringEvent(监控事件) - **主键**:`eventId` - **字段**: - `type`(枚举:utilization-alert/delta-alert/failover-alert/proxy-alert/test-result) - `accountId` 或 `moduleId`(可选) - `payload`(JSON,记录详情) - `severity`(INFO/WARN/CRITICAL) - `createdAt` - **关系**: - 供仪表板与告警系统消费 - 与 `HedgeExecution`、`OrderIntent` 产生的事件有关联 --- ## 状态与流程概述 1. **账户同步**:定期拉取交易所余额与仓位,更新 `ExchangeAccount` 与相关 `RiskEnvelope` 信息。 2. **行情刷新**:`MarketDataFeed` 维护实时顺序;当 WS 异常时生成 `SynthPriceSnapshot` 并触发 `MonitoringEvent`。 3. **信号生成**:`StrategyModule` 基于行情与账户状态生成 `OrderIntent`,并写入待执行队列。 4. **对冲执行**:控制平面根据 Delta 与利用率状态,调度 `HedgeExecution`,创建或取消订单,保持在宪章阈值内。 5. **观测与回溯**:所有关键操作写入 `MonitoringEvent`,日志保留 ≥90 天,可用于追溯与审计。