fix: stabilize long-running quote refresh

This commit is contained in:
王鹏
2026-11-09 10:42:08 +08:00
parent b7e0894f4b
commit 5f4df03581
6 changed files with 281 additions and 84 deletions

View File

@@ -58,15 +58,28 @@ class TencentQuoteProvider:
self.retries = retries
self._fetcher = fetcher or _default_fetcher
def fetch_quotes(self, instruments: Iterable[Instrument]) -> dict[str, QuoteSnapshot]:
@property
def uses_default_fetcher(self) -> bool:
"""Whether the provider can be driven by Qt's asynchronous network API."""
return self._fetcher is _default_fetcher
def build_request_url(self, instruments: Iterable[Instrument]) -> str | None:
symbols = [infer_tencent_symbol(instrument.code) for instrument in instruments]
if not symbols:
return {}
query = ",".join(symbols)
url = f"{self.endpoint}{query}"
raw = self._fetch_with_retry(url)
return None
return f"{self.endpoint}{','.join(symbols)}"
@staticmethod
def parse_response(raw: bytes) -> dict[str, QuoteSnapshot]:
return {quote.code: quote for quote in parse_tencent_response(raw)}
def fetch_quotes(self, instruments: Iterable[Instrument]) -> dict[str, QuoteSnapshot]:
url = self.build_request_url(instruments)
if url is None:
return {}
raw = self._fetch_with_retry(url)
return self.parse_response(raw)
def _fetch_with_retry(self, url: str) -> bytes:
last_error: Exception | None = None
for _ in range(self.retries + 1):