修复币本位期权浮盈二次折算:中控汇总与实例统计把已折 U 的数再乘指数。

约 -6.5U 被当成 ETH 再 ×2700 显示成 -1.7万U;汇总框直接按 U 展示,stats 不再对 open_float 二次换算。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-09-30 22:30:24 +08:00
parent 32746b0a34
commit d2d431e4c9
2 changed files with 34 additions and 24 deletions
+5 -13
View File
@@ -1846,32 +1846,24 @@ def register_options_routes(app: Flask, cfg: dict[str, Any]) -> None:
except Exception:
index_px = None
stats = compute_options_stats_from_history(history, index_px=index_px)
# sum_options_net_pnl_usdc 已按指数折 U;勿再 × 指数(否则顶栏会变成上万假亏)
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:
total_pnl = round(net_realized + float(open_float), 4)
elif stats.get("total_closed"):
total_pnl = round(net_realized, 4)
from lib.options.options_margin_mode_lib import is_coin_margin_mode
pnl_unit = "U" if is_coin_margin_mode() else str(stats.get("pnl_unit") or "USDC")
return jsonify(
{
"ok": True,
**stats,
"open_float_pnl": open_float,
"total_pnl": total_pnl,
"pnl_unit": pnl_unit,
}
)