Show pure-option source and net PnL on dashboard.

Restore 纯期权 label for non-hedge option rows and use close-preview net PnL instead of exchange upl.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-07-17 14:32:43 +08:00
parent c4c8ad172a
commit 549d8a015c
4 changed files with 40 additions and 13 deletions
+16 -6
View File
@@ -1057,7 +1057,7 @@ def resolve_position_monitor_source(pos: dict, hub_mon: Optional[dict]) -> str:
def _options_source_label(p: dict) -> str:
"""看板期权来源:仅对冲标期期/永期;纯期权或对不上监控显示 —."""
"""看板期权来源:期期/永期对冲,其余为纯期权."""
source = str(p.get("source") or "").strip()
label = str(p.get("source_label") or "").strip()
if source == "perp_options" or label == "永期对冲":
@@ -1067,7 +1067,9 @@ def _options_source_label(p: dict) -> str:
hedge = p.get("hedge_plan_target") if isinstance(p.get("hedge_plan_target"), dict) else None
if hedge:
return _hedge_source_label(hedge)
return ""
if label == "纯期权" or source in ("", "option"):
return "纯期权"
return label or "纯期权"
def _options_target_monitor_text(p: dict) -> str:
@@ -1115,19 +1117,27 @@ def format_dashboard_account_detail(ac: dict) -> dict[str, Any]:
row = dict(p)
row["source_label"] = _options_source_label(p)
row["target_monitor_text"] = _options_target_monitor_text(p)
try:
from lib.options.options_positions_lib import net_pnl_from_display_row
net = net_pnl_from_display_row(row)
except Exception:
net = None
row["net_pnl"] = round(float(net), 4) if net is not None else None
options_positions.append(row)
inst = row.get("inst_id") or "?"
opt_type = (row.get("opt_type") or "").upper()
label = "Call" if opt_type == "C" else "Put" if opt_type == "P" else opt_type or "OPT"
upl = row.get("upl")
line: dict[str, Any] = {
"kind": "options",
"source": row.get("source_label") or "",
"source": row.get("source_label") or "纯期权",
"text": f"期权 {inst} {label}",
}
if upl is not None:
if row.get("net_pnl") is not None:
line["pnl"] = row["net_pnl"]
elif row.get("upl") is not None:
try:
line["pnl"] = round(float(upl), 4)
line["pnl"] = round(float(row["upl"]), 4)
except (TypeError, ValueError):
pass
position_lines.append(line)