Files
eth_hedge_sim/docs/审计说明-2026-07-29-开平仓与实盘安全.md
dekun 101cb3c045 Fix ghost finalize on unknown perp size and open rollback hazards.
Distinguish exchange query None from flat zero; keep opening when size unknown; idempotent half_open cash; scan options while opening; continue manage after recover.

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

37 lines
1.7 KiB
Markdown
Raw Permalink 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)
## 结论(四轮后)
开平仓主路径已闭环:占槽 → 意图落库 → 期权 → 永续 → open;平仓先 mark pending 再平永续;崩溃可 `recover_opening`。第四轮修掉「查仓失败当空仓 finalize」等回归。
## 四轮关键项
| 轮次 | 关键修复 |
|------|----------|
| 1 | 到期双入账;abandon `allow_negative`;保证金模式;引擎锁;AUTH;盈亏查询 |
| 2 | abandon 假 residual;部分成交不当全成;residual LIVE 账本 |
| 3 | stamp + recover_opening;期权对账;已空不重卖/不下单;币安 orderId= |
| 4 | 查仓 `None``0`;回滚仅确认空仓;half_open/promote 现金幂等;opening any-option;开仓张数独立 |
## 开仓
1. `claim``assert`(永续+期权残留)→ `stamp` → 买期权 → `stamp` 均价
2. 开永续用 `perp_open_contracts_okx`(不跟残留)
3. 永续失败:查仓 `None`/有仓 → 保留 opening;确认空 → 回滚期权 / half_open
4. tick/启动/紧急:`recover_opening`(空清槽 / 仅期权 half_open / 双边 promote
## 平仓
1. 卖期权(已空则跳过)→ mark pending 仅一次
2. 查永续:`None` → 失败返回;`0` → finalize`>0` → 下单
3. abandon:已 pending 只续平;禁止假 residual
## 已知极少人工场景
- opening 无 `option_inst_id` 且交易所有不明期权:禁止自动清槽
- promote 入场价可能用指数近似(本地镜像;实盘盈亏可走交易所对账)
## 涉及文件
`live/reconcile.py` · `executor.py` · `binance_executor.py` · `okx_trade.py` · `binance_trade.py` · `strategy/engine.py` · `sim/matcher.py`