Skip to main content

Chart

Struct Chart 

Source
#[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
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§symbol: String

Stock symbol

§meta: ChartMeta

Chart 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

Source

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

Source

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.

Source

pub fn high_prices(&self) -> Vec<f64>

Extracts high prices from candles as a Vec<f64>.

Source

pub fn low_prices(&self) -> Vec<f64>

Extracts low prices from candles as a Vec<f64>.

Source

pub fn open_prices(&self) -> Vec<f64>

Extracts open prices from candles as a Vec<f64>.

Source

pub fn volumes(&self) -> Vec<f64>

Extracts volumes from candles as a Vec<f64>.

Source

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

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

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

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

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

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

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 Clone for Chart

Source§

fn clone(&self) -> Chart

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Chart

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Chart

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for Chart

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

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> 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

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> Key for T
where T: Clone,

Source§

fn align() -> usize

The alignment necessary for the key. Must return a power of two.
Source§

fn size(&self) -> usize

The size of the key in bytes.
Source§

unsafe fn init(&self, ptr: *mut u8)

Initialize the key in the given memory location. Read more
Source§

unsafe fn get<'a>(ptr: *const u8) -> &'a T

Get a reference to the key from the given memory location. Read more
Source§

unsafe fn drop_in_place(ptr: *mut u8)

Drop the key in place. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> PlanCallbackArgs for T

Source§

impl<T> PlanCallbackOut for T