yfinance-rs 0.1.0

Ergonomic Rust client for Yahoo Finance, supporting historical prices, real-time streaming, options, fundamentals, and more.
Documentation

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.

Crates.io Docs.rs CI Downloads License

Features

  • Historical Data: Fetch daily, weekly, or monthly OHLCV data.
  • Multi-Symbol Downloads: Concurrently download historical data for many symbols at once.
  • Real-time Streaming: Get live quote updates using WebSockets (with an HTTP polling fallback).
  • Company Profiles: Retrieve detailed information about companies, ETFs, and funds.
  • Options Chains: Fetch expiration dates and full option chains (calls and puts).
  • Financials: Access income statements, balance sheets, and cash flow statements (annual & quarterly).
  • Analyst Ratings: Get price targets, recommendations, and upgrade/downgrade history.
  • Holder Information: Get major, institutional, and mutual fund holder data.
  • ESG Scores: Fetch detailed Environmental, Social, and Governance ratings.
  • News: Retrieve the latest articles and press releases for a ticker.
  • Search: Find tickers by name or keyword.
  • Async API: Built on tokio and reqwest for non-blocking I/O.
  • High-Level Ticker Interface: 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.

Quick Start

To get started, add yfinance-rs to your Cargo.toml:

[dependencies]
yfinance-rs = "0.1.0"
tokio = { version = "1", features = ["full"] }

Then, create a YfClient and use a Ticker to fetch data.

use yfinance_rs::{Interval, Range, Ticker, YfClient};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = YfClient::default();
    let ticker = Ticker::new(client, "AAPL".to_string());

    // Get the latest quote
    let quote = ticker.quote().await?;
    println!("Latest price for AAPL: ${:.2}", quote.regular_market_price.unwrap_or(0.0));

    // Get historical data for the last 6 months
    let history = ticker.history(Some(Range::M6), Some(Interval::D1), false).await?;
    if let Some(last_bar) = history.last() {
        println!("Last closing price: ${:.2} on timestamp {}", last_bar.close, last_bar.ts);
    }

    // Get analyst recommendations
    let recs = ticker.recommendations().await?;
    if let Some(latest_rec) = recs.first() {
        println!("Latest recommendation period: {}", latest_rec.period);
    }

    Ok(())
}

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.