Show editable exit on live cards; price perp PnL via close-side book VWAP.

Align monitor profit-exit with the same book VWAP so card and auto-exit stay consistent.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-10-14 17:29:58 +08:00
parent 3f98ba1e88
commit 9295dcffe3
10 changed files with 597 additions and 10 deletions
+22 -1
View File
@@ -732,6 +732,11 @@ def _tick_po_option_primary(
symbol = str(perp.get("symbol") or "")
mark = None
ex = cfg.get("exchange")
if callable(ex):
try:
ex = ex()
except Exception:
ex = None
if ex is not None and symbol:
try:
t = ex.fetch_ticker(symbol)
@@ -750,6 +755,11 @@ def _tick_po_option_primary(
quote_fn = cfg.get("quote_option_contract")
ex_opt = cfg.get("exchange_options")
if callable(ex_opt):
try:
ex_opt = ex_opt()
except Exception:
ex_opt = None
bid = None
bid_sz = None
if callable(quote_fn) and ex_opt is not None:
@@ -765,6 +775,17 @@ def _tick_po_option_primary(
sheets = float(opt.get("size") or 1)
ct = float(opt.get("ct_mult") or 0.01)
contracts = float(perp.get("size") or plan.get("perp_size") or 0)
# 与持仓卡同口径:永续按平仓方向扫盘口 VWAP
from lib.hedge_plan.hedge_plan_book_lib import fetch_perp_close_vwap
book = fetch_perp_close_vwap(
ex,
symbol=symbol,
position_side=perp_dir,
contracts=contracts,
fallback_px=mark or entry,
)
perp_px = _sf(book.get("vwap")) or mark or entry
# 优先期权腿平仓(须买一流动性);盈利金额模式要求扣双边费后净利≥目标
if hit_opt:
@@ -781,7 +802,7 @@ def _tick_po_option_primary(
ct_mult=ct,
perp_direction=perp_dir,
perp_entry=float(entry or 0),
perp_mark=float(mark or 0),
perp_mark=float(perp_px or 0),
contracts=contracts,
contract_size=cs,
)