修复页面握库拉余额导致 database is locked 整页 500。
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1619,22 +1619,38 @@ def account_risk_status(conn):
|
||||
ensure_account_risk_schema,
|
||||
)
|
||||
|
||||
ensure_account_risk_schema(conn)
|
||||
now = app_now()
|
||||
st = compute_account_risk_status(
|
||||
conn,
|
||||
trading_day=get_trading_day(),
|
||||
now=now,
|
||||
fmt_local_ms=ms_to_app_local_str,
|
||||
)
|
||||
st = enrich_risk_status_countdown(st, now=now, daily_reset_hour=TRADING_DAY_RESET_HOUR)
|
||||
from lib.trade.trade_labels_lib import count_position_limit_active_monitors
|
||||
try:
|
||||
ensure_account_risk_schema(conn)
|
||||
st = compute_account_risk_status(
|
||||
conn,
|
||||
trading_day=get_trading_day(),
|
||||
now=now,
|
||||
fmt_local_ms=ms_to_app_local_str,
|
||||
)
|
||||
st = enrich_risk_status_countdown(st, now=now, daily_reset_hour=TRADING_DAY_RESET_HOUR)
|
||||
from lib.trade.trade_labels_lib import count_position_limit_active_monitors
|
||||
|
||||
return apply_position_limit_risk(
|
||||
st,
|
||||
count_position_limit_active_monitors(conn),
|
||||
max_active_positions=MAX_ACTIVE_POSITIONS,
|
||||
)
|
||||
return apply_position_limit_risk(
|
||||
st,
|
||||
count_position_limit_active_monitors(conn),
|
||||
max_active_positions=MAX_ACTIVE_POSITIONS,
|
||||
)
|
||||
except Exception as e:
|
||||
print(f"[account_risk_status] {e}", flush=True)
|
||||
return {
|
||||
"enabled": True,
|
||||
"status": "normal",
|
||||
"status_label": "正常",
|
||||
"can_trade": True,
|
||||
"reason": "",
|
||||
"cooloff_until_ms": None,
|
||||
"cooloff_until": None,
|
||||
"manual_close_count": 0,
|
||||
"daily_loss_count": 0,
|
||||
"daily_frozen": False,
|
||||
"freeze_remaining_sec": 0,
|
||||
}
|
||||
|
||||
|
||||
def hub_user_initiated_close(
|
||||
@@ -3863,6 +3879,11 @@ def render_main_page(page="options", embed_mode=None):
|
||||
conn = get_db()
|
||||
session_row = ensure_session(conn, trading_day)
|
||||
local_current_capital = float(session_row["current_capital"])
|
||||
try:
|
||||
conn.commit()
|
||||
except Exception:
|
||||
pass
|
||||
conn.close()
|
||||
from lib.instance.instance_embed_context_lib import (
|
||||
embed_render_plan,
|
||||
minimal_stats_bundle,
|
||||
@@ -3875,6 +3896,7 @@ def render_main_page(page="options", embed_mode=None):
|
||||
)
|
||||
|
||||
plan = embed_render_plan(page, embed_mode)
|
||||
# 拉交易所余额前不持库连接,避免 database is locked → 页面 500
|
||||
if plan.exchange_capitals:
|
||||
funding_capital, trading_capital = get_exchange_capitals()
|
||||
else:
|
||||
@@ -3938,6 +3960,7 @@ def render_main_page(page="options", embed_mode=None):
|
||||
options_margin_mode = "coin"
|
||||
options_underly = "ETH"
|
||||
recommended_capital = get_recommended_capital(capital_for_sizing)
|
||||
conn = get_db()
|
||||
key_list = (
|
||||
conn.execute("SELECT * FROM key_monitors").fetchall() if plan.key_list else []
|
||||
)
|
||||
@@ -4328,7 +4351,13 @@ def api_account_snapshot():
|
||||
conn = get_db()
|
||||
session_row = ensure_session(conn, trading_day)
|
||||
local_current_capital = float(session_row["current_capital"])
|
||||
try:
|
||||
conn.commit()
|
||||
except Exception:
|
||||
pass
|
||||
conn.close()
|
||||
force_refresh = (request.args.get("force") or "").strip().lower() in ("1", "true", "yes")
|
||||
# 拉交易所余额前不持库连接
|
||||
funding_capital, trading_capital = get_exchange_capitals(force=force_refresh)
|
||||
funding_usdt = round(funding_capital, FUNDS_DECIMALS) if funding_capital is not None else None
|
||||
# 顶栏只展示交易所余额;勿用会话资金回退(避免模拟盘 30U 残留到实盘)
|
||||
@@ -4372,6 +4401,7 @@ def api_account_snapshot():
|
||||
options_margin_mode = "coin"
|
||||
options_underly = "ETH"
|
||||
recommended_capital = get_recommended_capital(capital_for_sizing)
|
||||
conn = get_db()
|
||||
from lib.trade.trade_labels_lib import count_position_limit_active_monitors
|
||||
|
||||
position_limit_count = count_position_limit_active_monitors(conn)
|
||||
|
||||
Reference in New Issue
Block a user