alpaca_data/crypto/
enums.rs1use 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 Loc {
48 #[default]
49 Us,
50 Us1,
51 Us2,
52 Eu1,
53 Bs1,
54}
55
56impl Loc {
57 pub fn as_str(&self) -> &'static str {
58 match self {
59 Self::Us => "us",
60 Self::Us1 => "us-1",
61 Self::Us2 => "us-2",
62 Self::Eu1 => "eu-1",
63 Self::Bs1 => "bs-1",
64 }
65 }
66}
67
68impl Display for Loc {
69 fn fmt(&self, formatter: &mut Formatter<'_>) -> fmt::Result {
70 formatter.write_str(self.as_str())
71 }
72}
73
74#[cfg(test)]
75mod tests {
76 use super::Loc;
77
78 #[test]
79 fn loc_serializes_all_official_values() {
80 assert_eq!(Loc::Us.as_str(), "us");
81 assert_eq!(Loc::Us1.as_str(), "us-1");
82 assert_eq!(Loc::Us2.as_str(), "us-2");
83 assert_eq!(Loc::Eu1.as_str(), "eu-1");
84 assert_eq!(Loc::Bs1.as_str(), "bs-1");
85 }
86}