币本位期权数据统计按指数折算为U,不再误标USDC导致0.00

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-08-21 06:17:55 +08:00
parent 9421ff7360
commit 893a2cc115
5 changed files with 149 additions and 75 deletions
+27 -1
View File
@@ -1815,8 +1815,34 @@ def register_options_routes(app: Flask, cfg: dict[str, Any]) -> None:
if raw_live is None:
return jsonify({"ok": False, "msg": "获取期权持仓失败"})
history = load_options_history(ex, cfg)
stats = compute_options_stats_from_history(history)
index_px = None
try:
from lib.exchange.okx_options_lib import fetch_index_price
from lib.options.options_margin_mode_lib import (
is_coin_margin_mode,
normalize_options_margin_mode,
)
underly = (cfg.get("default_underly") or "ETH").strip().upper() or "ETH"
if is_coin_margin_mode(normalize_options_margin_mode(cfg.get("margin_mode"))):
index_px = fetch_index_price(ex, underly)
except Exception:
index_px = None
stats = compute_options_stats_from_history(history, index_px=index_px)
open_float = sum_options_net_pnl_usdc(cfg, ex, raw_live)
# 币本位浮盈为币数量,折算为 U 再与已平合计
if open_float is not None and str(stats.get("pnl_unit") or "") == "U":
px = index_px
if px is None or px <= 0:
for h in history:
try:
px = float(h.get("idx_px") or 0)
except (TypeError, ValueError):
px = 0
if px > 0:
break
if px and px > 0:
open_float = round(float(open_float) * float(px), 4)
net_realized = _safe_float(stats.get("net_realized_pnl")) or 0.0
total_pnl = None
if open_float is not None: