revert期权历史仍按币展示盈亏,U 口径只用于统计结算。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-10-08 23:58:02 +08:00
parent 70ebfb10e8
commit e0e2a94322
3 changed files with 9 additions and 25 deletions
+4 -7
View File
@@ -2833,15 +2833,12 @@
list.forEach(function (h) { list.forEach(function (h) {
const tr = document.createElement("tr"); const tr = document.createElement("tr");
const premCcy = posPremiumCcy(h); const premCcy = posPremiumCcy(h);
const premUnit = premCcy === "USDC" || premCcy === "USDT" ? "U" : premCcy; const unit = premCcy === "USDC" ? "U" : premCcy;
// 模拟盘盈亏已折 U 时用 pnl_display_ccy,勿再标 BTC
const pnlCcy = String(h.pnl_display_ccy || premCcy).toUpperCase();
const pnlUnit = pnlCcy === "USDC" || pnlCcy === "USDT" ? "U" : pnlCcy;
const premCore = fmtDisplay( const premCore = fmtDisplay(
h.premium_paid_fmt, h.premium_paid_fmt,
h.premium_paid != null ? fmtPremiumAmt(h.premium_paid, premCcy) : null h.premium_paid != null ? fmtPremiumAmt(h.premium_paid, premCcy) : null
); );
const premTxt = premCore === "—" ? "—" : premCore + " " + premUnit; const premTxt = premCore === "—" ? "—" : premCore + " " + unit;
const isOpen = h.status === "open"; const isOpen = h.status === "open";
const pnl = isOpen ? null : h.realized_pnl; const pnl = isOpen ? null : h.realized_pnl;
let pnlTxt = "—"; let pnlTxt = "—";
@@ -2849,9 +2846,9 @@
const n = Number(pnl); const n = Number(pnl);
const absCore = fmtDisplay( const absCore = fmtDisplay(
null, null,
pnlUnit === "U" ? fmt(Math.abs(n), 2) : fmtPremiumAmt(Math.abs(n), pnlCcy) fmtPremiumAmt(Math.abs(n), premCcy)
); );
pnlTxt = (n > 0 ? "+" : n < 0 ? "-" : "") + absCore + " " + pnlUnit; pnlTxt = (n > 0 ? "+" : n < 0 ? "-" : "") + absCore + " " + unit;
} }
const pnlCls = pnl > 0 ? "pos-pnl-profit" : pnl < 0 ? "pos-pnl-loss" : ""; const pnlCls = pnl > 0 ? "pos-pnl-profit" : pnl < 0 ? "pos-pnl-loss" : "";
const timeTxt = (h.closed_at || h.created_at || "—").replace("T", " ").slice(0, 19); const timeTxt = (h.closed_at || h.created_at || "—").replace("T", " ").slice(0, 19);
+2 -13
View File
@@ -1467,7 +1467,6 @@ def format_option_history_row(
realized = _safe_float(raw.get("realizedPnl")) realized = _safe_float(raw.get("realizedPnl"))
if realized is None: if realized is None:
realized = _safe_float(raw.get("pnl")) realized = _safe_float(raw.get("pnl"))
pnl_usdt = _safe_float(raw.get("_sim_realized_pnl_usdt"))
pnl_ratio = _safe_float(raw.get("pnlRatio")) pnl_ratio = _safe_float(raw.get("pnlRatio"))
close_type = str(raw.get("type") or "").strip() close_type = str(raw.get("type") or "").strip()
utime = _safe_float(raw.get("uTime")) utime = _safe_float(raw.get("uTime"))
@@ -1478,13 +1477,6 @@ def format_option_history_row(
premium_ccy = str(raw.get("_sim_premium_ccy") or "").strip().upper() or premium_ccy_for_mode( premium_ccy = str(raw.get("_sim_premium_ccy") or "").strip().upper() or premium_ccy_for_mode(
row_mode, uly or "ETH" 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"): if close_type in ("3", "4"):
status_label = "强平" status_label = "强平"
else: else:
@@ -1513,13 +1505,10 @@ def format_option_history_row(
"premium_paid": premium_paid, "premium_paid": premium_paid,
"premium_paid_fmt": format_premium_amount(premium_paid, ccy=premium_ccy), "premium_paid_fmt": format_premium_amount(premium_paid, ccy=premium_ccy),
"premium_ccy": premium_ccy, "premium_ccy": premium_ccy,
"pnl_display_ccy": pnl_display_ccy,
"margin_mode": row_mode, "margin_mode": row_mode,
"realized_pnl": realized, "realized_pnl": realized,
"realized_pnl_usdt": pnl_usdt if pnl_usdt is not None else ( "realized_pnl_usdt": _safe_float(raw.get("_sim_realized_pnl_usdt")),
float(realized) if pnl_display_ccy == "USDT" and realized is not None else None "realized_pnl_fmt": format_premium_amount(realized, ccy=premium_ccy),
),
"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, "pnl_ratio_pct": round(pnl_ratio * 100, 2) if pnl_ratio is not None else None,
"status": "closed", "status": "closed",
"status_label": status_label, "status_label": status_label,
+3 -5
View File
@@ -1291,9 +1291,9 @@ class SimBroker:
"closeAvgPx": str(close_px) if close_px is not None else "", "closeAvgPx": str(close_px) if close_px is not None else "",
"closeTotalPos": str(sheets), "closeTotalPos": str(sheets),
"openMaxPos": str(sheets), "openMaxPos": str(sheets),
# 展示用 U 盈亏;币数量仍放 raw 供对账 # 期权历史展示币数量盈亏;U 口径只写 _sim_realized_pnl_usdt 供统计
"realizedPnl": str(round(pnl_usdt, 4)) if pnl_usdt is not None else str(round(pnl, 8)), "realizedPnl": str(round(pnl, 8)),
"pnl": str(round(pnl_usdt, 4)) if pnl_usdt is not None else str(round(pnl, 8)), "pnl": str(round(pnl, 8)),
"pnlRatio": str(round(pnl_ratio, 8)) if pnl_ratio is not None else "", "pnlRatio": str(round(pnl_ratio, 8)) if pnl_ratio is not None else "",
"cTime": str(open_ms or ""), "cTime": str(open_ms or ""),
"uTime": str(close_ms or ""), "uTime": str(close_ms or ""),
@@ -1302,9 +1302,7 @@ class SimBroker:
"stk": str(strike) if strike is not None else "", "stk": str(strike) if strike is not None else "",
"_sim_premium_paid": paid, "_sim_premium_paid": paid,
"_sim_premium_ccy": ccy, "_sim_premium_ccy": ccy,
"_sim_realized_pnl_coin": pnl,
"_sim_realized_pnl_usdt": pnl_usdt, "_sim_realized_pnl_usdt": pnl_usdt,
"_sim_pnl_display_ccy": "USDT" if pnl_usdt is not None else ccy,
} }
) )
return out return out