修复币本位平仓/到期后未自动卖回,并消除模拟盘卖币时数据库锁定。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-10-07 10:47:25 +08:00
parent 474e0742f7
commit 265317672c
6 changed files with 156 additions and 4 deletions
+34
View File
@@ -285,6 +285,7 @@ def sync_open_options_trades(
"""
).fetchall()
updated = 0
closed_inst_ids: list[str] = []
now_ms = int(time.time() * 1000)
for row in rows:
inst_id = str(row["inst_id"] or "")
@@ -353,6 +354,7 @@ def sync_open_options_trades(
),
)
updated += 1
closed_inst_ids.append(inst_id)
if notify_cfg is not None:
try:
from lib.options.options_notify_lib import notify_options_close
@@ -373,9 +375,41 @@ def sync_open_options_trades(
pass
if notify_cfg is not None:
_notify_recent_unsent_expiry_closes(conn, notify_cfg)
_sell_spot_after_synced_closes(notify_cfg, closed_inst_ids)
return updated
def _sell_spot_after_synced_closes(
cfg: dict[str, Any],
closed_inst_ids: list[str],
) -> None:
"""同步关仓(含到期)后卖回币本位残留;空仓时再扫一遍交易户."""
if not isinstance(cfg, dict):
return
ex = cfg.get("exchange_options")
if ex is None:
return
try:
from lib.options.options_coin_open_lib import (
maybe_sell_spot_after_close,
sweep_spot_after_options_flat,
)
seen: set[str] = set()
for inst_id in closed_inst_ids or []:
iid = str(inst_id or "").strip()
if not iid or iid in seen:
continue
seen.add(iid)
try:
maybe_sell_spot_after_close(cfg, ex, inst_id=iid)
except Exception:
pass
sweep_spot_after_options_flat(cfg, ex)
except Exception:
pass
def _notify_recent_unsent_expiry_closes(
conn: sqlite3.Connection,
notify_cfg: dict[str, Any],