fix: stabilize long-running quote refresh
This commit is contained in:
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user