ZhuLinsen/daily_stock_analysis · warning · DataFetchError
BaostockFetcher 不支持港股 {stock_code},请使用 AkshareFetcher
Error message
BaostockFetcher 不支持港股 {stock_code},请使用 AkshareFetcher What it means
A guard DataFetchError raised in BaostockFetcher's fetch entry when _is_hk_market(stock_code) is True (and the US check above already passed). It is the fetch-path duplicate of the _convert_stock_code guard (line 151): HK codes never reach a baostock query, and the error text tells the caller to use AkshareFetcher.
Source
Thrown at data_provider/baostock_fetcher.py:209
"""
从 Baostock 获取原始数据
使用 query_history_k_data_plus() 获取日线数据
流程:
1. 检查是否为美股(不支持)
2. 使用上下文管理器管理连接
3. 转换股票代码格式
4. 调用 API 查询数据
5. 将结果转换为 DataFrame
"""
# 美股不支持,抛出异常让 DataFetcherManager 切换到其他数据源
if _is_us_code(stock_code):
raise DataFetchError(f"BaostockFetcher 不支持美股 {stock_code},请使用 AkshareFetcher 或 YfinanceFetcher")
# 港股不支持,抛出异常让 DataFetcherManager 切换到其他数据源
if _is_hk_market(stock_code):
raise DataFetchError(f"BaostockFetcher 不支持港股 {stock_code},请使用 AkshareFetcher")
# 北交所不支持,抛出异常让 DataFetcherManager 切换到其他数据源
if is_bse_code(stock_code):
raise DataFetchError(
f"BaostockFetcher 不支持北交所 {stock_code},将自动切换其他数据源"
)
# 转换代码格式
bs_code = self._convert_stock_code(stock_code)
logger.debug(f"调用 Baostock query_history_k_data_plus({bs_code}, {start_date}, {end_date})")
with self._baostock_session() as bs:
try:
# 查询日线数据
# adjustflag: 1-后复权,2-前复权,3-不复权
rs = bs.query_history_k_data_plus(
code=bs_code,View on GitHub (pinned to 5159bd72e8)
Solutions
- Filter markets upstream so HK codes never enter the Baostock attempt.
- Treat this error as a skip signal in the manager loop, not a retryable failure.
- Keep HK codes prefixed 'hk' so _is_hk_market detects them reliably.
Example fix
# manager-style loop
for fetcher in fetchers:
try:
return fetcher.fetch(code, start, end)
except DataFetchError as e:
if '不支持' in str(e):
continue # market not supported here; try next source
raise Defensive patterns
Strategy: fallback
Validate before calling
from data_provider.baostock_fetcher import _is_hk_market
if _is_hk_market(code):
skip_baostock = True # route directly to Akshare Try / catch
for fetcher in fetcher_chain:
try:
return fetcher.fetch(code, start, end)
except DataFetchError as e:
if '不支持' in str(e):
continue # market guard — try next source
raise Prevention
- Centralize market routing before the chain so HK codes never reach Baostock's guard.
- Use consistent 'hkNNNNN' code storage.
- Distinguish skip-worthy guard errors from retryable failures in the manager loop.
When it happens
Trigger: Calling BaostockFetcher.fetch with an HK market code ('hk00700', '00700') from a source chain that has not pre-filtered by market. Deterministic raise before login/query; zero network cost.
Common situations: HK watchlist entries routed through a default fetcher list; codes persisted in the DB in 'hkNNNNN' form hitting Baostock first during fallback iteration.
Related errors
- BaostockFetcher 不支持港股 {raw_code},请使用 AkshareFetcher
- BaostockFetcher 不支持美股 {stock_code},请使用 AkshareFetcher 或 Yfin
- BaostockFetcher 不支持北交所 {stock_code},将自动切换其他数据源
- Akshare 获取港股数据失败: {e}
- [AlphaVantage] {stock_code} is not a US stock
AI-assisted analysis of ZhuLinsen/daily_stock_analysis@5159bd72e8 (2026-08-15).
Data as JSON: /api/errors/7d7f4cb4307f1b37.
Report an issue: GitHub.