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
12#[derive(Clone, Copy, Debug, Default, Eq, PartialEq, Serialize, Deserialize)]
13pub enum Region {
14    #[default]
15    Us,
16    NonUs,
17    All,
18}
19
20impl Region {
21    #[must_use]
22    pub fn as_str(&self) -> &'static str {
23        match self {
24            Self::Us => "us",
25            Self::NonUs => "non_us",
26            Self::All => "all",
27        }
28    }
29}
30
31impl Display for Region {
32    fn fmt(&self, formatter: &mut Formatter<'_>) -> fmt::Result {
33        formatter.write_str(self.as_str())
34    }
35}
36
37impl Display for Sort {
38    fn fmt(&self, formatter: &mut Formatter<'_>) -> fmt::Result {
39        formatter.write_str(match self {
40            Self::Asc => "asc",
41            Self::Desc => "desc",
42        })
43    }
44}
45
46#[derive(Clone, Copy, Debug, Default, Eq, PartialEq, Serialize, Deserialize)]
47pub enum CorporateActionType {
48    #[default]
49    ForwardSplit,
50    ReverseSplit,
51    UnitSplit,
52    StockDividend,
53    CashDividend,
54    SpinOff,
55    CashMerger,
56    StockMerger,
57    StockAndCashMerger,
58    Redemption,
59    NameChange,
60    WorthlessRemoval,
61    RightsDistribution,
62    PartialCall,
63    Reorganization,
64}
65
66impl CorporateActionType {
67    #[must_use]
68    pub fn as_str(&self) -> &'static str {
69        match self {
70            Self::ForwardSplit => "forward_split",
71            Self::ReverseSplit => "reverse_split",
72            Self::UnitSplit => "unit_split",
73            Self::StockDividend => "stock_dividend",
74            Self::CashDividend => "cash_dividend",
75            Self::SpinOff => "spin_off",
76            Self::CashMerger => "cash_merger",
77            Self::StockMerger => "stock_merger",
78            Self::StockAndCashMerger => "stock_and_cash_merger",
79            Self::Redemption => "redemption",
80            Self::NameChange => "name_change",
81            Self::WorthlessRemoval => "worthless_removal",
82            Self::RightsDistribution => "rights_distribution",
83            Self::PartialCall => "partial_call",
84            Self::Reorganization => "reorganization",
85        }
86    }
87}
88
89impl Display for CorporateActionType {
90    fn fmt(&self, formatter: &mut Formatter<'_>) -> fmt::Result {
91        formatter.write_str(self.as_str())
92    }
93}
94
95#[derive(Clone, Copy, Debug, Eq, PartialEq, Serialize, Deserialize)]
96#[serde(rename_all = "snake_case")]
97pub enum CashDividendSubType {
98    Interest,
99    ReturnOfCapital,
100}
101
102#[derive(Clone, Copy, Debug, Eq, PartialEq, Serialize, Deserialize)]
103#[serde(rename_all = "snake_case")]
104pub enum PartialCallLotteryType {
105    Original,
106    Supplemental,
107}