financial_api/types/
a_share.rs1use super::wire::wire_enum;
2use crate::ValidationError;
3
4wire_enum! {
5 pub enum AuctionStage {
7 Live => "live",
8 Final => "final",
9 }
10}
11
12wire_enum! {
13 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 pub enum HotListPeriod {
27 Day => "day",
28 Hour => "hour",
29 }
30}
31
32wire_enum! {
33 pub enum DragonTigerBoard {
35 All => "all",
36 Organization => "org",
37 HotMoney => "hot_money",
38 }
39}
40
41wire_enum! {
42 pub enum SortDirection {
44 Ascending => "asc",
45 Descending => "desc",
46 }
47}
48
49wire_enum! {
50 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 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 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#[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 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}