Yahoo Finance CLI
2026-03-27
新闻来源:网淘吧
围观:14
电脑广告
手机广告
雅虎财经命令行工具
这是一个基于Node.js的命令行工具,用于通过yahoo-finance2库从雅虎财经获取全面的股票数据。
要求
- Node.js
yahoo-finance2库已全局安装或可作为yf命令使用
jq
brew install jq
npm install yahoo-finance2
sudo ln -s /opt/homebrew/bin/yahoo-finance /usr/local/bin/yf
安装
使用该工具可通过yf命令调用。其输出为JSON格式,可通过管道传递给jq
yf <module> <symbol> [queryOptions]
进行筛选。
模块
报价(实时价格与数据)
yf quote AAPL
yf quote AAPL | jq '.regularMarketPrice'
获取实时价格、涨跌幅及基础数据。
摘要报价(基本面数据等)
# Get specific sub-modules
yf quoteSummary AAPL '{"modules":["assetProfile", "financialData", "defaultKeyStatistics"]}'
# Common modules to request:
# - assetProfile (Company info, sector)
# - financialData (Target price, margins, cash)
# - defaultKeyStatistics (Enterprise value, float, shares)
# - calendarEvents (Earnings dates)
# - earnings (History and trend)
# - recommendationTrend (Analyst ratings)
# - upgradeDowngradeHistory
获取收益、财务数据、公司概况等详细模块信息。
获取技术和基本面洞察(估值、展望)。
yf insights AAPL
搜索
搜索代码。
yf search "Apple"
yf search "BTC-USD"
历史数据(已弃用)
获取历史OHLCV数据。注意:historical已弃用;请使用chart代替。
# Deprecated - use chart instead
yf historical AAPL '{"period1":"2024-01-01","period2":"2024-12-31"}'
# Recommended: use chart
yf chart AAPL '{"period1":"2024-01-01","period2":"2024-12-31"}'
趋势
查看当前趋势。
yf trendingSymbols US
示例
快速价格查询
# Full JSON then filter with jq
yf quote NVDA | jq '{symbol: .symbol, price: .regularMarketPrice, changePct: .regularMarketChangePercent}'
下个财报日期
# Use single quotes around the JSON option in zsh/bash
yf quoteSummary TSLA '{"modules":["calendarEvents"]}' | jq '.calendarEvents.earnings.earningsDate'
分析师推荐
yf quoteSummary AAPL '{"modules":["recommendationTrend"]}'
公司简介
yf quoteSummary MSFT '{"modules":["assetProfile"]}'
历史OHLCV
# Using chart (recommended)
yf chart AAPL '{"period1":"2024-01-01","period2":"2024-12-31","interval":"1d"}' | jq '.quotes[0:5]'
# Using historical (deprecated, but still works)
yf historical AAPL '{"period1":"2024-01-01","period2":"2024-12-31","interval":"1d"}' | jq '.[0:5]'
搜索代码
yf search 'Apple'
yf search 'BTC-USD'
趋势代码(美国)
yf trendingSymbols US
洞察(估值、展望)
yf insights AAPL
故障排除
- Cookies:该工具自动处理cookies(存储在
~/.yf2-cookies.json). 如果遇到问题,请尝试删除此文件。 - JSON 输出:输出为纯 JSON。使用
jq来解析它以用于脚本或提高可读性。
额外提示:
- 如果看到身份验证或解析错误,请删除 cookie 文件并重试:
rm -f ~/.yf2-cookies.json
yf quote AAPL
- 在 macOS 上使用 zsh 时,JSON 选项参数周围应优先使用单引号,并在内部使用双引号(参见上面的示例)。
- 如果只需要一个紧凑的数值(不使用 jq),请使用简短的 jq 过滤器,例如:
yf quote AAPL | jq -r '.regularMarketPrice'
文章底部电脑广告
手机广告位-内容正文底部
上一篇:NotebookLM CLI
下一篇:Brainstorming


微信扫一扫,打赏作者吧~