{"record":{"id":"897c071c646fd45a","repo":"ZhuLinsen/daily_stock_analysis","slug":"baostockfetcher-raw-code-aksharefetche","errorCode":null,"errorMessage":"BaostockFetcher 不支持港股 {raw_code}，请使用 AkshareFetcher","messagePattern":"BaostockFetcher 不支持港股 (.+?)，请使用 AkshareFetcher","errorType":"exception","errorClass":"DataFetchError","httpStatus":null,"severity":"warning","filePath":"data_provider/baostock_fetcher.py","lineNumber":151,"sourceCode":"        \"\"\"\n        转换股票代码为 Baostock 格式\n        \n        Baostock 要求的格式：\n        - 沪市：sh.600519\n        - 深市：sz.000001\n        \n        Args:\n            stock_code: 原始代码，如 '600519', '000001'\n            \n        Returns:\n            Baostock 格式代码，如 'sh.600519', 'sz.000001'\n        \"\"\"\n        raw_code = stock_code.strip()\n        upper = raw_code.upper()\n\n        # HK stocks are not supported by Baostock\n        if _is_hk_market(raw_code):\n            raise DataFetchError(f\"BaostockFetcher 不支持港股 {raw_code}，请使用 AkshareFetcher\")\n\n        # 保留既有小写 baostock 格式输入的内部容错，但用户配置仍推荐 6 位裸代码。\n        if raw_code.startswith(('sh.', 'sz.')):\n            return raw_code.lower()\n\n        exchange_hint = None\n        if upper.startswith(('SH', 'SS')) or upper.endswith(('.SH', '.SS')):\n            exchange_hint = 'sh'\n        elif upper.startswith('SZ') or upper.endswith('.SZ'):\n            exchange_hint = 'sz'\n\n        code = normalize_stock_code(raw_code)\n\n        if exchange_hint in ('sh', 'sz') and code.isdigit() and len(code) == 6:\n            return f\"{exchange_hint}.{code}\"\n        \n        # ETF: Shanghai ETF (51xx, 52xx, 56xx, 58xx) -> sh; Shenzhen ETF (15xx, 16xx, 18xx) -> sz\n        if len(code) == 6:","sourceCodeStart":133,"sourceCodeEnd":169,"githubUrl":"https://github.com/ZhuLinsen/daily_stock_analysis/blob/5159bd72e8373d215492dff122acc9d389e219c9/data_provider/baostock_fetcher.py#L133-L169","documentation":"A guard DataFetchError raised by BaostockFetcher._convert_stock_code when _is_hk_market(raw_code) is True. Baostock only serves mainland A-shares, so HK codes are rejected at code-conversion time with an explicit pointer to AkshareFetcher. This is a routing error by design: the manager should catch it and dispatch to an HK-capable source.","triggerScenarios":"Passing HK-style codes ('hk00700', '00700', '01810') into any BaostockFetcher fetch path that calls _convert_stock_code. The check runs before the sh./sz. prefix handling, so even 'hk...' formatted inputs are caught.","commonSituations":"Mixed-market watchlists where Baostock is first in the source chain; HK codes stored without the 'hk' prefix colliding with 5-digit ambiguity; legacy configs that previously routed everything to Baostock.","solutions":["Route by market before fetching: only send 6-digit A-share codes (or sh./sz. prefixed) to BaostockFetcher.","Catch this DataFetchError in the manager and try AkshareFetcher for the HK code.","Normalize HK codes with the 'hk' prefix at config load so market detection is unambiguous."],"exampleFix":"# before\ndf = baostock_fetcher.fetch('hk00700', start, end)  # raises\n\n# after\nif _is_hk_market(code):\n    df = akshare_fetcher.fetch(code, start, end)\nelse:\n    df = baostock_fetcher.fetch(code, start, end)","handlingStrategy":"validation","validationCode":"from data_provider.baostock_fetcher import _is_hk_market\nassert not _is_hk_market(code), f'{code} is HK — route to AkshareFetcher, not Baostock'","typeGuard":"from data_provider.baostock_fetcher import _is_hk_market\n\ndef is_baostock_code(code: str) -> bool:\n    \"\"\"Baostock serves mainland A-shares only.\"\"\"\n    return not _is_hk_market(code)","tryCatchPattern":"try:\n    df = baostock_fetcher.fetch(code, start, end)\nexcept DataFetchError as e:\n    if '不支持港股' in str(e):\n        df = akshare_fetcher.fetch(code, start, end)\n    else:\n        raise","preventionTips":["Store HK codes with the 'hk' prefix so market detection is deterministic.","Filter watchlists by market before assigning fetchers.","Treat '不支持' errors as routing skips, never as retries."],"tags":["baostock","hk-stocks","market-routing","stock-code"],"backgroundTag":null,"analyzedSha":"5159bd72e8373d215492dff122acc9d389e219c9","analyzedAt":"2026-08-15T01:59:36.292Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}