Skip to main content

financial_api/types/
a_share.rs

1use super::wire::wire_enum;
2use crate::ValidationError;
3
4wire_enum! {
5    /// Auction observation stage.
6    pub enum AuctionStage {
7        Live => "live",
8        Final => "final",
9    }
10}
11
12wire_enum! {
13    /// A-share anomaly tag.
14    pub enum AnomalyTag {
15        LimitUp => "LIMIT_UP",
16        LimitDown => "LIMIT_DOWN",
17        SharpRise => "SHARP_RISE",
18        SharpFall => "SHARP_FALL",
19        RapidRally => "RAPID_RALLY",
20        RapidDecline => "RAPID_DECLINE",
21    }
22}
23
24wire_enum! {
25    /// Ranking aggregation period.
26    pub enum HotListPeriod {
27        Day => "day",
28        Hour => "hour",
29    }
30}
31
32wire_enum! {
33    /// Dragon-tiger list board filter.
34    pub enum DragonTigerBoard {
35        All => "all",
36        Organization => "org",
37        HotMoney => "hot_money",
38    }
39}
40
41wire_enum! {
42    /// Sort direction used by paged special-data pools.
43    pub enum SortDirection {
44        Ascending => "asc",
45        Descending => "desc",
46    }
47}
48
49wire_enum! {
50    /// Sort key for the limit-up pool.
51    pub enum LimitUpSortField {
52        LastPrice => "last_price",
53        ConsecutiveDays => "continue_day_cnt",
54        SealedAmount => "seal_money",
55        LimitUpTime => "limit_up_time",
56    }
57}
58
59wire_enum! {
60    /// Sort key for the limit-down pool.
61    pub enum LimitDownSortField {
62        LastLimitTime => "last_limit_time",
63        FirstLimitTime => "first_limit_time",
64        LastPrice => "last_price",
65        PriceChangeRatio => "price_change_ratio_pct",
66        TurnoverRatio => "turnover_ratio_pct",
67    }
68}
69
70wire_enum! {
71    /// Sort key for the limit-break pool.
72    pub enum LimitBreakSortField {
73        PriceChangeRatio => "price_change_ratio_pct",
74        OpenTimes => "open_times",
75        LastPrice => "last_price",
76        TurnoverRatio => "turnover_ratio_pct",
77        Turnover => "turnover",
78    }
79}
80
81/// Validated pagination for special-data pools.
82#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
83pub struct Page {
84    number: u32,
85    size: u16,
86}
87
88impl Page {
89    pub const fn new(number: u32, size: u16) -> Result<Self, ValidationError> {
90        if number == 0 {
91            return Err(ValidationError::new("page", "must be at least 1"));
92        }
93        if size == 0 || size > 200 {
94            return Err(ValidationError::new("size", "must be in the range 1..=200"));
95        }
96        Ok(Self { number, size })
97    }
98
99    #[must_use]
100    pub const fn number(self) -> u32 {
101        self.number
102    }
103
104    #[must_use]
105    pub const fn size(self) -> u16 {
106        self.size
107    }
108}
109
110impl Default for Page {
111    fn default() -> Self {
112        Self {
113            number: 1,
114            size: 50,
115        }
116    }
117}
118
119wire_enum! {
120    /// Direction of a hot-list rank change.
121    pub enum RankTrend {
122        Up => "up",
123        Down => "down",
124        Flat => "flat",
125        Unknown => "unknown",
126    }
127}
128
129#[cfg(test)]
130mod tests {
131    use super::Page;
132
133    #[test]
134    fn special_data_page_bounds_are_enforced() {
135        assert!(Page::new(0, 50).is_err());
136        assert!(Page::new(1, 0).is_err());
137        assert!(Page::new(1, 1).is_ok());
138        assert!(Page::new(u32::MAX, 200).is_ok());
139        assert!(Page::new(1, 201).is_err());
140    }
141}