yf-quotes
A Rust CLI tool for downloading historical OHLCV (Open, High, Low, Close, Volume) stock data from Yahoo Finance.
Features
- 📈 Fetch historical stock data for any symbol
- 📊 Support for daily, weekly, and monthly intervals
- 🗓️ Flexible date ranges (predefined or custom)
- 📦 Output to JSON files (individual or combined)
- ⚡ Built-in rate limiting to avoid API throttling
- 🎯 Batch processing for multiple symbols
- ✨ Pretty-print JSON support
Installation
Build from source
The binary will be available at target/release/yf-quotes.
Add to PATH (optional)
# Copy to a directory in your PATH
Usage
Basic Examples
# Fetch 1 year of daily data for Apple
# Fetch data for multiple symbols
# Use custom date range
# Weekly data for 5 years
# Monthly data with pretty-printed JSON
Combined Output
# Combine multiple symbols into a single file
# Combine with custom filename
Advanced Options
# Custom output directory
# Adjust rate limiting (requests per minute)
# Enable verbose logging
CLI Arguments
| Argument | Short | Description | Default |
|---|---|---|---|
<SYMBOLS>... |
One or more stock symbols (required) | - | |
--start |
-s |
Start date in YYYY-MM-DD format | - |
--end |
-e |
End date in YYYY-MM-DD format | Today |
--range |
-r |
Predefined range: 1mo, 3mo, 6mo, 1y, 2y, 5y, 10y, ytd, max | - |
--interval |
-i |
Data interval: daily, weekly, monthly | daily |
--output-dir |
-o |
Output directory for JSON files | . |
--combine |
Combine all symbols into one file | false | |
--combined-filename |
Filename for combined output | combined.json | |
--pretty |
Pretty-print JSON output | false | |
--rate-limit |
Requests per minute | 5 | |
--verbose |
-v |
Enable verbose logging | false |
Note: Either --range or --start must be provided, but not both.
Output Format
Individual Symbol Output
Each symbol is saved to <symbol>.json (e.g., aapl.json):
Combined Output
When using --combine, all symbols are saved to a single file:
Predefined Date Ranges
| Range | Description |
|---|---|
1mo |
1 month |
3mo |
3 months |
6mo |
6 months |
1y |
1 year |
2y |
2 years |
5y |
5 years |
10y |
10 years |
ytd |
Year to date |
max |
Maximum available history |
Data Intervals
| Interval | Description |
|---|---|
daily |
Daily bars (default) |
weekly |
Weekly bars |
monthly |
Monthly bars |
Error Handling
The tool handles various error conditions:
- Invalid symbols: Warns and continues with other symbols
- Rate limiting: Built-in rate limiter prevents 429 errors
- No data available: Skips symbols with no data
- Network errors: Reports and continues with remaining symbols
Failed symbols are reported in the summary at the end.
Rate Limiting
Yahoo Finance has rate limits on API requests. The default is 5 requests per minute, which is conservative and should avoid rate limiting issues.
If you need to fetch many symbols, you can:
- Reduce the rate limit:
--rate-limit 3 - Split into multiple batches
- Use the
--combineflag to track progress better
Examples
Portfolio Tracking
# Track a portfolio of tech stocks
Historical Analysis
# Get 10 years of monthly data for S&P 500
Comparison Study
# Compare multiple stocks over the same period
License
MIT
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Disclaimer
This tool is for educational and research purposes only. Always verify data from official sources before making investment decisions.
Yahoo Finance data is provided by Yahoo Finance and subject to their terms of service.