{"record":{"id":"a587ac6912c74123","repo":"hsliuping/TradingAgents-CN","slug":"alpha-vantage-api-error-error-msg","errorCode":null,"errorMessage":"Alpha Vantage API Error: {error_msg}","messagePattern":"Alpha Vantage API Error: (.+?)","errorType":"error_code","errorClass":"AlphaVantageAPIError","httpStatus":null,"severity":"error","filePath":"tradingagents/dataflows/providers/us/alpha_vantage_common.py","lineNumber":208,"sourceCode":"        **params\n    }\n    \n    logger.debug(f\"📡 [Alpha Vantage] 请求 {function}: {params}\")\n    \n    for attempt in range(max_retries):\n        try:\n            # 发起请求\n            response = requests.get(base_url, params=request_params, timeout=30)\n            response.raise_for_status()\n            \n            # 解析响应\n            data = response.json()\n            \n            # 检查错误信息\n            if \"Error Message\" in data:\n                error_msg = data[\"Error Message\"]\n                logger.error(f\"❌ [Alpha Vantage] API 错误: {error_msg}\")\n                raise AlphaVantageAPIError(f\"Alpha Vantage API Error: {error_msg}\")\n            \n            # 检查速率限制\n            if \"Note\" in data and \"API call frequency\" in data[\"Note\"]:\n                logger.warning(f\"⚠️ [Alpha Vantage] 速率限制: {data['Note']}\")\n                \n                if attempt < max_retries - 1:\n                    wait_time = retry_delay * (attempt + 1)\n                    logger.info(f\"⏳ 等待 {wait_time} 秒后重试...\")\n                    time.sleep(wait_time)\n                    continue\n                else:\n                    raise AlphaVantageRateLimitError(\n                        \"Alpha Vantage API rate limit exceeded. \"\n                        \"Please wait a moment and try again, or upgrade your API plan.\"\n                    )\n            \n            # 检查信息字段（可能包含限制提示）\n            if \"Information\" in data:","sourceCodeStart":190,"sourceCodeEnd":226,"githubUrl":"https://github.com/hsliuping/TradingAgents-CN/blob/74783e8817d6cf6de29867880631cc555153f36b/tradingagents/dataflows/providers/us/alpha_vantage_common.py#L190-L226","documentation":"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.","triggerScenarios":"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'.","commonSituations":"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.","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"],"exampleFix":"# before\ndata = _make_api_request({'function':'GLOBAL_QUOTE','symbol':'600519.SS'})\n# after\ndata = _make_api_request({'function':'GLOBAL_QUOTE','symbol':'AAPL'})","handlingStrategy":"try-catch","validationCode":"import re\ndef valid_us_symbol(s: str) -> bool:\n    return bool(re.fullmatch(r'[A-Z]{1,5}(?:\\.[A-Z]{1,2})?', s))\nif not valid_us_symbol(symbol):\n    raise ValueError(f'bad symbol: {symbol}')","typeGuard":"def is_valid_us_symbol(symbol: str) -> bool:\n    import re\n    return bool(re.fullmatch(r'[A-Z]{1,5}', symbol))","tryCatchPattern":"from tradingagents.dataflows.providers.us.alpha_vantage_common import AlphaVantageAPIError\ntry:\n    data = _make_api_request(params)\nexcept AlphaVantageAPIError as e:\n    if 'API Error' in str(e):\n        logger.warning('AV rejected params %s: %s', params, e)\n        return None\n    raise","preventionTips":["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"],"tags":["python","alpha-vantage","api-error"],"backgroundTag":"api-error-response","analyzedSha":"74783e8817d6cf6de29867880631cc555153f36b","analyzedAt":"2026-08-28T11:39:07.729Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}