fix卖回VWAP必须落库并覆盖指数占位价,禁止预算反推开仓价。
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -585,52 +585,48 @@ def sync_options_from_local_trades(
|
||||
|
||||
status_label = "已平"
|
||||
pnl_u = None
|
||||
# 价已冻则只用库内价;缺价才问桥 VWAP(避免刷新改均价)
|
||||
prices_frozen = (
|
||||
open_idx is not None
|
||||
and open_idx > 0
|
||||
and sell_idx is not None
|
||||
and sell_idx > 0
|
||||
# 始终问桥:买/卖回 VWAP 优先于库内指数占位价(防预算反推开仓价、平仓指数冒充卖回价)
|
||||
opx, cpx, _gate = resolve_spot_vwap_prices(
|
||||
conn,
|
||||
bridge_id=r["bridge_id"],
|
||||
open_index_px=open_idx,
|
||||
close_index_px=sell_idx,
|
||||
)
|
||||
use_bridge = None if prices_frozen else r["bridge_id"]
|
||||
pnl_u, pnl_src = resolve_true_pnl_usdt_from_trade(
|
||||
premium_paid=prem,
|
||||
premium_received=r["premium_received"],
|
||||
realized_pnl=r["realized_pnl"],
|
||||
open_index_px=open_idx if (open_idx is not None and open_idx > 0) else None,
|
||||
close_index_px=sell_idx,
|
||||
open_index_px=opx,
|
||||
close_index_px=cpx,
|
||||
open_fee=ofee,
|
||||
close_fee=cfee,
|
||||
premium_ccy=ccy,
|
||||
fee_ccy=str(r["premium_ccy"] or ccy or ""),
|
||||
conn=conn if use_bridge is not None else None,
|
||||
bridge_id=use_bridge,
|
||||
conn=conn,
|
||||
bridge_id=r["bridge_id"],
|
||||
)
|
||||
if pnl_src == "pending_sell":
|
||||
status_label = "待卖回"
|
||||
pnl_u = None
|
||||
elif pnl_u is not None and pnl_src not in ("none", "pending_sell"):
|
||||
try:
|
||||
opx, cpx = open_idx, sell_idx
|
||||
if not prices_frozen:
|
||||
opx, cpx, _g = resolve_spot_vwap_prices(
|
||||
conn,
|
||||
bridge_id=r["bridge_id"],
|
||||
open_index_px=open_idx,
|
||||
close_index_px=sell_idx,
|
||||
)
|
||||
# 真盈亏U每次刷新按固定量+价重算;均价只补缺不覆盖
|
||||
# VWAP 非空时覆盖指数占位;币量字段不改
|
||||
conn.execute(
|
||||
"""
|
||||
UPDATE options_trades
|
||||
SET realized_pnl_usdt = ?,
|
||||
open_index_px = COALESCE(open_index_px, ?),
|
||||
close_index_px = COALESCE(close_index_px, ?),
|
||||
open_index_px = COALESCE(?, open_index_px),
|
||||
close_index_px = COALESCE(?, close_index_px),
|
||||
pnl_settled = 1
|
||||
WHERE id = ?
|
||||
""",
|
||||
(pnl_u, opx, cpx, trade_id),
|
||||
)
|
||||
if opx is not None and opx > 0:
|
||||
open_idx = opx
|
||||
open_idx_for_prem = opx
|
||||
if cpx is not None and cpx > 0:
|
||||
sell_idx = cpx
|
||||
except Exception:
|
||||
pass
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user