feat: CTP/SimNow 配置迁入系统设置,登录失败即时报错

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-06-25 16:46:01 +08:00
parent 72361233a0
commit 5a6c89c662
7 changed files with 267 additions and 39 deletions
+18
View File
@@ -366,6 +366,9 @@ def init_db():
if not get_setting("ths_refresh_token") and os.getenv("THS_REFRESH_TOKEN"):
set_setting("ths_refresh_token", os.getenv("THS_REFRESH_TOKEN"))
from ctp_settings import seed_ctp_settings_from_env
seed_ctp_settings_from_env(set_setting)
os.makedirs(UPLOAD_DIR, exist_ok=True)
expire_old_plans()
@@ -1706,6 +1709,17 @@ def settings():
flash("移动保本缓冲无效")
return redirect(url_for("settings"))
flash("交易模式已保存")
elif action == "ctp":
from ctp_settings import save_ctp_settings_from_form
save_ctp_settings_from_form(request.form, set_setting)
try:
from vnpy_bridge import get_bridge
get_bridge().mark_disconnected()
except Exception:
pass
flash("CTP 配置已保存,请在持仓监控页重连 CTP")
elif action == "nav":
items = {k: request.form.get(f"nav_{k}") == "on" for k in NAV_TOGGLES}
save_nav_items(set_setting, items)
@@ -1736,11 +1750,15 @@ def settings():
ctp_st = ctp_status(get_trading_mode(get_setting))
except Exception:
pass
from ctp_settings import get_ctp_settings_for_ui
return render_template(
"settings.html",
webhook=webhook,
username=username,
quote_label=get_quote_source_label(ctp_connected=bool(ctp_st.get("connected"))),
ctp_status=ctp_st,
ctp_cfg=get_ctp_settings_for_ui(),
trading_mode=get_setting("trading_mode", "simulation"),
position_sizing_mode=get_setting("position_sizing_mode", "fixed"),
fixed_lots=get_setting("fixed_lots", "1"),