Files
crypto_monitor/docs/对冲计划-以期权为主.md
T
dekun 20e0c2cb9f refactor(hedge): env-driven option-primary UI with grouped params
Move mode switch to HEDGE_PLAN_OPTION_PRIMARY, split left into capital/select/exit groups, and show perp quote above options with leverage auto-match.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-09 09:05:32 +08:00

72 lines
2.8 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-08-09 · 在现有永期**保险模式**上增加子模式,不新增 `OKX_TRADE_MODE`。
> 模式由 env `HEDGE_PLAN_OPTION_PRIMARY` 切换(默认 `true`),页面标题前显示标识,不可在页内切换。
## 1. 模式对照
| | 保险模式(`OPTION_PRIMARY=false`) | 以期权为主(`true`) |
|--|------------------|-------------------|
| UI 做多 | 永续多 + 买 Put | 买 Call + 永续空 |
| UI 做空 | 永续空 + 买 Call | 买 Put + 永续多 |
| 左卡 | 开仓价 / 张数 / TP / SL | 资金与杠杆 / 选约条件 / 出场条件 三组 |
| 右卡 | 上永续行情 · 下期权链 | 同上;期权表含杠杆(指数÷卖一),按类型自动匹配 |
| 选约 | 仅实值/平值 | 实/平/虚 + 间隔 + 杠杆门 |
| 开仓 | 受 `HEDGE_PLAN_OPEN_ORDER` | **强制先期权**,成交后**立即市价**开永续(**不挂**交易所 TP/SL) |
| 出场 | 交易所 TP/SL | 相对 K 的点数目标分叉 |
## 2. 左卡默认
| 字段 | 默认 |
|------|------|
| 权利金 | 用户填(USDC 预算) |
| 永续杠杆 | 100 |
| 期权杠杆 | 实/平 100;虚 200 |
| 期权:永续比例 | 实/平 2;虚 4 |
| 到期时间(最短 h) | 36 |
| 期权间隔(点) | 15 |
| 期权/永续目标位 | 相对 K 点数,须 **>0** |
## 3. 定仓
```
usable = 权利金 × 0.95
eth_qty = floor2(usable / ask) # ETH 名义,两位小数
sheets = floor(eth_qty / ct_mult) # 整张
perp_eth = eth_qty / 比例
contracts = perp_eth / contract_size
```
启动前再拉卖一重算;卖一深度不足则缩量。
## 4. 出场
触达任一目标位(做多 `index ≥ K+N`,做空 `index ≤ KN`)后立即执行:
| 触达 | 规则 |
|------|------|
| **期权目标** | 验买一流动性 + **扣费净利 > 0** → 先平期权再平永续 |
| **永续目标** | 市价平永续;期权 `hold_to_expiry` 至到期结算 |
净利:平仓/卖出手续费**按买入费率**估算(`HEDGE_PLAN_FEE_RATE` / `OKX_TAKER_FEE`,默认 0.0005)。
若期权目标因买一/净利未过、但永续目标已触达 → 改走永续目标。
期权已平永续失败 → `opt_target_perp_pending` 下轮只补平永续。
两腿仍开但期权到期 → 结算期权并平永续,避免裸奔。
## 5. 代码落点
| 文件 | 作用 |
|------|------|
| `lib/hedge_plan/hedge_plan_option_primary_lib.py` | 定仓/方向/目标/净利/校验 |
| `hedge_plan_orders_lib.py` | 路径、开平永续、启动前定仓刷新 |
| `hedge_plan_monitor_lib.py` | `_tick_po_option_primary*` |
| `hedge_plan_register.py` / `hedge_plan_db.py` | preview/start/persist`options-chain?option_primary&min_hours&strike_interval` |
| `hedge_plan.js` + `hedge_plan_panel.html` | env 模式标识、左三组参数、右上永续/右下期权 |
## 6. 测试
```bash
python -m unittest tests.test_hedge_plan_option_primary -v
```