fix: CTP连接改后台异步,避免多路重连互相阻塞

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-06-24 13:49:25 +08:00
parent 1d95950b5c
commit 049aaffdcf
4 changed files with 198 additions and 84 deletions
+16 -1
View File
@@ -586,8 +586,23 @@ def install_trading(app, *, login_required, require_nav, get_db, get_setting, se
@app.route("/api/ctp/connect", methods=["POST"])
@login_required
def api_ctp_connect():
from vnpy_bridge import ctp_start_connect
mode = get_trading_mode(get_setting)
force = bool((request.get_json(silent=True) or {}).get("force"))
body = request.get_json(silent=True) or {}
force = bool(body.get("force"))
info = ctp_start_connect(mode, force=force)
st = info.get("status") or ctp_status(mode)
acc = _ctp_account(mode) if st.get("connected") else {}
if st.get("connected"):
return jsonify({"ok": True, "status": st, "account": acc})
if info.get("connecting") or info.get("started"):
return jsonify({
"ok": True,
"connecting": True,
"status": st,
"account": acc,
})
try:
st = ctp_connect(mode, force=force)
acc = _ctp_account(mode)