fix多笔买/卖回用VWAP计入真盈亏,卖完再结算并标记待卖回。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-10-13 10:38:46 +08:00
parent 42a7ee9961
commit 53a624633d
11 changed files with 451 additions and 28 deletions
+20 -4
View File
@@ -591,19 +591,35 @@ def sync_options_from_local_trades(
close_fee=cfee,
premium_ccy=ccy,
fee_ccy=str(r["premium_ccy"] or ccy or ""),
conn=conn,
bridge_id=r["bridge_id"],
)
# 能算新公式则写回;算不出则清空旧冻结并标记「缺价未核」
# 能算新公式则写回;卖回未完成→待卖回;算不出→缺价未核
status_label = "已平"
if pnl_u is not None and pnl_src != "none":
if pnl_src == "pending_sell":
status_label = "待卖回"
pnl_u = None
elif pnl_u is not None and pnl_src not in ("none", "pending_sell"):
if frozen_usdt is None or abs(float(frozen_usdt) - float(pnl_u)) > 0.05:
try:
from lib.options.options_pnl_settle_lib import resolve_spot_vwap_prices
opx, cpx, _g = resolve_spot_vwap_prices(
conn,
bridge_id=r["bridge_id"],
open_index_px=open_idx,
close_index_px=sell_idx,
)
conn.execute(
"""
UPDATE options_trades
SET realized_pnl_usdt = ?, pnl_settled = 1
SET realized_pnl_usdt = ?,
open_index_px = COALESCE(?, open_index_px),
close_index_px = COALESCE(?, close_index_px),
pnl_settled = 1
WHERE id = ?
""",
(pnl_u, trade_id),
(pnl_u, opx, cpx, trade_id),
)
except Exception:
pass