hsliuping/TradingAgents-CN · error · AlphaVantageRateLimitError

Alpha Vantage API limit: {info_msg}

Error message

Alpha Vantage API limit: {info_msg}

What it means

Raised as AlphaVantageRateLimitError when the response's 'Information' field indicates a limit (e.g. free-tier monthly/day cap messages) and retries with backoff did not resolve it. Distinct from the 'Note' frequency case: 'Information' covers general limit notices.

Source

Thrown at tradingagents/dataflows/providers/us/alpha_vantage_common.py:238

                    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(
                            f"Alpha Vantage API limit: {info_msg}"
                        )
            
            # 成功获取数据
            logger.debug(f"✅ [Alpha Vantage] 请求成功: {function}")
            return data
            
        except requests.exceptions.Timeout:
            logger.warning(f"⚠️ [Alpha Vantage] 请求超时 (尝试 {attempt + 1}/{max_retries})")
            if attempt < max_retries - 1:
                time.sleep(retry_delay)
                continue
            else:
                raise AlphaVantageAPIError("Alpha Vantage API request timeout")
                
        except requests.exceptions.RequestException as e:
            logger.error(f"❌ [Alpha Vantage] 请求失败: {e}")
            if attempt < max_retries - 1:

View on GitHub (pinned to 74783e8817)

Solutions

  1. Upgrade the API plan or switch to a paid key
  2. Cache quote/kline/news responses aggressively to cut call volume
  3. Distribute calls across the day or batch through a single throttled worker
  4. Monitor remaining quota and stop before the cap

Example fix

# before
key = 'FREE_KEY'  # 25 calls/day
# after
key = os.environ['ALPHA_VANTAGE_PREMIUM_KEY']  # higher limit
Defensive patterns

Strategy: retry

Try / catch

from tradingagents.dataflows.providers.us.alpha_vantage_common import AlphaVantageRateLimitError
try:
    data = _make_api_request(params)
except AlphaVantageRateLimitError as e:
    if 'API limit' in str(e):
        data = fallback_datasource_fetch(params)  # or queue for tomorrow
    else:
        raise

Prevention

When it happens

Trigger: Exhausting the free-tier call allowance; Alpha Vantage returns {'Information': '...limit reached...'}, the loop retries a few times, then raises with the upstream info_msg.

Common situations: Free key hitting the 25/day cap mid-run, key shared across environments, or a long-running job that accumulates calls over days.

Related errors


AI-assisted analysis of hsliuping/TradingAgents-CN@74783e8817 (2026-08-28). Data as JSON: /api/errors/05fe9cf9bdb974f7. Report an issue: GitHub.