fix卖回VWAP必须落库并覆盖指数占位价,禁止预算反推开仓价。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-10-13 11:55:42 +08:00
parent dd979d9dd0
commit 11a083470d
7 changed files with 378 additions and 37 deletions
+22 -1
View File
@@ -778,6 +778,13 @@ def sell_residual_after_option_flat(
}
recovered = _safe_float(sell.get("usdt_recovered"))
sold_amt = _safe_float(sell.get("coin_sold"))
# 缺 USDT 回报时用成交价×币量补,保证 close_sell VWAP 能落库
if (recovered is None or recovered <= 0) and sold_amt is not None and sold_amt > 0:
fill_px = _safe_float(sell.get("fill_px"))
if fill_px is not None and fill_px > 0:
recovered = round(float(sold_amt) * float(fill_px), 8)
sell = dict(sell)
sell["usdt_recovered"] = recovered
# 平仓后卖回(可多笔):累加 close_sell_* 供卖回 VWAP;开仓多余卖回不走这里
add_bridge_close_sell_fill(
c,
@@ -809,6 +816,7 @@ def sell_residual_after_option_flat(
"bridge_id": bid,
"bridge_status": BRIDGE_PENDING_SELL,
}
sell_vwap = bridge_sell_vwap(c, bid)
update_bridge(
c,
bid,
@@ -818,13 +826,26 @@ def sell_residual_after_option_flat(
message="期权已平,币已卖回 USDT",
close=True,
)
# 卖回 VWAP 写入关联已平仓(覆盖平仓时指数占位价)
if sell_vwap is not None and float(sell_vwap) > 0:
try:
c.execute(
"""
UPDATE options_trades
SET close_index_px = ?
WHERE bridge_id = ? AND status = 'closed'
""",
(float(sell_vwap), int(bid)),
)
except Exception:
pass
return {
"ok": True,
"sell": sell,
"bridge_id": bid,
"bridge_status": BRIDGE_CLOSED,
"sell_complete": True,
"sell_vwap": bridge_sell_vwap(c, bid),
"sell_vwap": sell_vwap,
}
if get_db is not None: