Deduct round-trip taker fees from estimated perp PnL.

Unify hub/instance TP profit, calc_pnl, and push/accounting to net of 0.05% per side; leave exchange floating PnL unchanged.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-07-17 15:12:52 +08:00
parent d5e6132b13
commit 2269bc51ff
13 changed files with 307 additions and 20 deletions
+10 -1
View File
@@ -2157,6 +2157,7 @@ def format_hold_minutes(minutes):
def calc_pnl(direction, trigger_price, exit_price, margin_capital, leverage):
"""估算净盈亏(USDT):价差毛利 − 双边 taker 费(默认各 0.05%)."""
try:
trigger = float(trigger_price)
exit_p = float(exit_price)
@@ -2168,7 +2169,15 @@ def calc_pnl(direction, trigger_price, exit_price, margin_capital, leverage):
pnl_ratio = (trigger - exit_p) / trigger
else:
pnl_ratio = (exit_p - trigger) / trigger
return round(margin * lev * pnl_ratio, 4)
notional = margin * lev
gross = notional * pnl_ratio
try:
from lib.trade.trade_fee_lib import net_pnl_after_fee
net = net_pnl_after_fee(gross, trigger, exit_p, open_notional=notional)
return float(net) if net is not None else round(gross, 4)
except Exception:
return round(gross, 4)
except Exception:
return 0.0