This commit is contained in:
aaron 2026-02-20 22:29:07 +08:00
parent 466ff60b57
commit 753ef72ea0

View File

@ -41,18 +41,18 @@ class PriceMonitorService:
self._poll_interval = 3 # 轮询间隔(秒) self._poll_interval = 3 # 轮询间隔(秒)
self._session = requests.Session() self._session = requests.Session()
logger.info("价格监控服务初始化完成(轮询模式)") logger.info(f"[PriceMonitor:{id(self)}] 价格监控服务初始化完成(轮询模式)")
def start(self): def start(self):
"""启动价格轮询""" """启动价格轮询"""
if self.running: if self.running:
logger.debug("价格监控服务已在运行") logger.debug(f"[PriceMonitor:{id(self)}] 价格监控服务已在运行")
return return
self.running = True self.running = True
def _poll_loop(): def _poll_loop():
logger.info(f"价格轮询已启动,间隔 {self._poll_interval}") logger.info(f"[PriceMonitor:{id(self)}] 价格轮询已启动,间隔 {self._poll_interval}")
while self.running: while self.running:
try: try:
self._fetch_prices() self._fetch_prices()
@ -148,14 +148,19 @@ class PriceMonitorService:
Args: Args:
symbol: 交易对 "BTCUSDT" symbol: 交易对 "BTCUSDT"
""" """
import traceback
symbol = symbol.upper() symbol = symbol.upper()
# 添加调用栈追踪
stack = traceback.extract_stack()
caller = stack[-2] if len(stack) >= 2 else None
if symbol in self.subscribed_symbols: if symbol in self.subscribed_symbols:
logger.debug(f"已订阅 {symbol}") logger.debug(f"[PriceMonitor:{id(self)}] {symbol} 已订阅,跳过 (来自: {caller})")
return return
self.subscribed_symbols.add(symbol) self.subscribed_symbols.add(symbol)
logger.info(f"已订阅 {symbol} 价格更新") logger.info(f"[PriceMonitor:{id(self)}] 已订阅 {symbol} 价格更新 (来自: {caller},当前订阅: {self.subscribed_symbols})")
# 如果服务未启动,自动启动 # 如果服务未启动,自动启动
if not self.running: if not self.running: