Fix btc_eth live card option premium USDT conversion.

Use option (BTC) index for coin-to-U; never fall back to ETH perp mark. Also add no-server-ops Cursor rule.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-10-14 20:48:10 +08:00
parent e1fd77cd06
commit e8f33c3c52
4 changed files with 153 additions and 19 deletions
+22 -5
View File
@@ -1775,14 +1775,31 @@ def execute_manual_close_plan(cfg: dict[str, Any], conn: Any, plan_id: int) -> d
notes.append("卖币失败: " + str(sell_r.get("msg") or ""))
total = float(opt_pnl) + float(perp_pnl)
# 期权币本位盈亏换算到 U(粗):用指数
# 期权币本位盈亏换算到 U:用期权标的指数(跨币=BTC,禁止×ETH)
try:
fetch_idx = cfg.get("fetch_index_price")
idx = float(fetch_idx(uly) or 0) if callable(fetch_idx) else 0.0
from lib.hedge_plan.hedge_plan_live_positions_lib import resolve_option_index_px
from lib.hedge_plan.hedge_po_mode_lib import get_hedge_po_mode, is_cross_asset, option_underlying
mode = str(plan.get("po_mode") or get_hedge_po_mode())
opt_u = str(plan.get("option_underlying") or plan.get("underlying") or option_underlying(mode) or uly).upper()
ex_idx = cfg.get("exchange_options") or cfg.get("exchange")
if callable(ex_idx):
try:
ex_idx = ex_idx()
except Exception:
ex_idx = None
idx = float(
resolve_option_index_px(
cfg,
opt_u,
ex_opt=ex_idx,
cross_asset=is_cross_asset(mode),
perp_fallback=None,
)
or 0
)
# opt_pnl 可能已是币;若为币且绝对值很小则 × 指数
# resolve_option_leg_realized_pnl 对币本位通常返回币;统一展示用 preview 风格
if abs(opt_pnl) < 10 and idx > 0 and abs(opt_pnl * idx) > abs(opt_pnl):
# 更可能是币单位
opt_pnl_u = opt_pnl * idx
else:
opt_pnl_u = opt_pnl