修复期权历史/复盘金额为0:模拟盘合成历史、币本位按ETH精度展示,复盘折算为U。
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1437,6 +1437,7 @@ def format_option_history_row(
|
||||
ct_mult: float = 0.01,
|
||||
) -> dict[str, Any]:
|
||||
"""标准化 OKX positions-history 单条记录供前端展示."""
|
||||
from lib.options.options_margin_mode_lib import margin_mode_from_inst_id, premium_ccy_for_mode
|
||||
from lib.options.options_pricing_lib import total_premium
|
||||
|
||||
inst_id = str(raw.get("instId") or "").strip()
|
||||
@@ -1447,11 +1448,14 @@ def format_option_history_row(
|
||||
sheets = _safe_float(raw.get("openMaxPos"))
|
||||
sheets_i = int(abs(sheets or 0))
|
||||
eth_amount = round(abs(sheets or 0) * ct_mult, 8) if sheets else 0.0
|
||||
premium_paid = (
|
||||
round(total_premium(open_avg, eth_amount), 8)
|
||||
if open_avg is not None and eth_amount > 0
|
||||
else None
|
||||
)
|
||||
# 模拟盘可直接带权利金;否则用开仓均价×名义
|
||||
premium_paid = _safe_float(raw.get("_sim_premium_paid"))
|
||||
if premium_paid is None:
|
||||
premium_paid = (
|
||||
round(total_premium(open_avg, eth_amount), 8)
|
||||
if open_avg is not None and eth_amount > 0
|
||||
else None
|
||||
)
|
||||
realized = _safe_float(raw.get("realizedPnl"))
|
||||
if realized is None:
|
||||
realized = _safe_float(raw.get("pnl"))
|
||||
@@ -1461,6 +1465,10 @@ def format_option_history_row(
|
||||
ctime = _safe_float(raw.get("cTime"))
|
||||
opt_type, strike = option_fields_from_inst_id(inst_id)
|
||||
uly = str(raw.get("uly") or inst_id.split("-")[0] or "").replace("-USD_UM", "").replace("-USD", "")
|
||||
row_mode = margin_mode_from_inst_id(inst_id) if inst_id else "usdc"
|
||||
premium_ccy = str(raw.get("_sim_premium_ccy") or "").strip().upper() or premium_ccy_for_mode(
|
||||
row_mode, uly or "ETH"
|
||||
)
|
||||
if close_type in ("3", "4"):
|
||||
status_label = "强平"
|
||||
else:
|
||||
@@ -1487,8 +1495,11 @@ def format_option_history_row(
|
||||
"close_avg_px": close_avg,
|
||||
"close_avg_px_fmt": format_option_px(close_avg, tick_sz) if close_avg is not None else None,
|
||||
"premium_paid": premium_paid,
|
||||
"premium_paid_fmt": format_usdc_amount(premium_paid),
|
||||
"premium_paid_fmt": format_premium_amount(premium_paid, ccy=premium_ccy),
|
||||
"premium_ccy": premium_ccy,
|
||||
"margin_mode": row_mode,
|
||||
"realized_pnl": realized,
|
||||
"realized_pnl_fmt": format_premium_amount(realized, ccy=premium_ccy),
|
||||
"pnl_ratio_pct": round(pnl_ratio * 100, 2) if pnl_ratio is not None else None,
|
||||
"status": "closed",
|
||||
"status_label": status_label,
|
||||
@@ -1531,7 +1542,12 @@ def format_live_option_history_row(
|
||||
"close_avg_px_fmt": None,
|
||||
"premium_paid": row.get("premium_paid"),
|
||||
"premium_paid_fmt": row.get("premium_paid_fmt"),
|
||||
"premium_ccy": row.get("premium_ccy"),
|
||||
"margin_mode": row.get("margin_mode"),
|
||||
"realized_pnl": row.get("upl"),
|
||||
"realized_pnl_fmt": format_premium_amount(
|
||||
_safe_float(row.get("upl")), ccy=str(row.get("premium_ccy") or "USDC")
|
||||
),
|
||||
"pnl_ratio_pct": row.get("upl_ratio_pct"),
|
||||
"status": "open",
|
||||
"status_label": "持仓中",
|
||||
|
||||
Reference in New Issue
Block a user