修复币本位期权历史权利金/盈亏显示0.00;复盘盈亏按指数换算为U
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1456,6 +1456,15 @@ 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", "")
|
||||
try:
|
||||
from lib.options.options_margin_mode_lib import margin_mode_from_inst_id, premium_ccy_for_mode
|
||||
|
||||
row_mode = margin_mode_from_inst_id(inst_id) if inst_id else "usdc"
|
||||
premium_ccy = premium_ccy_for_mode(row_mode, uly or "ETH")
|
||||
except Exception:
|
||||
row_mode = "usdc"
|
||||
premium_ccy = "USDC"
|
||||
idx_px = _safe_float(raw.get("idxPx") or raw.get("idx_px"))
|
||||
if close_type in ("3", "4"):
|
||||
status_label = "强平"
|
||||
else:
|
||||
@@ -1477,12 +1486,17 @@ def format_option_history_row(
|
||||
"strike": strike,
|
||||
"sheets": sheets_i,
|
||||
"eth_amount": eth_amount,
|
||||
"ct_mult": ct_mult,
|
||||
"open_avg_px": open_avg,
|
||||
"open_avg_px_fmt": format_option_px(open_avg, tick_sz) if open_avg is not None else None,
|
||||
"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,
|
||||
"margin_mode_label": "币本位" if row_mode == "coin" else "USDC",
|
||||
"idx_px": idx_px,
|
||||
"realized_pnl": realized,
|
||||
"pnl_ratio_pct": round(pnl_ratio * 100, 2) if pnl_ratio is not None else None,
|
||||
"status": "closed",
|
||||
@@ -1505,6 +1519,7 @@ def format_live_option_history_row(
|
||||
inst_id = str(row.get("inst_id") or "").strip()
|
||||
pos_id = str((row.get("raw") or {}).get("posId") or "").strip() or None
|
||||
close_ms = open_ms
|
||||
premium_ccy = str(row.get("premium_ccy") or "USDC").strip().upper() or "USDC"
|
||||
return {
|
||||
"source": "live",
|
||||
"history_key": option_history_row_key(
|
||||
@@ -1526,6 +1541,10 @@ 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": premium_ccy,
|
||||
"margin_mode": row.get("margin_mode"),
|
||||
"margin_mode_label": row.get("margin_mode_label"),
|
||||
"idx_px": row.get("idx_px"),
|
||||
"realized_pnl": row.get("upl"),
|
||||
"pnl_ratio_pct": row.get("upl_ratio_pct"),
|
||||
"status": "open",
|
||||
|
||||
Reference in New Issue
Block a user