pub struct Tickers { /* private fields */ }Expand description
Multi-symbol ticker for efficient batch operations.
Tickers optimizes data fetching for multiple symbols by:
- Using batch endpoints where available (e.g., /v7/finance/quote)
- Fetching concurrently when batch endpoints don’t exist
- Sharing a single authenticated client across all symbols
- Caching results per symbol
§Example
use finance_query::Tickers;
// Create tickers for multiple symbols
let tickers = Tickers::new(["AAPL", "MSFT", "GOOGL"]).await?;
// Batch fetch all quotes (single API call)
let quotes = tickers.quotes().await?;
for (symbol, quote) in "es.quotes {
let price = quote.regular_market_price.as_ref().and_then(|v| v.raw).unwrap_or(0.0);
println!("{}: ${:.2}", symbol, price);
}
// Fetch charts concurrently
use finance_query::{Interval, TimeRange};
let charts = tickers.charts(Interval::OneDay, TimeRange::OneMonth).await?;Implementations§
Source§impl Tickers
impl Tickers
Sourcepub fn builder<S, I>(symbols: I) -> TickersBuilder
pub fn builder<S, I>(symbols: I) -> TickersBuilder
Creates a new builder for Tickers
Sourcepub fn client_handle(&self) -> ClientHandle
pub fn client_handle(&self) -> ClientHandle
Returns a shareable handle to this instance’s authenticated session.
Pass the handle to Ticker or other Tickers builders
via .client() to reuse the same session without re-authenticating.
Sourcepub async fn quotes(&self) -> Result<BatchQuotesResponse>
pub async fn quotes(&self) -> Result<BatchQuotesResponse>
Batch fetch quotes for all symbols.
Uses /v7/finance/quote endpoint - fetches all symbols in a single API call. When logos are enabled, makes a parallel call for logo URLs.
Use TickersBuilder::logo() to enable logo fetching
for this tickers instance.
Sourcepub async fn quote(&self, symbol: &str) -> Result<Quote>
pub async fn quote(&self, symbol: &str) -> Result<Quote>
Get a specific quote by symbol (from cache or fetch all)
Sourcepub async fn charts(
&self,
interval: Interval,
range: TimeRange,
) -> Result<BatchChartsResponse>
pub async fn charts( &self, interval: Interval, range: TimeRange, ) -> Result<BatchChartsResponse>
Batch fetch charts for all symbols concurrently
Chart data cannot be batched in a single request, so this fetches all charts concurrently using tokio for maximum performance.
Sourcepub async fn chart(
&self,
symbol: &str,
interval: Interval,
range: TimeRange,
) -> Result<Chart>
pub async fn chart( &self, symbol: &str, interval: Interval, range: TimeRange, ) -> Result<Chart>
Get a specific chart by symbol
Sourcepub async fn charts_range(
&self,
interval: Interval,
start: i64,
end: i64,
) -> Result<BatchChartsResponse>
pub async fn charts_range( &self, interval: Interval, start: i64, end: i64, ) -> Result<BatchChartsResponse>
Batch fetch chart data for a custom date range for all symbols concurrently.
Unlike charts() which uses predefined time ranges,
this method accepts absolute start/end timestamps. Results are not cached
since custom ranges have unbounded key space.
§Arguments
interval- Time interval between data pointsstart- Start date as Unix timestamp (seconds since epoch)end- End date as Unix timestamp (seconds since epoch)
Sourcepub async fn spark(
&self,
interval: Interval,
range: TimeRange,
) -> Result<BatchSparksResponse>
pub async fn spark( &self, interval: Interval, range: TimeRange, ) -> Result<BatchSparksResponse>
Batch fetch spark data for all symbols in a single request.
Spark data is optimized for sparkline rendering, returning only close prices.
Unlike charts(), this fetches all symbols in ONE API call, making it
much more efficient for displaying price trends on dashboards or watchlists.
§Arguments
interval- Time interval between data points (e.g.,Interval::FiveMinutes)range- Time range to fetch (e.g.,TimeRange::OneDay)
§Example
use finance_query::{Tickers, Interval, TimeRange};
let tickers = Tickers::new(["AAPL", "MSFT", "GOOGL"]).await?;
let sparks = tickers.spark(Interval::FiveMinutes, TimeRange::OneDay).await?;
for (symbol, spark) in &sparks.sparks {
if let Some(change) = spark.percent_change() {
println!("{}: {:.2}%", symbol, change);
}
}Sourcepub async fn dividends(
&self,
range: TimeRange,
) -> Result<BatchDividendsResponse>
pub async fn dividends( &self, range: TimeRange, ) -> Result<BatchDividendsResponse>
Batch fetch dividends for all symbols
Returns dividend history for all symbols, filtered by the specified time range. Dividends are cached per symbol after the first chart fetch.
§Arguments
range- Time range to filter dividends
§Example
use finance_query::{Tickers, TimeRange};
let tickers = Tickers::new(["AAPL", "MSFT"]).await?;
let dividends = tickers.dividends(TimeRange::OneYear).await?;
for (symbol, divs) in ÷nds.dividends {
println!("{}: {} dividends", symbol, divs.len());
}Sourcepub async fn splits(&self, range: TimeRange) -> Result<BatchSplitsResponse>
pub async fn splits(&self, range: TimeRange) -> Result<BatchSplitsResponse>
Batch fetch stock splits for all symbols
Returns stock split history for all symbols, filtered by the specified time range. Splits are cached per symbol after the first chart fetch.
§Arguments
range- Time range to filter splits
§Example
use finance_query::{Tickers, TimeRange};
let tickers = Tickers::new(["NVDA", "TSLA"]).await?;
let splits = tickers.splits(TimeRange::FiveYears).await?;
for (symbol, sp) in &splits.splits {
for split in sp {
println!("{}: {}", symbol, split.ratio);
}
}Sourcepub async fn capital_gains(
&self,
range: TimeRange,
) -> Result<BatchCapitalGainsResponse>
pub async fn capital_gains( &self, range: TimeRange, ) -> Result<BatchCapitalGainsResponse>
Batch fetch capital gains for all symbols
Returns capital gain distribution history for all symbols, filtered by the specified time range. This is primarily relevant for mutual funds and ETFs. Capital gains are cached per symbol after the first chart fetch.
§Arguments
range- Time range to filter capital gains
§Example
use finance_query::{Tickers, TimeRange};
let tickers = Tickers::new(["VFIAX", "VTI"]).await?;
let gains = tickers.capital_gains(TimeRange::TwoYears).await?;
for (symbol, cg) in &gains.capital_gains {
println!("{}: {} distributions", symbol, cg.len());
}Sourcepub async fn financials(
&self,
statement_type: StatementType,
frequency: Frequency,
) -> Result<BatchFinancialsResponse>
pub async fn financials( &self, statement_type: StatementType, frequency: Frequency, ) -> Result<BatchFinancialsResponse>
Batch fetch financial statements for all symbols
Fetches the specified financial statement type for all symbols concurrently. Financial statements are cached per (symbol, statement_type, frequency) tuple.
§Arguments
statement_type- Type of statement (Income, Balance, CashFlow)frequency- Annual or Quarterly
§Example
use finance_query::{Tickers, StatementType, Frequency};
let tickers = Tickers::new(["AAPL", "MSFT", "GOOGL"]).await?;
let financials = tickers.financials(StatementType::Income, Frequency::Annual).await?;
for (symbol, stmt) in &financials.financials {
if let Some(revenue) = stmt.statement.get("TotalRevenue") {
println!("{}: {:?}", symbol, revenue);
}
}Sourcepub async fn news(&self) -> Result<BatchNewsResponse>
pub async fn news(&self) -> Result<BatchNewsResponse>
Batch fetch news articles for all symbols
Fetches recent news articles for all symbols concurrently using scrapers. News articles are cached per symbol.
§Example
use finance_query::Tickers;
let tickers = Tickers::new(["AAPL", "MSFT"]).await?;
let news = tickers.news().await?;
for (symbol, articles) in &news.news {
println!("{}: {} articles", symbol, articles.len());
for article in articles.iter().take(3) {
println!(" - {}", article.title);
}
}Sourcepub async fn recommendations(
&self,
limit: u32,
) -> Result<BatchRecommendationsResponse>
pub async fn recommendations( &self, limit: u32, ) -> Result<BatchRecommendationsResponse>
Batch fetch recommendations for all symbols
Fetches analyst recommendations and similar stocks for all symbols concurrently. Recommendations are cached per (symbol, limit) tuple — different limits produce different API responses and are cached independently.
§Arguments
limit- Maximum number of similar stocks to return per symbol
§Example
use finance_query::Tickers;
let tickers = Tickers::new(["AAPL", "MSFT"]).await?;
let recommendations = tickers.recommendations(10).await?;
for (symbol, rec) in &recommendations.recommendations {
println!("{}: {} recommendations", symbol, rec.count());
for similar in &rec.recommendations {
println!(" - {}: score {}", similar.symbol, similar.score);
}
}Sourcepub async fn options(&self, date: Option<i64>) -> Result<BatchOptionsResponse>
pub async fn options(&self, date: Option<i64>) -> Result<BatchOptionsResponse>
Batch fetch options chains for all symbols
Fetches options chains for the specified expiration date for all symbols concurrently. Options are cached per (symbol, date) tuple.
§Arguments
date- Optional expiration date (Unix timestamp). If None, fetches nearest expiration.
§Example
use finance_query::Tickers;
let tickers = Tickers::new(["AAPL", "MSFT"]).await?;
let options = tickers.options(None).await?;
for (symbol, opts) in &options.options {
println!("{}: {} expirations", symbol, opts.expiration_dates().len());
}Sourcepub async fn indicators(
&self,
interval: Interval,
range: TimeRange,
) -> Result<BatchIndicatorsResponse>
pub async fn indicators( &self, interval: Interval, range: TimeRange, ) -> Result<BatchIndicatorsResponse>
Batch calculate all technical indicators for all symbols
Calculates complete indicator summaries for all symbols from their chart data. Indicators are cached per (symbol, interval, range) tuple.
§Arguments
interval- The time interval for each candlerange- The time range to fetch data for
§Example
use finance_query::{Tickers, Interval, TimeRange};
let tickers = Tickers::new(["AAPL", "MSFT"]).await?;
let indicators = tickers.indicators(Interval::OneDay, TimeRange::ThreeMonths).await?;
for (symbol, ind) in &indicators.indicators {
println!("{}: RSI(14) = {:?}, SMA(20) = {:?}", symbol, ind.rsi_14, ind.sma_20);
}Sourcepub fn add_symbols(&mut self, symbols: &[impl AsRef<str>])
pub fn add_symbols(&mut self, symbols: &[impl AsRef<str>])
Add symbols to the watch list
Adds new symbols to track without affecting existing cached data.
§Example
use finance_query::Tickers;
let mut tickers = Tickers::new(["AAPL"]).await?;
tickers.add_symbols(&["MSFT", "GOOGL"]);
assert_eq!(tickers.len(), 3);Sourcepub async fn remove_symbols(&mut self, symbols: &[impl AsRef<str>])
pub async fn remove_symbols(&mut self, symbols: &[impl AsRef<str>])
Remove symbols from the watch list
Removes symbols and clears their cached data to free memory.
§Example
use finance_query::Tickers;
let mut tickers = Tickers::new(["AAPL", "MSFT", "GOOGL"]).await?;
tickers.remove_symbols(&["MSFT"]);
assert_eq!(tickers.len(), 2);Sourcepub async fn clear_cache(&self)
pub async fn clear_cache(&self)
Clear all cached data and fetch guards, forcing fresh fetches on next access.
Use this when you need up-to-date data from a long-lived Tickers instance.
Also clears fetch guard maps to prevent unbounded growth.
Sourcepub async fn clear_quote_cache(&self)
pub async fn clear_quote_cache(&self)
Clear only the cached quote data.
The next call to quotes() or quote() will re-fetch from the API.
Sourcepub async fn clear_chart_cache(&self)
pub async fn clear_chart_cache(&self)
Clear only the cached chart, spark, and events data.
The next call to charts(), spark(), dividends(), splits(),
or capital_gains() will re-fetch from the API.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Tickers
impl !RefUnwindSafe for Tickers
impl Send for Tickers
impl Sync for Tickers
impl Unpin for Tickers
impl UnsafeUnpin for Tickers
impl !UnwindSafe for Tickers
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more