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

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
+26 -3
View File
@@ -458,6 +458,13 @@ def _sync_options_trades(
conn.commit()
finally:
conn.close()
try:
from lib.options.options_coin_open_lib import sweep_spot_after_options_flat
sweep_spot_after_options_flat(cfg, ex)
_mark_balances_stale(cfg)
except Exception:
pass
def register_options_routes(app: Flask, cfg: dict[str, Any]) -> None:
@@ -1694,12 +1701,20 @@ def register_options_routes(app: Flask, cfg: dict[str, Any]) -> None:
data = request.get_json(silent=True) or {}
underlying = (data.get("underlying") or cfg.get("default_underly") or "ETH").strip().upper()
inst_id = (data.get("inst_id") or "").strip() or None
from lib.options.options_spot_bridge_lib import sell_residual_after_option_flat
conn = cfg["get_db"]()
try:
init_options_tables(conn)
from lib.options.options_spot_bridge_lib import sell_residual_after_option_flat
try:
conn.commit()
except Exception:
pass
out = sell_residual_after_option_flat(conn, ex, underlying=underlying, inst_id=inst_id)
try:
conn.commit()
except Exception:
pass
if out.get("ok"):
_mark_balances_stale(cfg)
return jsonify(out)
@@ -1976,12 +1991,20 @@ def _start_monitor_thread(app: Flask, cfg: dict[str, Any]) -> None:
return 0
live_ids = {str(p.get("instId") or "") for p in raw if str(p.get("instId") or "")}
reconcile_live_open_trades(conn, live_inst_ids=live_ids)
return sync_open_options_trades(
n = sync_open_options_trades(
conn,
live_inst_ids=live_ids,
fetch_history_fn=lambda inst_id: fetch_option_position_history(ex, inst_id),
notify_cfg=cfg,
)
try:
from lib.options.options_coin_open_lib import sweep_spot_after_options_flat
sweep_spot_after_options_flat(cfg, ex)
_mark_balances_stale(cfg)
except Exception:
pass
return n
def _target_close(inst_id: str) -> dict[str, Any]:
from lib.options.options_target_lib import close_option_by_bid_depth