ZhuLinsen/daily_stock_analysis · error · DataFetchError
TushareFetcher 不支持美股 {raw_code},请使用 AkshareFetcher 或 Yfinanc
Error message
TushareFetcher 不支持美股 {raw_code},请使用 AkshareFetcher 或 YfinanceFetcher What it means
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.
Source
Thrown at data_provider/tushare_fetcher.py:405
Tushare 格式代码,如 '600519.SH', '000001.SZ'
"""
raw_code = stock_code.strip()
# Already has suffix.
if '.' in raw_code:
upper = raw_code.upper()
code = normalize_stock_code(raw_code)
exchange_hint = self._detect_exchange_hint(raw_code)
if exchange_hint in ("SH", "SZ", "BJ") and code.isdigit():
return f"{code}.{exchange_hint}"
ts_code = upper
if ts_code.endswith('.SS'):
return f"{ts_code[:-3]}.SH"
return ts_code
if _is_us_code(raw_code):
raise DataFetchError(f"TushareFetcher 不支持美股 {raw_code},请使用 AkshareFetcher 或 YfinanceFetcher")
if _is_hk_market(raw_code):
#raise DataFetchError(f"TushareFetcher 不支持港股 {raw_code},请使用 AkshareFetcher")
return normalize_stock_code(raw_code)
code = normalize_stock_code(raw_code)
exchange_hint = self._detect_exchange_hint(raw_code)
if exchange_hint == "SH":
return f"{code}.SH"
if exchange_hint == "SZ":
return f"{code}.SZ"
if exchange_hint == "BJ":
return f"{code}.BJ"
# ETF: determine exchange by prefix
if code.startswith(_ETF_SH_PREFIXES) and len(code) == 6:
return f"{code}.SH"View on GitHub (pinned to 5159bd72e8)
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.
Example fix
# before
df = tushare_fetcher.get_stock_data("AAPL", start, end) # DataFetchError
# after
from data_provider.tushare_fetcher import _is_us_code
fetcher = yfinance_fetcher if _is_us_code(code) else tushare_fetcher
df = fetcher.get_stock_data(code, start, end) Defensive patterns
Strategy: type-guard
Validate before calling
from data_provider.tushare_fetcher import _is_us_code fetcher = yfinance_fetcher if _is_us_code(stock_code) else tushare_fetcher df = fetcher.get_stock_data(stock_code, start, end)
Type guard
from data_provider.tushare_fetcher import _is_us_code
def is_us_symbol(code: str) -> bool:
"""True when the code is a US ticker unsupported by Tushare daily endpoints."""
return _is_us_code(code) Try / catch
try:
df = tushare_fetcher.get_stock_data(code, start, end)
except DataFetchError as e:
if "不支持美股" in str(e):
df = yfinance_fetcher.get_stock_data(code, start, end)
else:
raise Prevention
- Filter US codes out of the CN pipeline at dispatch, not inside each provider.
- Maintain one shared market classifier used by every fetcher chain.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- PytdxFetcher 不支持美股 {stock_code},请使用 AkshareFetcher 或 Yfinanc
- TushareFetcher 不支持美股 {stock_code},请使用 AkshareFetcher 或 Yfina
- AkshareFetcher 不支持美股 {stock_code},请使用 YfinanceFetcher 获取正确的复
- PytdxFetcher 不支持港股 {stock_code},请使用 AkshareFetcher
- PytdxFetcher 不支持北交所 {stock_code},将自动切换其他数据源
AI-assisted analysis of ZhuLinsen/daily_stock_analysis@5159bd72e8 (2026-08-15).
Data as JSON: /api/errors/a0868a771071ad2d.
Report an issue: GitHub.