deribit_http/model/
option.rs1use crate::HttpError;
7use crate::prelude::OptionType;
8use chrono::{DateTime, Utc};
9use pretty_simple_display::{DebugPretty, DisplaySimple};
10use serde::{Deserialize, Serialize};
11use serde_json::Value;
12
13#[derive(DebugPretty, DisplaySimple, Clone, PartialEq, Serialize, Deserialize)]
18pub struct OptionInfo {
19 pub symbol: String,
21 pub option_type: OptionType,
23 pub strike_price: f64,
25 pub expiration_date: String,
27}
28
29impl OptionInfo {
30 pub fn parse_from_string(option_string: &str) -> Result<Self, HttpError> {
33 let parts: Vec<&str> = option_string.split('-').collect();
34
35 if parts.len() != 4 {
37 return Err(HttpError::ParseError("InvalidFormat".to_string()));
38 }
39
40 let symbol = parts[0].to_string();
41 let expiration_date = parts[1].to_string();
42
43 let strike_price = parts[2]
45 .parse::<f64>()
46 .map_err(|_| HttpError::ParseError("InvalidStrikePrice".to_string()))?;
47
48 let option_type = match parts[3].to_uppercase().as_str() {
50 "C" => OptionType::Call,
51 "P" => OptionType::Put,
52 _ => return Err(HttpError::ParseError("InvalidOptionType".to_string())),
53 };
54
55 if expiration_date.len() != 7 {
57 return Err(HttpError::ParseError("InvalidExpirationDate".to_string()));
58 };
59
60 Ok(OptionInfo {
61 symbol,
62 option_type,
63 strike_price,
64 expiration_date,
65 })
66 }
67}
68
69#[derive(DebugPretty, DisplaySimple, Clone, Serialize, Deserialize)]
71pub struct Spread {
72 pub bid: Option<f64>,
74 pub ask: Option<f64>,
76 pub mid: Option<f64>,
78}
79
80#[derive(DebugPretty, DisplaySimple, Clone, Serialize, Deserialize)]
82pub struct BasicGreeks {
83 pub delta_call: Option<f64>,
85 pub delta_put: Option<f64>,
87 pub gamma: Option<f64>,
89}
90
91#[derive(DebugPretty, DisplaySimple, Clone, Serialize, Deserialize)]
93pub struct BasicOptionData {
94 pub strike_price: f64,
96 pub call_bid: Option<f64>,
98 pub call_ask: Option<f64>,
100 pub put_bid: Option<f64>,
102 pub put_ask: Option<f64>,
104 pub implied_volatility: (Option<f64>, Option<f64>),
106 pub delta_call: Option<f64>,
108 pub delta_put: Option<f64>,
110 pub gamma: Option<f64>,
112 pub volume: f64,
114 pub open_interest: f64,
116 pub expiration_date: Option<DateTime<Utc>>,
118 pub underlying_price: Option<f64>,
120 pub risk_free_rate: f64,
122 pub extra_fields: Option<Value>,
124}