Fix target-exit mismatch: correct close reason and executable PnL gate.

Locked premium exits no longer label as fixed_usdt; mark/book optimism no longer triggers close into a realized loss.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-08-07 22:05:34 +08:00
parent a88d708ea3
commit bf3441537e
6 changed files with 74 additions and 31 deletions
+15 -7
View File
@@ -73,20 +73,28 @@ def enrich_live_unrealized(
option_upl = float(base.get("option_upl") or 0.0) # 期权净盈亏(本地)
option2_upl = float(base.get("option2_upl") or 0.0) # 期期 Put 腿
# 盯盘/达标:离场费 ≈ 入场费 → 合计扣 已付×2
est_close = float(fees_paid)
# 期期无永续:perp_upl 一般为 0;仍加 option2
net_pnl = perp_upl + option_upl + option2_upl - fees_paid * 2.0 + funding
# 盯盘/达标:离场费已在 base.net_pnl(盘口可成交价)计入;这里只叠加资金费。
# 勿用交易所永续标记 UPL 覆盖净利,否则会虚高触发达标、成交后变亏。
book_net = base.get("net_pnl")
if book_net is not None:
net_pnl = float(book_net) + funding
else:
fees_est = float(fees_paid) * 2.0
net_pnl = perp_upl + option_upl + option2_upl - fees_est + funding
out = dict(base)
out["perp_upl"] = perp_upl
out["perp_upl"] = float(base.get("perp_upl") or perp_upl)
out["perp_upl_exchange"] = perp_upl
out["option_upl"] = option_upl
out["option2_upl"] = option2_upl
out["fees_paid"] = fees_paid
out["funding_usdt"] = funding
out["est_close_fees"] = est_close
out["est_close_fees"] = float(base.get("est_close_fees") or fees_paid)
out["net_pnl"] = net_pnl
out["pnl_source"] = "live_exchange"
out["net_pnl_exchange"] = (
perp_upl + option_upl + option2_upl - float(fees_paid) * 2.0 + funding
)
out["pnl_source"] = "live_book_plus_funding"
return out