Skip to main content

yfinance/
lib.rs

1//! Async Rust client for Yahoo Finance.
2//!
3//! This crate is a port of the popular Python [`yfinance`](https://github.com/ranaroussi/yfinance)
4//! library. It provides access to Yahoo Finance market data: quotes, historical OHLCV,
5//! fundamentals, holders, options chains, search, and more.
6//!
7//! # Quick start
8//!
9//! ```no_run
10//! use yfinance::{YfClient, Ticker, Period, Interval};
11//!
12//! # async fn run() -> yfinance::Result<()> {
13//! let client = YfClient::new()?;
14//! let ticker = Ticker::new(&client, "AAPL");
15//!
16//! // 1 month of daily candles
17//! let history = ticker
18//!     .history()
19//!     .period(Period::M1)
20//!     .interval(Interval::D1)
21//!     .auto_adjust(true)
22//!     .fetch()
23//!     .await?;
24//!
25//! for row in &history.rows {
26//!     println!("{}  O={} H={} L={} C={} V={}",
27//!         row.timestamp, row.open, row.high, row.low, row.close, row.volume);
28//! }
29//!
30//! // Fundamentals
31//! let info = ticker.info().await?;
32//! println!("{}: {}", info.symbol, info.long_name.unwrap_or_default());
33//! # Ok(()) }
34//! ```
35//!
36//! # Disclaimer
37//!
38//! This library is **not** affiliated with, endorsed, or vetted by Yahoo, Inc.
39//! It uses Yahoo's publicly available APIs. Use at your own risk and respect
40//! their [terms of service](https://policies.yahoo.com/us/en/yahoo/terms/index.htm).
41
42#![deny(rust_2018_idioms)]
43#![warn(missing_debug_implementations)]
44#![cfg_attr(docsrs, feature(doc_cfg))]
45
46pub mod analysis;
47pub mod calendar;
48pub mod client;
49#[cfg(feature = "dataframe")]
50pub mod dataframe;
51pub mod domain;
52pub mod download;
53pub mod earnings;
54pub mod error;
55pub mod esg;
56pub mod fundamentals;
57pub mod history;
58pub mod holders;
59pub mod info;
60pub mod isin;
61pub mod lookup;
62pub mod news;
63pub mod options;
64pub mod profile;
65pub mod quote;
66pub mod repair;
67pub mod search;
68pub mod shares;
69#[cfg(feature = "stream")]
70pub mod stream;
71pub mod ticker;
72pub mod types;
73
74pub mod test_fixtures;
75
76pub(crate) mod wire;
77
78/// Forward our internal `log` events to the `tracing` ecosystem. Idempotent
79/// — safe to call multiple times. No-op without the `tracing` feature.
80#[cfg(feature = "tracing")]
81pub fn init_tracing_bridge() {
82    let _ = tracing_log::LogTracer::init();
83}
84
85/// Initialise a default `tracing-subscriber` for tests / examples. Reads
86/// `RUST_LOG` for the env-filter and falls back to `info`. Available with
87/// the `tracing-subscriber` feature.
88#[cfg(feature = "tracing-subscriber")]
89pub fn init_tracing_for_tests() {
90    use tracing_subscriber::{fmt, EnvFilter};
91    init_tracing_bridge();
92    let filter = std::env::var("RUST_LOG")
93        .ok()
94        .and_then(|s| EnvFilter::try_new(s).ok())
95        .unwrap_or_else(|| EnvFilter::new("info"));
96    let _ = fmt::Subscriber::builder()
97        .with_env_filter(filter)
98        .with_target(true)
99        .try_init();
100}
101
102pub use analysis::{
103    EarningsEstimate, EarningsTrendRow, EpsRevisions, EpsTrend, PriceTarget, RecommendationRow,
104    RecommendationSummary, RevenueEstimate, UpgradeDowngradeRow,
105};
106pub use calendar::Calendar;
107pub use client::{ApiPreference, CacheMode, RetryConfig, YfClient, YfClientBuilder};
108pub use domain::{Industry, Market, Sector};
109pub use download::{download, DownloadBuilder, MultiHistory};
110pub use earnings::{Earnings, EarningsEps, EarningsQuarter, EarningsYear};
111pub use error::{Error, Result};
112pub use esg::{EsgInvolvement, EsgScores, EsgSummary};
113pub use history::{Action, History, HistoryBuilder, OhlcvRow};
114pub use info::Info;
115pub use lookup::{Lookup, LookupBuilder, LookupRow, LookupType};
116pub use news::{NewsArticle, NewsBuilder, NewsTab};
117pub use options::{OptionChain, OptionContract};
118pub use profile::{Address, CompanyProfile, FundProfile, Profile};
119pub use quote::{batch as batch_quotes, FastInfo, Quote};
120pub use repair::{repair_history, RepairReport};
121pub use search::{Search, SearchBuilder, SearchNews, SearchQuote};
122pub use shares::ShareCount;
123pub use ticker::Ticker;
124pub use types::{Interval, Period};