fix: align unrealized PnL across four exchange instances via hub_position_metrics
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -460,17 +460,22 @@ def enrich_trend_plan(cfg: dict, row) -> dict:
|
||||
and d.get("avg_entry_price") is not None
|
||||
):
|
||||
try:
|
||||
from hub_position_metrics import estimate_linear_swap_upnl_usdt
|
||||
|
||||
entry = float(d["avg_entry_price"])
|
||||
mark = float(met["mark_price"])
|
||||
margin = float(d.get("plan_margin_capital") or 0)
|
||||
leverage = int(d.get("leverage") or 1)
|
||||
calc_pnl = getattr(m, "calc_pnl", None)
|
||||
if callable(calc_pnl) and entry > 0 and margin > 0:
|
||||
d["floating_pnl"] = float(
|
||||
calc_pnl(direction, entry, mark, margin, leverage)
|
||||
)
|
||||
else:
|
||||
d["floating_pnl"] = None
|
||||
qty = None
|
||||
cs = 1.0
|
||||
get_qty = getattr(m, "get_live_position_contracts", None)
|
||||
get_cs = getattr(m, "get_contract_size", None)
|
||||
if callable(get_qty):
|
||||
qty = get_qty(ex_sym, direction)
|
||||
if callable(get_cs):
|
||||
cs = float(get_cs(ex_sym))
|
||||
upnl = estimate_linear_swap_upnl_usdt(
|
||||
direction, entry, mark, qty, cs
|
||||
)
|
||||
d["floating_pnl"] = float(upnl) if upnl is not None else None
|
||||
except (TypeError, ValueError):
|
||||
d["floating_pnl"] = None
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user