fix模拟盘盈亏:收回×卖回价 − 开仓U权利金 − 手续费,历史按U展示。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-10-08 23:56:23 +08:00
parent a0ee1fa8a0
commit 70ebfb10e8
6 changed files with 179 additions and 45 deletions
+13 -1
View File
@@ -1467,6 +1467,7 @@ def format_option_history_row(
realized = _safe_float(raw.get("realizedPnl"))
if realized is None:
realized = _safe_float(raw.get("pnl"))
pnl_usdt = _safe_float(raw.get("_sim_realized_pnl_usdt"))
pnl_ratio = _safe_float(raw.get("pnlRatio"))
close_type = str(raw.get("type") or "").strip()
utime = _safe_float(raw.get("uTime"))
@@ -1477,6 +1478,13 @@ def format_option_history_row(
premium_ccy = str(raw.get("_sim_premium_ccy") or "").strip().upper() or premium_ccy_for_mode(
row_mode, uly or "ETH"
)
# 模拟盘已冻结 U 盈亏时,盈亏列按 U 展示(权利金仍为币)
pnl_display_ccy = str(raw.get("_sim_pnl_display_ccy") or "").strip().upper()
if pnl_usdt is not None:
realized = float(pnl_usdt)
pnl_display_ccy = "USDT"
elif not pnl_display_ccy:
pnl_display_ccy = premium_ccy
if close_type in ("3", "4"):
status_label = "强平"
else:
@@ -1505,9 +1513,13 @@ def format_option_history_row(
"premium_paid": premium_paid,
"premium_paid_fmt": format_premium_amount(premium_paid, ccy=premium_ccy),
"premium_ccy": premium_ccy,
"pnl_display_ccy": pnl_display_ccy,
"margin_mode": row_mode,
"realized_pnl": realized,
"realized_pnl_fmt": format_premium_amount(realized, ccy=premium_ccy),
"realized_pnl_usdt": pnl_usdt if pnl_usdt is not None else (
float(realized) if pnl_display_ccy == "USDT" and realized is not None else None
),
"realized_pnl_fmt": format_premium_amount(realized, ccy=pnl_display_ccy),
"pnl_ratio_pct": round(pnl_ratio * 100, 2) if pnl_ratio is not None else None,
"status": "closed",
"status_label": status_label,