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:
+13
-2
@@ -12,6 +12,7 @@ import threading
|
||||
import time
|
||||
from typing import Callable
|
||||
|
||||
from ctp_settings import is_ctp_auto_connect_enabled
|
||||
from vnpy_bridge import ctp_try_auto_reconnect
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -27,13 +28,23 @@ def _auto_reconnect_enabled() -> bool:
|
||||
)
|
||||
|
||||
|
||||
def start_ctp_reconnect_worker(*, get_mode_fn: Callable[[], str], interval: int = RECONNECT_INTERVAL_SEC) -> None:
|
||||
def start_ctp_reconnect_worker(
|
||||
*,
|
||||
get_mode_fn: Callable[[], str],
|
||||
get_setting_fn: Callable[[str, str], str] | None = None,
|
||||
interval: int = RECONNECT_INTERVAL_SEC,
|
||||
) -> None:
|
||||
"""定时检测 CTP 连接,断线后自动重连。"""
|
||||
|
||||
def _loop() -> None:
|
||||
while True:
|
||||
try:
|
||||
if _auto_reconnect_enabled():
|
||||
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():
|
||||
mode = get_mode_fn()
|
||||
if ctp_try_auto_reconnect(mode):
|
||||
logger.debug("CTP 连接正常 [%s]", mode)
|
||||
|
||||
Reference in New Issue
Block a user