ZhuLinsen/daily_stock_analysis · error · DataFetchError

TencentFetcher unsupported stock code: {stock_code}

Error message

TencentFetcher unsupported stock code: {stock_code}

What it means

DataFetchError raised in TencentFetcher._fetch_raw_data when _to_tencent_symbol(code) returns falsy after normalize_stock_code — the code's market/format cannot be mapped to a Tencent kline symbol (shXXXXXX/szXXXXXX/hkXXXXX/us... style). It fails before the HTTP request to web.ifzq.gtimg.cn is made.

Source

Thrown at data_provider/tencent_fetcher.py:46

    name = "TencentFetcher"
    # This direct endpoint is the last-resort A-share daily fallback. Keeping
    # it at priority 0 made a single Efinance failure skip the richer built-in
    # fallback chain and try Tencent before AkShare/PyTDX/Baostock/YFinance.
    priority = 5
    allow_empty_daily_data = True

    _KLINE_ENDPOINT = "https://web.ifzq.gtimg.cn/appstock/app/fqkline/get"
    _HTTP_TIMEOUT_SECONDS = 8

    def __init__(self) -> None:
        self.priority = _read_tencent_priority()

    def _fetch_raw_data(self, stock_code: str, start_date: str, end_date: str) -> pd.DataFrame:
        code = normalize_stock_code(stock_code)
        symbol = _to_tencent_symbol(code)
        if not symbol:
            raise DataFetchError(f"TencentFetcher unsupported stock code: {stock_code}")

        lookback = _estimate_lookback_days(start_date=start_date, end_date=end_date)
        explicit_start = _format_tencent_date(start_date)
        explicit_end = _format_tencent_date(end_date)
        explicit_window = (
            f"{explicit_start},{explicit_end}"
            if explicit_start and explicit_end
            else ","
        )
        response = requests.get(
            self._KLINE_ENDPOINT,
            params={"param": f"{symbol},day,{explicit_window},{lookback},qfq"},
            headers={"User-Agent": "Mozilla/5.0", "Accept": "application/json,text/plain,*/*"},
            timeout=self._HTTP_TIMEOUT_SECONDS,
        )
        response.raise_for_status()
        payload = response.json()
        rows = _extract_kline_rows(payload, symbol=symbol)

View on GitHub (pinned to 5159bd72e8)

Solutions

  1. Normalize the code first (normalize_stock_code) and confirm the market is supported by Tencent klines (A股, 港股, 美股主要标的).
  2. Extend or fix _to_tencent_symbol if a legitimate market format is unmapped.
  3. Let the DataFetcherManager fall back to the next provider on this error instead of calling TencentFetcher directly for exotic codes.

Example fix

# before
df = tencent_fetcher.get_stock_data("832566", start, end)  # DataFetchError if BSE unmapped

# after
from src.utils.stock_utils import normalize_stock_code
code = normalize_stock_code(raw)
symbol = _to_tencent_symbol(code)
if symbol:
    df = tencent_fetcher.get_stock_data(code, start, end)
else:
    df = manager.get_stock_data(code, start, end)
Defensive patterns

Strategy: validation

Validate before calling

from data_provider.tencent_fetcher import _to_tencent_symbol
from src.utils.stock_utils import normalize_stock_code

if not _to_tencent_symbol(normalize_stock_code(stock_code)):
    df = manager.get_stock_data(stock_code, start, end)  # skip Tencent
else:
    df = tencent_fetcher.get_stock_data(stock_code, start, end)

Type guard

def tencent_supports(code: str) -> bool:
    """True when the normalized code maps to a Tencent kline symbol."""
    return bool(_to_tencent_symbol(normalize_stock_code(code)))

Try / catch

try:
    df = tencent_fetcher.get_stock_data(code, start, end)
except DataFetchError as e:
    if "unsupported stock code" in str(e):
        df = manager.get_stock_data(code, start, end)
    else:
        raise

Prevention

When it happens

Trigger: Calling TencentFetcher daily-data fetch with codes outside its supported markets or in unrecognized formats: BSE codes, exotic suffixes, malformed tickers.

Common situations: TencentFetcher enabled in a multi-market chain while the watchlist contains 北交所 or unusual codes; upstream normalization producing formats _to_tencent_symbol does not recognize; new market added without symbol mapping.

Related errors


AI-assisted analysis of ZhuLinsen/daily_stock_analysis@5159bd72e8 (2026-08-15). Data as JSON: /api/errors/86502a4071177ffd. Report an issue: GitHub.