Use the Yahoo Finance API to query global stock market data, supporting markets such as Hong Kong stocks, A-shares, and US stocks.
Features
- Real-time stock quotes - Get real-time stock quotes (about 15 minutes delayed)
- Basic company information - Query company overview, industry, market cap, and other information
- Historical price data - Get historical price data (supports multiple time ranges and intervals)
- Search stocks - Search stocks by company name or ticker symbol
Supported markets
- Hong Kong stocks(Hong Kong Stock Exchange)
- A-shares(Shanghai & Shenzhen Stock Exchange)
- US stocks(US Stock Markets)
- Other global markets
Stock ticker format
Hong Kong stocks
- Tencent Holdings:
0700.HK - Alibaba:
9988.HK - Xiaomi Group:
1810.HK - Meituan:
3690.HK - BYD:
1211.HK
A-shares
- Shanghai Composite Index:
000001.SS - Kweichow Moutai:
600519.SS - Wuliangye:
000858.SZ - CATL:
300750.SZ
US stocks
- Apple:
AAPL - Tesla:
TSLA - Microsoft:
MSFT
Usage
1. Query real-time stock quotes
node ~/.openclaw/workspace-stock/yahoo-finance/scripts/query.mjs quote 0700.HK
2. Query basic company information
node ~/.openclaw/workspace-stock/yahoo-finance/scripts/query.mjs profile 9988.HK
3. Get historical price data
node ~/.openclaw/workspace-stock/yahoo-finance/scripts/query.mjs history 0700.HK --range 1mo --interval 1d
4. Search stocks
node ~/.openclaw/workspace-stock/yahoo-finance/scripts/query.mjs search "Tencent"
Parameter description
Historical data range (--range)
1d- 1 day5d- 5 days1mo- 1 month3mo- 3 months6mo- 6 months1y- 1 year2y- 2 years5y- 5 years10y- 10 yearsytd- Year to datemax- Maximum range
Data interval (--interval)
1m,2m,5m,15m,30m,60m,90m- Minute level1h- Hourly1d- Daily5d- 5-day1wk- Weekly1mo- Monthly3mo- Quarterly
Examples
Query Tencent stock price
node ~/.openclaw/workspace-stock/yahoo-finance/scripts/query.mjs quote 0700.HK
Output:
📈 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
Query Alibaba company information
node ~/.openclaw/workspace-stock/yahoo-finance/scripts/query.mjs profile 9988.HK
Get Xiaomi's daily candlestick chart for the last 3 months
node ~/.openclaw/workspace-stock/yahoo-finance/scripts/query.mjs history 1810.HK --range 3mo --interval 1d
Search BYD
node ~/.openclaw/workspace-stock/yahoo-finance/scripts/query.mjs search "BYD"
Module import usage
Import and use in other scripts:
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);
Notes
- Data delay: Yahoo Finance free data usually has a delay of about 15 minutes
- Request frequency: Although there is no explicit request limit, reasonable use is recommended to avoid overly frequent requests
- Data accuracy: Data is for reference only and does not constitute investment advice
- API stability: Yahoo Finance is an unofficial API and may change
Technical details
- Uses Node.js native
httpsmodule - RESTful API calls
- JSON format output
- Supports both command-line and module import usage
- Completely free, no API Key required