finance-query 3.0.0

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

// line 20: compile-only (no_run)
#[cfg(feature = "crypto")]
#[rustfmt::skip]
#[allow(dead_code)]
fn doc_block_line_20() {
    use finance_query::crypto;

    #[tokio::main]
    async fn main() -> Result<(), Box<dyn std::error::Error>> {
        let top = crypto::coins("usd", 10).await?;
        assert!(!top.is_empty(), "should return coins");
        assert!(top.len() <= 10);

        for coin in &top {
            let price = coin.current_price.unwrap_or(0.0);
            let change = coin.price_change_percentage_24h.unwrap_or(0.0);
            let rank = coin.market_cap_rank.unwrap_or(0);
            println!(
                "#{} {} ({}): ${:.2} ({:+.2}%)",
                rank, coin.name, coin.symbol, price, change
            );
        }
        Ok(())
    }
}

// line 49: compile-only (no_run)
#[cfg(feature = "crypto")]
#[rustfmt::skip]
#[allow(dead_code)]
fn doc_block_line_49() {
    use finance_query::crypto;

    #[tokio::main]
    async fn main() -> Result<(), Box<dyn std::error::Error>> {
        let btc = crypto::coin("bitcoin", "usd").await?;
        assert_eq!(btc.id, "bitcoin");
        assert_eq!(btc.symbol.to_uppercase(), "BTC");
        let price = btc.current_price.unwrap_or(0.0);
        assert!(price > 0.0, "BTC price should be positive");
        println!("Bitcoin: ${:.2}", price);
        Ok(())
    }
}

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

    #[tokio::main]
    async fn main() -> Result<(), Box<dyn std::error::Error>> {
        let providers = Providers::builder()
            .route(Capability::CRYPTO, [Provider::CoinGecko])
            .build()
            .await?;
        let btc = providers.crypto("bitcoin");
        let quote = btc.quote("usd").await?;
        println!("BTC: {:?}", quote.price);
        Ok(())
    }
}

// line 161: compile-only (no_run)
#[cfg(feature = "crypto")]
#[rustfmt::skip]
#[allow(dead_code)]
fn doc_block_line_161() {
    use finance_query::{Capability, Interval, Provider, Providers, TimeRange};

    #[tokio::main]
    async fn main() -> Result<(), Box<dyn std::error::Error>> {
        let providers = Providers::builder()
            .route(Capability::CRYPTO, [Provider::CoinGecko])
            .build()
            .await?;
        // Ticker id ("BTC") so the default Yahoo CHART route resolves "BTC-USD".
        let btc = providers.crypto("BTC");
        let chart = btc.chart("usd", Interval::OneDay, TimeRange::OneMonth).await?;
        let history = btc.history("usd", TimeRange::OneMonth).await?;
        println!("{} candles", chart.candles.len() + history.candles.len());
        Ok(())
    }
}

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

    #[tokio::main]
    async fn main() -> Result<(), Box<dyn std::error::Error>> {
        let providers = Providers::builder()
            .route(Capability::CRYPTO, [Provider::CoinGecko])
            .build()
            .await?;
        let btc = providers.crypto("BTC");

        let summary = btc
            .indicators("usd", Interval::OneDay, TimeRange::ThreeMonths)
            .await?;
        if let Some(rsi) = summary.rsi_14 {
            println!("RSI(14): {:.2}", rsi);
        }

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

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