Files
eth_hedge_sim/docs/审计说明-2026-07-29-开平仓与实盘安全.md
T
dekun 44fd0371b9 Fix OKX abandon residual double-book and fill/residual ledger holes.
After dual-close leaves option pending, continue close_group instead of false residual; reject partial fills on wait timeout; LIVE residual settle allow_negative.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-29 20:20:36 +08:00

44 lines
2.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 审计说明 — 开/平仓逻辑与实盘安全(2026-07-29)
## 范围
- 开仓 / 平仓 / 到期双腿平仓 / 弃期权只平永续
- LIVE 执行器(OKX / 币安)本地账本与交易所一致性
- 手动开平仓 API 与策略引擎并发
- 鉴权密钥、资金可开判定、平仓盈亏查询
## 结论摘要(含第二轮复审)
| 严重度 | 问题 | 处置 |
|--------|------|------|
| Critical | 到期双平:`_mark` 后仍二次入账期权 | **已修**(第一轮) |
| Critical | 弃期权 `apply_cash``allow_negative` | **已修**(第一轮) |
| Critical | OKX abandon:双腿已平期权落 pending 后仍记 residual → 到期再结期权双计 | **已修**(第二轮):pending 则续 `close_group` |
| High | 平仓用当前保证金模式 | **已修**(第一轮,OKX |
| High | 手动开平无引擎锁 | **已修**(第一轮) |
| High | `_wait_fill` 超时把部分成交当全成 | **已修**(第二轮):超时仅接受 `filled` |
| High | residual 结算无 `allow_negative`LIVE | **已修**(第二轮) |
| High | `opening` 卡住无恢复 | **部分**:紧急全平明确告警;不自动清槽(防裸仓清槽) |
| Med | positions-history / AUTH / 币安可开误调 OKX | **已修**(第一轮) |
| Med | 币安 `orderId` 误匹配卡 opening | **已修**(第二轮):仅 `orderId=` |
## 第二轮仍残留(已知)
- 开仓两腿成交后、写 DB 前进程崩溃 → 交易所满仓、本地 `opening`(需人工对账)。
- 启动对账主要看永续,不查期权裸仓。
- 币安未持久化/使用 `perp_margin_mode`;可开资金未接币安余额。
- LIVE 仅拒绝默认 `AUTH_SECRET`,弱自定义密钥不拦截。
## 开/平仓自检要点
1. 期权先平并 `_mark_option_closed_perp_pending`,再平永续;finalize 跳过期权二次入账。
2. abandon:若已 pending,只续平永续,**禁止**再插 residual。
3. LIVE 成交后本地账本一律允许透支镜像。
4. 手动开平与引擎共用 `_lock`
## 涉及文件
- `backend/app/live/executor.py` / `binance_executor.py` / `okx_trade.py`
- `backend/app/sim/matcher.py` / `strategy/engine.py`
- `backend/app/api/sim.py` / `settings.py` / `main.py`