kiteticker_async_manager/models/
mode.rs1use serde_repr::{Deserialize_repr, Serialize_repr};
2
3#[derive(
4 Debug,
5 Clone,
6 Copy,
7 Deserialize_repr,
8 Serialize_repr,
9 Default,
10 PartialEq,
11 PartialOrd,
12)]
13#[repr(u8)]
14pub enum Mode {
18 LTP = 1,
19 #[default]
20 Quote = 2,
21 Full = 3,
22}
23
24impl Mode {
25 pub fn to_websocket_string(&self) -> &'static str {
27 match self {
28 Mode::LTP => "ltp",
29 Mode::Quote => "quote",
30 Mode::Full => "full",
31 }
32 }
33}
34
35impl TryFrom<usize> for Mode {
36 type Error = String;
37 fn try_from(value: usize) -> Result<Self, Self::Error> {
38 match value {
39 8 => Ok(Self::LTP),
40 44 => Ok(Self::Quote),
41 184 => Ok(Self::Full),
42 _ => Err(format!("Invalid packet size: {}", value)),
43 }
44 }
45}