$npx -y skills add gauss314/skills --skill yahoo-financeAPI no oficial de Yahoo Finance: precios, históricos, fundamentales, opciones, noticias en JSON puro sin wrappers.
| 1 | # Yahoo Finance — API Directa (sin yfinance) |
| 2 | |
| 3 | API no oficial de Yahoo Finance. Accedé a datos de **acciones, ETFs, crypto, forex, bonos, índices, opciones, fundamentos y noticias** mediante **requests HTTP directos** sin usar `yfinance` ni ningún wrapper. |
| 4 | |
| 5 | **Base URL:** `https://query1.finance.yahoo.com` |
| 6 | **Alternativa:** `https://query2.finance.yahoo.com` |
| 7 | |
| 8 | --- |
| 9 | |
| 10 | ## ⚠️ Importante |
| 11 | |
| 12 | - Yahoo **no tiene API pública oficial** desde 2017. Estos endpoints son no oficiales y pueden cambiar sin aviso. |
| 13 | - Algunos endpoints requieren autenticación via **cookie + crumb** (abajo se explica). |
| 14 | - El endpoint `v8/finance/chart` funciona sin autenticación (solo User-Agent de navegador). |
| 15 | - Siempre implementar **rate limiting** y **manejo de errores**. |
| 16 | |
| 17 | --- |
| 18 | |
| 19 | ## Documentación completa |
| 20 | |
| 21 | Para referencia exhaustiva de todos los endpoints, campos, JSON structures, códigos de error, tickers internacionales, estrategias de rate limiting y ejemplos detallados, ver: |
| 22 | |
| 23 | 📖 **[references/API_REFERENCE.md](./references/API_REFERENCE.md)** |
| 24 | |
| 25 | Ese documento incluye: |
| 26 | - Los **33 módulos** de `quoteSummary` con cada campo documentado |
| 27 | - JSON responses **completas** de cada endpoint |
| 28 | - **Tickers internacionales** (`.BA` para Argentina, `.SA` para Brasil, etc.) |
| 29 | - **WebSocket streaming** |
| 30 | - **Screener**, **lookup**, **trending** |
| 31 | - **Estrategias de rate limiting** con exponential backoff y rotación de User-Agent |
| 32 | |
| 33 | --- |
| 34 | |
| 35 | ## Autenticación: Cookie + Crumb |
| 36 | |
| 37 | Varios endpoints requieren un **crumb** (token CSRF) que se obtiene con cookies de sesión. |
| 38 | |
| 39 | ```python |
| 40 | import requests |
| 41 | |
| 42 | BASE = "https://query1.finance.yahoo.com" |
| 43 | HEADERS = { |
| 44 | "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36" |
| 45 | } |
| 46 | |
| 47 | def yahoo_session(): |
| 48 | """Retorna requests.Session con cookie A3 y crumb.""" |
| 49 | s = requests.Session() |
| 50 | s.headers.update(HEADERS) |
| 51 | s.get("https://fc.yahoo.com", timeout=10) |
| 52 | crumb = s.get(f"{BASE}/v1/test/getcrumb", timeout=10).text.strip() |
| 53 | s.params = {"crumb": crumb} |
| 54 | return s |
| 55 | |
| 56 | # Uso: |
| 57 | # s = yahoo_session() |
| 58 | # r = s.get("https://query1.finance.yahoo.com/v7/finance/quote?symbols=AAPL,MSFT") |
| 59 | ``` |
| 60 | |
| 61 | ### Endpoints según autenticación |
| 62 | |
| 63 | | Sin auth (solo User-Agent) | Requieren crumb | |
| 64 | |----------------------------|-----------------| |
| 65 | | `v8/finance/chart` (históricos) | `v7/finance/quote` (precios) | |
| 66 | | `v1/finance/search` (búsqueda) | `v10/finance/quoteSummary` (fundamentos) | |
| 67 | | `v1/finance/trending` (tendencias) | `v7/finance/options` (opciones) | |
| 68 | | `v1/finance/lookup` (lookup) | `v6/finance/recommendationsbysymbol` | |
| 69 | |
| 70 | --- |
| 71 | |
| 72 | ## Endpoints — Resumen rápido |
| 73 | |
| 74 | ### 1. Históricos OHLCV — `v8/finance/chart` |
| 75 | |
| 76 | GET https://query1.finance.yahoo.com/v8/finance/chart/{symbol}?range=1y&interval=1d |
| 77 | |
| 78 | | Parámetro | Ejemplos | |
| 79 | |-----------|----------| |
| 80 | | `range` | `1d`, `5d`, `1mo`, `3mo`, `6mo`, `1y`, `5y`, `10y`, `ytd`, `max` | |
| 81 | | `interval` | `1m`, `5m`, `15m`, `1h`, `1d`, `1wk`, `1mo` | |
| 82 | | `events` | `div,splits` (incluye dividendos y splits) | |
| 83 | |
| 84 | ```python |
| 85 | import requests |
| 86 | headers = {"User-Agent": "Mozilla/5.0 (...) Chrome/120.0.0.0 Safari/537.36"} |
| 87 | r = requests.get("https://query1.finance.yahoo.com/v8/finance/chart/AAPL", |
| 88 | params={"range": "1y", "interval": "1d", "events": "div,splits"}, |
| 89 | headers=headers) |
| 90 | data = r.json()["chart"]["result"][0] |
| 91 | # data["timestamp"] -> fechas Unix |
| 92 | # data["indicators"]["quote"][0] -> open, high, low, close, volume |
| 93 | # data["indicators"]["adjclose"][0] -> precios ajustados |
| 94 | # data["events"] -> dividendos y splits |
| 95 | ``` |
| 96 | |
| 97 | ### 2. Quote — `v7/finance/quote` |
| 98 | |
| 99 | ```python |
| 100 | s = yahoo_session() |
| 101 | r = s.get("https://query1.finance.yahoo.com/v7/finance/quote?symbols=AAPL,MSFT,GOOGL") |
| 102 | quotes = r.json()["quoteResponse"]["result"] |
| 103 | for q in quotes: |
| 104 | print(q["symbol"], q["regularMarketPrice"], q["regularMarketChangePercent"]) |
| 105 | ``` |
| 106 | |
| 107 | Campos: `regularMarketPrice`, `regularMarketChangePercent`, `marketCap`, `trailingPE`, `fiftyTwoWeekHigh/Low`, `dividendYield`, `volume`, `marketState` (PRE/REGULAR/POST/CLOSED). |
| 108 | |
| 109 | ### 3. Fundamentos — `v10/finance/quoteSummary` |
| 110 | |
| 111 | ```python |
| 112 | s = yahoo_session() |
| 113 | r = s.get("https://query1.finance.yahoo.com/v10/finance/quoteSummary/AAPL", |
| 114 | params={"modules": "assetProfile,financialData,defaultKeyStatistics,incomeStatementHistory,balanceSheetHistory,cashflowStatementHistory,earnings,recommendationTrend"}) |
| 115 | fundamentals = r.json()["quoteSummary"]["result"][0] |
| 116 | profile = fundamentals["assetProfile"] # sector, industry, employees, description |
| 117 | financials = fundamentals["financialData"] # EBITDA, revenue, margins, ROE, ROA |
| 118 | stats = fundamentals["defaultKeyStatistics"] # beta, shares, PE, PEG, short info |
| 119 | ``` |
| 120 | |
| 121 | Hay **33 módulos disponibles**. Ver lista completa en [API_REFERENCE.md sección 4](./references/API_REFERENCE.md#4-v10financequotesummary--fundamentos). |
| 122 | |
| 123 | ### 4. Opciones — `v7/finance/options` |
| 124 | |
| 125 | ```python |
| 126 | s = yahoo_ses |