This commit is contained in:
2026-06-24 11:02:42 +08:00
parent c59c1b9fc4
commit ee8fc60eae
7 changed files with 105 additions and 16 deletions
+15 -8
View File
@@ -545,11 +545,19 @@ class RealQmtV:
PrintLog(LogLevel.ERROR, f'- [市场数据订阅失败-{e}]')
def _on_market_data(self, datas: dict):
"""xtquant 行情回调 — 收到行情即标记市场活跃"""
"""xtquant 行情回调 — 收到行情即标记市场活跃(但需满足 09:15 后才激活)"""
self.lastMarketDataUpdateTimestamp = time.time()
if not self.isMarketActive:
self.isMarketActive = True
eBus.event_bus.publish(eBus.EventMarketActiveSwitch, True)
# 检查当前时间是否已过 09:15(集合竞价结束后才激活市场状态)
import zoneinfo
beijing_tz = zoneinfo.ZoneInfo("Asia/Shanghai")
now = datetime.datetime.now(beijing_tz)
t = now.time()
activation_time = datetime.time(9, 15)
if t >= activation_time:
self.isMarketActive = True
eBus.event_bus.publish(eBus.EventMarketActiveSwitch, True)
PrintLog(LogLevel.INFO, f'- [行情] 市场激活 (时间 {t.strftime("%H:%M:%S")} >= 09:15)')
eBus.event_bus.publish(eBus.MarketDataUpdate, datas)
def _is_trading_time(self) -> bool:
@@ -567,17 +575,16 @@ class RealQmtV:
return (morning_start <= t <= morning_end) or (afternoon_start <= t <= afternoon_end)
def _market_data_watchdog(self):
"""行情活跃监控 — 超过 120 秒无行情 且 非交易时间 则标记市场不活跃"""
"""行情活跃监控 — 超过 120 秒无行情 则标记市场不活跃(无论是否交易时间)"""
while True:
time.sleep(15)
if self.isMarketActive:
elapsed = time.time() - self.lastMarketDataUpdateTimestamp
# 非交易时间直接标记休市;交易时间内才用超时判断
if not self._is_trading_time() or elapsed > 120:
# 只有超过 120 秒无行情才标记不活跃,不再区分交易时间
if elapsed > 120:
self.isMarketActive = False
eBus.event_bus.publish(eBus.EventMarketActiveSwitch, False)
if not self._is_trading_time():
PrintLog(LogLevel.INFO, '- [行情] 非交易时间,市场标记为不活跃')
PrintLog(LogLevel.INFO, f'- [行情] 超过 {elapsed:.0f} 秒无数据,市场标记为不活跃')
def stopMarketDataSubscription(self):
"""停止市场数据订阅"""