Skip to main content

finance_query/adapters/fmp/
models.rs

1//! Shared types for Financial Modeling Prep API responses.
2
3use serde::{Deserialize, Serialize};
4
5// ============================================================================
6// Enums
7// ============================================================================
8
9/// Financial statement period.
10#[derive(Debug, Clone, Copy, PartialEq, Eq)]
11pub enum Period {
12    /// Annual financial statements.
13    Annual,
14    /// Quarterly financial statements.
15    Quarter,
16}
17
18impl Period {
19    /// Convert to FMP API parameter string.
20    pub fn as_str(&self) -> &'static str {
21        match self {
22            Self::Annual => "annual",
23            Self::Quarter => "quarter",
24        }
25    }
26}
27
28// ============================================================================
29// Quote types
30// ============================================================================
31
32/// Real-time quote from FMP.
33#[derive(Debug, Clone, Serialize, Deserialize)]
34#[non_exhaustive]
35pub struct FmpQuote {
36    /// Ticker symbol.
37    pub symbol: String,
38    /// Company name.
39    pub name: Option<String>,
40    /// Current price.
41    pub price: Option<f64>,
42    /// Price change.
43    pub change: Option<f64>,
44    /// Price change percentage.
45    #[serde(rename = "changesPercentage")]
46    pub changes_percentage: Option<f64>,
47    /// Day low.
48    #[serde(rename = "dayLow")]
49    pub day_low: Option<f64>,
50    /// Day high.
51    #[serde(rename = "dayHigh")]
52    pub day_high: Option<f64>,
53    /// 52-week low.
54    #[serde(rename = "yearLow")]
55    pub year_low: Option<f64>,
56    /// 52-week high.
57    #[serde(rename = "yearHigh")]
58    pub year_high: Option<f64>,
59    /// Market capitalization.
60    #[serde(rename = "marketCap")]
61    pub market_cap: Option<f64>,
62    /// Trading volume.
63    pub volume: Option<f64>,
64    /// Average volume.
65    #[serde(rename = "avgVolume")]
66    pub avg_volume: Option<f64>,
67    /// Open price.
68    pub open: Option<f64>,
69    /// Previous close price.
70    #[serde(rename = "previousClose")]
71    pub previous_close: Option<f64>,
72    /// Earnings per share.
73    pub eps: Option<f64>,
74    /// Price-to-earnings ratio.
75    pub pe: Option<f64>,
76    /// Unix timestamp.
77    pub timestamp: Option<i64>,
78    /// Exchange name.
79    pub exchange: Option<String>,
80    /// Earnings announcement date.
81    #[serde(rename = "earningsAnnouncement")]
82    pub earnings_announcement: Option<String>,
83}
84
85// ============================================================================
86// Historical price types
87// ============================================================================
88
89/// A single historical daily price point.
90#[derive(Debug, Clone, Serialize, Deserialize)]
91#[non_exhaustive]
92pub struct HistoricalPrice {
93    /// Date (YYYY-MM-DD).
94    pub date: Option<String>,
95    /// Open price.
96    pub open: Option<f64>,
97    /// High price.
98    pub high: Option<f64>,
99    /// Low price.
100    pub low: Option<f64>,
101    /// Close price.
102    pub close: Option<f64>,
103    /// Adjusted close price.
104    #[serde(rename = "adjClose")]
105    pub adj_close: Option<f64>,
106    /// Trading volume.
107    pub volume: Option<f64>,
108    /// Unadjusted volume.
109    #[serde(rename = "unadjustedVolume")]
110    pub unadjusted_volume: Option<f64>,
111    /// Price change.
112    pub change: Option<f64>,
113    /// Price change percentage.
114    #[serde(rename = "changePercent")]
115    pub change_percent: Option<f64>,
116    /// Volume-weighted average price.
117    pub vwap: Option<f64>,
118    /// Human-readable date label.
119    pub label: Option<String>,
120    /// Change over time (cumulative).
121    #[serde(rename = "changeOverTime")]
122    pub change_over_time: Option<f64>,
123}
124
125/// Historical price response wrapper (FMP wraps daily history in this).
126#[derive(Debug, Clone, Serialize, Deserialize)]
127#[non_exhaustive]
128pub struct HistoricalPriceResponse {
129    /// Ticker symbol.
130    pub symbol: Option<String>,
131    /// Historical price data points.
132    pub historical: Vec<HistoricalPrice>,
133}
134
135/// A single intraday price point (1min, 5min, 15min, 30min, 1hour, 4hour).
136#[derive(Debug, Clone, Serialize, Deserialize)]
137#[non_exhaustive]
138pub struct IntradayPrice {
139    /// Datetime string.
140    pub date: Option<String>,
141    /// Open price.
142    pub open: Option<f64>,
143    /// High price.
144    pub high: Option<f64>,
145    /// Low price.
146    pub low: Option<f64>,
147    /// Close price.
148    pub close: Option<f64>,
149    /// Trading volume.
150    pub volume: Option<f64>,
151}