hsliuping/TradingAgents-CN · error · AlphaVantageRateLimitError
Alpha Vantage API rate limit exceeded. Please wait a moment
Error message
Alpha Vantage API rate limit exceeded. Please wait a moment and try again, or upgrade your API plan.
What it means
Raised as AlphaVantageRateLimitError when the response contains an 'Note' about API call frequency and all retry attempts (with linear backoff) have been exhausted. Free Alpha Vantage keys are limited to ~25 requests/day (5/min historically).
Source
Thrown at tradingagents/dataflows/providers/us/alpha_vantage_common.py:220
data = response.json()
# 检查错误信息
if "Error Message" in data:
error_msg = data["Error Message"]
logger.error(f"❌ [Alpha Vantage] API 错误: {error_msg}")
raise AlphaVantageAPIError(f"Alpha Vantage API Error: {error_msg}")
# 检查速率限制
if "Note" in data and "API call frequency" in data["Note"]:
logger.warning(f"⚠️ [Alpha Vantage] 速率限制: {data['Note']}")
if attempt < max_retries - 1:
wait_time = retry_delay * (attempt + 1)
logger.info(f"⏳ 等待 {wait_time} 秒后重试...")
time.sleep(wait_time)
continue
else:
raise AlphaVantageRateLimitError(
"Alpha Vantage API rate limit exceeded. "
"Please wait a moment and try again, or upgrade your API plan."
)
# 检查信息字段(可能包含限制提示)
if "Information" in data:
info_msg = data["Information"]
logger.warning(f"⚠️ [Alpha Vantage] 信息: {info_msg}")
# 如果是速率限制信息
if "premium" in info_msg.lower() or "limit" in info_msg.lower():
if attempt < max_retries - 1:
wait_time = retry_delay * (attempt + 1)
logger.info(f"⏳ 等待 {wait_time} 秒后重试...")
time.sleep(wait_time)
continue
else:
raise AlphaVantageRateLimitError(View on GitHub (pinned to 74783e8817)
Solutions
- Wait for the quota window to reset (up to a minute for rate limit, next day for daily cap) and throttle callers to ≤5 req/min
- Upgrade the Alpha Vantage plan or use a premium key
- Cache responses and add a request budget/semaphore around _make_api_request
Example fix
# before
for sym in symbols:
_get_us_quote_from_alpha_vantage(sym) # no throttle
# after
for sym in symbols:
_get_us_quote_from_alpha_vantage(sym)
time.sleep(13) # ~4-5 req/min on free tier Defensive patterns
Strategy: retry
Try / catch
from tradingagents.dataflows.providers.us.alpha_vantage_common import AlphaVantageRateLimitError
try:
data = _make_api_request(params)
except AlphaVantageRateLimitError:
time.sleep(65)
data = _make_api_request(params) # single patient retry Prevention
- Throttle to ≤5 requests/min with a token bucket
- Cache responses (quotes rarely change intra-minute)
- Budget daily calls; stop fetching when near the free-tier cap
- Consider a paid plan for batch workloads
When it happens
Trigger: Bursting requests until the daily/minute quota is hit — the built-in retries sleep and retry, then re-raise this error when the limit persists across all attempts.
Common situations: Batch-importing many US symbols with a free key, polling loops without throttling, or sharing a key across multiple services.
Related errors
- Alpha Vantage API limit: {info_msg}
- Failed to get data from Alpha Vantage after {max_retries} at
- ❌ Alpha Vantage API Key 未配置!\n请通过以下任一方式配置:\n1. Web 后台配置(推荐):
- Alpha Vantage API Error: {error_msg}
- Alpha Vantage API request timeout
AI-assisted analysis of hsliuping/TradingAgents-CN@74783e8817 (2026-08-28).
Data as JSON: /api/errors/9a77afbd982ed620.
Report an issue: GitHub.