finance-query 3.0.0

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

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

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

        println!("RSI(14): {:?}", indicators.rsi_14);
        println!("SMA(200): {:?}", indicators.sma_200);
        println!("MACD: {:?}", indicators.macd);
        Ok(())
    }
}

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

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

        // All indicators calculated at once with standard periods
        println!("RSI(14): {:?}", indicators.rsi_14);
        println!("SMA(200): {:?}", indicators.sma_200);
        println!("MACD: {:?}", indicators.macd);
        Ok(())
    }
}

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

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

        // Calculate indicators with custom periods
        let sma_15 = chart.sma(15);           // Custom period: 15
        let rsi_21 = chart.rsi(21)?;          // Custom period: 21
        let macd = chart.macd(12, 26, 9)?;    // Custom MACD parameters

        // Access the last value
        if let Some(&last_sma) = sma_15.last().and_then(|v| v.as_ref()) {
            println!("Latest SMA(15): {:.2}", last_sma);
        }

        // Candlestick patterns (same chart, no extra request)
        let signals = chart.patterns();
        Ok(())
    }
}

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

    #[tokio::main]
    async fn main() -> Result<(), Box<dyn std::error::Error>> {
        let ticker = Ticker::new("AAPL").await?;
        let chart = ticker.chart(Interval::OneDay, TimeRange::ThreeMonths).await?;
        let rsi = chart.rsi(14)?;
        let signals = chart.patterns();

        // Find bars where RSI is oversold AND a bullish pattern just completed
        for (i, (pattern, rsi_val)) in signals.iter().zip(rsi.iter()).enumerate() {
            let is_bullish_pattern = pattern
                .map(|p| p.sentiment() == PatternSentiment::Bullish)
                .unwrap_or(false);
            let is_oversold = rsi_val.map(|r| r < 30.0).unwrap_or(false);

            if is_bullish_pattern && is_oversold {
                println!(
                    "Strong buy signal at bar {}: {:?} with RSI={:.1}",
                    i,
                    pattern.unwrap(),
                    rsi_val.unwrap()
                );
            }
        }
        Ok(())
    }
}

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

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

        // Simple indicators (Option<f64>)
        if let Some(rsi) = indicators.rsi_14 {
            println!("RSI(14): {:.2}", rsi);
            if rsi < 30.0 {
                println!("  Oversold");
            } else if rsi > 70.0 {
                println!("  Overbought");
            }
        }

        // Moving averages
        if let Some(sma200) = indicators.sma_200 {
            println!("SMA(200): {:.2}", sma200);
        }

        // MACD (compound - MacdData struct)
        if let Some(macd) = indicators.macd {
            if let Some(line) = macd.macd {
                println!("MACD Line: {:.4}", line);
            }
            if let Some(signal) = macd.signal {
                println!("Signal: {:.4}", signal);
            }
            if let Some(histogram) = macd.histogram {
                println!("Histogram: {:.4}", histogram);
            }
        }

        // Stochastic (StochasticData struct)
        if let Some(stoch) = indicators.stochastic {
            if let Some(k) = stoch.k {
                println!("%K: {:.2}", k);
            }
            if let Some(d) = stoch.d {
                println!("%D: {:.2}", d);
            }
        }

        // Bollinger Bands (BollingerBandsData struct)
        if let Some(bb) = indicators.bollinger_bands {
            if let Some(upper) = bb.upper {
                println!("Upper: {:.2}", upper);
            }
            if let Some(middle) = bb.middle {
                println!("Middle: {:.2}", middle);
            }
            if let Some(lower) = bb.lower {
                println!("Lower: {:.2}", lower);
            }
        }

        // Aroon (AroonData struct)
        if let Some(aroon) = indicators.aroon {
            if let Some(up) = aroon.aroon_up {
                println!("Aroon Up: {:.2}", up);
            }
            if let Some(down) = aroon.aroon_down {
                println!("Aroon Down: {:.2}", down);
            }
        }

        // Ichimoku (IchimokuData struct)
        if let Some(ichimoku) = indicators.ichimoku {
            if let Some(conversion) = ichimoku.conversion_line {
                println!("Conversion Line: {:.2}", conversion);
            }
            if let Some(base) = ichimoku.base_line {
                println!("Base Line: {:.2}", base);
            }
        }
        Ok(())
    }
}

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

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

        let df = indicators.to_dataframe()?;
        println!("{}", df);
        Ok(())
    }
}

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

    #[tokio::main]
    async fn main() -> Result<(), Box<dyn std::error::Error>> {
        let ticker = Ticker::new("AAPL").await?;

        // First call fetches and caches
        let ind1 = ticker.indicators(Interval::OneDay, TimeRange::OneMonth).await?;

        // Second call returns cached result
        let ind2 = ticker.indicators(Interval::OneDay, TimeRange::OneMonth).await?;

        // Different range: fetches new data
        let ind3 = ticker.indicators(Interval::OneDay, TimeRange::ThreeMonths).await?;
        Ok(())
    }
}

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

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

        let sma_200 = indicators.sma_200.unwrap_or(0.0);
        let ema_50 = indicators.ema_50.unwrap_or(0.0);
        let ema_20 = indicators.ema_20.unwrap_or(0.0);

        if ema_20 > ema_50 && ema_50 > sma_200 {
            println!("Uptrend confirmed");
        }
        Ok(())
    }
}

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

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

        if let Some(rsi) = indicators.rsi_14 {
            if rsi < 30.0 {
                println!("Oversold");
            } else if rsi > 70.0 {
                println!("Overbought");
            }
        }
        Ok(())
    }
}

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

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

        if let Some(macd) = indicators.macd
            && let (Some(line), Some(signal)) = (macd.macd, macd.signal)
        {
            if line > signal {
                println!("Bullish MACD crossover");
            } else {
                println!("Bearish MACD crossover");
            }
        }
        Ok(())
    }
}

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

        #[tokio::main]
        async fn main() -> Result<(), Box<dyn std::error::Error>> {
            // Good: Store result once, access multiple indicators
            let ticker = Ticker::new("AAPL").await?;
            let indicators = ticker.indicators(Interval::OneDay, TimeRange::ThreeMonths).await?;

            if let Some(rsi) = indicators.rsi_14
                && rsi < 30.0
            {
                // Oversold - check other indicators from same result
                if let Some(macd) = &indicators.macd
                    && let (Some(line), Some(signal)) = (macd.macd, macd.signal)
                    && line > signal
                {
                    println!("Potential buy: RSI oversold + MACD bullish");
                }
            }

            // Less efficient: Multiple calls recalculate all indicators
            let rsi_result = ticker.indicators(Interval::OneDay, TimeRange::ThreeMonths).await?;
            if let Some(rsi) = rsi_result.rsi_14 { /* ... */ }
            let macd_result = ticker.indicators(Interval::OneDay, TimeRange::ThreeMonths).await?;
            // Still wastes CPU recalculating all indicators
            Ok(())
        }
}