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:
@@ -74,6 +74,7 @@ def _load_persisted_last_error() -> str:
|
||||
|
||||
_position_refresh_callback: Optional[Callable[[], None]] = None
|
||||
_tick_sl_tp_callback: Optional[Callable[[str, str, float], None]] = None
|
||||
_ctp_connected_callback: Optional[Callable[[str], None]] = None
|
||||
_position_refresh_debounce_lock = threading.Lock()
|
||||
_position_refresh_debounce_ts: float = 0.0
|
||||
|
||||
@@ -89,6 +90,24 @@ def set_tick_sl_tp_callback(fn: Optional[Callable[[str, str, float], None]]) ->
|
||||
_tick_sl_tp_callback = fn
|
||||
|
||||
|
||||
def set_ctp_connected_callback(fn: Optional[Callable[[str], None]]) -> None:
|
||||
"""CTP 交易通道登录成功后回调(mode=simulation|live)。"""
|
||||
global _ctp_connected_callback
|
||||
_ctp_connected_callback = fn
|
||||
|
||||
|
||||
def _fire_ctp_connected_callback(mode: str) -> None:
|
||||
fn = _ctp_connected_callback
|
||||
if not fn:
|
||||
return
|
||||
try:
|
||||
threading.Thread(
|
||||
target=fn, args=(mode,), daemon=True, name="ctp-connected-cb",
|
||||
).start()
|
||||
except Exception as exc:
|
||||
logger.debug("ctp connected callback: %s", exc)
|
||||
|
||||
|
||||
def _fire_position_refresh_callback() -> None:
|
||||
fn = _position_refresh_callback
|
||||
if not fn:
|
||||
@@ -634,6 +653,7 @@ class CtpBridge:
|
||||
except Exception as exc:
|
||||
logger.debug("post-connect calibrate: %s", exc)
|
||||
_fire_position_refresh_burst()
|
||||
_fire_ctp_connected_callback(mode)
|
||||
return
|
||||
finally:
|
||||
self._ee.unregister(EVENT_LOG, _on_log)
|
||||
|
||||
Reference in New Issue
Block a user