yfinance-rs
An ergonomic, async-first Rust client for the unofficial Yahoo Finance API.
This crate provides a simple and efficient way to fetch financial data from Yahoo Finance.
It is designed to feel familiar to users of the popular Python yfinance library, but
leverages Rust's powerful type system and async capabilities for performance and safety.
Features
Core Data
- Historical Data: Fetch daily, weekly, or monthly OHLCV data with automatic split/dividend adjustments.
- Real-time Quotes: Get live quote updates with detailed market information.
- Fast Quotes: Optimized quote fetching with essential data only (
fast_info). - Multi-Symbol Downloads: Concurrently download historical data for many symbols at once.
- Batch Quotes: Fetch quotes for multiple symbols efficiently.
Corporate Actions & Dividends
- Dividend History: Fetch complete dividend payment history with amounts and dates.
- Stock Splits: Get stock split history with split ratios.
- Capital Gains: Retrieve capital gains distributions (especially for mutual funds).
- All Corporate Actions: Comprehensive access to dividends, splits, and capital gains in one call.
Financial Statements & Fundamentals
- Income Statements: Access annual and quarterly income statements.
- Balance Sheets: Get annual and quarterly balance sheet data.
- Cash Flow Statements: Fetch annual and quarterly cash flow data.
- Earnings Data: Historical earnings, revenue estimates, and EPS data.
- Shares Outstanding: Historical data on shares outstanding (annual and quarterly).
- Corporate Calendar: Earnings dates, ex-dividend dates, and dividend payment dates.
Options & Derivatives
- Options Chains: Fetch expiration dates and full option chains (calls and puts).
- Option Contracts: Detailed option contract information including Greeks.
Analysis & Research
- Analyst Ratings: Get price targets, recommendations, and upgrade/downgrade history.
- Earnings Trends: Detailed earnings and revenue estimates from analysts.
- Recommendations Summary: Summary of current analyst recommendations.
- Upgrades/Downgrades: History of analyst rating changes.
Ownership & Holders
- Major Holders: Get major, institutional, and mutual fund holder data.
- Institutional Holders: Top institutional shareholders and their holdings.
- Mutual Fund Holders: Mutual fund ownership breakdown.
- Insider Transactions: Recent insider buying and selling activity.
- Insider Roster: Company insiders and their current holdings.
- Net Share Activity: Summary of insider purchase/sale activity.
ESG & Sustainability
- ESG Scores: Fetch detailed Environmental, Social, and Governance ratings.
- ESG Involvement: Specific ESG involvement and controversy data.
News & Information
- Company News: Retrieve the latest articles and press releases for a ticker.
- Company Profiles: Detailed information about companies, ETFs, and funds.
- Search: Find tickers by name or keyword.
Real-time Streaming
- WebSocket Streaming: Get live quote updates using WebSockets (preferred method).
- HTTP Polling: Fallback polling method for real-time data.
- Configurable Streaming: Customize update frequency and change-only filtering.
Advanced Features
- Data Repair: Automatic detection and repair of price outliers.
- Data Rounding: Control price precision and rounding.
- Missing Data Handling: Configurable handling of NA/missing values.
- Back Adjustment: Alternative price adjustment methods.
- Historical Metadata: Timezone and other metadata for historical data.
- ISIN Lookup: Get International Securities Identification Numbers.
Developer Experience
- Async API: Built on
tokioandreqwestfor non-blocking I/O. - High-Level
TickerInterface: A convenient, yfinance-like struct for accessing all data for a single symbol. - Builder Pattern: Fluent builders for constructing complex queries.
- Configurable Retries: Automatic retries with exponential backoff for transient network errors.
- Caching: Configurable caching behavior for API responses.
- Custom Timeouts: Configurable request timeouts and connection settings.
Quick Start
To get started, add yfinance-rs to your Cargo.toml:
[]
= "0.1.2"
= { = "1", = ["full"] }
Then, create a YfClient and use a Ticker to fetch data.
use ;
async
Advanced Examples
Multi-Symbol Data Download
use ;
use ;
let client = default;
let symbols = vec!;
let results = new
.symbols
.range
.interval
.auto_adjust
.actions
.repair // Fix price outliers
.rounding // Round to 2 decimal places
.run
.await?;
for in &results.series
Real-time Streaming
use ;
use Duration;
let config = StreamConfig ;
let = new
.symbols
.method
.config
.start?;
// Process updates
while let Some = receiver.recv.await
// Stop the stream
handle.stop.await;
Financial Statements
let ticker = new;
// Get quarterly financials
let income_stmt = ticker.quarterly_income_stmt.await?;
let balance_sheet = ticker.quarterly_balance_sheet.await?;
let cashflow = ticker.quarterly_cashflow.await?;
// Get shares outstanding
let shares = ticker.quarterly_shares.await?;
if let Some = shares.first
Options Trading
let ticker = new;
// Get available expiration dates
let expirations = ticker.options.await?;
// Get option chain for nearest expiration
if let Some = expirations.first
Advanced Analysis
let ticker = new;
// Get comprehensive analyst data
let price_target = ticker.analyst_price_target.await?;
let recs_summary = ticker.recommendations_summary.await?;
let upgrades = ticker.upgrades_downgrades.await?;
let earnings_trends = ticker.earnings_trend.await?;
println!;
println!;
Holder Information
let ticker = new;
// Get ownership breakdown
let major_holders = ticker.major_holders.await?;
let institutional = ticker.institutional_holders.await?;
let mutual_funds = ticker.mutual_fund_holders.await?;
let insider_transactions = ticker.insider_transactions.await?;
for holder in &major_holders
ESG & Sustainability
let ticker = new;
let esg = ticker.sustainability.await?;
println!;
println!;
println!;
println!;
Advanced Client Configuration
use ;
use Duration;
let client = default
.timeout
.retry_config
.build?;
// Use with custom cache settings
let ticker = new
.cache_mode // Skip caching for this ticker
.retry_policy;
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit a pull request or open an issue.