依赖安装
pip3 install yfinance
代码
import yfinance as yf
data = yf.download("QQQ", start="2025-06-01", end="2025-07-23", interval="15m")
// 保存到文件中
data.to_csv("QQQ.cvs")
运行结果
常见问题
- 报错
YFRateLimitError('Too Many Requests. Rate limited. Try after a while.')
字面意思是请求频率太高,但实际是网络受限制,加个全局VPN可以解决 - 报错
YFPricesMissingError('possibly delisted; no price data found (15m 2020-01-01 -> 2025-07-23) (Yahoo error = "15m data not available for startTime=1577854800 and endTime=1753243200. The requested range must be within the last 60 days.")')
每次请求的数据范围不能太大,需要分批下载数据
美股开户
使用这个链接注册,可获得最高1000美元股票奖励
https://ibkr.com/referral/haobo109

