finance-query 3.0.0

A Rust library for querying financial data
Documentation
// @generated by `cargo soothfast docs gen-tests`
// source: docs/library/ticker.md
#![allow(unused)]

// line 34: compile-only (no_run)
#[rustfmt::skip]
#[allow(dead_code)]
fn doc_block_line_34() {
    #[tokio::main]
    async fn main() -> Result<(), Box<dyn std::error::Error>> {
        use finance_query::{Ticker, Region};
        use std::time::Duration;

        // Using region enum (recommended - sets lang and region code correctly)
        let ticker = Ticker::builder("2330.TW")
            .region(Region::Taiwan)
            .timeout(Duration::from_secs(30))
            .build()
            .await?;

        // With logo fetching and in-memory cache (TTL: 5 minutes)
        let ticker = Ticker::builder("AAPL")
            .logo()
            .cache(Duration::from_secs(300))
            .build()
            .await?;

        // Manual language/region configuration
        let ticker = Ticker::builder("AAPL")
            .lang("en-US")
            .region_code("US")
            .timeout(Duration::from_secs(20))
            .proxy("http://proxy.example.com:8080")
            .build()
            .await?;
        Ok(())
    }
}

// line 86: compile-only (no_run)
#[cfg(all(feature = "polygon", feature = "fmp"))]
#[rustfmt::skip]
#[allow(dead_code)]
fn doc_block_line_86() {
    #[tokio::main]
    async fn main() -> Result<(), Box<dyn std::error::Error>> {
        use finance_query::{Capability, Fetch, Provider, Providers};

        // Route quote to Polygon (fallback Yahoo), fundamentals to FMP (fallback Yahoo)
        let providers = Providers::builder()
            .route(Capability::QUOTE, [Provider::Polygon, Provider::Yahoo])
            .route(Capability::FUNDAMENTALS, [Provider::Fmp, Provider::Yahoo])
            .fetch(Fetch::Sequential)
            .build()
            .await?;

        // All tickers from this Providers share the same connections
        let aapl = providers.ticker("AAPL").build().await?;
        let msft = providers.ticker("MSFT").build().await?;
        Ok(())
    }
}

// line 1864: compile-only (no_run)
#[rustfmt::skip]
#[allow(dead_code)]
fn doc_block_line_1864() {
        #[tokio::main]
        async fn main() -> Result<(), Box<dyn std::error::Error>> {
            use finance_query::{Ticker, Interval, TimeRange};
            use finance_query::format::Raw;

            // Good: Reuse ticker for multiple operations
            let ticker = Ticker::builder("AAPL").logo().build().await?;
            let quote = ticker.quote::<Raw>().await?;
            let chart = ticker.chart(Interval::OneDay, TimeRange::OneMonth).await?;
            let profile = ticker.asset_profile().await?;

            // Less efficient: Creating new tickers each time
            // (loses caching benefits, re-authenticates with Yahoo each time)
            let ticker1 = Ticker::builder("AAPL").logo().build().await?;
            let quote = ticker1.quote::<Raw>().await?;
            let ticker2 = Ticker::new("AAPL").await?;
            let chart = ticker2.chart(Interval::OneDay, TimeRange::OneMonth).await?;
            Ok(())
        }
}