#[non_exhaustive]pub struct Chart {
pub symbol: String,
pub meta: ChartMeta,
pub candles: Vec<Candle>,
pub interval: Option<Interval>,
pub range: Option<TimeRange>,
}Expand description
Fully typed chart data
Aggregates chart metadata and candles into a single convenient structure. This is the recommended type for serialization and API responses. Used for both single symbol and batch historical data requests.
Note: This struct cannot be manually constructed - use Ticker::chart() to obtain chart data.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.symbol: StringStock symbol
meta: ChartMetaChart metadata (exchange, currency, 52-week range, etc.)
candles: Vec<Candle>OHLCV candles/bars
interval: Option<Interval>Time interval used (e.g., Interval::OneDay)
range: Option<TimeRange>Time range used (e.g., TimeRange::OneYear)
Implementations§
Source§impl Chart
impl Chart
Sourcepub fn to_dataframe(&self) -> PolarsResult<DataFrame>
pub fn to_dataframe(&self) -> PolarsResult<DataFrame>
Converts the candles to a polars DataFrame.
Each candle becomes a row with columns for timestamp, open, high, low, close, volume.
Source§impl Chart
impl Chart
Sourcepub fn close_prices(&self) -> Vec<f64>
pub fn close_prices(&self) -> Vec<f64>
Extracts close prices from candles as a Vec<f64>.
This is a convenience method for passing price data to indicator functions.
Sourcepub fn high_prices(&self) -> Vec<f64>
pub fn high_prices(&self) -> Vec<f64>
Extracts high prices from candles as a Vec<f64>.
Sourcepub fn low_prices(&self) -> Vec<f64>
pub fn low_prices(&self) -> Vec<f64>
Extracts low prices from candles as a Vec<f64>.
Sourcepub fn open_prices(&self) -> Vec<f64>
pub fn open_prices(&self) -> Vec<f64>
Extracts open prices from candles as a Vec<f64>.
Sourcepub fn sma(&self, period: usize) -> Vec<Option<f64>>
pub fn sma(&self, period: usize) -> Vec<Option<f64>>
Calculate Simple Moving Average (SMA) on close prices.
§Example
use finance_query::{Ticker, Interval, TimeRange};
let ticker = Ticker::new("AAPL").await?;
let chart = ticker.chart(Interval::OneDay, TimeRange::OneMonth).await?;
let sma_20 = chart.sma(20);Sourcepub fn ema(&self, period: usize) -> Vec<Option<f64>>
pub fn ema(&self, period: usize) -> Vec<Option<f64>>
Calculate Exponential Moving Average (EMA) on close prices.
§Example
use finance_query::{Ticker, Interval, TimeRange};
let ticker = Ticker::new("AAPL").await?;
let chart = ticker.chart(Interval::OneDay, TimeRange::OneMonth).await?;
let ema_12 = chart.ema(12);Sourcepub fn rsi(&self, period: usize) -> Result<Vec<Option<f64>>>
pub fn rsi(&self, period: usize) -> Result<Vec<Option<f64>>>
Calculate Relative Strength Index (RSI) on close prices.
Returns values between 0 and 100. Readings above 70 indicate overbought, below 30 indicate oversold conditions.
§Example
use finance_query::{Ticker, Interval, TimeRange};
let ticker = Ticker::new("AAPL").await?;
let chart = ticker.chart(Interval::OneDay, TimeRange::OneMonth).await?;
let rsi = chart.rsi(14)?;Sourcepub fn macd(
&self,
fast_period: usize,
slow_period: usize,
signal_period: usize,
) -> Result<MacdResult>
pub fn macd( &self, fast_period: usize, slow_period: usize, signal_period: usize, ) -> Result<MacdResult>
Calculate Moving Average Convergence Divergence (MACD).
Standard parameters are (12, 26, 9).
§Example
use finance_query::{Ticker, Interval, TimeRange};
let ticker = Ticker::new("AAPL").await?;
let chart = ticker.chart(Interval::OneDay, TimeRange::OneMonth).await?;
let macd_result = chart.macd(12, 26, 9)?;
println!("MACD Line: {:?}", macd_result.macd_line);
println!("Signal Line: {:?}", macd_result.signal_line);
println!("Histogram: {:?}", macd_result.histogram);Sourcepub fn bollinger_bands(
&self,
period: usize,
std_dev_multiplier: f64,
) -> Result<BollingerBands>
pub fn bollinger_bands( &self, period: usize, std_dev_multiplier: f64, ) -> Result<BollingerBands>
Calculate Bollinger Bands.
Standard parameters are (20, 2.0) for period and std_dev_multiplier.
§Example
use finance_query::{Ticker, Interval, TimeRange};
let ticker = Ticker::new("AAPL").await?;
let chart = ticker.chart(Interval::OneDay, TimeRange::OneMonth).await?;
let bb = chart.bollinger_bands(20, 2.0)?;
println!("Upper: {:?}", bb.upper);
println!("Middle: {:?}", bb.middle);
println!("Lower: {:?}", bb.lower);Sourcepub fn atr(&self, period: usize) -> Result<Vec<Option<f64>>>
pub fn atr(&self, period: usize) -> Result<Vec<Option<f64>>>
Calculate Average True Range (ATR).
ATR measures market volatility. Standard period is 14.
§Example
use finance_query::{Ticker, Interval, TimeRange};
let ticker = Ticker::new("AAPL").await?;
let chart = ticker.chart(Interval::OneDay, TimeRange::OneMonth).await?;
let atr = chart.atr(14)?;Sourcepub fn patterns(&self) -> Vec<Option<CandlePattern>>
pub fn patterns(&self) -> Vec<Option<CandlePattern>>
Detect candlestick patterns across all bars.
Returns a Vec<Option<CandlePattern>> of the same length as candles.
Some(pattern) means a pattern was detected on that bar; None means
no pattern matched. Three-bar patterns take precedence over two-bar,
which take precedence over one-bar.
§Example
use finance_query::{Ticker, Interval, TimeRange};
use finance_query::indicators::{CandlePattern, PatternSentiment};
let ticker = Ticker::new("AAPL").await?;
let chart = ticker.chart(Interval::OneDay, TimeRange::SixMonths).await?;
let signals = chart.patterns();
let bullish_count = signals
.iter()
.filter(|s| s.map(|p| p.sentiment() == PatternSentiment::Bullish).unwrap_or(false))
.count();
println!("{bullish_count} bullish patterns in the last 6 months");Trait Implementations§
Source§impl<'de> Deserialize<'de> for Chart
impl<'de> Deserialize<'de> for Chart
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for Chart
impl RefUnwindSafe for Chart
impl Send for Chart
impl Sync for Chart
impl Unpin for Chart
impl UnsafeUnpin for Chart
impl UnwindSafe for Chart
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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