1use serde::{Deserialize, Serialize};
2use chrono::{DateTime, Utc};
3
4#[derive(Debug, Clone, Serialize, Deserialize)]
6pub struct Quote {
7 pub symbol: String,
9
10 pub last_price: f64,
12
13 pub change: f64,
15
16 pub change_percent: f64,
18
19 pub volume: u64,
21
22 pub average_volume: u64,
24
25 pub bid_price: f64,
27
28 pub bid_size: u64,
30
31 pub ask_price: f64,
33
34 pub ask_size: u64,
36
37 pub high: f64,
39
40 pub low: f64,
42
43 pub open: f64,
45
46 pub prev_close: f64,
48
49 pub fifty_two_week_high: f64,
51
52 pub fifty_two_week_low: f64,
54
55 pub market_cap: Option<f64>,
57
58 pub pe_ratio: Option<f64>,
60
61 pub timestamp: DateTime<Utc>,
63}
64
65#[derive(Debug, Clone, Serialize, Deserialize)]
67pub struct Bar {
68 pub symbol: String,
70
71 pub open: f64,
73
74 pub high: f64,
76
77 pub low: f64,
79
80 pub close: f64,
82
83 pub volume: u64,
85
86 pub timestamp: DateTime<Utc>,
88}
89
90#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
92#[serde(rename_all = "lowercase")]
93pub enum TimeFrame {
94 Minute1,
96
97 Minute5,
99
100 Minute15,
102
103 Minute30,
105
106 Hour1,
108
109 Hour4,
111
112 Day1,
114
115 Week1,
117
118 Month1,
120}
121
122#[derive(Debug, Clone, Serialize, Deserialize)]
124pub struct BarQueryParams {
125 pub symbol: String,
127
128 pub time_frame: TimeFrame,
130
131 pub start_date: Option<DateTime<Utc>>,
133
134 pub end_date: Option<DateTime<Utc>>,
136
137 pub limit: Option<u32>,
139}
140
141impl BarQueryParams {
142 pub fn new(symbol: impl Into<String>, time_frame: TimeFrame) -> Self {
144 Self {
145 symbol: symbol.into(),
146 time_frame,
147 start_date: None,
148 end_date: None,
149 limit: None,
150 }
151 }
152
153 pub fn start_date(mut self, start_date: DateTime<Utc>) -> Self {
155 self.start_date = Some(start_date);
156 self
157 }
158
159 pub fn end_date(mut self, end_date: DateTime<Utc>) -> Self {
161 self.end_date = Some(end_date);
162 self
163 }
164
165 pub fn limit(mut self, limit: u32) -> Self {
167 self.limit = Some(limit);
168 self
169 }
170}
171
172#[derive(Debug, Clone, Serialize, Deserialize)]
174pub struct OptionContract {
175 pub symbol: String,
177
178 pub underlying_symbol: String,
180
181 pub strike_price: f64,
183
184 pub expiration_date: DateTime<Utc>,
186
187 pub option_type: OptionType,
189
190 pub last_price: f64,
192
193 pub change: f64,
195
196 pub change_percent: f64,
198
199 pub volume: u64,
201
202 pub open_interest: u64,
204
205 pub bid_price: f64,
207
208 pub bid_size: u64,
210
211 pub ask_price: f64,
213
214 pub ask_size: u64,
216
217 pub implied_volatility: f64,
219
220 pub delta: f64,
222
223 pub gamma: f64,
225
226 pub theta: f64,
228
229 pub vega: f64,
231
232 pub rho: f64,
234}
235
236#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
238#[serde(rename_all = "UPPERCASE")]
239pub enum OptionType {
240 Call,
242
243 Put,
245}
246
247#[derive(Debug, Clone, Serialize, Deserialize)]
249pub struct OptionChain {
250 pub underlying_symbol: String,
252
253 pub expiration_dates: Vec<DateTime<Utc>>,
255
256 pub strike_prices: Vec<f64>,
258
259 pub contracts: Vec<OptionContract>,
261}
262
263#[derive(Debug, Clone, Serialize, Deserialize)]
265pub struct OptionChainQueryParams {
266 pub underlying_symbol: String,
268
269 pub expiration_date: Option<DateTime<Utc>>,
271
272 pub strike_price: Option<f64>,
274
275 pub option_type: Option<OptionType>,
277}
278
279impl OptionChainQueryParams {
280 pub fn new(underlying_symbol: impl Into<String>) -> Self {
282 Self {
283 underlying_symbol: underlying_symbol.into(),
284 expiration_date: None,
285 strike_price: None,
286 option_type: None,
287 }
288 }
289
290 pub fn expiration_date(mut self, expiration_date: DateTime<Utc>) -> Self {
292 self.expiration_date = Some(expiration_date);
293 self
294 }
295
296 pub fn strike_price(mut self, strike_price: f64) -> Self {
298 self.strike_price = Some(strike_price);
299 self
300 }
301
302 pub fn option_type(mut self, option_type: OptionType) -> Self {
304 self.option_type = Some(option_type);
305 self
306 }
307}
308
309#[derive(Debug, Clone, Serialize, Deserialize)]
311pub struct NewsArticle {
312 pub id: String,
314
315 pub title: String,
317
318 pub summary: String,
320
321 pub url: String,
323
324 pub source: String,
326
327 pub publish_date: DateTime<Utc>,
329
330 pub symbols: Vec<String>,
332}
333
334#[derive(Debug, Clone, Serialize, Deserialize)]
336pub struct NewsQueryParams {
337 pub symbol: Option<String>,
339
340 pub start_date: Option<DateTime<Utc>>,
342
343 pub end_date: Option<DateTime<Utc>>,
345
346 pub limit: Option<u32>,
348}
349
350impl NewsQueryParams {
351 pub fn new() -> Self {
353 Self {
354 symbol: None,
355 start_date: None,
356 end_date: None,
357 limit: None,
358 }
359 }
360
361 pub fn symbol(mut self, symbol: impl Into<String>) -> Self {
363 self.symbol = Some(symbol.into());
364 self
365 }
366
367 pub fn start_date(mut self, start_date: DateTime<Utc>) -> Self {
369 self.start_date = Some(start_date);
370 self
371 }
372
373 pub fn end_date(mut self, end_date: DateTime<Utc>) -> Self {
375 self.end_date = Some(end_date);
376 self
377 }
378
379 pub fn limit(mut self, limit: u32) -> Self {
381 self.limit = Some(limit);
382 self
383 }
384}
385
386impl Default for NewsQueryParams {
387 fn default() -> Self {
388 Self::new()
389 }
390}