Skip to main content

alpaca_data/stocks/
enums.rs

1use std::fmt::{self, Display, Formatter};
2
3use serde::{Deserialize, Serialize};
4
5#[derive(Clone, Copy, Debug, Default, Eq, PartialEq, Serialize, Deserialize)]
6pub enum Sort {
7    #[default]
8    Asc,
9    Desc,
10}
11
12impl Display for Sort {
13    fn fmt(&self, formatter: &mut Formatter<'_>) -> fmt::Result {
14        formatter.write_str(match self {
15            Self::Asc => "asc",
16            Self::Desc => "desc",
17        })
18    }
19}
20
21#[derive(Clone, Debug, Eq, PartialEq, Hash, Serialize, Deserialize)]
22#[serde(transparent)]
23pub struct Currency(String);
24
25impl Currency {
26    #[must_use]
27    pub fn usd() -> Self {
28        Self::from("USD")
29    }
30
31    #[must_use]
32    pub fn as_str(&self) -> &str {
33        &self.0
34    }
35}
36
37impl Default for Currency {
38    fn default() -> Self {
39        Self::usd()
40    }
41}
42
43impl From<&str> for Currency {
44    fn from(value: &str) -> Self {
45        Self(value.to_owned())
46    }
47}
48
49impl From<String> for Currency {
50    fn from(value: String) -> Self {
51        Self(value)
52    }
53}
54
55impl Display for Currency {
56    fn fmt(&self, formatter: &mut Formatter<'_>) -> fmt::Result {
57        formatter.write_str(self.as_str())
58    }
59}
60
61#[derive(Clone, Debug, Eq, PartialEq, Hash, Serialize, Deserialize)]
62#[serde(transparent)]
63pub struct TimeFrame(String);
64
65impl TimeFrame {
66    #[must_use]
67    pub fn min_1() -> Self {
68        Self::from("1Min")
69    }
70
71    #[must_use]
72    pub fn day_1() -> Self {
73        Self::from("1Day")
74    }
75
76    #[must_use]
77    pub fn as_str(&self) -> &str {
78        &self.0
79    }
80}
81
82impl Default for TimeFrame {
83    fn default() -> Self {
84        Self::min_1()
85    }
86}
87
88impl From<&str> for TimeFrame {
89    fn from(value: &str) -> Self {
90        Self(value.to_owned())
91    }
92}
93
94impl From<String> for TimeFrame {
95    fn from(value: String) -> Self {
96        Self(value)
97    }
98}
99
100impl Display for TimeFrame {
101    fn fmt(&self, formatter: &mut Formatter<'_>) -> fmt::Result {
102        formatter.write_str(self.as_str())
103    }
104}
105
106#[derive(Clone, Debug, Eq, PartialEq, Hash, Serialize, Deserialize)]
107#[serde(transparent)]
108pub struct Adjustment(String);
109
110impl Adjustment {
111    #[must_use]
112    pub fn raw() -> Self {
113        Self::from("raw")
114    }
115
116    #[must_use]
117    pub fn split() -> Self {
118        Self::from("split")
119    }
120
121    #[must_use]
122    pub fn dividend() -> Self {
123        Self::from("dividend")
124    }
125
126    #[must_use]
127    pub fn spin_off() -> Self {
128        Self::from("spin-off")
129    }
130
131    #[must_use]
132    pub fn all() -> Self {
133        Self::from("all")
134    }
135
136    #[must_use]
137    pub fn as_str(&self) -> &str {
138        &self.0
139    }
140}
141
142impl Default for Adjustment {
143    fn default() -> Self {
144        Self::raw()
145    }
146}
147
148impl From<&str> for Adjustment {
149    fn from(value: &str) -> Self {
150        Self(value.to_owned())
151    }
152}
153
154impl From<String> for Adjustment {
155    fn from(value: String) -> Self {
156        Self(value)
157    }
158}
159
160impl Display for Adjustment {
161    fn fmt(&self, formatter: &mut Formatter<'_>) -> fmt::Result {
162        formatter.write_str(self.as_str())
163    }
164}
165
166#[derive(Clone, Copy, Debug, Default, Eq, PartialEq, Serialize, Deserialize)]
167pub enum DataFeed {
168    DelayedSip,
169    Iex,
170    Otc,
171    #[default]
172    Sip,
173    Boats,
174    Overnight,
175}
176
177impl Display for DataFeed {
178    fn fmt(&self, formatter: &mut Formatter<'_>) -> fmt::Result {
179        formatter.write_str(match self {
180            Self::DelayedSip => "delayed_sip",
181            Self::Iex => "iex",
182            Self::Otc => "otc",
183            Self::Sip => "sip",
184            Self::Boats => "boats",
185            Self::Overnight => "overnight",
186        })
187    }
188}
189
190#[derive(Clone, Copy, Debug, Default, Eq, PartialEq, Serialize, Deserialize)]
191pub enum AuctionFeed {
192    #[default]
193    Sip,
194}
195
196impl AuctionFeed {
197    #[must_use]
198    pub fn as_str(&self) -> &'static str {
199        match self {
200            Self::Sip => "sip",
201        }
202    }
203}
204
205impl Display for AuctionFeed {
206    fn fmt(&self, formatter: &mut Formatter<'_>) -> fmt::Result {
207        formatter.write_str(self.as_str())
208    }
209}
210
211#[derive(Clone, Copy, Debug, Default, Eq, PartialEq, Serialize, Deserialize)]
212pub enum TickType {
213    #[default]
214    Trade,
215    Quote,
216}
217
218impl TickType {
219    #[must_use]
220    pub fn as_str(&self) -> &'static str {
221        match self {
222            Self::Trade => "trade",
223            Self::Quote => "quote",
224        }
225    }
226}
227
228impl Display for TickType {
229    fn fmt(&self, formatter: &mut Formatter<'_>) -> fmt::Result {
230        formatter.write_str(self.as_str())
231    }
232}
233
234#[derive(Clone, Copy, Debug, Default, Eq, PartialEq, Serialize, Deserialize)]
235pub enum Tape {
236    #[default]
237    A,
238    B,
239    C,
240}
241
242impl Tape {
243    #[must_use]
244    pub fn as_str(&self) -> &'static str {
245        match self {
246            Self::A => "A",
247            Self::B => "B",
248            Self::C => "C",
249        }
250    }
251}
252
253impl Display for Tape {
254    fn fmt(&self, formatter: &mut Formatter<'_>) -> fmt::Result {
255        formatter.write_str(self.as_str())
256    }
257}