ZhuLinsen/daily_stock_analysis · error · RateLimitError
Tushare 配额超限: {e}
Error message
Tushare 配额超限: {e} What it means
Raised as RateLimitError when the underlying Tushare pro call throws an exception whose message contains 'quota', '配额', 'limit', or '权限'. Tushare enforces per-integration credit limits (e.g. daily() needs 120 points, hk_daily needs higher tier); exceeding your account tier or calling an API you have no permission for produces these messages. The fetcher re-classifies the generic failure as RateLimitError so upstream logic can back off or switch sources.
Source
Thrown at data_provider/tushare_fetcher.py:544
end_date=ts_end,
)
else:
# Regular A-share stocks use daily interface
df = self._api.daily(
ts_code=ts_code,
start_date=ts_start,
end_date=ts_end,
)
return df
except Exception as e:
error_msg = str(e).lower()
# 检测配额超限
if any(keyword in error_msg for keyword in ['quota', '配额', 'limit', '权限']):
logger.warning(f"Tushare 配额可能超限: {e}")
raise RateLimitError(f"Tushare 配额超限: {e}") from e
raise DataFetchError(f"Tushare 获取数据失败: {e}") from e
def _normalize_data(self, df: pd.DataFrame, stock_code: str) -> pd.DataFrame:
"""
标准化 Tushare 数据
Tushare daily / fund_daily 返回的列名:
ts_code, trade_date, open, high, low, close, pre_close, change, pct_chg, vol, amount
需要映射到标准列名:
date, open, high, low, close, volume, amount, pct_chg
单位缩放仅适用于 A 股(及 ETF 等使用同一套单位的接口):
- vol 按「手」计,乘以 100 转为「股」
- amount 按「千元」计,乘以 1000 转为「元」
港股 hk_daily 返回的 vol / amount 已是可直接使用的量级,不做上述缩放。View on GitHub (pinned to 5159bd72e8)
Solutions
- Check your points/quota on tushare.pro and wait for daily quota reset (2000 calls/day at base tier) or upgrade the tier for the specific interface.
- Reduce Tushare call volume: cache results, widen fetch intervals, batch by trade_date instead of per-symbol where the API allows.
- Let the RateLimitError trigger the existing fallback chain to Akshare/Yfinance for the remaining symbols.
- If the underlying message is a false positive (e.g. a network error containing 'limit'), fix the keyword classification or the network issue rather than treating it as quota.
Example fix
# before
for code in watchlist: # 500 symbols on a free token
tushare_fetcher.fetch_stock_data(code) # -> RateLimitError: 配额超限
# after
try:
df = tushare_fetcher.fetch_stock_data(code)
except RateLimitError:
df = akshare_fetcher.fetch_stock_data(code) # fallback source Defensive patterns
Strategy: fallback
Validate before calling
# No pre-call API to query quota; mitigate by budgeting calls before the batch max_tushare_calls = 480 # stay under the free-tier daily limit count = cached_tushare_call_count() use_tushare = count < max_tushare_calls
Try / catch
from data_provider.base import RateLimitError, DataFetchError
try:
df = tushare_fetcher.fetch_stock_data(code)
except RateLimitError:
df = akshare_fetcher.fetch_stock_data(code) # quota exhausted -> switch source
except DataFetchError:
df = yfinance_fetcher.fetch_stock_data(code) Prevention
- Cache Tushare responses; do not re-fetch unchanged symbols within a day.
- Batch by trade_date where the API allows one call for many symbols.
- Track call counts per day and stop before hitting the tier limit.
- Catch RateLimitError specifically so quota exhaustion switches sources instead of retrying.
When it happens
Trigger: Calling daily()/fund_daily()/hk_daily more times or at a lower credit tier than the account allows: e.g. free 120-point account calling daily() repeatedly across a large stock list, or calling hk_daily without HK-quote permission. Any exception string containing 'limit' (including some network-layer 'connection limit' texts) also matches the keyword filter.
Common situations: Batch analysis of many stocks exhausting the daily call quota; new code path using an ETF/HK interface the token's tier does not cover; free-tier token used in scheduled GitHub Actions runs.
Related errors
- Akshare 所有渠道获取失败: {last_error}
- Akshare(EM) 可能被限流: {e}
- Akshare 可能被限流: {e}
- [AlphaVantage] Rate limited: {data['Note']}
- 所有数据源获取 {stock_code} 失败: {errors joined by newline}
AI-assisted analysis of ZhuLinsen/daily_stock_analysis@5159bd72e8 (2026-08-15).
Data as JSON: /api/errors/160e773dfb62171b.
Report an issue: GitHub.