{"record":{"id":"7d7f4cb4307f1b37","repo":"ZhuLinsen/daily_stock_analysis","slug":"baostockfetcher-stock-code-aksharefetc-7d7f4c","errorCode":null,"errorMessage":"BaostockFetcher 不支持港股 {stock_code}，请使用 AkshareFetcher","messagePattern":"BaostockFetcher 不支持港股 (.+?)，请使用 AkshareFetcher","errorType":"exception","errorClass":"DataFetchError","httpStatus":null,"severity":"warning","filePath":"data_provider/baostock_fetcher.py","lineNumber":209,"sourceCode":"        \"\"\"\n        从 Baostock 获取原始数据\n        \n        使用 query_history_k_data_plus() 获取日线数据\n        \n        流程：\n        1. 检查是否为美股（不支持）\n        2. 使用上下文管理器管理连接\n        3. 转换股票代码格式\n        4. 调用 API 查询数据\n        5. 将结果转换为 DataFrame\n        \"\"\"\n        # 美股不支持，抛出异常让 DataFetcherManager 切换到其他数据源\n        if _is_us_code(stock_code):\n            raise DataFetchError(f\"BaostockFetcher 不支持美股 {stock_code}，请使用 AkshareFetcher 或 YfinanceFetcher\")\n\n        # 港股不支持，抛出异常让 DataFetcherManager 切换到其他数据源\n        if _is_hk_market(stock_code):\n            raise DataFetchError(f\"BaostockFetcher 不支持港股 {stock_code}，请使用 AkshareFetcher\")\n\n        # 北交所不支持，抛出异常让 DataFetcherManager 切换到其他数据源\n        if is_bse_code(stock_code):\n            raise DataFetchError(\n                f\"BaostockFetcher 不支持北交所 {stock_code}，将自动切换其他数据源\"\n            )\n        \n        # 转换代码格式\n        bs_code = self._convert_stock_code(stock_code)\n        \n        logger.debug(f\"调用 Baostock query_history_k_data_plus({bs_code}, {start_date}, {end_date})\")\n        \n        with self._baostock_session() as bs:\n            try:\n                # 查询日线数据\n                # adjustflag: 1-后复权，2-前复权，3-不复权\n                rs = bs.query_history_k_data_plus(\n                    code=bs_code,","sourceCodeStart":191,"sourceCodeEnd":227,"githubUrl":"https://github.com/ZhuLinsen/daily_stock_analysis/blob/5159bd72e8373d215492dff122acc9d389e219c9/data_provider/baostock_fetcher.py#L191-L227","documentation":"A guard DataFetchError raised in BaostockFetcher's fetch entry when _is_hk_market(stock_code) is True (and the US check above already passed). It is the fetch-path duplicate of the _convert_stock_code guard (line 151): HK codes never reach a baostock query, and the error text tells the caller to use AkshareFetcher.","triggerScenarios":"Calling BaostockFetcher.fetch with an HK market code ('hk00700', '00700') from a source chain that has not pre-filtered by market. Deterministic raise before login/query; zero network cost.","commonSituations":"HK watchlist entries routed through a default fetcher list; codes persisted in the DB in 'hkNNNNN' form hitting Baostock first during fallback iteration.","solutions":["Filter markets upstream so HK codes never enter the Baostock attempt.","Treat this error as a skip signal in the manager loop, not a retryable failure.","Keep HK codes prefixed 'hk' so _is_hk_market detects them reliably."],"exampleFix":"# manager-style loop\nfor fetcher in fetchers:\n    try:\n        return fetcher.fetch(code, start, end)\n    except DataFetchError as e:\n        if '不支持' in str(e):\n            continue  # market not supported here; try next source\n        raise","handlingStrategy":"fallback","validationCode":"from data_provider.baostock_fetcher import _is_hk_market\nif _is_hk_market(code):\n    skip_baostock = True  # route directly to Akshare","typeGuard":null,"tryCatchPattern":"for fetcher in fetcher_chain:\n    try:\n        return fetcher.fetch(code, start, end)\n    except DataFetchError as e:\n        if '不支持' in str(e):\n            continue  # market guard — try next source\n        raise","preventionTips":["Centralize market routing before the chain so HK codes never reach Baostock's guard.","Use consistent 'hkNNNNN' code storage.","Distinguish skip-worthy guard errors from retryable failures in the manager loop."],"tags":["baostock","hk-stocks","market-routing","guard"],"backgroundTag":null,"analyzedSha":"5159bd72e8373d215492dff122acc9d389e219c9","analyzedAt":"2026-08-15T01:59:36.292Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}