ZhuLinsen/daily_stock_analysis · warning · DataFetchError
TushareFetcher 不支持美股 {stock_code},请使用 AkshareFetcher 或 Yfina
Error message
TushareFetcher 不支持美股 {stock_code},请使用 AkshareFetcher 或 YfinanceFetcher What it means
TushareFetcher explicitly rejects US stock codes because Tushare pro has no US daily-quote interface in this integration. The guard runs after the API-init check and before rate limiting, so any US ticker reaching TushareFetcher fails immediately with DataFetchError. The message points at the two fetchers that do support US symbols (AkshareFetcher, YfinanceFetcher).
Source
Thrown at data_provider/tushare_fetcher.py:490
从 Tushare 获取原始数据
根据代码类型选择不同接口:
- 普通股票:daily()
- ETF 基金:fund_daily()
流程:
1. 检查 API 是否可用
2. 检查是否为美股(不支持)
3. 执行速率限制检查
4. 转换股票代码格式
5. 根据代码类型选择接口并调用
"""
if self._api is None:
raise DataFetchError("Tushare API 未初始化,请检查 Token 配置")
# US stocks not supported
if _is_us_code(stock_code):
raise DataFetchError(f"TushareFetcher 不支持美股 {stock_code},请使用 AkshareFetcher 或 YfinanceFetcher")
# Rate-limit check
self._check_rate_limit()
is_hk = _is_hk_market(stock_code)
# 判断是否为 ETF / 港股,以选择不同接口
is_etf = _is_etf_code(stock_code)
if is_hk:
ts_code = self._convert_hk_stock_code_for_tushare(stock_code)
api_name = "hk_daily"
else:
ts_code = self._convert_stock_code(stock_code)
api_name = "fund_daily" if is_etf else "daily"
# Convert date format (Tushare requires YYYYMMDD)
ts_start = start_date.replace('-', '')
ts_end = end_date.replace('-', '')
View on GitHub (pinned to 5159bd72e8)
Solutions
- Ensure the data_provider fetcher chain includes AkshareFetcher or YfinanceFetcher so US symbols fall through to a supporting source (this error should trigger fallback, not abort).
- If you call fetchers directly, route by market: use YfinanceFetcher/AkshareFetcher for US codes and TushareFetcher only for A-shares/HK/ETF.
- Check the stock code format being passed — an A-share code that got mangled into a letter ticker can false-positive this guard.
- If the whole run aborts on this error, inspect the fallback orchestrator: a single source rejecting a symbol must not be fatal (AGENTS.md data-source guardrail).
Example fix
# before
fetcher = TushareFetcher()
df = fetcher.fetch_stock_data('AAPL') # -> DataFetchError 不支持美股
# after
from data_provider.yfinance_fetcher import YfinanceFetcher
df = YfinanceFetcher().fetch_stock_data('AAPL') if _is_us_code('AAPL') else TushareFetcher().fetch_stock_data('AAPL') Defensive patterns
Strategy: type-guard
Validate before calling
from data_provider.tushare_fetcher import _is_us_code
if _is_us_code(stock_code):
fetcher = yfinance_fetcher # or akshare_fetcher
else:
fetcher = tushare_fetcher Type guard
def is_tushare_supported(code: str) -> bool:
"""TushareFetcher covers A-shares/HK/ETF; US codes are rejected."""
return not _is_us_code(code) Try / catch
try:
df = tushare_fetcher.fetch_stock_data(code)
except DataFetchError as e:
if "不支持美股" in str(e):
df = yfinance_fetcher.fetch_stock_data(code)
else:
raise Prevention
- Route symbols by market before choosing a fetcher; never send US tickers to TushareFetcher.
- Keep Akshare/Yfinance in the chain so this rejection triggers fallback, not abort.
- Test the fetch chain with a mixed A/HK/US list in CI.
When it happens
Trigger: Passing a US-style code (matched by _is_us_code, e.g. 'AAPL', 'MSFT.US') to TushareFetcher.fetch_stock_data. Happens when the multi-source fetch chain is ordered with Tushare first for a mixed watchlist (e.g. --stocks 600519,hk00700,AAPL) or when a US ETF is misclassified as A-share ETF.
Common situations: Mixed A/HK/US stock lists where the fallback chain tries every fetcher per symbol; user configures TUSHARE as preferred source globally; code normalization produces something _is_us_code matches (letters-only tickers).
Related errors
- TushareFetcher 不支持美股 {raw_code},请使用 AkshareFetcher 或 Yfinanc
- AkshareFetcher 不支持美股 {stock_code},请使用 YfinanceFetcher 获取正确的复
- Akshare 获取美股数据失败: {e}
- PytdxFetcher 不支持美股 {stock_code},请使用 AkshareFetcher 或 Yfinanc
- Tushare 配额超限: {e}
AI-assisted analysis of ZhuLinsen/daily_stock_analysis@5159bd72e8 (2026-08-15).
Data as JSON: /api/errors/6732c4ed41485527.
Report an issue: GitHub.