finance_query/models/chart/data.rs
1/// Chart aggregate module
2///
3/// Contains the fully typed Chart structure for historical data.
4use super::{Candle, ChartMeta};
5use serde::{Deserialize, Serialize};
6
7/// Fully typed chart data
8///
9/// Aggregates chart metadata and candles into a single convenient structure.
10/// This is the recommended type for serialization and API responses.
11/// Used for both single symbol and batch historical data requests.
12///
13/// Note: This struct cannot be manually constructed - use `Ticker::chart()` to obtain chart data.
14#[non_exhaustive]
15#[derive(Debug, Clone, Serialize, Deserialize)]
16pub struct Chart {
17 /// Stock symbol
18 pub symbol: String,
19
20 /// Chart metadata (exchange, currency, 52-week range, etc.)
21 pub meta: ChartMeta,
22
23 /// OHLCV candles/bars
24 pub candles: Vec<Candle>,
25
26 /// Time interval used (e.g., "1d", "1h")
27 #[serde(skip_serializing_if = "Option::is_none")]
28 pub interval: Option<String>,
29
30 /// Time range used (e.g., "1mo", "1y")
31 #[serde(skip_serializing_if = "Option::is_none")]
32 pub range: Option<String>,
33}
34
35#[cfg(feature = "dataframe")]
36impl Chart {
37 /// Converts the candles to a polars DataFrame.
38 ///
39 /// Each candle becomes a row with columns for timestamp, open, high, low, close, volume.
40 pub fn to_dataframe(&self) -> ::polars::prelude::PolarsResult<::polars::prelude::DataFrame> {
41 Candle::vec_to_dataframe(&self.candles)
42 }
43}