finance_query/models/options/
contract.rs1use serde::{Deserialize, Serialize};
2use std::ops::Deref;
3
4#[derive(Debug, Clone, Default, Serialize, Deserialize)]
9#[serde(transparent)]
10pub struct Contracts(pub Vec<OptionContract>);
11
12impl Deref for Contracts {
13 type Target = Vec<OptionContract>;
14
15 fn deref(&self) -> &Self::Target {
16 &self.0
17 }
18}
19
20impl IntoIterator for Contracts {
21 type Item = OptionContract;
22 type IntoIter = std::vec::IntoIter<OptionContract>;
23
24 fn into_iter(self) -> Self::IntoIter {
25 self.0.into_iter()
26 }
27}
28
29impl<'a> IntoIterator for &'a Contracts {
30 type Item = &'a OptionContract;
31 type IntoIter = std::slice::Iter<'a, OptionContract>;
32
33 fn into_iter(self) -> Self::IntoIter {
34 self.0.iter()
35 }
36}
37
38#[cfg(feature = "dataframe")]
39impl Contracts {
40 pub fn to_dataframe(&self) -> ::polars::prelude::PolarsResult<::polars::prelude::DataFrame> {
42 OptionContract::vec_to_dataframe(&self.0)
43 }
44}
45
46#[non_exhaustive]
50#[derive(Debug, Clone, Serialize, Deserialize)]
51#[cfg_attr(feature = "dataframe", derive(crate::ToDataFrame))]
52#[serde(rename_all = "camelCase")]
53pub struct OptionContract {
54 pub contract_symbol: String,
56
57 pub strike: f64,
59
60 pub currency: Option<String>,
62
63 pub last_price: Option<f64>,
65
66 pub change: Option<f64>,
68
69 pub percent_change: Option<f64>,
71
72 pub volume: Option<i64>,
74
75 pub open_interest: Option<i64>,
77
78 pub bid: Option<f64>,
80
81 pub ask: Option<f64>,
83
84 pub contract_size: Option<String>,
86
87 pub expiration: Option<i64>,
89
90 pub last_trade_date: Option<i64>,
92
93 pub implied_volatility: Option<f64>,
95
96 pub in_the_money: Option<bool>,
98}