Enrich WeCom open/close notifies with Chinese qty, margin, and PnL.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-08-02 08:58:49 +08:00
parent aab0b9bdf6
commit 0e3b9e53ac
8 changed files with 373 additions and 32 deletions
+23
View File
@@ -349,15 +349,33 @@ class Matcher:
except Exception:
logger.exception("lock exit target failed group=%s", group_id)
leverage = self.ledger.get_setting_float("leverage", s.leverage)
perp_margin = (
abs(float(pf.fill_px) * float(perp_qty)) / float(leverage)
if leverage and float(leverage) > 0
else None
)
return OpenResult(
ok=True,
group_id=group_id,
detail="opened",
data={
"group_id": group_id,
"bias": bias,
"option_side": option_side,
"perp_side": perp_side,
"option_inst_id": option_inst_id,
"strike": strike,
"expiry_ymd": expiry_ymd,
"perp": pf.to_dict(),
"option": of.to_dict(),
"perp_qty_eth": float(perp_qty),
"option_qty_eth": float(opt_qty),
"perp_entry_px": float(pf.fill_px),
"option_entry_px": float(of.fill_px),
"initial_premium": initial_premium,
"perp_margin": perp_margin,
"leverage": float(leverage) if leverage else None,
"fees": pf.fee + of.fee,
"open_sequence": ["option", "perp"],
},
@@ -617,8 +635,10 @@ class Matcher:
"perp_pnl": perp_pnl,
"option_pnl": opt_pnl,
"net": net_after_all_fees,
"net_pnl": net_after_all_fees,
"fees_open": open_fees,
"fees_close": pf.fee + of.fee,
"fees": float(open_fees) + float(pf.fee) + float(of.fee),
"close_sequence": ["option", "perp"],
"cash_delta": opt_cash + perp_pnl - pf.fee,
"option_close_bid": float(close_bid),
@@ -788,7 +808,10 @@ class Matcher:
"reason": reason,
"mode": "target_perp_only",
"perp_pnl": perp_pnl,
"option_pnl": None,
"interim_net": interim_net,
"net": interim_net,
"net_pnl": interim_net,
"option_abandoned": True,
"strike": float(strike),
"spot": float(spot),