{"record":{"id":"a0868a771071ad2d","repo":"ZhuLinsen/daily_stock_analysis","slug":"tusharefetcher-raw-code-aksharefetcher","errorCode":null,"errorMessage":"TushareFetcher 不支持美股 {raw_code}，请使用 AkshareFetcher 或 YfinanceFetcher","messagePattern":"TushareFetcher 不支持美股 (.+?)，请使用 AkshareFetcher 或 YfinanceFetcher","errorType":"exception","errorClass":"DataFetchError","httpStatus":null,"severity":"error","filePath":"data_provider/tushare_fetcher.py","lineNumber":405,"sourceCode":"            Tushare 格式代码，如 '600519.SH', '000001.SZ'\n        \"\"\"\n        raw_code = stock_code.strip()\n        \n        # Already has suffix.\n        if '.' in raw_code:\n            upper = raw_code.upper()\n            code = normalize_stock_code(raw_code)\n            exchange_hint = self._detect_exchange_hint(raw_code)\n            if exchange_hint in (\"SH\", \"SZ\", \"BJ\") and code.isdigit():\n                return f\"{code}.{exchange_hint}\"\n\n            ts_code = upper\n            if ts_code.endswith('.SS'):\n                return f\"{ts_code[:-3]}.SH\"\n            return ts_code\n\n        if _is_us_code(raw_code):\n            raise DataFetchError(f\"TushareFetcher 不支持美股 {raw_code}，请使用 AkshareFetcher 或 YfinanceFetcher\")\n\n        if _is_hk_market(raw_code):\n            #raise DataFetchError(f\"TushareFetcher 不支持港股 {raw_code}，请使用 AkshareFetcher\")\n            return normalize_stock_code(raw_code)\n\n        code = normalize_stock_code(raw_code)\n        exchange_hint = self._detect_exchange_hint(raw_code)\n\n        if exchange_hint == \"SH\":\n            return f\"{code}.SH\"\n        if exchange_hint == \"SZ\":\n            return f\"{code}.SZ\"\n        if exchange_hint == \"BJ\":\n            return f\"{code}.BJ\"\n\n        # ETF: determine exchange by prefix\n        if code.startswith(_ETF_SH_PREFIXES) and len(code) == 6:\n            return f\"{code}.SH\"","sourceCodeStart":387,"sourceCodeEnd":423,"githubUrl":"https://github.com/ZhuLinsen/daily_stock_analysis/blob/5159bd72e8373d215492dff122acc9d389e219c9/data_provider/tushare_fetcher.py#L387-L423","documentation":"DataFetchError raised inside TushareFetcher's code conversion when _is_us_code(raw_code) is true: the official Tushare Pro daily endpoint used here does not cover US equities, so the fetcher refuses US tickers and directs the caller to AkshareFetcher or YfinanceFetcher.","triggerScenarios":"Passing a US-format ticker (matched by _is_us_code: e.g. AAPL, US.AAPL, AAPL.O) into any TushareFetcher method that converts codes before calling the API.","commonSituations":"Mixed-market watchlists routed through the A-share Tushare path; market classification upstream failing to tag US codes; tests using US tickers against the CN pipeline.","solutions":["Dispatch US symbols to YfinanceFetcher or AkshareFetcher before the Tushare path.","Ensure the multi-market router excludes TushareFetcher from the US chain.","Guard call sites with _is_us_code when the manager is bypassed."],"exampleFix":"# before\ndf = tushare_fetcher.get_stock_data(\"AAPL\", start, end)  # DataFetchError\n\n# after\nfrom data_provider.tushare_fetcher import _is_us_code\nfetcher = yfinance_fetcher if _is_us_code(code) else tushare_fetcher\ndf = fetcher.get_stock_data(code, start, end)","handlingStrategy":"type-guard","validationCode":"from data_provider.tushare_fetcher import _is_us_code\n\nfetcher = yfinance_fetcher if _is_us_code(stock_code) else tushare_fetcher\ndf = fetcher.get_stock_data(stock_code, start, end)","typeGuard":"from data_provider.tushare_fetcher import _is_us_code\n\ndef is_us_symbol(code: str) -> bool:\n    \"\"\"True when the code is a US ticker unsupported by Tushare daily endpoints.\"\"\"\n    return _is_us_code(code)","tryCatchPattern":"try:\n    df = tushare_fetcher.get_stock_data(code, start, end)\nexcept DataFetchError as e:\n    if \"不支持美股\" in str(e):\n        df = yfinance_fetcher.get_stock_data(code, start, end)\n    else:\n        raise","preventionTips":["Filter US codes out of the CN pipeline at dispatch, not inside each provider.","Maintain one shared market classifier used by every fetcher chain."],"tags":["tushare","market-coverage","us-stocks","routing"],"backgroundTag":null,"analyzedSha":"5159bd72e8373d215492dff122acc9d389e219c9","analyzedAt":"2026-08-15T01:59:36.292Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}