Fix server hang: stop CTP reconnect storm and throttle live account polling.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -2904,27 +2904,27 @@ def ctp_start_connect(mode: str, *, force: bool = False, scheduled: bool = False
|
||||
|
||||
|
||||
def ctp_session_needs_reconnect(mode: str) -> bool:
|
||||
"""连接看似在线但不可交易、无资金回报或会话过旧时需强制重连。"""
|
||||
"""连接看似在线但不可交易或会话过旧时需强制重连(连接进行中不重复发起)。"""
|
||||
if _use_ctp_worker_client():
|
||||
st = ctp_ipc_client.status(mode)
|
||||
if st.get("connecting"):
|
||||
return False
|
||||
if not st.get("connected"):
|
||||
return True
|
||||
if not st.get("td_logged_in"):
|
||||
return True
|
||||
return False
|
||||
b = get_bridge()
|
||||
if b.connect_in_progress():
|
||||
return False
|
||||
if b.connected_mode != mode:
|
||||
return True
|
||||
since_connect = time.time() - float(getattr(b, "_last_connect_ok_ts", 0) or 0)
|
||||
if since_connect < 120:
|
||||
return False
|
||||
if not b._td_logged_in():
|
||||
return True
|
||||
age = time.time() - float(getattr(b, "_last_connect_ok_ts", 0) or 0)
|
||||
if age > 3 * 3600:
|
||||
return True
|
||||
try:
|
||||
acc = b.get_account()
|
||||
if float(acc.get("balance") or 0) <= 0:
|
||||
return True
|
||||
except Exception:
|
||||
if since_connect > 3 * 3600:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
Reference in New Issue
Block a user