{"record":{"id":"c513f5274d7efcdb","repo":"ZhuLinsen/daily_stock_analysis","slug":"pytdxfetcher-stock-code-aksharefetcher-c513f5","errorCode":null,"errorMessage":"PytdxFetcher 不支持港股 {stock_code}，请使用 AkshareFetcher","messagePattern":"PytdxFetcher 不支持港股 (.+?)，请使用 AkshareFetcher","errorType":"exception","errorClass":"DataFetchError","httpStatus":null,"severity":"error","filePath":"data_provider/pytdx_fetcher.py","lineNumber":328,"sourceCode":"    def _fetch_raw_data(self, stock_code: str, start_date: str, end_date: str) -> pd.DataFrame:\n        \"\"\"\n        从通达信获取原始数据\n        \n        使用 get_security_bars() 获取日线数据\n        \n        流程：\n        1. 检查是否为美股（不支持）\n        2. 使用上下文管理器管理连接\n        3. 判断市场代码\n        4. 调用 API 获取 K 线数据\n        \"\"\"\n        # 美股不支持，抛出异常让 DataFetcherManager 切换到其他数据源\n        if _is_us_code(stock_code):\n            raise DataFetchError(f\"PytdxFetcher 不支持美股 {stock_code}，请使用 AkshareFetcher 或 YfinanceFetcher\")\n\n        # 港股不支持，抛出异常让 DataFetcherManager 切换到其他数据源\n        if _is_hk_market(stock_code):\n            raise DataFetchError(f\"PytdxFetcher 不支持港股 {stock_code}，请使用 AkshareFetcher\")\n\n        # 北交所不支持，抛出异常让 DataFetcherManager 切换到其他数据源\n        if is_bse_code(stock_code):\n            raise DataFetchError(\n                f\"PytdxFetcher 不支持北交所 {stock_code}，将自动切换其他数据源\"\n            )\n        \n        market, code = self._get_market_code(stock_code)\n        \n        # 计算需要获取的交易日数量（估算）\n        from datetime import datetime as dt\n        start_dt = dt.strptime(start_date, '%Y-%m-%d')\n        end_dt = dt.strptime(end_date, '%Y-%m-%d')\n        days = (end_dt - start_dt).days\n        count = min(max(days * 5 // 7 + 10, 30), 800)  # 估算交易日，最大 800 条\n        \n        logger.debug(f\"调用 Pytdx get_security_bars(market={market}, code={code}, count={count})\")\n        ","sourceCodeStart":310,"sourceCodeEnd":346,"githubUrl":"https://github.com/ZhuLinsen/daily_stock_analysis/blob/5159bd72e8373d215492dff122acc9d389e219c9/data_provider/pytdx_fetcher.py#L310-L346","documentation":"DataFetchError raised in PytdxFetcher._fetch_raw_data when _is_hk_market(stock_code) is true. The TDX servers this fetcher connects to do not carry Hong Kong quotes, so HK symbols are rejected and the manager is directed to AkshareFetcher for HK data.","triggerScenarios":"Passing an HK-format code (e.g. 00700, hk00700, 00700.HK — anything matched by _is_hk_market) to PytdxFetcher for daily historical data.","commonSituations":"Analyzing 港股 watchlists through the A-share pipeline; normalization upstream turning HK codes into a shape that slips past earlier filters; single fetcher reused across markets.","solutions":["Route HK symbols to AkshareFetcher (or another HK-capable provider) before calling PytdxFetcher.","Ensure the market dispatcher maps hk* codes to the HK provider chain.","Guard the call site with _is_hk_market if the manager is not in play."],"exampleFix":"# before\ndf = pytdx_fetcher.get_stock_data(\"hk00700\", start, end)  # DataFetchError\n\n# after\nfrom data_provider.pytdx_fetcher import _is_hk_market\nif _is_hk_market(code):\n    df = akshare_fetcher.get_stock_data(code, start, end)\nelse:\n    df = pytdx_fetcher.get_stock_data(code, start, end)","handlingStrategy":"type-guard","validationCode":"from data_provider.pytdx_fetcher import _is_hk_market\n\nif _is_hk_market(stock_code):\n    fetcher = akshare_fetcher\nelse:\n    fetcher = pytdx_fetcher","typeGuard":"from data_provider.pytdx_fetcher import _is_hk_market\n\ndef is_hk_symbol(code: str) -> bool:\n    \"\"\"True when the code is an HK-market symbol unsupported by pytdx.\"\"\"\n    return _is_hk_market(code)","tryCatchPattern":"try:\n    df = pytdx_fetcher.get_stock_data(code, start, end)\nexcept DataFetchError as e:\n    if \"不支持港股\" in str(e):\n        df = akshare_fetcher.get_stock_data(code, start, end)\n    else:\n        raise","preventionTips":["Route hk* codes to the HK provider chain at dispatch time.","Watch for normalization changes that re-shape HK codes before they hit pytdx."],"tags":["pytdx","market-coverage","hk-stocks","routing"],"backgroundTag":null,"analyzedSha":"5159bd72e8373d215492dff122acc9d389e219c9","analyzedAt":"2026-08-15T01:59:36.292Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}