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
+20 -4
View File
@@ -315,10 +315,18 @@ def _roll_leg_preview(
cs = float(contract_size) if contract_size else 1.0
if direction == "long":
loss_at_sl = (new_avg - sl) * new_qty * cs
reward_at_tp = (tp - new_avg) * new_qty * cs
reward_gross = (tp - new_avg) * new_qty * cs
else:
loss_at_sl = (sl - new_avg) * new_qty * cs
reward_at_tp = (new_avg - tp) * new_qty * cs
reward_gross = (new_avg - tp) * new_qty * cs
try:
from lib.trade.trade_fee_lib import net_pnl_after_fee
reward_at_tp = net_pnl_after_fee(reward_gross, new_avg, tp, new_qty, cs)
if reward_at_tp is None:
reward_at_tp = reward_gross
except Exception:
reward_at_tp = reward_gross
return {
"add_amount_raw": q2,
"qty_after": new_qty,
@@ -412,10 +420,18 @@ def calc_roll_calculator(
if direction == "long":
first_loss = (avg - initial_sl) * qty_f * cs
first_profit = (tp - avg) * qty_f * cs
first_profit_gross = (tp - avg) * qty_f * cs
else:
first_loss = (initial_sl - avg) * qty_f * cs
first_profit = (avg - tp) * qty_f * cs
first_profit_gross = (avg - tp) * qty_f * cs
try:
from lib.trade.trade_fee_lib import net_pnl_after_fee
first_profit = net_pnl_after_fee(first_profit_gross, avg, tp, qty_f, cs)
if first_profit is None:
first_profit = first_profit_gross
except Exception:
first_profit = first_profit_gross
rows.append(
{