finance-query 3.0.0

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

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

    #[tokio::main]
    async fn main() -> Result<(), Box<dyn std::error::Error>> {
        let providers = Providers::builder().build().await?;
        let spx = providers.index("^GSPC");
        let quote = spx.quote().await?;
        let chart = spx.chart(Interval::OneDay, TimeRange::OneMonth).await?;
        let history = spx.history(TimeRange::OneMonth).await?;
        println!("{}: {:?} ({} candles)", quote.symbol, quote.price, chart.candles.len() + history.candles.len());
        Ok(())
    }
}

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

    #[tokio::main]
    async fn main() -> Result<(), Box<dyn std::error::Error>> {
        let providers = Providers::builder()
            .route(Capability::INDICES, [Provider::Polygon, Provider::Yahoo])
            .build()
            .await?;
        let spx = providers.index("I:SPX");
        let quote = spx.quote().await?;
        println!("S&P 500: {:?}", quote.price);
        Ok(())
    }
}

// line 84: compile-only (no_run)
#[rustfmt::skip]
#[allow(dead_code)]
fn doc_block_line_84() {
    use finance_query::Providers;

    #[tokio::main]
    async fn main() -> Result<(), Box<dyn std::error::Error>> {
        let providers = Providers::builder().build().await?;
        let spx = providers.index("^GSPC");
        let quote = spx.quote().await?;
        println!("S&P 500: {:?}", quote.price);
        Ok(())
    }
}

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

    #[tokio::main]
    async fn main() -> Result<(), Box<dyn std::error::Error>> {
        let providers = Providers::builder().build().await?;
        let spx = providers.index("^GSPC");
        let chart = spx.chart(Interval::OneDay, TimeRange::OneMonth).await?;
        println!("Candles: {}", chart.candles.len());
        Ok(())
    }
}

// line 118: compile-only (no_run)
#[rustfmt::skip]
#[allow(dead_code)]
fn doc_block_line_118() {
    use finance_query::{Providers, TimeRange};

    #[tokio::main]
    async fn main() -> Result<(), Box<dyn std::error::Error>> {
        let providers = Providers::builder().build().await?;
        let spx = providers.index("^GSPC");
        let history = spx.history(TimeRange::OneMonth).await?;
        println!("Candles: {}", history.candles.len());
        Ok(())
    }
}

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

    #[tokio::main]
    async fn main() -> Result<(), Box<dyn std::error::Error>> {
        let providers = Providers::builder()
            .route(Capability::INDICES, [Provider::Wikipedia])
            .build()
            .await?;
        let spx = providers.index("^GSPC");
        for member in spx.constituents().await?.iter().take(5) {
            println!("{}: {}", member.symbol, member.name.as_deref().unwrap_or("?"));
        }
        Ok(())
    }
}

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

    #[tokio::main]
    async fn main() -> Result<(), Box<dyn std::error::Error>> {
        let providers = Providers::builder()
            .route(Capability::INDICES, [Provider::Fmp])
            .build()
            .await?;
        let ndx = providers.index("^NDX");
        let members = ndx.constituents().await?;
        println!("Nasdaq-100 constituents: {}", members.len());
        Ok(())
    }
}

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

    #[tokio::main]
    async fn main() -> Result<(), Box<dyn std::error::Error>> {
        let providers = Providers::builder()
            .route(Capability::INDICES, [Provider::Fmp])
            .build()
            .await?;
        let spx = providers.index("^GSPC");
        for change in spx.constituent_changes().await?.iter().take(5) {
            println!(
                "{}: +{} -{}",
                change.date.as_deref().unwrap_or("?"),
                change.added_security.as_deref().unwrap_or("-"),
                change.removed_ticker.as_deref().unwrap_or("-")
            );
        }
        Ok(())
    }
}

// line 204: compile-only (no_run)
#[cfg(feature = "risk")]
#[rustfmt::skip]
#[allow(dead_code)]
fn doc_block_line_204() {
    use finance_query::indicators::Indicator;
    use finance_query::{Interval, Providers, TimeRange};

    #[tokio::main]
    async fn main() -> Result<(), Box<dyn std::error::Error>> {
        let providers = Providers::builder().build().await?;
        let spx = providers.index("^GSPC");
        let summary = spx.indicators(Interval::OneDay, TimeRange::ThreeMonths).await?;
        if let Some(rsi) = summary.rsi_14 {
            println!("RSI(14): {:.2}", rsi);
        }

        let rsi_21 = spx
            .indicator(Indicator::Rsi(21), Interval::OneDay, TimeRange::ThreeMonths)
            .await?;

        let risk = spx.risk(Interval::OneDay, TimeRange::OneYear).await?;
        println!("VaR 95%:      {:.2}%", risk.var_95 * 100.0);
        println!("Max Drawdown: {:.2}%", risk.max_drawdown * 100.0);
        Ok(())
    }
}