hsliuping/TradingAgents-CN · error · AlphaVantageAPIError
Alpha Vantage API Error: {error_msg}
Error message
Alpha Vantage API Error: {error_msg} What it means
Raised by _make_api_request when the Alpha Vantage JSON response contains an 'Error Message' field, wrapped as AlphaVantageAPIError. The upstream message typically means an invalid API function name, wrong parameters, or an unrecognized symbol.
Source
Thrown at tradingagents/dataflows/providers/us/alpha_vantage_common.py:208
**params
}
logger.debug(f"📡 [Alpha Vantage] 请求 {function}: {params}")
for attempt in range(max_retries):
try:
# 发起请求
response = requests.get(base_url, params=request_params, timeout=30)
response.raise_for_status()
# 解析响应
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:View on GitHub (pinned to 74783e8817)
Solutions
- Read error_msg in the exception: it states the exact upstream reason
- Validate/normalize the symbol before requesting (plain US tickers)
- Verify the API function name and parameters against Alpha Vantage docs
- If the symbol is genuinely unsupported, use a different data source for it
Example fix
# before
data = _make_api_request({'function':'GLOBAL_QUOTE','symbol':'600519.SS'})
# after
data = _make_api_request({'function':'GLOBAL_QUOTE','symbol':'AAPL'}) Defensive patterns
Strategy: try-catch
Validate before calling
import re
def valid_us_symbol(s: str) -> bool:
return bool(re.fullmatch(r'[A-Z]{1,5}(?:\.[A-Z]{1,2})?', s))
if not valid_us_symbol(symbol):
raise ValueError(f'bad symbol: {symbol}') Type guard
def is_valid_us_symbol(symbol: str) -> bool:
import re
return bool(re.fullmatch(r'[A-Z]{1,5}', symbol)) Try / catch
from tradingagents.dataflows.providers.us.alpha_vantage_common import AlphaVantageAPIError
try:
data = _make_api_request(params)
except AlphaVantageAPIError as e:
if 'API Error' in str(e):
logger.warning('AV rejected params %s: %s', params, e)
return None
raise Prevention
- Normalize/validate tickers before calling AV
- Pin parameter names to the AV docs; add tests per function used
- Log the upstream error_msg — it names the exact bad parameter
When it happens
Trigger: Requesting an invalid/unsupported symbol (e.g. a malformed ticker), an invalid `function` parameter, or bad parameter combos that Alpha Vantage rejects with 'Error Message'.
Common situations: Passing exchange-suffixed tickers Alpha Vantage doesn't recognize, typos in the function name when extending the provider, or API behavior changes after a parameter rename.
Related errors
- ❌ Alpha Vantage API Key 未配置!\n请通过以下任一方式配置:\n1. Web 后台配置(推荐):
- Alpha Vantage API rate limit exceeded. Please wait a moment
- Alpha Vantage API limit: {info_msg}
- Alpha Vantage API request timeout
- Alpha Vantage API request failed: {e}
AI-assisted analysis of hsliuping/TradingAgents-CN@74783e8817 (2026-08-28).
Data as JSON: /api/errors/a587ac6912c74123.
Report an issue: GitHub.