bybit/models/
options_ticker.rs1use crate::prelude::*;
2
3#[derive(Serialize, Deserialize, Clone, Debug)]
8pub struct OptionsTicker {
9 pub symbol: String,
11
12 #[serde(rename = "bid1Price")]
14 pub bid1_price: String,
15
16 #[serde(rename = "bid1Size")]
18 pub bid1_size: String,
19
20 #[serde(rename = "bid1Iv")]
22 pub bid1_iv: String,
23
24 #[serde(rename = "ask1Price")]
26 pub ask1_price: String,
27
28 #[serde(rename = "ask1Size")]
30 pub ask1_size: String,
31
32 #[serde(rename = "ask1Iv")]
34 pub ask1_iv: String,
35
36 #[serde(rename = "lastPrice")]
38 pub last_price: String,
39
40 #[serde(rename = "highPrice24h")]
42 pub high_price_24h: String,
43
44 #[serde(rename = "lowPrice24h")]
46 pub low_price_24h: String,
47
48 #[serde(rename = "markPrice")]
50 pub mark_price: String,
51
52 #[serde(rename = "indexPrice")]
54 pub index_price: String,
55
56 #[serde(rename = "markIv")]
58 pub mark_iv: String,
59
60 #[serde(rename = "underlyingPrice")]
62 pub underlying_price: String,
63
64 #[serde(rename = "openInterest")]
66 pub open_interest: String,
67
68 #[serde(rename = "turnover24h")]
70 pub turnover_24h: String,
71
72 #[serde(rename = "volume24h")]
74 pub volume_24h: String,
75
76 #[serde(rename = "totalVolume")]
78 pub total_volume: String,
79
80 #[serde(rename = "totalTurnover")]
82 pub total_turnover: String,
83
84 pub delta: String,
86
87 pub gamma: String,
89
90 pub vega: String,
92
93 pub theta: String,
95
96 #[serde(rename = "predictedDeliveryPrice")]
98 pub predicted_delivery_price: String,
99
100 #[serde(rename = "change24h")]
102 pub change_24h: String,
103}
104
105impl OptionsTicker {
106 pub fn new(symbol: String) -> Self {
108 Self {
109 symbol,
110 bid1_price: String::new(),
111 bid1_size: String::new(),
112 bid1_iv: String::new(),
113 ask1_price: String::new(),
114 ask1_size: String::new(),
115 ask1_iv: String::new(),
116 last_price: String::new(),
117 high_price_24h: String::new(),
118 low_price_24h: String::new(),
119 mark_price: String::new(),
120 index_price: String::new(),
121 mark_iv: String::new(),
122 underlying_price: String::new(),
123 open_interest: String::new(),
124 turnover_24h: String::new(),
125 volume_24h: String::new(),
126 total_volume: String::new(),
127 total_turnover: String::new(),
128 delta: String::new(),
129 gamma: String::new(),
130 vega: String::new(),
131 theta: String::new(),
132 predicted_delivery_price: String::new(),
133 change_24h: String::new(),
134 }
135 }
136
137 pub fn bid1_price_f64(&self) -> Option<f64> {
139 self.bid1_price.parse().ok()
140 }
141
142 pub fn ask1_price_f64(&self) -> Option<f64> {
144 self.ask1_price.parse().ok()
145 }
146
147 pub fn last_price_f64(&self) -> Option<f64> {
149 self.last_price.parse().ok()
150 }
151
152 pub fn mark_price_f64(&self) -> Option<f64> {
154 self.mark_price.parse().ok()
155 }
156
157 pub fn index_price_f64(&self) -> Option<f64> {
159 self.index_price.parse().ok()
160 }
161
162 pub fn underlying_price_f64(&self) -> Option<f64> {
164 self.underlying_price.parse().ok()
165 }
166
167 pub fn spread(&self) -> Option<f64> {
169 let bid = self.bid1_price_f64()?;
170 let ask = self.ask1_price_f64()?;
171 Some(ask - bid)
172 }
173
174 pub fn mid_price(&self) -> Option<f64> {
176 let bid = self.bid1_price_f64()?;
177 let ask = self.ask1_price_f64()?;
178 Some((bid + ask) / 2.0)
179 }
180
181 pub fn change_24h_f64(&self) -> Option<f64> {
183 self.change_24h.parse().ok()
184 }
185
186 pub fn high_price_24h_f64(&self) -> Option<f64> {
188 self.high_price_24h.parse().ok()
189 }
190
191 pub fn low_price_24h_f64(&self) -> Option<f64> {
193 self.low_price_24h.parse().ok()
194 }
195
196 pub fn open_interest_f64(&self) -> Option<f64> {
198 self.open_interest.parse().ok()
199 }
200
201 pub fn volume_24h_f64(&self) -> Option<f64> {
203 self.volume_24h.parse().ok()
204 }
205
206 pub fn turnover_24h_f64(&self) -> Option<f64> {
208 self.turnover_24h.parse().ok()
209 }
210
211 pub fn total_volume_f64(&self) -> Option<f64> {
213 self.total_volume.parse().ok()
214 }
215
216 pub fn total_turnover_f64(&self) -> Option<f64> {
218 self.total_turnover.parse().ok()
219 }
220
221 pub fn delta_f64(&self) -> Option<f64> {
223 self.delta.parse().ok()
224 }
225
226 pub fn gamma_f64(&self) -> Option<f64> {
228 self.gamma.parse().ok()
229 }
230
231 pub fn vega_f64(&self) -> Option<f64> {
233 self.vega.parse().ok()
234 }
235
236 pub fn theta_f64(&self) -> Option<f64> {
238 self.theta.parse().ok()
239 }
240
241 pub fn bid1_iv_f64(&self) -> Option<f64> {
243 self.bid1_iv.parse().ok()
244 }
245
246 pub fn ask1_iv_f64(&self) -> Option<f64> {
248 self.ask1_iv.parse().ok()
249 }
250
251 pub fn mark_iv_f64(&self) -> Option<f64> {
253 self.mark_iv.parse().ok()
254 }
255
256 pub fn predicted_delivery_price_f64(&self) -> Option<f64> {
258 self.predicted_delivery_price.parse().ok()
259 }
260
261 pub fn bid1_size_f64(&self) -> Option<f64> {
263 self.bid1_size.parse().ok()
264 }
265
266 pub fn ask1_size_f64(&self) -> Option<f64> {
268 self.ask1_size.parse().ok()
269 }
270
271 pub fn bid_ask_size_ratio(&self) -> Option<f64> {
273 let bid_size = self.bid1_size_f64()?;
274 let ask_size = self.ask1_size_f64()?;
275 if ask_size == 0.0 {
276 return None;
277 }
278 Some(bid_size / ask_size)
279 }
280
281 pub fn total_size(&self) -> Option<f64> {
283 let bid_size = self.bid1_size_f64()?;
284 let ask_size = self.ask1_size_f64()?;
285 Some(bid_size + ask_size)
286 }
287
288 pub fn iv_spread(&self) -> Option<f64> {
290 let bid_iv = self.bid1_iv_f64()?;
291 let ask_iv = self.ask1_iv_f64()?;
292 Some(ask_iv - bid_iv)
293 }
294
295 pub fn mid_iv(&self) -> Option<f64> {
297 let bid_iv = self.bid1_iv_f64()?;
298 let ask_iv = self.ask1_iv_f64()?;
299 Some((bid_iv + ask_iv) / 2.0)
300 }
301}