修复持仓轮询时 SQLite database is locked 错误。
单连接复用并提交风控写入,启用 WAL 与 busy_timeout,缓存风控表 schema 初始化。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+38
-30
@@ -326,18 +326,23 @@ def install_trading(app, *, login_required, get_db, get_setting, set_setting, fe
|
||||
@login_required
|
||||
def api_trading_live():
|
||||
conn = get_db()
|
||||
init_strategy_tables(conn)
|
||||
mode = get_trading_mode(get_setting)
|
||||
ctp_st = ctp_status(mode)
|
||||
rows = _build_trading_live_rows(conn)
|
||||
conn.close()
|
||||
return jsonify({
|
||||
"rows": rows,
|
||||
"capital": _capital(get_db()),
|
||||
"ctp_status": ctp_st,
|
||||
"trading_mode_label": trading_mode_label(get_setting),
|
||||
"risk_status": get_risk_status(get_db()),
|
||||
})
|
||||
try:
|
||||
init_strategy_tables(conn)
|
||||
mode = get_trading_mode(get_setting)
|
||||
ctp_st = ctp_status(mode)
|
||||
rows = _build_trading_live_rows(conn)
|
||||
capital = _capital(conn)
|
||||
risk = get_risk_status(conn)
|
||||
conn.commit()
|
||||
return jsonify({
|
||||
"rows": rows,
|
||||
"capital": capital,
|
||||
"ctp_status": ctp_st,
|
||||
"trading_mode_label": trading_mode_label(get_setting),
|
||||
"risk_status": risk,
|
||||
})
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
@app.route("/api/trading/close", methods=["POST"])
|
||||
@login_required
|
||||
@@ -595,24 +600,27 @@ def install_trading(app, *, login_required, get_db, get_setting, set_setting, fe
|
||||
@login_required
|
||||
def api_account_snapshot():
|
||||
conn = get_db()
|
||||
init_strategy_tables(conn)
|
||||
mode = get_trading_mode(get_setting)
|
||||
ctp_st = ctp_status(mode)
|
||||
capital = _capital(conn)
|
||||
risk = get_risk_status(conn)
|
||||
ctp_acc = _ctp_account(mode) if ctp_st.get("connected") else {}
|
||||
positions = _ctp_positions(mode) if ctp_st.get("connected") else []
|
||||
conn.close()
|
||||
return jsonify({
|
||||
"capital": capital,
|
||||
"trading_mode": mode,
|
||||
"trading_mode_label": trading_mode_label(get_setting),
|
||||
"sizing_mode": get_sizing_mode(get_setting),
|
||||
"risk_status": risk,
|
||||
"ctp_status": ctp_st,
|
||||
"ctp_account": ctp_acc,
|
||||
"positions": positions,
|
||||
})
|
||||
try:
|
||||
init_strategy_tables(conn)
|
||||
mode = get_trading_mode(get_setting)
|
||||
ctp_st = ctp_status(mode)
|
||||
capital = _capital(conn)
|
||||
risk = get_risk_status(conn)
|
||||
conn.commit()
|
||||
ctp_acc = _ctp_account(mode) if ctp_st.get("connected") else {}
|
||||
positions = _ctp_positions(mode) if ctp_st.get("connected") else []
|
||||
return jsonify({
|
||||
"capital": capital,
|
||||
"trading_mode": mode,
|
||||
"trading_mode_label": trading_mode_label(get_setting),
|
||||
"sizing_mode": get_sizing_mode(get_setting),
|
||||
"risk_status": risk,
|
||||
"ctp_status": ctp_st,
|
||||
"ctp_account": ctp_acc,
|
||||
"positions": positions,
|
||||
})
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
@app.route("/api/recommend/list")
|
||||
@login_required
|
||||
|
||||
Reference in New Issue
Block a user