1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
4pub enum DayCountBasis {
5 #[serde(rename = "ACT/365")]
6 Act365,
7 #[serde(rename = "ACT/365.25")]
8 Act36525,
9 #[serde(rename = "ACT/360")]
10 Act360,
11}
12
13impl DayCountBasis {
14 pub fn from_option_str(value: Option<&str>) -> Self {
15 match value.unwrap_or("ACT/365.25") {
16 "ACT/365" => Self::Act365,
17 "ACT/360" => Self::Act360,
18 _ => Self::Act36525,
19 }
20 }
21
22 pub fn denominator(self) -> f64 {
23 match self {
24 Self::Act365 => 365.0,
25 Self::Act36525 => 365.25,
26 Self::Act360 => 360.0,
27 }
28 }
29}
30
31#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
32#[serde(rename_all = "snake_case")]
33pub enum MarketSession {
34 Premarket,
35 Regular,
36 AfterHours,
37 Closed,
38}
39
40#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
41#[serde(rename_all = "lowercase")]
42pub enum WeekdayCode {
43 Mon,
44 Tue,
45 Wed,
46 Thu,
47 Fri,
48 Sat,
49 Sun,
50}
51
52#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
53pub struct MarketHours {
54 pub date: String,
55 pub is_trading_date: bool,
56 pub is_early_close: bool,
57 pub premarket_open: Option<String>,
58 pub regular_open: Option<String>,
59 pub regular_close: Option<String>,
60 pub after_hours_close: Option<String>,
61}
62
63#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
64pub struct TradingDayInfo {
65 pub date: String,
66 pub is_trading_date: bool,
67 pub is_market_holiday: bool,
68 pub is_early_close: bool,
69 pub market_hours: MarketHours,
70}
71
72#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
73pub struct DurationParts {
74 pub sign: i8,
75 pub total_seconds: i64,
76 pub days: i64,
77 pub hours: i64,
78 pub minutes: i64,
79 pub seconds: i64,
80}
81
82#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
83pub struct DateRange {
84 pub start_date: String,
85 pub end_date: String,
86}
87
88#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
89pub struct TimestampParts {
90 pub date: String,
91 pub timestamp: String,
92 pub year: i32,
93 pub month: u32,
94 pub day: u32,
95 pub hour: u32,
96 pub minute: u32,
97 pub second: u32,
98 pub hhmm: u32,
99 pub hhmm_string: String,
100 pub weekday_from_sunday: u32,
101}