webull_rs/models/
market.rs

1use serde::{Deserialize, Serialize};
2use chrono::{DateTime, Utc};
3
4/// Real-time quote information.
5#[derive(Debug, Clone, Serialize, Deserialize)]
6pub struct Quote {
7    /// Symbol of the security
8    pub symbol: String,
9    
10    /// Last trade price
11    pub last_price: f64,
12    
13    /// Change in price
14    pub change: f64,
15    
16    /// Percentage change in price
17    pub change_percent: f64,
18    
19    /// Volume of shares traded
20    pub volume: u64,
21    
22    /// Average volume
23    pub average_volume: u64,
24    
25    /// Bid price
26    pub bid_price: f64,
27    
28    /// Bid size
29    pub bid_size: u64,
30    
31    /// Ask price
32    pub ask_price: f64,
33    
34    /// Ask size
35    pub ask_size: u64,
36    
37    /// Day's high price
38    pub high: f64,
39    
40    /// Day's low price
41    pub low: f64,
42    
43    /// Opening price
44    pub open: f64,
45    
46    /// Previous close price
47    pub prev_close: f64,
48    
49    /// 52-week high price
50    pub fifty_two_week_high: f64,
51    
52    /// 52-week low price
53    pub fifty_two_week_low: f64,
54    
55    /// Market cap
56    pub market_cap: Option<f64>,
57    
58    /// Price-to-earnings ratio
59    pub pe_ratio: Option<f64>,
60    
61    /// Timestamp of the quote
62    pub timestamp: DateTime<Utc>,
63}
64
65/// Bar data for a security.
66#[derive(Debug, Clone, Serialize, Deserialize)]
67pub struct Bar {
68    /// Symbol of the security
69    pub symbol: String,
70    
71    /// Opening price
72    pub open: f64,
73    
74    /// High price
75    pub high: f64,
76    
77    /// Low price
78    pub low: f64,
79    
80    /// Closing price
81    pub close: f64,
82    
83    /// Volume of shares traded
84    pub volume: u64,
85    
86    /// Timestamp of the bar
87    pub timestamp: DateTime<Utc>,
88}
89
90/// Time frame for bar data.
91#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
92#[serde(rename_all = "lowercase")]
93pub enum TimeFrame {
94    /// 1-minute bars
95    Minute1,
96    
97    /// 5-minute bars
98    Minute5,
99    
100    /// 15-minute bars
101    Minute15,
102    
103    /// 30-minute bars
104    Minute30,
105    
106    /// 1-hour bars
107    Hour1,
108    
109    /// 4-hour bars
110    Hour4,
111    
112    /// Daily bars
113    Day1,
114    
115    /// Weekly bars
116    Week1,
117    
118    /// Monthly bars
119    Month1,
120}
121
122/// Parameters for querying bar data.
123#[derive(Debug, Clone, Serialize, Deserialize)]
124pub struct BarQueryParams {
125    /// Symbol to query
126    pub symbol: String,
127    
128    /// Time frame for the bars
129    pub time_frame: TimeFrame,
130    
131    /// Start date for the query
132    pub start_date: Option<DateTime<Utc>>,
133    
134    /// End date for the query
135    pub end_date: Option<DateTime<Utc>>,
136    
137    /// Maximum number of bars to return
138    pub limit: Option<u32>,
139}
140
141impl BarQueryParams {
142    /// Create new bar query parameters.
143    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    /// Set the start date filter.
154    pub fn start_date(mut self, start_date: DateTime<Utc>) -> Self {
155        self.start_date = Some(start_date);
156        self
157    }
158    
159    /// Set the end date filter.
160    pub fn end_date(mut self, end_date: DateTime<Utc>) -> Self {
161        self.end_date = Some(end_date);
162        self
163    }
164    
165    /// Set the limit.
166    pub fn limit(mut self, limit: u32) -> Self {
167        self.limit = Some(limit);
168        self
169    }
170}
171
172/// Option contract information.
173#[derive(Debug, Clone, Serialize, Deserialize)]
174pub struct OptionContract {
175    /// Symbol of the option contract
176    pub symbol: String,
177    
178    /// Underlying symbol
179    pub underlying_symbol: String,
180    
181    /// Strike price
182    pub strike_price: f64,
183    
184    /// Expiration date
185    pub expiration_date: DateTime<Utc>,
186    
187    /// Option type (call/put)
188    pub option_type: OptionType,
189    
190    /// Last trade price
191    pub last_price: f64,
192    
193    /// Change in price
194    pub change: f64,
195    
196    /// Percentage change in price
197    pub change_percent: f64,
198    
199    /// Volume of contracts traded
200    pub volume: u64,
201    
202    /// Open interest
203    pub open_interest: u64,
204    
205    /// Bid price
206    pub bid_price: f64,
207    
208    /// Bid size
209    pub bid_size: u64,
210    
211    /// Ask price
212    pub ask_price: f64,
213    
214    /// Ask size
215    pub ask_size: u64,
216    
217    /// Implied volatility
218    pub implied_volatility: f64,
219    
220    /// Delta
221    pub delta: f64,
222    
223    /// Gamma
224    pub gamma: f64,
225    
226    /// Theta
227    pub theta: f64,
228    
229    /// Vega
230    pub vega: f64,
231    
232    /// Rho
233    pub rho: f64,
234}
235
236/// Type of option contract.
237#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
238#[serde(rename_all = "UPPERCASE")]
239pub enum OptionType {
240    /// Call option
241    Call,
242    
243    /// Put option
244    Put,
245}
246
247/// Option chain information.
248#[derive(Debug, Clone, Serialize, Deserialize)]
249pub struct OptionChain {
250    /// Underlying symbol
251    pub underlying_symbol: String,
252    
253    /// Expiration dates
254    pub expiration_dates: Vec<DateTime<Utc>>,
255    
256    /// Strike prices
257    pub strike_prices: Vec<f64>,
258    
259    /// Option contracts
260    pub contracts: Vec<OptionContract>,
261}
262
263/// Parameters for querying option chains.
264#[derive(Debug, Clone, Serialize, Deserialize)]
265pub struct OptionChainQueryParams {
266    /// Underlying symbol
267    pub underlying_symbol: String,
268    
269    /// Expiration date filter
270    pub expiration_date: Option<DateTime<Utc>>,
271    
272    /// Strike price filter
273    pub strike_price: Option<f64>,
274    
275    /// Option type filter
276    pub option_type: Option<OptionType>,
277}
278
279impl OptionChainQueryParams {
280    /// Create new option chain query parameters.
281    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    /// Set the expiration date filter.
291    pub fn expiration_date(mut self, expiration_date: DateTime<Utc>) -> Self {
292        self.expiration_date = Some(expiration_date);
293        self
294    }
295    
296    /// Set the strike price filter.
297    pub fn strike_price(mut self, strike_price: f64) -> Self {
298        self.strike_price = Some(strike_price);
299        self
300    }
301    
302    /// Set the option type filter.
303    pub fn option_type(mut self, option_type: OptionType) -> Self {
304        self.option_type = Some(option_type);
305        self
306    }
307}
308
309/// Market news article.
310#[derive(Debug, Clone, Serialize, Deserialize)]
311pub struct NewsArticle {
312    /// Article ID
313    pub id: String,
314    
315    /// Article title
316    pub title: String,
317    
318    /// Article summary
319    pub summary: String,
320    
321    /// Article URL
322    pub url: String,
323    
324    /// Article source
325    pub source: String,
326    
327    /// Article publish date
328    pub publish_date: DateTime<Utc>,
329    
330    /// Related symbols
331    pub symbols: Vec<String>,
332}
333
334/// Parameters for querying news articles.
335#[derive(Debug, Clone, Serialize, Deserialize)]
336pub struct NewsQueryParams {
337    /// Symbol filter
338    pub symbol: Option<String>,
339    
340    /// Start date filter
341    pub start_date: Option<DateTime<Utc>>,
342    
343    /// End date filter
344    pub end_date: Option<DateTime<Utc>>,
345    
346    /// Maximum number of articles to return
347    pub limit: Option<u32>,
348}
349
350impl NewsQueryParams {
351    /// Create new news query parameters.
352    pub fn new() -> Self {
353        Self {
354            symbol: None,
355            start_date: None,
356            end_date: None,
357            limit: None,
358        }
359    }
360    
361    /// Set the symbol filter.
362    pub fn symbol(mut self, symbol: impl Into<String>) -> Self {
363        self.symbol = Some(symbol.into());
364        self
365    }
366    
367    /// Set the start date filter.
368    pub fn start_date(mut self, start_date: DateTime<Utc>) -> Self {
369        self.start_date = Some(start_date);
370        self
371    }
372    
373    /// Set the end date filter.
374    pub fn end_date(mut self, end_date: DateTime<Utc>) -> Self {
375        self.end_date = Some(end_date);
376        self
377    }
378    
379    /// Set the limit.
380    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}