finance-query 3.0.0

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

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

    #[tokio::main]
    async fn main() -> Result<(), Box<dyn std::error::Error>> {
        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 42: compile-only (no_run)
#[rustfmt::skip]
#[allow(dead_code)]
fn doc_block_line_42() {
    use finance_query::streaming::PriceStream;

    #[tokio::main]
    async fn main() -> Result<(), Box<dyn std::error::Error>> {
        let mut stream = PriceStream::subscribe(["AAPL", "GOOGL"]).await?;
        Ok(())
    }
}

// line 54: compile-only (no_run)
#[rustfmt::skip]
#[allow(dead_code)]
fn doc_block_line_54() {
    use finance_query::streaming::PriceStreamBuilder;
    use std::time::Duration;

    #[tokio::main]
    async fn main() -> Result<(), Box<dyn std::error::Error>> {
        let mut stream = PriceStreamBuilder::new()
            .symbols(["AAPL", "MSFT", "NVDA"])
            .retry(Duration::from_secs(5))
            .build()
            .await?;
        Ok(())
    }
}

// line 73: compile-only (no_run)
#[rustfmt::skip]
#[allow(dead_code)]
fn doc_block_line_73() {
    use finance_query::streaming::PriceStream;

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

        // Add more symbols
        stream.add_symbols(["NVDA", "TSLA"]).await;

        // Remove symbols
        stream.remove_symbols(["AAPL"]).await;
        Ok(())
    }
}

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

    #[tokio::main]
    async fn main() -> Result<(), Box<dyn std::error::Error>> {
        let mut stream1 = PriceStream::subscribe(["AAPL", "NVDA"]).await?;
        let mut stream2 = stream1.resubscribe();

        // Both streams receive the same updates
        tokio::spawn(async move {
            while let Some(price) = stream2.next().await {
                println!("Consumer 2: {} ${:.2}", price.id, price.price);
            }
        });

        while let Some(price) = stream1.next().await {
            println!("Consumer 1: {} ${:.2}", price.id, price.price);
        }
        Ok(())
    }
}

// line 144: compile-only (no_run)
#[rustfmt::skip]
#[allow(dead_code)]
fn doc_block_line_144() {
    use finance_query::streaming::{MarketHoursType, PriceStream};
    use futures::StreamExt;

    #[tokio::main]
    async fn main() -> Result<(), Box<dyn std::error::Error>> {
        let mut stream = PriceStream::subscribe(["AAPL", "MSFT", "GOOGL"]).await?;

        while let Some(price) = stream.next().await {
            // Only process regular market updates
            if price.market_hours == MarketHoursType::RegularMarket {
                println!("{}: ${:.2}", price.id, price.price);
            }
        }
        Ok(())
    }
}

// line 164: compile-only (no_run)
#[rustfmt::skip]
#[allow(dead_code)]
fn doc_block_line_164() {
    use finance_query::streaming::PriceStream;

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

        // ... use stream ...

        stream.close().await;
        Ok(())
    }
}

// line 190: compile-only (no_run)
#[rustfmt::skip]
#[allow(dead_code)]
fn doc_block_line_190() {
    use finance_query::streaming::NewsStream;
    use finance_query::feeds::FeedSource;
    use futures::StreamExt;

    #[tokio::main]
    async fn main() {
        let mut stream =
            NewsStream::subscribe([FeedSource::Bloomberg, FeedSource::MarketWatch]).await;

        while let Some(entry) = stream.next().await {
            println!("[{}] {}", entry.source, entry.title);
        }
    }
}

// line 211
#[rustfmt::skip]
#[test]
fn doc_block_line_211() {
    use finance_query::streaming::NewsStreamBuilder;
    use finance_query::feeds::FeedSource;
    use std::time::Duration;

    #[tokio::main]
    async fn main() {
        let stream = NewsStreamBuilder::new()
            .sources(vec![FeedSource::FederalReserve, FeedSource::SecPressReleases])
            .poll_interval(Duration::from_secs(60))
            .build()
            .await;

        // ... consume stream.next() as in the examples above ...

        stream.close().await;
    }
    main();
}

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

    #[tokio::main]
    async fn main() {
        let stream = NewsStream::subscribe([FeedSource::Bloomberg]).await;

        stream.add_sources([FeedSource::WsjMarkets]).await;
        stream.remove_sources([FeedSource::Bloomberg]).await;

        let other_consumer = stream.resubscribe();

        stream.close().await;
    }
}