关于 investing
investing 是通过解析 Investing.com 公开网页提取市场与公司数据的命令行技能,无需 API 密钥或身份验证。它支持行情、历史价格、财务报表及其他工具数据的查询。
主要功能
- 01获取多类金融工具的报价
- 02搜索金融工具并下载站点地图
- 03查询历史 OHLCV 数据
- 04解析公司简介和财务报表
- 05获取比率、股息及财报历史
适用场景
- 01查询股票或货币对报价
- 02查看金融工具的历史价格
- 03检查公司财务和股息记录
安装
复制下面的命令,在终端中运行。
npx skills add https:/ / github.com/ gauss314/ skills --skill investing安装后在 Claude Code 中输入/investing确认已加载。
附带文件references/REFERENCE.mdscripts/fetch_investing.py
详细介绍
Investing.com — 通过 HTML 抓取数据
用于通过解析公开 HTML 提取 Investing.com 数据的技能。无需 API key,无需身份验证。
⚠️ 法律与技术声明
- Investing.com 不提供公开 API。数据通过 Cloudflare 机器人防护从 HTML 页面提取。
- 必需依赖:
curl_cffi(在 TLS 层模拟 Chrome 120 — 纯requests会返回 Cloudflare 验证页面,而非数据)。 - 严格的速率限制: 请求间隔应保持在 1–2 秒。请求过于频繁时,Cloudflare 会返回 429/403。脚本会自动退避重试。
- 数据有延迟: 页面显示的价格为最近一个可用收盘价(美国股票延迟 15–20 分钟,其他品种也类似)。
- 遵守 Investing.com 的服务条款。 请求频率不得超过每秒 1–2 次。请勿用于大规模再分发。
- Investing.com 保留屏蔽 IP 段的权利。此技能可能随时停止工作。
脚本
| 脚本 | 描述 |
|---|---|
| fetch_investing.py | 主脚本:包含所有可用模式 |
安装依赖
pip install curl_cffi
纯
requests无法使用。Cloudflare 会检测并拦截。
快速使用
# === COTIZACIONES (auto-detect tipo) ===
python scripts/fetch_investing.py quote gold
python scripts/fetch_investing.py quote eur-usd
python scripts/fetch_investing.py quote us-spx-500
python scripts/fetch_investing.py quote bitcoin
python scripts/fetch_investing.py quote ypf-sa --type equities
python scripts/fetch_investing.py quote apple-computer-inc -q
# === BUSQUEDA EN SITEMAPS ===
python scripts/fetch_investing.py search YPF
python scripts/fetch_investing.py search gold --category commodities
python scripts/fetch_investing.py search MERVAL --category indices
python scripts/fetch_investing.py search AR --category currencies --limit 30
# === SITEMAPS COMPLETOS ===
python scripts/fetch_investing.py sitemap commodities # 344 instrumentos
python scripts/fetch_investing.py sitemap currencies # 2,394 cruces
python scripts/fetch_investing.py sitemap indices # 20K+ indices
python scripts/fetch_investing.py sitemap equities # 81K+ acciones
python scripts/fetch_investing.py sitemap etfs # 30K+ ETFs
# === HISTORICO OHLCV ===
python scripts/fetch_investing.py historical gold
python scripts/fetch_investing.py historical eur-usd
python scripts/fetch_investing.py historical ypf-sa --pages 5 # ~115 dias
python scripts/fetch_investing.py historical apple-computer-inc
# === FUNDAMENTALS ===
python scripts/fetch_investing.py profile apple-computer-inc
python scripts/fetch_investing.py financials apple-computer-inc --ftype income
python scripts/fetch_investing.py financials apple-computer-inc --ftype balance
python scripts/fetch_investing.py financials apple-computer-inc --ftype cashflow
python scripts/fetch_investing.py ratios apple-computer-inc
python scripts/fetch_investing.py dividends apple-computer-inc
python scripts/fetch_investing.py earnings apple-computer-inc
# === GUARDAR A ARCHIVO ===
python scripts/fetch_investing.py quote gold -o gold_quote.json
python scripts/fetch_investing.py historical ypf-sa -o ypf_hist.json
# === MODO SILENCIOSO (solo JSON, sin logs) ===
python scripts/fetch_investing.py quote gold -q
可用模式
| 模式 | 数据 | 端点 |
|---|---|---|
quote | 报价(价格、变动、OHLC、成交量、pair_id) | www.investing.com/{type}/{slug} |
search | 在公开站点地图中进行模糊搜索 | XML 站点地图 |
sitemap | 下载完整站点地图(工具 URL) | XML 站点地图 |
historical | 从 HTML 表格获取 OHLCV 历史数据 | /{type}/{slug}-historical-data |
profile | 描述、行业、子行业、国家、总部、员工人数 | /{type}/{slug}-company-profile |
financials | 利润表 / 资产负债表 / 现金流量表(TTM + 最近 5 年) | /{type}/{slug}-income-statement 等 |
ratios | 利润率、回报率、估值比率 | /{type}/{slug}-ratios |
dividends | 完整的股息历史记录 | /{type}/{slug}-dividends |
earnings | 财报历史(实际 EPS 与预期 EPS) | /{type}/{slug}-earnings |
工具类型
| 类型 | --type | Slug 示例 | 覆盖数量 |
|---|---|---|---|
| 股票(普通股/ADR) | equities | apple-computer-inc、ypf-sa、ggal | 81,518 |
| 大宗商品 | commodities | gold、crude-oil、brent-oil | 344 |
| 指数 | indices | us-spx-500、ibovespa、dax | 20,000+ |
| 货币对(外汇) | currencies | eur-usd、usd-ars、brl-usd | 2,394 |
| ETF | etfs | spdr-s-p-500、vanguard-ftse-all-world | 30,000+ |
| 加密货币 | crypto | bitcoin、ethereum | 4,135+ 种币,20K+ 个交易对 |
| 利率 / 债券 | rates-bonds | (不在直接站点地图中) | 20,000+ |
| 基金 | funds | (不在直接站点地图中) | 100K+ |
| 证书 | certificates | (不在直接站点地图中) | 6,222 |
自动检测: 如果不传入
--type,脚本会依次尝试 commodities → currencies → indices → etfs → crypto → equities。股票的处理速度最慢且速率限制最严格,因此会最后尝试。
实用 Slug(阿根廷 / 拉美)
| Slug | 名称 | 符号 | 类型 |
|---|---|---|---|
ypf-sa | YPF Sociedad Anonima | YPF | equities |
ypf-sociedad | YPF Sociedad(变体) | YPF | equities |
pampa-energia | Pampa Energia SA | PAMPm | equities |
pampa-energia-sa | Pampa Energia ADR | PAM | equities |
central-puerto | Central Puerto S.A. | CEPUm | equities |
central-puerto-adr | Central Puerto ADR | CEPU | equities |
tenaris | Tenaris SA | TENR | equities |
tenaris-sa | Tenaris ADR | TS | equities |
bbva | Banco Bilbao Vizcaya Argentaria | BBVA | equities |
banco-macro-sa | Banco Macro SA | BMA | equities |
mercadolibre | MercadoLibre | MELI | equities |
mercadolibre-inc | MercadoLibre Inc | MELI | equities |
globant-sa | Globant SA | GLOB | equities |
globant-cedear | Globant CEDEAR | GLOBm | equities |
despegar-com | Despegar | DESP | equities |
despegar-ba | Despegar Buenos Aires | DESPm | equities |
galicia-b | Grupo Financiero Galicia(BA) | GGALm | equities |
grupo-financiero-galicia-sa-adr | Grupo Financiero Galicia ADR | GGAL | equities |
edenor | Edenor | EDNm | equities |
transportadora-de-gas-del-sur-sa | TGS SA | TGSm | equities |
siderar | Ternium / Siderar | TXR | equities |
aluar | Aluar | ALUA | equities |
mirgor | Mirgor | MIRG | equities |
loma-negra | Loma Negra | LOMA | equities |
cresud | Cresud | CRESY | equities |
transener | Transener | TRAN | equities |
capex | Capex | CAPX | equities |
solvay | Solvay | SOLB | equities |
holcim | Holcim | HCMLY | equities |
consultatio-s. | Consultatio | CONO | equities |
garovaglio | Garovaglio | GCLA | equities |
laboratorios-richmond | Laboratorios Richmond | RICH | equities |
longvie | Longvie | LONG | equities |
rigolleau | Rigolleau | RIGO | equities |
货币(FX)
| Slug | 货币对 | 备注 |
|---|---|---|
usd-ars | USD/ARS(官方) | 官方美元 |
eur-usd | EUR/USD | 主要货币对 |
brl-usd | BRL/USD(官方) | 巴西官方美元 |
mxn-usd | MXN/USD(官方) | 墨西哥比索 |
ars-brl | ARS/BRL | 阿根廷比索兑巴西雷亚尔 |
ars-mxn | ARS/MXN | 阿根廷比索兑墨西哥比索 |
aed-ars | AED/ARS | 迪拉姆 → 比索 |
MEP / CCL / Blue: Investing.com 不会以此类形式提供这些衍生货币对。对于 MEP/CCL/blue,请使用 data912,该服务支持这些货币对。
返回的数据
quote
{
"last": "4,501.47", // precio formateado (con separadores)
"last_raw": 4501.47, // precio como float
"change": -0.78, // cambio absoluto vs last_close
"change_pct": -0.02, // (no siempre presente)
"last_close": 4502.25, // (no siempre presente)
"bid": 4500.74, // bid (commodities, currencies)
"ask": 4501.19, // ask
"open": 4502.5, // apertura del dia
"high": 4508.75, // maximo del dia
"low": 4499.97, // minimo del dia
"volume": 1633, // volumen
"avg_volume": 0, // volumen promedio
"prev_close": null, // cierre anterior
"pair_id": 1057391, // ID interno de investing.com
"name": "Gold Futures", // nombre completo
"symbol": "GC", // ticker
"currency": "USD", // moneda
"exchange": null, // exchange
"country": null, // pais
"updated_epoch": 1749091200, // timestamp ultima actualizacion
"page_title": "Gold Futures - Investing.com",
"slug": "gold",
"type": "commodities",
"url": "https://www.investing.com/commodities/gold"
}
注意: 并非所有字段都会出现在所有金融工具中。股票通常包含
last、last_raw、change、bid、ask、open、high、low、volume、prev_close、pair_id、name、symbol、currency、exchange。大宗商品通常还会包含updated_epoch。
historical
{
"slug": "gold",
"type": "commodities",
"count": 23,
"rows": [
{
"date": "Jun 04, 2026",
"price": "4,497.70",
"open": "4,481.76",
"high": "4,543.12",
"low": "4,470.55",
"vol": "3.16K",
"change_pct": "+0.69%"
},
...
]
}
默认 23 天(1 页)。使用
--pages 5可获取约 115 天的数据,依此类推。
financials
返回包含各期间(TTM、2024、2023、2022、2021、2020)及标签和值行的结构:
{
"slug": "apple-computer-inc",
"type": "equities",
"ftype": "income",
"periods": ["TTM", "2024", "2023", "2022", "2021", "2020"],
"count": 23,
"rows": [
{"label": "Total Revenue", "values": ["394,328", "385,100", "383,285", "394,328", "365,817", "274,515"]},
{"label": "Gross Profit", "values": ["170,000", ...]},
...
]
}
--ftype income|balance|cashflow
ratios
结构与 financials 相同,但包含比率(利润率、回报率、估值等)。
dividends
包含单元格(日期、股息、收益率等)的行数组:
{
"slug": "apple-computer-inc",
"type": "equities",
"count": 18,
"rows": [
["Ex-Dividend Date", "May 09, 2025", "Quarterly", "0.26", "..."],
...
]
}
earnings
行数组(日期、实际 EPS、预估 EPS、意外值等):
{
"slug": "apple-computer-inc",
"type": "equities",
"count": 20,
"rows": [
["Aug 01, 2024", "Q3 2024", "1.40", "1.35", "+3.70%", "..."],
...
]
}
技术注意事项
为什么用 curl_cffi 而不是 requests?
Investing.com 使用 Cloudflare,并在 TLS 层实施反机器人保护。User-Agent 并不重要——Cloudflare 会进行 TLS 指纹识别,并拒绝非真实浏览器的客户端。
requests(纯 Python,使用 Python urllib3 的 TLS 指纹):会被拦截,返回 challenge HTML。curl_cffi.requests.Session(impersonate="chrome120"):可以通过 challenge,因为它会模拟 Chrome 120 的 TLS 指纹。
curl_cffi 是基于 curl-impersonate 的封装(一个预加载了指纹的 libcurl 分支)。这是一个提供 Windows/Mac/Linux 预编译 wheel 的库——安装后即可使用,无需编译任何内容。
速率限制与 Cloudflare
Cloudflare 会施加严格的速率限制:
- /equities/ 是速率限制最严格的路径(请求最多、保护最强)
- /commodities/、/currencies/、/indices/ 的限制较宽松
- 如果几秒内发出 10+ 个请求 → 返回 429 或带有 "Just a moment..." 的 403
- 建议的退避时间:请求间隔 2-3 秒
- 如果收到 429,请等待 1-2 分钟
脚本通过重试和指数退避来处理这种情况。如果 IP 已被重点标记,唯一的解决办法就是等待或使用住宅代理。
类型自动检测
如果未传入 --type,脚本会逐一尝试 6 个路径。这会触发 6 个请求,可能导致速率限制。**建议:**只要知道类型,就始终传入 --type。
尝试顺序(从最快开始):
commodities(344 个工具)currencies(2,394 个)indices(20K+ 个)etfs(30K+ 个)crypto(4K+ 个)equities(81K+ 个,受速率限制)
站点地图
站点地图是唯一完全公开且不受速率限制的数据来源。它们适用于:
- 发现工具 slug(没有公开的“搜索”API)
- 构建本地目录
- 备份列表
各站点地图中的工具数量(已于 2026-06-04 验证):
- equities:81,518(9 个文件)
- commodities:344(1 个文件)
- indices:20,000+(2 个文件)
- currencies:2,394(2 个文件)
- etfs:30,000+(3 个文件)
- crypto coins:4,135
- crypto pairs:20,000+(2 个文件)
- rates/bonds:20,000+(2 个文件)
- funds:100K+(11 个文件)
- certificates:6,222
限制
- **严格的速率限制:**密集使用时,CF 可能会封锁 IP。这是网站的问题,不是脚本的问题。
- Cloudflare 可能随时通过更改 challenge 使此技能失效。
- **历史数据采用分页:**默认获取 23 天的数据,需要传入
--pages才能获取更多。
技能结构
skills/investing/
├── SKILL.md # Este archivo (guia rapida)
├── references/
│ └── REFERENCE.md # Documentacion completa + endpoints
└── scripts/
└── fetch_investing.py # Script principal
**详细文档:**请参阅 references/REFERENCE.md,了解端点、JSON 结构、示例和故障排除的完整文档。