{"record":{"id":"6e3a8fdec784b86e","repo":"ZhuLinsen/daily_stock_analysis","slug":"efinancefetcher-stock-code-aksharefetc","errorCode":null,"errorMessage":"EfinanceFetcher 不支持美股 {stock_code}，请使用 AkshareFetcher 或 YfinanceFetcher","messagePattern":"EfinanceFetcher 不支持美股 (.+?)，请使用 AkshareFetcher 或 YfinanceFetcher","errorType":"exception","errorClass":"DataFetchError","httpStatus":null,"severity":"warning","filePath":"data_provider/efinance_fetcher.py","lineNumber":381,"sourceCode":"    def _fetch_raw_data(self, stock_code: str, start_date: str, end_date: str) -> pd.DataFrame:\n        \"\"\"\n        从 efinance 获取原始数据\n        \n        根据代码类型自动选择 API：\n        - 美股：不支持，抛出异常让 DataFetcherManager 切换到其他数据源\n        - 普通股票：使用 ef.stock.get_quote_history()\n        - ETF 基金：使用 ef.stock.get_quote_history()（ETF 是交易所证券，使用股票 K 线接口）\n        \n        流程：\n        1. 判断代码类型（美股/股票/ETF）\n        2. 设置随机 User-Agent\n        3. 执行速率限制（随机休眠）\n        4. 调用对应的 efinance API\n        5. 处理返回数据\n        \"\"\"\n        # 美股不支持，抛出异常让 DataFetcherManager 切换到 AkshareFetcher/YfinanceFetcher\n        if _is_us_code(stock_code):\n            raise DataFetchError(f\"EfinanceFetcher 不支持美股 {stock_code}，请使用 AkshareFetcher 或 YfinanceFetcher\")\n\n        # efinance 的历史 K 线接口在港股代码上可能返回非预期市场数据，\n        # 明确跳过并交给 AkShare/Tushare/YFinance/Longbridge 等港股路径兜底。\n        if _is_hk_market(stock_code):\n            raise DataFetchError(f\"EfinanceFetcher 不支持港股日线 {stock_code}，请使用 AkshareFetcher 或其他港股数据源\")\n        \n        # 根据代码类型选择不同的获取方法\n        if _is_etf_code(stock_code):\n            return self._fetch_etf_data(stock_code, start_date, end_date)\n        else:\n            return self._fetch_stock_data(stock_code, start_date, end_date)\n    \n    def _fetch_stock_data(self, stock_code: str, start_date: str, end_date: str) -> pd.DataFrame:\n        \"\"\"\n        获取普通 A 股历史数据\n        \n        数据来源：ef.stock.get_quote_history()\n        ","sourceCodeStart":363,"sourceCodeEnd":399,"githubUrl":"https://github.com/ZhuLinsen/daily_stock_analysis/blob/5159bd72e8373d215492dff122acc9d389e219c9/data_provider/efinance_fetcher.py#L363-L399","documentation":"Intentional capability guard in EfinanceFetcher._fetch_raw_data: efinance's Eastmoney backend does not serve US equities, so US tickers (regex ^[A-Z]{1,5}(\\.[A-Z])?$) are rejected immediately so DataFetcherManager can fail over to AkShare/YFinance without wasting a request.","triggerScenarios":"Calling EfinanceFetcher.get_daily_data directly (bypassing the manager's market filter) with a US symbol like 'AAPL' or 'BRK.B'. Through the manager this normally never surfaces because the fetcher is filtered out for market='us'.","commonSituations":"Custom code iterating over fetchers manually instead of using DataFetcherManager; unit tests exercising every registered fetcher with a mixed stock list.","solutions":["Route US codes through DataFetcherManager.get_daily_data so the US source_order (Finnhub/AlphaVantage/YFinance/Longbridge) is used.","If calling fetchers directly, gate on _is_us_code / market detection before invoking EfinanceFetcher.","Treat this exception as a skip signal, not a hard failure — catch DataFetchError and move to the next source."],"exampleFix":"# before\nfor f in manager.fetchers:\n    df = f.get_daily_data('AAPL', ...)  # raises for efinance\n# after\ndf = manager.get_daily_data('AAPL', ...)  # market-routed","handlingStrategy":"validation","validationCode":"from data_provider.efinance_fetcher import _is_us_code\nif _is_us_code(code):\n    df = manager.get_daily_data(code, ...)  # US chain\nelse:\n    df = efinance_fetcher.get_daily_data(code, ...)","typeGuard":"def is_us_ticker(code: str) -> bool:\n    return _is_us_code(code)","tryCatchPattern":"try:\n    df = fetcher.get_daily_data(code, ...)\nexcept DataFetchError as e:\n    if '不支持美股' in str(e):\n        continue  # capability skip, not an error","preventionTips":["Always route by market via DataFetcherManager rather than calling fetchers directly.","Treat capability-guard messages ('不支持...') as skip signals in custom loops.","Cover market routing in tests for every fetcher you register."],"tags":["efinance","us-stocks","capability-guard","failover"],"backgroundTag":null,"analyzedSha":"5159bd72e8373d215492dff122acc9d389e219c9","analyzedAt":"2026-08-15T01:59:36.292Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}