Skip to main content

futucli/cmd/analysis/
option_args.rs

1//! v1.4.110+ split (from cmd/analysis.rs): option_args domain.
2//!
3//! pub items: OptionChainGreekFilterArgs.
4
5use serde::Serialize;
6use tabled::Tabled;
7
8// ============================================================
9// option-chain
10// ============================================================
11
12#[derive(Tabled)]
13pub(super) struct OptionChainRow {
14    #[tabled(rename = "Strike Time")]
15    pub strike_time: String,
16    #[tabled(rename = "Calls")]
17    pub call_count: usize,
18    #[tabled(rename = "Puts")]
19    pub put_count: usize,
20    #[tabled(rename = "Example Call")]
21    pub example_call: String,
22    #[tabled(rename = "Example Put")]
23    pub example_put: String,
24}
25
26#[derive(Serialize)]
27pub(super) struct OptionChainJson {
28    pub strike_time: String,
29    pub call_symbols: Vec<String>,
30    pub put_symbols: Vec<String>,
31}
32
33#[derive(Debug, Clone, Default)]
34pub struct OptionChainGreekFilterArgs {
35    pub delta_min: Option<f64>,
36    pub delta_max: Option<f64>,
37    pub iv_min: Option<f64>,
38    pub iv_max: Option<f64>,
39    pub oi_min: Option<f64>,
40    pub oi_max: Option<f64>,
41    pub gamma_min: Option<f64>,
42    pub gamma_max: Option<f64>,
43    pub vega_min: Option<f64>,
44    pub vega_max: Option<f64>,
45    pub theta_min: Option<f64>,
46    pub theta_max: Option<f64>,
47}
48
49impl OptionChainGreekFilterArgs {
50    pub fn into_data_filter(self) -> Option<futu_proto::qot_get_option_chain::DataFilter> {
51        let any_filter = self.delta_min.is_some()
52            || self.delta_max.is_some()
53            || self.iv_min.is_some()
54            || self.iv_max.is_some()
55            || self.oi_min.is_some()
56            || self.oi_max.is_some()
57            || self.gamma_min.is_some()
58            || self.gamma_max.is_some()
59            || self.vega_min.is_some()
60            || self.vega_max.is_some()
61            || self.theta_min.is_some()
62            || self.theta_max.is_some();
63
64        any_filter.then_some(futu_proto::qot_get_option_chain::DataFilter {
65            implied_volatility_min: self.iv_min,
66            implied_volatility_max: self.iv_max,
67            delta_min: self.delta_min,
68            delta_max: self.delta_max,
69            gamma_min: self.gamma_min,
70            gamma_max: self.gamma_max,
71            vega_min: self.vega_min,
72            vega_max: self.vega_max,
73            theta_min: self.theta_min,
74            theta_max: self.theta_max,
75            rho_min: None,
76            rho_max: None,
77            net_open_interest_min: None,
78            net_open_interest_max: None,
79            open_interest_min: self.oi_min,
80            open_interest_max: self.oi_max,
81            vol_min: None,
82            vol_max: None,
83        })
84    }
85}