Alpha Vantage API Integration
Financial data API providing stocks, forex, crypto, technical indicators, fundamental data, economic indicators, and AI-powered news sentiment analysis.
Quick Start
Authentication
# Environment variable (recommended)
export ALPHAVANTAGE_API_KEY="your_api_key"
# Or in .env file
ALPHAVANTAGE_API_KEY=your_api_key
Basic Usage (Python)
import requests
import os
API_KEY = os.getenv("ALPHAVANTAGE_API_KEY")
BASE_URL = "https://www.alphavantage.co/query"
def get_quote(symbol: str) -> dict:
"""Get real-time quote for a symbol."""
response = requests.get(BASE_URL, params={
"function": "GLOBAL_QUOTE",
"symbol": symbol,
"apikey": API_KEY
})
return response.json().get("Global Quote", {})
# Example
quote = get_quote("AAPL")
print(f"AAPL: ${quote['05. price']} ({quote['10. change percent']})")
Using Python Package
from alpha_vantage.timeseries import TimeSeries
from alpha_vantage.techindicators import TechIndicators
# Time series data
ts = TimeSeries(key=API_KEY, output_format='pandas')
data, meta = ts.get_daily(symbol='AAPL', outputsize='compact')
# Technical indicators
ti = TechIndicators(key=API_KEY, output_format='pandas')
rsi, meta = ti.get_rsi(symbol='AAPL', interval='daily', time_period=14)
API Functions Reference
Stock Time Series
| Function | Description | Free |
|---|
TIME_SERIES_INTRADAY | 1-60min intervals | ✅ |
TIME_SERIES_DAILY | Daily OHLCV | ✅ |
TIME_SERIES_DAILY_ADJUSTED | With splits/dividends | ⚠️ Premium |
TIME_SERIES_WEEKLY | Weekly OHLCV | ✅ |
TIME_SERIES_MONTHLY | Monthly OHLCV | ✅ |
GLOBAL_QUOTE | Latest quote | ✅ |
SYMBOL_SEARCH | Search symbols | ✅ |
Fundamental Data
| Function | Description | Free |
|---|
OVERVIEW | Company overview | ✅ |
INCOME_STATEMENT | Income statements | ✅ |
BALANCE_SHEET | Balance sheets | ✅ |
CASH_FLOW | Cash flow statements | ✅ |
EARNINGS | Earnings history | ✅ |
EARNINGS_CALENDAR | Upcoming earnings | ✅ |
IPO_CALENDAR | Upcoming IPOs | ✅ |
Forex
| Function | Description | Free |
|---|
CURRENCY_EXCHANGE_RATE | Real-time rate | ✅ |
FX_INTRADAY | Intraday forex | ✅ |
FX_DAILY | Daily forex | ✅ |
FX_WEEKLY | Weekly forex | ✅ |
FX_MONTHLY | Monthly forex | ✅ |
Cryptocurrency
| Function | Description | Free |
|---|
CURRENCY_EXCHANGE_RATE | Crypto rate | ✅ |
DIGITAL_CURRENCY_DAILY | Daily crypto | ✅ |
DIGITAL_CURRENCY_WEEKLY | Weekly crypto | ✅ |
DIGITAL_CURRENCY_MONTHLY | Monthly crypto | ✅ |
Technical Indicators (50+)
| Category | Indicators |
|---|
| Trend | SMA, EMA, WMA, DEMA, TEMA, KAMA, MAMA, T3, TRIMA |
| Momentum | RSI, MACD, STOCH, WILLR, ADX, CCI, MFI, ROC, AROON, MOM |
| Volatility | BBANDS, ATR, NATR, TRANGE |
| Volume | OBV, AD, ADOSC |
| Hilbert | HT_TRENDLINE, HT_SINE, HT_PHASOR, etc. |
Economic Indicators
| Function | Description | Free |
|---|
REAL_GDP | US GDP | ✅ |
CPI | Consumer Price Index | ✅ |
INFLATION | Inflation rate | ✅ |
UNEMPLOYMENT | Unemployment rate | ✅ |
FEDERAL_FUNDS_RATE | Fed funds rate | ✅ |
TREASURY_YIELD | Treasury yields | ✅ |
Alpha Intelligence
| Function | Description | Free |
|---|
NEWS_SENTIMENT | AI sentiment analysis | ✅ |
TOP_GAINERS_LOSERS | Market movers | ✅ |
INSIDER_TRANSACTIONS | Insider trades | ⚠️ Premium |
ANALYTICS_FIXED_WINDOW | Analytics | ⚠️ Premium |
Rate Limits
| Tier | Daily | Per Minute | Price |
|---|
| Free | 25 | 5 | $0 |
| Premium | Unlimited | 75-1,200 | $49.99-$249.99/mo |
Important: Rate limits are IP-based, not key-based.
Common Tasks
Task: Get Daily Stock Data
def get_daily_data(symbol: str, full: bool = False) -> dict:
"""Get daily OHLCV data."""
response = requests.get(BASE_URL, params={
"function": "TIME_SERIES_DAILY",
"symbol": symbol,
"outputsize": "full" if full else "compact",
"apikey": API_KEY
})
return response.json().get("Time Series (Daily)", {})
# Example
data = get_daily_data("AAPL")
latest = list(data.items())[0]
print(f"{latest[0]}: Close ${latest[1]['4. close']}")
Task: Get Technical Indicator
def get_rsi(symbol: str, period: int = 14) -> dict:
"""Get RSI indicator values."""
response = requests.get(BASE_URL, params={
"function": "RSI",
"symbol": symbol,
"interval": "daily",
"time_period": period,
"series_type": "close",
"apikey": API_KEY
})
return response.json().get("Technical Analysis: RSI", {})
# Example
rsi = get_rsi("AAPL")
latest_rsi = list(rsi.values())[0]["RSI"]
print(f"AAPL R
...