修复粉尘桥拦开仓,并继续消除模拟盘嵌套握锁导致的 database is locked。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-10-07 11:28:29 +08:00
parent 030b237981
commit ea3e029eb9
7 changed files with 196 additions and 33 deletions
+21
View File
@@ -69,6 +69,12 @@ def open_coin_option_buy_full(
parts = inst_id.split("-")
underlying = (parts[0] if parts else "ETH").upper()
# 先清粉尘 pending 桥(自管短连接),再开业务连接,避免模拟盘读余额嵌套锁库
try:
_spot_bridge.clear_dust_pending_sell_bridges(cfg["get_db"], ex)
except Exception:
pass
conn = cfg["get_db"]()
try:
init_options_tables(conn)
@@ -142,6 +148,11 @@ def open_coin_option_buy_full(
buy_usdt = float(plan["buy_usdt"])
sheets = int(plan["sheets"])
# 买币/读余额(模拟盘写钱包)前必须提交释放锁
try:
conn.commit()
except Exception:
pass
# 1) 仅买「权利金×现货缓冲」所需 USDT,不全额兑换预算
coin_before = _spot_bridge.fetch_trading_coin_available(ex, underlying) or 0.0
buy = _spot_bridge.spot_market_buy_coin_with_usdt(ex, underlying=underlying, usdt_amount=buy_usdt)
@@ -161,6 +172,10 @@ def open_coin_option_buy_full(
inst_id=inst_id,
message="已买币,待开期权",
)
try:
conn.commit()
except Exception:
pass
# 等余额落账
time.sleep(1.5)
try:
@@ -501,6 +516,12 @@ def sweep_spot_after_options_flat(
except Exception as e:
return {"ok": False, "msg": f"持仓查询失败: {e}"}
# 先关掉只剩粉尘的 pending 桥,避免拦开仓又看不到重试按钮
try:
_spot_bridge.clear_dust_pending_sell_bridges(cfg["get_db"], exchange)
except Exception:
pass
sold: list[dict[str, Any]] = []
for uly in ("BTC", "ETH"):
if uly in live_uly: