Skip to main content

yfinance_rs/core/
models.rs

1// Re-export types from paft explicitly
2pub use paft::aggregates::Snapshot;
3pub use paft::market::action::Action;
4pub use paft::market::quote::Quote;
5pub use paft::market::requests::history::{Interval, Range};
6pub use paft::market::responses::history::{
7    AdjustmentAnchor, AdjustmentMethod, Candle, CorporateActionAdjustmentCause,
8    CorporateActionAdjustmentCauses, HistoryMeta, HistoryResponse, Ohlc, OhlcPriceBasis,
9    PriceBasis,
10};
11use paft::money::Price;
12use serde::{Deserialize, Serialize};
13
14/// Fast quote-oriented information for a ticker.
15///
16/// This mirrors Python yfinance's `Ticker.fast_info` surface while keeping
17/// instant-in-time quote data separate from derived moving-average metrics.
18#[non_exhaustive]
19#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
20pub struct FastInfo {
21    /// Instant-in-time market snapshot data.
22    pub snapshot: Snapshot,
23    /// Price moving averages exposed by Yahoo's quote surfaces.
24    pub moving_averages: MovingAverages,
25}
26
27/// Price moving averages exposed in fast ticker information.
28#[non_exhaustive]
29#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Default)]
30pub struct MovingAverages {
31    /// 50 trading-day average price.
32    pub fifty_day: Option<Price>,
33    /// 200 trading-day average price.
34    pub two_hundred_day: Option<Price>,
35}
36
37// Helper functions for converting to string representations
38pub(crate) const fn range_as_str(range: Range) -> &'static str {
39    range.code()
40}
41
42pub(crate) const fn interval_as_str(interval: Interval) -> &'static str {
43    interval.code()
44}