finance-query 3.0.0

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

// line 43
#[rustfmt::skip]
#[test]
fn doc_block_line_43() {
    use finance_query::FinanceError;

    let error = FinanceError::RateLimited { retry_after: Some(2) };

    match &error {
        FinanceError::RateLimited { retry_after } => {
            if let Some(secs) = retry_after {
                // In async code, back off before retrying:
                // tokio::time::sleep(std::time::Duration::from_secs(*secs)).await;
                assert_eq!(*secs, 2);
            }
        }
        FinanceError::SymbolNotFound { symbol, .. } => {
            eprintln!("Symbol not found: {:?}", symbol);
        }
        _ => eprintln!("{}", error),
    }
}

// line 171: compile-only (no_run)
#[rustfmt::skip]
#[allow(dead_code)]
fn doc_block_line_171() {
    use finance_query::Tickers;

    #[tokio::main]
    async fn main() -> Result<(), Box<dyn std::error::Error>> {
        let tickers = Tickers::builder(vec!["AAPL", "MSFT", "NOTREAL"]).build().await?;
        let response = tickers.quotes().await?;

        // Successful fetch — but individual symbols may have failed
        for (symbol, error_str) in &response.errors {
            eprintln!("{}: {}", symbol, error_str);
        }

        // Convenience methods
        println!("Success: {}, Failed: {}", response.success_count(), response.error_count());
        if !response.all_successful() {
            eprintln!("Some symbols failed");
        }
        Ok(())
    }
}

// line 197
#[rustfmt::skip]
#[test]
fn doc_block_line_197() {
    use finance_query::{FinanceError, Operation, Provider};

    let error = FinanceError::NotSupported {
        provider: Provider::Yahoo,
        operation: Operation::Quote,
        candidates: Vec::new(),
    };

    match &error {
        FinanceError::NotSupported { provider, operation, .. } => {
            // e.g. AlphaVantage doesn't do options — expected
            eprintln!("{} does not support {}", provider, operation);
        }
        FinanceError::NoProviderAvailable { operation, .. } => {
            // No configured provider supports this operation
            eprintln!("No provider available for {:?}", operation);
        }
        _ => {}
    }
}