Loading...
Loading...
API no oficial de Yahoo Finance: precios, históricos, fundamentales, opciones, noticias en JSON puro sin wrappers.
npx skill4agent add gauss314/skills yahoo-financeyfinancehttps://query1.finance.yahoo.comhttps://query2.finance.yahoo.comv8/finance/chartquoteSummary.BA.SAimport requests
BASE = "https://query1.finance.yahoo.com"
HEADERS = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"
}
def yahoo_session():
"""Retorna requests.Session con cookie A3 y crumb."""
s = requests.Session()
s.headers.update(HEADERS)
s.get("https://fc.yahoo.com", timeout=10)
crumb = s.get(f"{BASE}/v1/test/getcrumb", timeout=10).text.strip()
s.params = {"crumb": crumb}
return s
# Uso:
# s = yahoo_session()
# r = s.get("https://query1.finance.yahoo.com/v7/finance/quote?symbols=AAPL,MSFT")| Sin auth (solo User-Agent) | Requieren crumb |
|---|---|
| |
| |
| |
| |
v8/finance/chart| Parámetro | Ejemplos |
|---|---|
| |
| |
| |
import requests
headers = {"User-Agent": "Mozilla/5.0 (...) Chrome/120.0.0.0 Safari/537.36"}
r = requests.get("https://query1.finance.yahoo.com/v8/finance/chart/AAPL",
params={"range": "1y", "interval": "1d", "events": "div,splits"},
headers=headers)
data = r.json()["chart"]["result"][0]
# data["timestamp"] -> fechas Unix
# data["indicators"]["quote"][0] -> open, high, low, close, volume
# data["indicators"]["adjclose"][0] -> precios ajustados
# data["events"] -> dividendos y splitsv7/finance/quotes = yahoo_session()
r = s.get("https://query1.finance.yahoo.com/v7/finance/quote?symbols=AAPL,MSFT,GOOGL")
quotes = r.json()["quoteResponse"]["result"]
for q in quotes:
print(q["symbol"], q["regularMarketPrice"], q["regularMarketChangePercent"])regularMarketPriceregularMarketChangePercentmarketCaptrailingPEfiftyTwoWeekHigh/LowdividendYieldvolumemarketStatev10/finance/quoteSummarys = yahoo_session()
r = s.get("https://query1.finance.yahoo.com/v10/finance/quoteSummary/AAPL",
params={"modules": "assetProfile,financialData,defaultKeyStatistics,incomeStatementHistory,balanceSheetHistory,cashflowStatementHistory,earnings,recommendationTrend"})
fundamentals = r.json()["quoteSummary"]["result"][0]
profile = fundamentals["assetProfile"] # sector, industry, employees, description
financials = fundamentals["financialData"] # EBITDA, revenue, margins, ROE, ROA
stats = fundamentals["defaultKeyStatistics"] # beta, shares, PE, PEG, short infov7/finance/optionss = yahoo_session()
r = s.get("https://query1.finance.yahoo.com/v7/finance/options/AAPL")
data = r.json()["optionChain"]["result"][0]
expirations = data["expirationDates"]
strikes = data["strikes"]
options = data["options"][0] # calls + putsv1/finance/searchr = requests.get("https://query1.finance.yahoo.com/v1/finance/search",
params={"q": "Apple", "quotesCount": 3, "newsCount": 5},
headers=HEADERS)
data = r.json()
# data["quotes"] -> tickers encontrados
# data["news"] -> noticias relacionadas| Script | Descripción |
|---|---|
| fetch_all.py | Script integral: fetch de histórico + quote + fundamentals + opciones + search + recomendaciones. Genérico para cualquier ticker con argumentos CLI. |
| fetch_quote.py | Fetch rápido de quote + fundamentals por ticker. |
| download_historical.py | Descarga históricos OHLCV a CSV. |
python scripts/fetch_all.py --ticker AAPL --all # Todo lo disponible
python scripts/fetch_all.py --ticker GGAL --all --range 5y --interval 1d # GGAL con 5 años
python scripts/fetch_all.py --ticker MSFT --chart --range max # Histórico completo
python scripts/fetch_all.py --ticker NVDA --quote --fundamentals # Quote + fundamentals
python scripts/fetch_all.py --ticker TSLA --all --all-modules # Todos los módulos (~33)
python scripts/fetch_all.py --ticker AAPL --options # Solo opciones
python scripts/fetch_all.py -t AAPL -o mi_data.json -q # Output a archivo, quiet--all--chart--quote--fundamentals--options--search--range--interval--modules--all-modules--output>> Chart (1y, 1d)... OK 250 bars
>> Quote... OK Price: $50.33 (-1.62%)
>> Fundamentals... OK 12 módulos (core)
>> Options... OK 5 expiration dates, 17 calls, 19 puts
>> Search+News... OK 5 news items
Guardado en: ggal_temp.json (123 KB)| Mercado | Sufijo | Ejemplo |
|---|---|---|
| Argentina (BCBA) | | |
| Brasil (Bovespa) | | |
| México (BMV) | | |
| Crypto | | |
| Forex | | |
| Índices | | |
| Límite | Comportamiento |
|---|---|
| ~2 req/s | Seguro |
| 3-5 req/s | Probabilidad alta de 429 |
| >10 req/s | IP block temporal |
time.sleep(0.5)| Error | Causa | Solución |
|---|---|---|
| Falta crumb | Usar |
| Rate limit | Esperar 30-60s |
| Crumb expirado | Regenerar crumb |
| Ticker inválido | Verificar con search primero |
| User-Agent default | Setear uno de navegador |
skills/yahoo-finance/
├── SKILL.md # Este archivo (quickstart)
├── references/
│ └── API_REFERENCE.md # Documentación completa de todos los endpoints
└── scripts/
├── fetch_all.py # Script integral (recomendado)
├── fetch_quote.py # Quote + fundamentals rápido
└── download_historical.py # Históricos a CSV