Skip to main content

alpaca_data/corporate_actions/
enums.rs

1use std::fmt::{self, Display, Formatter};
2
3use serde::{Deserialize, Serialize};
4
5#[derive(Clone, Copy, Debug, Default, Eq, PartialEq, Serialize, Deserialize)]
6pub enum Sort {
7    #[default]
8    Asc,
9    Desc,
10}
11
12impl Display for Sort {
13    fn fmt(&self, formatter: &mut Formatter<'_>) -> fmt::Result {
14        formatter.write_str(match self {
15            Self::Asc => "asc",
16            Self::Desc => "desc",
17        })
18    }
19}
20
21#[derive(Clone, Copy, Debug, Default, Eq, PartialEq, Serialize, Deserialize)]
22pub enum CorporateActionType {
23    #[default]
24    ForwardSplit,
25    ReverseSplit,
26    UnitSplit,
27    StockDividend,
28    CashDividend,
29    SpinOff,
30    CashMerger,
31    StockMerger,
32    StockAndCashMerger,
33    Redemption,
34    NameChange,
35    WorthlessRemoval,
36    RightsDistribution,
37}
38
39impl CorporateActionType {
40    #[must_use]
41    pub fn as_str(&self) -> &'static str {
42        match self {
43            Self::ForwardSplit => "forward_split",
44            Self::ReverseSplit => "reverse_split",
45            Self::UnitSplit => "unit_split",
46            Self::StockDividend => "stock_dividend",
47            Self::CashDividend => "cash_dividend",
48            Self::SpinOff => "spin_off",
49            Self::CashMerger => "cash_merger",
50            Self::StockMerger => "stock_merger",
51            Self::StockAndCashMerger => "stock_and_cash_merger",
52            Self::Redemption => "redemption",
53            Self::NameChange => "name_change",
54            Self::WorthlessRemoval => "worthless_removal",
55            Self::RightsDistribution => "rights_distribution",
56        }
57    }
58}
59
60impl Display for CorporateActionType {
61    fn fmt(&self, formatter: &mut Formatter<'_>) -> fmt::Result {
62        formatter.write_str(self.as_str())
63    }
64}