Add CTP auto-connect toggle to stop off-hours reconnect attempts.
When disabled, disconnect immediately and skip auto-reconnect, premarket connect, and TCP probes that fail outside SimNow trading hours. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -34,6 +34,30 @@ LIVE_FIELDS: tuple[tuple[str, str, str, str], ...] = (
|
||||
|
||||
PASSWORD_DB_KEYS = frozenset({"simnow_password", "ctp_live_password"})
|
||||
|
||||
CTP_AUTO_CONNECT_KEY = "ctp_auto_connect"
|
||||
CTP_DISABLED_HINT = "CTP 自动连接已关闭(非交易时段建议关闭,避免反复连接失败)"
|
||||
|
||||
|
||||
def is_ctp_auto_connect_enabled(get_setting=None) -> bool:
|
||||
"""系统设置:是否允许 CTP 连接(含自动重连、盘前连接、手动连接)。"""
|
||||
if get_setting is None:
|
||||
from fee_specs import get_setting as _gs
|
||||
|
||||
get_setting = _gs
|
||||
val = (get_setting(CTP_AUTO_CONNECT_KEY, "1") or "1").strip().lower()
|
||||
return val in ("1", "true", "yes", "on")
|
||||
|
||||
|
||||
def save_ctp_auto_connect(form: Any, set_setting: Callable[[str, str], None]) -> bool:
|
||||
enabled = (form.get("ctp_auto_connect") or "").strip().lower() in (
|
||||
"1",
|
||||
"on",
|
||||
"true",
|
||||
"yes",
|
||||
)
|
||||
set_setting(CTP_AUTO_CONNECT_KEY, "1" if enabled else "0")
|
||||
return enabled
|
||||
|
||||
|
||||
def _get_db_setting(key: str, default: str = "") -> str:
|
||||
from fee_specs import get_setting
|
||||
@@ -85,6 +109,7 @@ def get_ctp_settings_for_ui() -> dict[str, Any]:
|
||||
if db_key in PASSWORD_DB_KEYS:
|
||||
ui[f"{db_key}_set"] = bool(ui[db_key])
|
||||
ui[db_key] = ""
|
||||
ui["ctp_auto_connect"] = is_ctp_auto_connect_enabled()
|
||||
return ui
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user