alpaca_data/stocks/
enums.rs1use std::fmt::{self, Display, Formatter};
2
3pub use crate::common::enums::{Currency, 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, Debug, Eq, PartialEq)]
47pub struct Adjustment(String);
48
49impl Adjustment {
50 pub fn raw() -> Self {
51 Self::from("raw")
52 }
53
54 pub fn split() -> Self {
55 Self::from("split")
56 }
57
58 pub fn dividend() -> Self {
59 Self::from("dividend")
60 }
61
62 pub fn spin_off() -> Self {
63 Self::from("spin-off")
64 }
65
66 pub fn all() -> Self {
67 Self::from("all")
68 }
69
70 pub fn as_str(&self) -> &str {
71 &self.0
72 }
73}
74
75impl Default for Adjustment {
76 fn default() -> Self {
77 Self::raw()
78 }
79}
80
81impl From<&str> for Adjustment {
82 fn from(value: &str) -> Self {
83 Self(value.to_string())
84 }
85}
86
87impl From<String> for Adjustment {
88 fn from(value: String) -> Self {
89 Self(value)
90 }
91}
92
93impl Display for Adjustment {
94 fn fmt(&self, formatter: &mut Formatter<'_>) -> fmt::Result {
95 formatter.write_str(self.as_str())
96 }
97}
98
99#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
100pub enum DataFeed {
101 DelayedSip,
102 Iex,
103 Otc,
104 #[default]
105 Sip,
106 Boats,
107 Overnight,
108}
109
110impl Display for DataFeed {
111 fn fmt(&self, formatter: &mut Formatter<'_>) -> fmt::Result {
112 formatter.write_str(match self {
113 Self::DelayedSip => "delayed_sip",
114 Self::Iex => "iex",
115 Self::Otc => "otc",
116 Self::Sip => "sip",
117 Self::Boats => "boats",
118 Self::Overnight => "overnight",
119 })
120 }
121}
122
123#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
124pub enum AuctionFeed {
125 #[default]
126 Sip,
127}
128
129impl AuctionFeed {
130 pub fn as_str(&self) -> &'static str {
131 match self {
132 Self::Sip => "sip",
133 }
134 }
135}
136
137impl Display for AuctionFeed {
138 fn fmt(&self, formatter: &mut Formatter<'_>) -> fmt::Result {
139 formatter.write_str(self.as_str())
140 }
141}
142
143#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
144pub enum TickType {
145 #[default]
146 Trade,
147 Quote,
148}
149
150impl TickType {
151 pub fn as_str(&self) -> &'static str {
152 match self {
153 Self::Trade => "trade",
154 Self::Quote => "quote",
155 }
156 }
157}
158
159impl Display for TickType {
160 fn fmt(&self, formatter: &mut Formatter<'_>) -> fmt::Result {
161 formatter.write_str(self.as_str())
162 }
163}
164
165#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
166pub enum Tape {
167 #[default]
168 A,
169 B,
170 C,
171}
172
173impl Tape {
174 pub fn as_str(&self) -> &'static str {
175 match self {
176 Self::A => "A",
177 Self::B => "B",
178 Self::C => "C",
179 }
180 }
181}
182
183impl Display for Tape {
184 fn fmt(&self, formatter: &mut Formatter<'_>) -> fmt::Result {
185 formatter.write_str(self.as_str())
186 }
187}