Fix empty recommend list and CTP premarket auto-connect.

Correct main_code order in product refresh, refresh on CTP connect, and limit reconnect to trading or premarket windows.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-06-29 08:24:10 +08:00
parent f8ff97f93d
commit b02c9d6ca0
10 changed files with 297 additions and 27 deletions
+7 -4
View File
@@ -12,6 +12,7 @@ import threading
import time
from typing import Callable
from ctp_premarket_connect import should_auto_connect_now
from ctp_settings import is_ctp_auto_connect_enabled
from vnpy_bridge import ctp_try_auto_reconnect
@@ -34,7 +35,7 @@ def start_ctp_reconnect_worker(
get_setting_fn: Callable[[str, str], str] | None = None,
interval: int = RECONNECT_INTERVAL_SEC,
) -> None:
"""定时检测 CTP 连接,断线后自动重连"""
"""定时检测 CTP 连接;仅在交易时段或盘前窗口内尝试重连,避免非交易时段反复登录"""
def _loop() -> None:
while True:
@@ -42,9 +43,11 @@ def start_ctp_reconnect_worker(
gs = get_setting_fn
if gs is None:
from fee_specs import get_setting as gs
if not is_ctp_auto_connect_enabled(gs):
pass
elif _auto_reconnect_enabled():
if (
is_ctp_auto_connect_enabled(gs)
and _auto_reconnect_enabled()
and should_auto_connect_now()
):
mode = get_mode_fn()
if ctp_try_auto_reconnect(mode):
logger.debug("CTP 连接正常 [%s]", mode)