Count exit fees in live/SIM net PnL as entry fee x2.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -37,8 +37,8 @@ def enrich_live_unrealized(
|
||||
) -> dict[str, Any]:
|
||||
"""
|
||||
在 Matcher.unrealized 结果上覆盖 LIVE 口径:
|
||||
net = 永续交易所UPL + 期权净盈亏(本地) − 已付手续费 + 资金费(signed)
|
||||
不再扣预估平仓费。
|
||||
net = 永续交易所UPL + 期权净盈亏(本地) − 入场手续费×2 + 资金费(signed)
|
||||
离场手续费按入场手续费估算(开+平 ≈ 已付×2)。
|
||||
"""
|
||||
if not base.get("has_position"):
|
||||
return base
|
||||
@@ -72,25 +72,9 @@ def enrich_live_unrealized(
|
||||
logger.warning("live unrealized exchange overlay failed: %s", e)
|
||||
|
||||
option_upl = float(base.get("option_upl") or 0.0) # 期权净盈亏(本地)
|
||||
# LIVE 达标口径:必须扣预估平仓手续费(与 SIM / 策略说明一致)
|
||||
try:
|
||||
from ..config import get_settings
|
||||
|
||||
fr = float(get_settings().fee_rate or 0.0005)
|
||||
except Exception:
|
||||
fr = 0.0005
|
||||
notional_est = abs(float(base.get("perp_notional") or 0.0)) + abs(
|
||||
float(base.get("option_notional") or 0.0)
|
||||
)
|
||||
if notional_est <= 0:
|
||||
# 兜底:用标记价粗算
|
||||
notional_est = abs(float(base.get("spot") or 0.0)) * (
|
||||
abs(float(base.get("perp_qty_eth") or 0.0))
|
||||
+ abs(float(base.get("option_qty_eth") or 0.0))
|
||||
)
|
||||
est_close = max(0.0, notional_est * fr * 2.0)
|
||||
# 资金费 signed:付出为负;再减估平仓费
|
||||
net_pnl = perp_upl + option_upl - fees_paid + funding - est_close
|
||||
# 盯盘/达标:离场费 ≈ 入场费 → 合计扣 已付×2
|
||||
est_close = float(fees_paid)
|
||||
net_pnl = perp_upl + option_upl - fees_paid * 2.0 + funding
|
||||
|
||||
out = dict(base)
|
||||
out["perp_upl"] = perp_upl
|
||||
|
||||
Reference in New Issue
Block a user