finance-query 3.0.0

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

// line 41: compile-only (no_run)
#[rustfmt::skip]
#[allow(dead_code)]
fn doc_block_line_41() {
    use finance_query::{Ticker, Interval, TimeRange, format::Raw};

    #[tokio::main]
    async fn main() -> Result<(), Box<dyn std::error::Error>> {
        // Default: Yahoo Finance (no API key required)
        let ticker = Ticker::builder("AAPL").logo().build().await?;

        // Get quote
        let quote = ticker.quote::<Raw>().await?;
        println!("{}: ${:.2}", quote.symbol,
            quote.regular_market_price.unwrap_or(0.0));

        // Get chart
        let chart = ticker.chart(Interval::OneDay, TimeRange::OneMonth).await?;
        println!("Candles: {}", chart.candles.len());

        Ok(())
    }
}

// line 74: compile-only (no_run)
#[cfg(feature = "polygon")]
#[rustfmt::skip]
#[allow(dead_code)]
fn doc_block_line_74() {
    use finance_query::{Capability, Fetch, Provider, Providers};

    #[tokio::main]
    async fn main() -> Result<(), Box<dyn std::error::Error>> {
        // Route quote to Polygon, fall back to Yahoo (routing lives on Providers::builder)
        let providers = Providers::builder()
            .route(Capability::QUOTE, [Provider::Polygon, Provider::Yahoo])
            .fetch(Fetch::Sequential)
            .build()
            .await?;
        let ticker = providers.ticker("AAPL").build().await?;
        Ok(())
    }
}

// line 96: compile-only (no_run)
#[rustfmt::skip]
#[allow(dead_code)]
fn doc_block_line_96() {
    use finance_query::{Ticker, format::Raw};

    #[tokio::main]
    async fn main() -> Result<(), Box<dyn std::error::Error>> {
        // Quotes, financials, options, news
        let ticker = Ticker::builder("MSFT").logo().build().await?;
        let quote = ticker.quote::<Raw>().await?; // fetch quote with logo if available
        let financials = ticker.financial_data().await?;
        let options = ticker.options(None).await?;
        Ok(())
    }
}

// line 114: compile-only (no_run)
#[rustfmt::skip]
#[allow(dead_code)]
fn doc_block_line_114() {
    use finance_query::{Interval, Tickers, TimeRange};

    #[tokio::main]
    async fn main() -> Result<(), Box<dyn std::error::Error>> {
        // Fetch multiple symbols efficiently
        let tickers = Tickers::builder(vec!["AAPL", "MSFT", "GOOGL"]).logo().build().await?;
        let quotes = tickers.quotes().await?; // fetch quotes with logos if available
        let sparks = tickers.spark(Interval::OneDay, TimeRange::FiveDays).await?;
        Ok(())
    }
}

// line 131: compile-only (no_run)
#[rustfmt::skip]
#[allow(dead_code)]
fn doc_block_line_131() {
    use finance_query::{finance, Screener, SearchOptions};

    #[tokio::main]
    async fn main() -> Result<(), Box<dyn std::error::Error>> {
        // Search, screeners, trending stocks
        let results = finance::search("Tesla", &SearchOptions::default()).await?;
        let actives = finance::screener(Screener::MostActives, 25).await?;
        let trending = finance::trending(None).await?;
        Ok(())
    }
}

// line 150: compile-only (no_run)
#[cfg(feature = "dataframe")]
#[rustfmt::skip]
#[allow(dead_code)]
fn doc_block_line_150() {
    use finance_query::{Interval, Ticker, TimeRange};

    #[tokio::main]
    async fn main() -> Result<(), Box<dyn std::error::Error>> {
        // Convert to Polars DataFrames
        let ticker = Ticker::new("AAPL").await?;
        let chart = ticker.chart(Interval::OneDay, TimeRange::OneMonth).await?;
        let df = chart.to_dataframe()?;
        println!("Rows: {}", df.height());
        Ok(())
    }
}

// line 168: compile-only (no_run)
#[cfg(feature = "indicators")]
#[rustfmt::skip]
#[allow(dead_code)]
fn doc_block_line_168() {
    use finance_query::{Interval, Ticker, TimeRange};

    #[tokio::main]
    async fn main() -> Result<(), Box<dyn std::error::Error>> {
        // 42 indicators: RSI, MACD, Bollinger Bands, etc.
        let ticker = Ticker::new("AAPL").await?;
        let indicators = ticker.indicators(Interval::OneDay, TimeRange::ThreeMonths).await?;

        if let Some(rsi) = indicators.rsi_14 {
            println!("RSI: {:.2}", rsi);
        }
        Ok(())
    }
}

// line 188: compile-only (no_run)
#[cfg(feature = "backtesting")]
#[rustfmt::skip]
#[allow(dead_code)]
fn doc_block_line_188() {
    use finance_query::backtesting::SmaCrossover;
    use finance_query::{Interval, Ticker, TimeRange};

    #[tokio::main]
    async fn main() -> Result<(), Box<dyn std::error::Error>> {
        // Test strategies against historical data
        let ticker = Ticker::new("AAPL").await?;
        let result = ticker.backtest(
            SmaCrossover::new(10, 20),
            Interval::OneDay,
            TimeRange::OneYear,
            None,
        ).await?;

        println!("Return: {:.2}%", result.metrics.total_return_pct);
        Ok(())
    }
}

// line 212: compile-only (no_run)
#[rustfmt::skip]
#[allow(dead_code)]
fn doc_block_line_212() {
    use finance_query::streaming::PriceStream;
    use futures::StreamExt;

    #[tokio::main]
    async fn main() -> Result<(), Box<dyn std::error::Error>> {
        // Subscribe to real-time price updates via WebSocket
        let mut stream = PriceStream::subscribe(["AAPL", "NVDA", "TSLA"]).await?;

        while let Some(price) = stream.next().await {
            println!("{}: ${:.2} ({:+.2}%)",
                price.id,
                price.price,
                price.change_percent
            );
        }
        Ok(())
    }
}

// line 236: compile-only (no_run)
#[rustfmt::skip]
#[allow(dead_code)]
fn doc_block_line_236() {
    use finance_query::edgar;

    #[tokio::main]
    async fn main() -> Result<(), Box<dyn std::error::Error>> {
        // Init once per process (SEC requires contact email)
        edgar::init("user@example.com")?;

        // Resolve ticker to CIK number
        let cik = edgar::resolve_cik("AAPL").await?;  // 320193

        // Fetch all SEC filings metadata
        let submissions = edgar::submissions(cik).await?;
        if let Some(recent) = submissions.filings.as_ref().and_then(|f| f.recent.as_ref()) {
            println!("Recent filings: {}", recent.form.len());
        }

        // Fetch structured XBRL financial data
        let facts = edgar::company_facts(cik).await?;
        Ok(())
    }
}

// line 263: compile-only (no_run)
#[cfg(feature = "risk")]
#[rustfmt::skip]
#[allow(dead_code)]
fn doc_block_line_263() {
    use finance_query::{Interval, Ticker, TimeRange};

    #[tokio::main]
    async fn main() -> Result<(), Box<dyn std::error::Error>> {
        // VaR, Sharpe/Sortino/Calmar ratio, Beta, max drawdown
        let ticker = Ticker::new("AAPL").await?;
        let summary = ticker.risk(Interval::OneDay, TimeRange::OneYear, Some("SPY")).await?;

        println!("VaR 95%:      {:.2}%", summary.var_95 * 100.0);
        println!("Sharpe:       {:.2}", summary.sharpe.unwrap_or(0.0));
        println!("Max Drawdown: {:.2}%", summary.max_drawdown * 100.0);
        println!("Beta vs SPY:  {:.2}", summary.beta.unwrap_or(0.0));
        Ok(())
    }
}