
Yahoo Finance
Give your coding agent live quotes, company profiles, and symbol search across HK, A-share, and US tickers via Yahoo Finance without building HTTP plumbing yourself.
Install
npx skills add https://github.com/xiaonan0527/openclaw-stock-market-skills --skill yahoo-financeWhat is this skill?
- CLI commands for quote, company profile, and ticker search via query.mjs
- Supports HK (.HK), Shanghai/Shenzhen (.SS/.SZ), and US symbols (e.g. AAPL, TSLA)
- HTTPS client with retry logic and explicit handling for HTTP 429 rate limits
- Dual base URLs (query1 and query2 finance.yahoo.com) for resilient fetches
- Runnable examples for 0700.HK, 9988.HK, and Xiaomi search out of the box
Adoption & trust: 1 installs on skills.sh; 3 GitHub stars; 3/3 security scanners passed (skills.sh audits); trending (+100% hot-view momentum).
Recommended Skills
Journey fit
Market-data hooks land when you are wiring backends and agent tools, not when you are still ideating without a product shape. integrations is the canonical shelf because the skill is a Node CLI and module around external Yahoo Finance endpoints for agent workflows.
Common Questions / FAQ
Is Yahoo Finance safe to install?
skills.sh reports 3 of 3 security scanners passed. Review the Security Audits panel on this page before installing in production.
SKILL.md
READMESKILL.md - Yahoo Finance
# Yahoo Finance Skill 查询全球股票信息,支持港股、A股、美股等市场。 ## 快速开始 ```bash # 查询腾讯股价 node scripts/query.mjs quote 0700.HK # 查询阿里巴巴公司信息 node scripts/query.mjs profile 9988.HK # 搜索股票 node scripts/query.mjs search "Xiaomi" ``` ## 支持的市场 - 港股:0700.HK (腾讯), 9988.HK (阿里巴巴), 1810.HK (小米) - A股:600519.SS (茅台), 000858.SZ (五粮液) - 美股:AAPL, TSLA, MSFT 详细文档请查看 [SKILL.md](SKILL.md) #!/usr/bin/env node /** * Yahoo Finance Query Script * 使用 Yahoo Finance API 查询股票信息(支持港股、A股、美股等全球市场) * 支持 CLI 和模块导入两种使用方式 */ import https from 'https'; import { fileURLToPath } from 'url'; const BASE_URL = 'https://query1.finance.yahoo.com'; const BASE_URL2 = 'https://query2.finance.yahoo.com'; /** * 发送 HTTPS GET 请求(带重试机制) */ async function httpsGet(url, retries = 2, delay = 1000) { for (let i = 0; i <= retries; i++) { try { return await new Promise((resolve, reject) => { https.get(url, { headers: { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36' } }, (res) => { let data = ''; res.on('data', (chunk) => data += chunk); res.on('end', () => { // 检查 HTTP 状态码 if (res.statusCode !== 200) { const preview = data.substring(0, 200); if (res.statusCode === 429) { reject(new Error(`Yahoo Finance API 请求频率过高 (HTTP 429)。请稍后再试,或使用其他数据源。`)); } else if (res.statusCode === 404) { reject(new Error(`股票代码不存在或 API 路径错误 (HTTP 404)。请检查股票代码格式。`)); } else { reject(new Error(`HTTP ${res.statusCode}: ${preview}`)); } return; } // 尝试解析 JSON try { resolve(JSON.parse(data)); } catch (e) { reject(new Error(`无法解析 API 响应 (非 JSON 格式): ${data.substring(0, 200)}`)); } }); }).on('error', reject); }); } catch (error) { // 如果是 429 错误且还有重试次数,等待后重试 if (error.message.includes('429') && i < retries) { console.error(`⚠️ 请求失败 (${i + 1}/${retries + 1}),${delay}ms 后重试...`); await new Promise(resolve => setTimeout(resolve, delay)); delay *= 2; // 指数退避 continue; } // 其他错误或重试次数用完,直接抛出 throw error; } } } /** * 查询实时股票报价(仅返回数据,不打印) */ export async function fetchQuote(symbol) { const url = `${BASE_URL}/v8/finance/chart/${encodeURIComponent(symbol)}?interval=1d&range=1d`; const data = await httpsGet(url); if (!data.chart || !data.chart.result || data.chart.result.length === 0) { throw new Error(`No data found for symbol: ${symbol}`); } const result = data.chart.result[0]; const meta = result.meta; const quote = result.indicators.quote[0]; return { symbol: meta.symbol, currency: meta.currency, exchangeName: meta.exchangeName, regularMarketPrice: meta.regularMarketPrice, regularMarketOpen: quote.open[quote.open.length - 1], regularMarketDayHigh: meta.regularMarketDayHigh, regularMarketDayLow: meta.regularMarketDayLow, regularMarketVolume: meta.regularMarketVolume, previousClose: meta.chartPreviousClose, regularMarketChange: meta.regularMarketPrice - meta.chartPreviousClose, regularMarketChangePercent: ((meta.regularMarketPrice - meta.chartPreviousClose) / meta.chartPreviousClose * 100), regularMarketTime: new Date(meta.regularMarketTime * 1000) }; } /** * 查询公司基本信息(仅返回数据,不打印) */ export async function fetchProfile(symbol) { const url = `${BASE_URL2}/v10/finance/quoteSummary/${encodeURIComponent(symbol)}?modules=assetProfile,summaryDetail,price`; const data = await httpsGet(url); if (!data.quoteSummary || !data.quoteSummary.result || data.quoteSummary.result.length === 0) { throw new Error(`No profile data found for symbol: ${symbol}`); } const result = data.quoteSummary.result[0]; const profile = result.assetProfile || {}; const summary = result.sum