alpaca_data/options/
enums.rs

1use std::fmt::{self, Display, Formatter};
2
3pub use crate::common::enums::Sort;
4
5#[derive(Clone, Debug, Eq, PartialEq)]
6pub struct TimeFrame(String);
7
8impl TimeFrame {
9    pub fn min_1() -> Self {
10        Self::from("1Min")
11    }
12
13    pub fn day_1() -> Self {
14        Self::from("1Day")
15    }
16
17    pub fn as_str(&self) -> &str {
18        &self.0
19    }
20}
21
22impl Default for TimeFrame {
23    fn default() -> Self {
24        Self::min_1()
25    }
26}
27
28impl From<&str> for TimeFrame {
29    fn from(value: &str) -> Self {
30        Self(value.to_string())
31    }
32}
33
34impl From<String> for TimeFrame {
35    fn from(value: String) -> Self {
36        Self(value)
37    }
38}
39
40impl Display for TimeFrame {
41    fn fmt(&self, formatter: &mut Formatter<'_>) -> fmt::Result {
42        formatter.write_str(self.as_str())
43    }
44}
45
46#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
47pub enum ContractType {
48    #[default]
49    Call,
50    Put,
51}
52
53impl ContractType {
54    pub fn as_str(&self) -> &'static str {
55        match self {
56            Self::Call => "call",
57            Self::Put => "put",
58        }
59    }
60}
61
62impl Display for ContractType {
63    fn fmt(&self, formatter: &mut Formatter<'_>) -> fmt::Result {
64        formatter.write_str(self.as_str())
65    }
66}
67
68#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
69pub enum OptionsFeed {
70    #[default]
71    Opra,
72    Indicative,
73}
74
75impl OptionsFeed {
76    pub fn as_str(&self) -> &'static str {
77        match self {
78            Self::Opra => "opra",
79            Self::Indicative => "indicative",
80        }
81    }
82}
83
84impl Display for OptionsFeed {
85    fn fmt(&self, formatter: &mut Formatter<'_>) -> fmt::Result {
86        formatter.write_str(self.as_str())
87    }
88}
89
90#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
91pub enum TickType {
92    #[default]
93    Trade,
94    Quote,
95}
96
97impl TickType {
98    pub fn as_str(&self) -> &'static str {
99        match self {
100            Self::Trade => "trade",
101            Self::Quote => "quote",
102        }
103    }
104}
105
106impl Display for TickType {
107    fn fmt(&self, formatter: &mut Formatter<'_>) -> fmt::Result {
108        formatter.write_str(self.as_str())
109    }
110}