This commit is contained in:
2026-06-16 11:07:09 +08:00
parent 2d8a0c3bca
commit 2e3202968d
4 changed files with 223 additions and 57 deletions
+5 -13
View File
@@ -536,11 +536,7 @@ class RealQmtV:
seq = xtdata.subscribe_whole_quote(['SH', 'SZ'], self._on_market_data)
PrintLog(LogLevel.INFO, f'- [市场数据订阅成功-真实] seq={seq}')
# 订阅成功即标记市场活跃,避免策略初始化时因等待首条数据被误判为休市
self.isMarketActive = True
eBus.event_bus.publish(eBus.EventMarketActiveSwitch, True)
# 启动行情活跃监控线程
# 启动行情活跃监控线程(默认不活跃,收到行情后激活)
self._market_data_thread = threading.Thread(
target=self._market_data_watchdog, daemon=True
)
@@ -549,24 +545,20 @@ class RealQmtV:
PrintLog(LogLevel.ERROR, f'- [市场数据订阅失败-{e}]')
def _on_market_data(self, datas: dict):
"""xtquant 行情回调 — 将数据转换为事件总线格式"""
"""xtquant 行情回调 — 收到行情即标记市场活跃"""
self.lastMarketDataUpdateTimestamp = time.time()
if not self.isMarketActive:
self.isMarketActive = True
eBus.event_bus.publish(eBus.EventMarketActiveSwitch, True)
# xtquant 返回 "600519.SH" 格式 keyUI 使用纯代码 "600519"
# 构建同时包含两种 key 的数据确保匹配
# 直接发布 xtquant 原始数据(代码带 .SH/.SZ 后缀)
eBus.event_bus.publish(eBus.MarketDataUpdate, datas)
def _market_data_watchdog(self):
"""行情活跃监控 — 超过 30 秒无数据则标记市场不活跃"""
"""行情活跃监控 — 超过 120 秒无行情则标记市场不活跃"""
while True:
time.sleep(10)
time.sleep(15)
if self.isMarketActive:
elapsed = time.time() - self.lastMarketDataUpdateTimestamp
if elapsed > 30:
if elapsed > 120:
self.isMarketActive = False
eBus.event_bus.publish(eBus.EventMarketActiveSwitch, False)
PrintLog(LogLevel.WARNING, f'- [行情] 超过 {elapsed:.0f} 秒无更新,市场标记为不活跃')