1use std::fmt::{self, Display, Formatter};
3use std::os::raw::c_char;
4
5use num_enum::{IntoPrimitive, TryFromPrimitive};
6
7use crate::Error;
8#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
11pub enum Side {
12 Ask,
14 Bid,
16 None,
18}
19
20impl From<Side> for char {
21 fn from(side: Side) -> Self {
22 match side {
23 Side::Ask => 'A',
24 Side::Bid => 'B',
25 Side::None => 'N',
26 }
27 }
28}
29
30impl From<Side> for c_char {
31 fn from(side: Side) -> Self {
32 char::from(side) as c_char
33 }
34}
35
36#[cfg(feature = "serde")]
37impl serde::Serialize for Side {
38 fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
39 serializer.serialize_char(char::from(*self))
40 }
41}
42
43#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
45pub enum Action {
46 Modify,
48 Trade,
50 Cancel,
52 Add,
54 Clear,
56}
57
58impl From<Action> for char {
59 fn from(action: Action) -> Self {
60 match action {
61 Action::Modify => 'M',
62 Action::Trade => 'T',
63 Action::Cancel => 'C',
64 Action::Add => 'A',
65 Action::Clear => 'R',
66 }
67 }
68}
69
70impl From<Action> for c_char {
71 fn from(action: Action) -> Self {
72 char::from(action) as c_char
73 }
74}
75
76#[cfg(feature = "serde")]
77impl serde::Serialize for Action {
78 fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
79 serializer.serialize_char(char::from(*self))
80 }
81}
82
83#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, TryFromPrimitive)]
86#[cfg_attr(
87 feature = "serde",
88 derive(serde::Serialize),
89 serde(rename_all = "snake_case")
90)]
91#[repr(u8)]
92pub enum SType {
93 ProductId = 0,
95 Native = 1,
97 Smart = 2,
99}
100
101impl std::str::FromStr for SType {
102 type Err = Error;
103
104 fn from_str(s: &str) -> Result<Self, Self::Err> {
105 match s {
106 "product_id" => Ok(SType::ProductId),
107 "native" => Ok(SType::Native),
108 "smart" => Ok(SType::Smart),
109 _ => Err(Error::TypeConversion(
110 "Value doesn't match a valid symbol type",
111 )),
112 }
113 }
114}
115
116impl SType {
117 pub fn as_str(&self) -> &'static str {
119 match self {
120 SType::Native => "native",
121 SType::Smart => "smart",
122 SType::ProductId => "product_id",
123 }
124 }
125}
126
127impl Display for SType {
128 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
129 f.write_str(self.as_str())
130 }
131}
132
133#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, TryFromPrimitive)]
135#[repr(u16)]
136pub enum Schema {
137 Mbo = 0,
139 Mbp1 = 1,
141 Mbp10 = 2,
143 Tbbo = 3,
145 Trades = 4,
147 Ohlcv1S = 5,
149 Ohlcv1M = 6,
151 Ohlcv1H = 7,
153 Ohlcv1D = 8,
155 Definition = 9,
157 Statistics = 10,
159 Status = 11,
161}
162
163impl std::str::FromStr for Schema {
164 type Err = Error;
165
166 fn from_str(s: &str) -> Result<Self, Self::Err> {
167 match s {
168 "mbo" => Ok(Schema::Mbo),
169 "mbp-1" => Ok(Schema::Mbp1),
170 "mbp-10" => Ok(Schema::Mbp10),
171 "tbbo" => Ok(Schema::Tbbo),
172 "trades" => Ok(Schema::Trades),
173 "ohlcv-1s" => Ok(Schema::Ohlcv1S),
174 "ohlcv-1m" => Ok(Schema::Ohlcv1M),
175 "ohlcv-1h" => Ok(Schema::Ohlcv1H),
176 "ohlcv-1d" => Ok(Schema::Ohlcv1D),
177 "definition" => Ok(Schema::Definition),
178 "statistics" => Ok(Schema::Statistics),
179 "status" => Ok(Schema::Status),
180 _ => Err(Error::TypeConversion("Value doesn't match a valid schema")),
181 }
182 }
183}
184
185impl Schema {
186 pub fn as_str(&self) -> &'static str {
188 match self {
189 Schema::Mbo => "mbo",
190 Schema::Mbp1 => "mbp-1",
191 Schema::Mbp10 => "mbp-10",
192 Schema::Tbbo => "tbbo",
193 Schema::Trades => "trades",
194 Schema::Ohlcv1S => "ohlcv-1s",
195 Schema::Ohlcv1M => "ohlcv-1m",
196 Schema::Ohlcv1H => "ohlcv-1h",
197 Schema::Ohlcv1D => "ohlcv-1d",
198 Schema::Definition => "definition",
199 Schema::Statistics => "statistics",
200 Schema::Status => "status",
201 }
202 }
203}
204
205#[cfg(feature = "serde")]
206impl serde::Serialize for Schema {
207 fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
208 serializer.serialize_str(self.as_str())
209 }
210}
211
212impl Display for Schema {
213 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
214 f.write_str(self.as_str())
215 }
216}
217
218#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, TryFromPrimitive)]
220#[cfg_attr(
221 feature = "serde",
222 derive(serde::Serialize),
223 serde(rename_all = "lowercase")
224)]
225#[repr(u8)]
226pub enum Encoding {
227 Dbz = 0,
229 Csv = 1,
231 Json = 2,
233}
234
235impl std::str::FromStr for Encoding {
236 type Err = Error;
237
238 fn from_str(s: &str) -> Result<Self, Self::Err> {
239 match s {
240 "dbz" => Ok(Encoding::Dbz),
241 "csv" => Ok(Encoding::Csv),
242 "json" => Ok(Encoding::Json),
243 _ => Err(Error::TypeConversion(
244 "Value doesn't match a valid encoding",
245 )),
246 }
247 }
248}
249
250impl Encoding {
251 pub fn as_str(&self) -> &'static str {
253 match self {
254 Encoding::Dbz => "dbz",
255 Encoding::Csv => "csv",
256 Encoding::Json => "json",
257 }
258 }
259}
260
261impl Display for Encoding {
262 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
263 f.write_str(self.as_str())
264 }
265}
266
267#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, TryFromPrimitive)]
269#[cfg_attr(
270 feature = "serde",
271 derive(serde::Serialize),
272 serde(rename_all = "lowercase")
273)]
274#[repr(u8)]
275pub enum Compression {
276 None = 0,
278 ZStd = 1,
280}
281impl std::str::FromStr for Compression {
282 type Err = Error;
283
284 fn from_str(s: &str) -> Result<Self, Self::Err> {
285 match s {
286 "none" => Ok(Compression::None),
287 "zstd" => Ok(Compression::ZStd),
288 _ => Err(Error::TypeConversion(
289 "Value doesn't match a valid compression",
290 )),
291 }
292 }
293}
294
295impl Compression {
296 pub fn as_str(&self) -> &'static str {
298 match self {
299 Compression::None => "none",
300 Compression::ZStd => "zstd",
301 }
302 }
303}
304
305impl Display for Compression {
306 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
307 f.write_str(self.as_str())
308 }
309}
310
311#[repr(u8)]
312#[derive(Clone, Copy, Debug, PartialEq, Eq, IntoPrimitive)]
313#[cfg_attr(feature = "serde", derive(serde::Serialize))]
314#[doc(hidden)]
315pub enum SecurityUpdateAction {
316 Add = b'A',
317 Modify = b'M',
318 Delete = b'D',
319 Invalid = b'~',
321}