Show option net P/L from bid recycle minus premium.

Rename floating P/L to net P/L, align ROI, and display bid depth as price/liquidity for only the levels needed to close.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-07-15 20:54:15 +08:00
parent da3975e42e
commit e15eca76f3
6 changed files with 114 additions and 23 deletions
+7 -3
View File
@@ -51,11 +51,15 @@ def build_options_hub_snapshot(cfg: dict[str, Any]) -> dict[str, Any]:
upl_total = 0.0
has_upl = False
for p in positions:
upl = p.get("upl")
if upl is None:
# 汇总优先用买盘净盈亏,与持仓卡「净盈亏」一致
preview = p.get("close_preview") or {}
net = preview.get("estimated_pnl")
if net is None:
net = p.get("upl")
if net is None:
continue
has_upl = True
upl_total += float(upl)
upl_total += float(net)
bal = cfg["fetch_options_balances"](ex)
stats = _compute_options_stats(ex, cfg)
return {
+8 -2
View File
@@ -70,6 +70,7 @@ def estimate_close_by_bids(
"total_received": 0.0,
"avg_px": None,
"estimated_pnl": None,
"estimated_pnl_ratio_pct": None,
}
for i, level in enumerate(bids or [], start=1):
if remaining <= 0:
@@ -98,10 +99,14 @@ def estimate_close_by_bids(
remaining -= take
covered = target - remaining
avg_px = (total_received / eth_amount_from_sheets(covered, ct_mult)) if covered > 0 else None
# 净盈亏 = 按买盘可回收 − 全部权利金(与「可落袋」口径一致;买一不够会展开更多档)
estimated_pnl = None
estimated_pnl_ratio_pct = None
if premium_paid is not None and covered > 0:
paid_basis = float(premium_paid) * (covered / target)
estimated_pnl = round(total_received - paid_basis, 4)
paid = float(premium_paid)
estimated_pnl = round(total_received - paid, 4)
if paid > 0:
estimated_pnl_ratio_pct = round(estimated_pnl / paid * 100.0, 2)
return {
"levels": levels,
"covered_sheets": covered,
@@ -109,6 +114,7 @@ def estimate_close_by_bids(
"total_received": round(total_received, 4),
"avg_px": round(avg_px, 4) if avg_px is not None else None,
"estimated_pnl": estimated_pnl,
"estimated_pnl_ratio_pct": estimated_pnl_ratio_pct,
}