Skip to main content

Tickers

Struct Tickers 

Source
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 &quotes.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

Source

pub async fn new<S, I>(symbols: I) -> Result<Self>
where S: Into<String>, I: IntoIterator<Item = S>,

Creates new tickers with default configuration

§Arguments
  • symbols - Iterable of stock symbols (e.g., ["AAPL", "MSFT"])
§Example
use finance_query::Tickers;

let tickers = Tickers::new(["AAPL", "MSFT", "GOOGL"]).await?;
Source

pub fn builder<S, I>(symbols: I) -> TickersBuilder
where S: Into<String>, I: IntoIterator<Item = S>,

Creates a new builder for Tickers

Source

pub fn symbols(&self) -> Vec<&str>

Returns the symbols this tickers instance manages

Source

pub fn len(&self) -> usize

Number of symbols

Source

pub fn is_empty(&self) -> bool

Check if empty

Source

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.

Source

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.

Source

pub async fn quote(&self, symbol: &str) -> Result<Quote>

Get a specific quote by symbol (from cache or fetch all)

Source

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.

Source

pub async fn chart( &self, symbol: &str, interval: Interval, range: TimeRange, ) -> Result<Chart>

Get a specific chart by symbol

Source

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 points
  • start - Start date as Unix timestamp (seconds since epoch)
  • end - End date as Unix timestamp (seconds since epoch)
Source

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);
    }
}
Source

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 &dividends.dividends {
    println!("{}: {} dividends", symbol, divs.len());
}
Source

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);
    }
}
Source

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());
}
Source

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);
    }
}
Source

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);
    }
}
Source

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);
    }
}
Source

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());
}
Source

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 candle
  • range - 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);
}
Source

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);
Source

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);
Source

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.

Source

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.

Source

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§

Source§

impl Debug for Tickers

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> PlanCallbackArgs for T

Source§

impl<T> PlanCallbackOut for T