
Yahoo Finance
- 101 installs
- 3 repo stars
- Updated March 8, 2026
- xiaonan0527/openclaw-stock-market-skills
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.
About
Yahoo Finance is an agent skill that wraps Yahoo’s public quote APIs in a small Node script you can call from the terminal or import into tooling. Solo and indie builders use it when a stock-trading bot, portfolio assistant, or research agent needs current prices, issuer metadata, or symbol discovery across Hong Kong, mainland China, and US listings without maintaining scrapers. The workflow is deliberately narrow: run quote for a ticker, profile for fundamentals-style company blocks, or search for fuzzy name matches. Because responses come straight from Yahoo, you should treat rate limits and occasional outages as production concerns and cache or backoff in your own layer. It fits Claude Code, Cursor, and similar agents that can execute Node and need procedural steps for finance integrations rather than one-off chat guesses about tickers.
- 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
Yahoo Finance by the numbers
- 101 all-time installs (skills.sh)
- +1 installs in the week ending Jul 27, 2026 (Skillselion tracking)
- Ranked #522 of 1,106 Finance & Trading skills by installs in the Skillselion catalog
- Security screen: LOW risk (skills.sh audit)
- Data as of Jul 27, 2026 (Skillselion catalog sync)
npx skills add https://github.com/xiaonan0527/openclaw-stock-market-skills --skill yahoo-financeAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 101 |
|---|---|
| repo stars | ★ 3 |
| Security audit | 3 / 3 scanners passed |
| Last updated | March 8, 2026 |
| Repository | xiaonan0527/openclaw-stock-market-skills ↗ |
What it does
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.
Files
Yahoo Finance 股票查询 Skill
使用 Yahoo Finance API 查询全球股票市场数据,支持港股、A股、美股等市场。
功能
1. 实时股票报价 - 获取股票的实时报价(延迟约15分钟) 2. 公司基本信息 - 查询公司概况、行业、市值等信息 3. 历史价格数据 - 获取历史价格数据(支持多种时间范围和间隔) 4. 搜索股票 - 根据公司名称或代码搜索股票
支持的市场
- 港股(Hong Kong Stock Exchange)
- A股(Shanghai & Shenzhen Stock Exchange)
- 美股(US Stock Markets)
- 全球其他市场
股票代码格式
港股
- 腾讯控股:
0700.HK - 阿里巴巴:
9988.HK - 小米集团:
1810.HK - 美团:
3690.HK - 比亚迪:
1211.HK
A股
- 上证指数:
000001.SS - 贵州茅台:
600519.SS - 五粮液:
000858.SZ - 宁德时代:
300750.SZ
美股
- 苹果:
AAPL - 特斯拉:
TSLA - 微软:
MSFT
使用方法
1. 查询实时股票报价
node ~/.openclaw/workspace-stock/yahoo-finance/scripts/query.mjs quote 0700.HK2. 查询公司基本信息
node ~/.openclaw/workspace-stock/yahoo-finance/scripts/query.mjs profile 9988.HK3. 获取历史价格数据
node ~/.openclaw/workspace-stock/yahoo-finance/scripts/query.mjs history 0700.HK --range 1mo --interval 1d4. 搜索股票
node ~/.openclaw/workspace-stock/yahoo-finance/scripts/query.mjs search "Tencent"参数说明
历史数据范围 (--range)
1d- 1天5d- 5天1mo- 1个月3mo- 3个月6mo- 6个月1y- 1年2y- 2年5y- 5年10y- 10年ytd- 年初至今max- 最大范围
数据间隔 (--interval)
1m,2m,5m,15m,30m,60m,90m- 分钟级1h- 小时1d- 日线5d- 5日线1wk- 周线1mo- 月线3mo- 季线
示例
查询腾讯股价
node ~/.openclaw/workspace-stock/yahoo-finance/scripts/query.mjs quote 0700.HK输出:
📈 0700.HK 实时报价:
交易所: HKSE
货币: HKD
当前价格: HKD 385.60
开盘价: HKD 382.00
最高价: HKD 388.20
最低价: HKD 380.40
前收盘: HKD 383.00
涨跌额: HKD 2.60
涨跌幅: 0.68%
成交量: 25,432,100查询阿里巴巴公司信息
node ~/.openclaw/workspace-stock/yahoo-finance/scripts/query.mjs profile 9988.HK获取小米最近3个月的日K线
node ~/.openclaw/workspace-stock/yahoo-finance/scripts/query.mjs history 1810.HK --range 3mo --interval 1d搜索比亚迪
node ~/.openclaw/workspace-stock/yahoo-finance/scripts/query.mjs search "BYD"模块导入使用
在其他脚本中导入使用:
import { fetchQuote, fetchProfile, fetchHistory, fetchSearch } from '../yahoo-finance/scripts/query.mjs';
// 查询腾讯股价
const quote = await fetchQuote('0700.HK');
console.log(quote.regularMarketPrice);
// 查询公司信息
const profile = await fetchProfile('9988.HK');
console.log(profile.longName);
// 获取历史数据
const history = await fetchHistory('1810.HK', '1mo', '1d');
console.log(history.close);
// 搜索股票
const results = await fetchSearch('Tencent');
console.log(results.quotes);注意事项
1. 数据延迟:Yahoo Finance 免费数据通常有15分钟左右的延迟 2. 请求频率:虽然没有明确的请求限制,但建议合理使用,避免过于频繁的请求 3. 数据准确性:数据仅供参考,不构成投资建议 4. API 稳定性:Yahoo Finance 是非官方 API,可能会有变动
技术细节
- 使用 Node.js 原生
https模块 - RESTful API 调用
- JSON 格式输出
- 支持命令行和模块导入两种使用方式
- 完全免费,无需 API Key
Yahoo Finance Skill
查询全球股票信息,支持港股、A股、美股等市场。
快速开始
# 查询腾讯股价
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
#!/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.summaryDetail || {};
const price = result.price || {};
return {
symbol: price.symbol,
shortName: price.shortName,
longName: price.longName,
currency: price.currency,
exchange: price.exchangeName,
sector: profile.sector,
industry: profile.industry,
country: profile.country,
website: profile.website,
marketCap: price.marketCap?.raw,
employees: profile.fullTimeEmployees,
description: profile.longBusinessSummary,
fiftyTwoWeekHigh: summary.fiftyTwoWeekHigh?.raw,
fiftyTwoWeekLow: summary.fiftyTwoWeekLow?.raw,
dividendYield: summary.dividendYield?.raw
};
}
/**
* 获取历史价格数据(仅返回数据,不打印)
*/
export async function fetchHistory(symbol, range = '1mo', interval = '1d') {
const url = `${BASE_URL}/v8/finance/chart/${encodeURIComponent(symbol)}?interval=${interval}&range=${range}`;
const data = await httpsGet(url);
if (!data.chart || !data.chart.result || data.chart.result.length === 0) {
throw new Error(`No history data found for symbol: ${symbol}`);
}
const result = data.chart.result[0];
const timestamps = result.timestamp;
const quote = result.indicators.quote[0];
return {
symbol: result.meta.symbol,
timestamps,
open: quote.open,
high: quote.high,
low: quote.low,
close: quote.close,
volume: quote.volume
};
}
/**
* 搜索股票(仅返回数据,不打印)
*/
export async function fetchSearch(query) {
const url = `${BASE_URL}/v1/finance/search?q=${encodeURIComponent(query)}"esCount=10&newsCount=0`;
const data = await httpsGet(url);
if (!data.quotes) {
return { count: 0, quotes: [] };
}
return {
count: data.quotes.length,
quotes: data.quotes.map(q => ({
symbol: q.symbol,
shortname: q.shortname || q.longname,
exchange: q.exchange,
type: q.quoteType
}))
};
}
// ============ CLI 功能(带打印输出) ============
/**
* 查询实时股票报价(CLI版本,带打印)
*/
async function getQuote(symbol) {
const data = await fetchQuote(symbol);
console.log(`\n📈 ${data.symbol} 实时报价:\n`);
console.log(`交易所: ${data.exchangeName}`);
console.log(`货币: ${data.currency}`);
console.log(`当前价格: ${data.currency} ${data.regularMarketPrice.toFixed(2)}`);
console.log(`开盘价: ${data.currency} ${data.regularMarketOpen?.toFixed(2) || 'N/A'}`);
console.log(`最高价: ${data.currency} ${data.regularMarketDayHigh.toFixed(2)}`);
console.log(`最低价: ${data.currency} ${data.regularMarketDayLow.toFixed(2)}`);
console.log(`前收盘: ${data.currency} ${data.previousClose.toFixed(2)}`);
console.log(`涨跌额: ${data.currency} ${data.regularMarketChange.toFixed(2)}`);
console.log(`涨跌幅: ${data.regularMarketChangePercent.toFixed(2)}%`);
console.log(`成交量: ${data.regularMarketVolume.toLocaleString()}`);
console.log(`时间: ${data.regularMarketTime.toLocaleString('zh-CN')}`);
return data;
}
/**
* 查询公司基本信息(CLI版本,带打印)
*/
async function getProfile(symbol) {
const data = await fetchProfile(symbol);
console.log(`\n🏢 ${data.symbol} 公司信息:\n`);
console.log(`公司名称: ${data.longName || data.shortName}`);
console.log(`交易所: ${data.exchange}`);
console.log(`货币: ${data.currency}`);
console.log(`行业: ${data.sector || 'N/A'}`);
console.log(`细分行业: ${data.industry || 'N/A'}`);
console.log(`国家: ${data.country || 'N/A'}`);
console.log(`市值: ${data.marketCap ? (data.marketCap / 1e9).toFixed(2) + 'B' : 'N/A'}`);
console.log(`员工数: ${data.employees?.toLocaleString() || 'N/A'}`);
console.log(`52周最高: ${data.fiftyTwoWeekHigh?.toFixed(2) || 'N/A'}`);
console.log(`52周最低: ${data.fiftyTwoWeekLow?.toFixed(2) || 'N/A'}`);
console.log(`股息率: ${data.dividendYield ? (data.dividendYield * 100).toFixed(2) + '%' : 'N/A'}`);
console.log(`网站: ${data.website || 'N/A'}`);
if (data.description) {
console.log(`\n公司简介:`);
console.log(data.description.substring(0, 300) + '...');
}
return data;
}
/**
* 获取历史价格数据(CLI版本,带打印)
*/
async function getHistory(symbol, range = '1mo', interval = '1d') {
const data = await fetchHistory(symbol, range, interval);
console.log(`\n📊 ${data.symbol} 历史数据 (${range}, ${interval}):\n`);
console.log(`数据点数: ${data.timestamps.length}`);
// 显示最近5个数据点
const count = Math.min(5, data.timestamps.length);
console.log(`\n最近${count}个交易日:`);
for (let i = data.timestamps.length - count; i < data.timestamps.length; i++) {
const date = new Date(data.timestamps[i] * 1000).toLocaleDateString('zh-CN');
const open = data.open[i]?.toFixed(2) || 'N/A';
const high = data.high[i]?.toFixed(2) || 'N/A';
const low = data.low[i]?.toFixed(2) || 'N/A';
const close = data.close[i]?.toFixed(2) || 'N/A';
const volume = data.volume[i]?.toLocaleString() || 'N/A';
console.log(`${date}: 开${open} 高${high} 低${low} 收${close} 量${volume}`);
}
return data;
}
/**
* 搜索股票(CLI版本,带打印)
*/
async function searchSymbol(query) {
const data = await fetchSearch(query);
console.log(`\n🔍 搜索结果: "${query}"\n`);
if (data.count === 0) {
console.log('未找到匹配的股票');
return data;
}
console.log(`找到 ${data.count} 个结果:\n`);
data.quotes.forEach((item, i) => {
console.log(`${i + 1}. ${item.symbol} - ${item.shortname} (${item.exchange}, ${item.type})`);
});
return data;
}
/**
* 主函数(仅在 CLI 模式下执行)
*/
async function main() {
const args = process.argv.slice(2);
if (args.length === 0) {
console.log(`
Yahoo Finance Query Tool
用法:
node query.mjs <command> <symbol> [options]
命令:
quote <symbol> 查询实时股票报价
profile <symbol> 查询公司基本信息
history <symbol> 获取历史价格数据
search <query> 搜索股票
选项:
--range <range> 历史数据范围 (1d, 5d, 1mo, 3mo, 6mo, 1y, 2y, 5y, 10y, ytd, max)
--interval <interval> 数据间隔 (1m, 2m, 5m, 15m, 30m, 60m, 90m, 1h, 1d, 5d, 1wk, 1mo, 3mo)
股票代码格式:
港股: 0700.HK (腾讯), 9988.HK (阿里巴巴), 1810.HK (小米)
A股: 000001.SS (上证), 600519.SS (茅台), 000858.SZ (五粮液)
美股: AAPL, TSLA, MSFT
示例:
node query.mjs quote 0700.HK # 查询腾讯股价
node query.mjs profile 9988.HK # 查询阿里巴巴公司信息
node query.mjs history 0700.HK --range 1mo --interval 1d
node query.mjs search "Tencent" # 搜索腾讯
`);
process.exit(0);
}
const command = args[0];
const symbol = args[1];
// 解析选项
const options = {};
for (let i = 2; i < args.length; i += 2) {
if (args[i].startsWith('--')) {
options[args[i].substring(2)] = args[i + 1];
}
}
try {
switch (command) {
case 'quote':
await getQuote(symbol);
break;
case 'profile':
await getProfile(symbol);
break;
case 'history':
await getHistory(symbol, options.range || '1mo', options.interval || '1d');
break;
case 'search':
await searchSymbol(symbol);
break;
default:
console.error(`未知命令: ${command}`);
process.exit(1);
}
} catch (error) {
console.error(`\n❌ 错误: ${error.message}`);
process.exit(1);
}
}
// 仅在直接运行时执行 main(),作为模块导入时不执行
if (import.meta.url === `file://${process.argv[1]}`) {
main();
}
Yahoo Finance Skill 创建完成 ✅
功能测试
✅ 已测试通过
1. 搜索功能 - 可以搜索全球股票 2. 港股报价 - 成功查询腾讯(0700.HK)、阿里巴巴(9988.HK)、小米(1810.HK) 3. 实时数据 - 数据实时更新,包含价格、涨跌幅、成交量等
测试结果示例
腾讯控股 (0700.HK)
- 当前价格: HKD 506.00
- 涨跌幅: -0.88%
- 成交量: 32,965,498
阿里巴巴 (9988.HK)
- 当前价格: HKD 129.90
- 涨跌幅: -3.64%
- 成交量: 163,125,092
小米集团 (1810.HK)
- 当前价格: HKD 32.00
- 涨跌幅: +1.33%
- 成交量: 205,307,041
Skill 结构
yahoo-finance/
├── SKILL.md # 完整文档
├── README.md # 快速开始
└── scripts/
└── query.mjs # 查询脚本(支持 CLI 和模块导入)使用方式
1. CLI 命令行
# 查询港股报价
node yahoo-finance/scripts/query.mjs quote 0700.HK
# 查询公司信息
node yahoo-finance/scripts/query.mjs profile 9988.HK
# 搜索股票
node yahoo-finance/scripts/query.mjs search "Tencent"
# 获取历史数据
node yahoo-finance/scripts/query.mjs history 0700.HK --range 1mo --interval 1d2. 模块导入
import { fetchQuote, fetchProfile, fetchHistory, fetchSearch } from '../yahoo-finance/scripts/query.mjs';
const quote = await fetchQuote('0700.HK');
const profile = await fetchProfile('9988.HK');支持的市场
- ✅ 港股 (HK)
- ✅ A股 (SS/SZ)
- ✅ 美股 (US)
- ✅ 全球其他市场
与 Finnhub Skill 对比
| 功能 | Finnhub | Yahoo Finance |
|---|---|---|
| 美股 | ✅ 优秀 | ✅ 良好 |
| 港股 | ❌ 不支持 | ✅ 支持 |
| A股 | ❌ 不支持 | ✅ 支持 |
| 分析师评级 | ✅ 支持 | ❌ 不支持 |
| API Key | 需要 | 不需要 |
| 请求限制 | 60/分钟 | 无明确限制 |
建议使用场景
- 美股 + 分析师数据 → 使用 Finnhub
- 港股 + A股 → 使用 Yahoo Finance
- 全球市场概览 → 使用 Yahoo Finance
下一步
可以在 generate-report.mjs 中集成 Yahoo Finance,支持港股动量报告。
Related skills
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.