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 AuctionPhase {
15 Live => "live",
16 Final => "final",
17 Closed => "closed",
18 }
19}
20
21wire_enum! {
22 pub enum AnomalyTag {
24 LimitUp => "LIMIT_UP",
25 LimitDown => "LIMIT_DOWN",
26 SharpRise => "SHARP_RISE",
27 SharpFall => "SHARP_FALL",
28 RapidRally => "RAPID_RALLY",
29 RapidDecline => "RAPID_DECLINE",
30 }
31}
32
33wire_enum! {
34 pub enum HotListPeriod {
36 Day => "day",
37 Hour => "hour",
38 }
39}
40
41wire_enum! {
42 pub enum DragonTigerBoard {
44 All => "all",
45 Organization => "org",
46 HotMoney => "hot_money",
47 }
48}
49
50wire_enum! {
51 pub enum SortDirection {
53 Ascending => "asc",
54 Descending => "desc",
55 }
56}
57
58wire_enum! {
59 pub enum LimitUpSortField {
61 LastPrice => "last_price",
62 ConsecutiveDays => "continue_day_cnt",
63 SealedAmount => "seal_money",
64 LimitUpTime => "limit_up_time",
65 }
66}
67
68wire_enum! {
69 pub enum LimitDownSortField {
71 LastLimitTime => "last_limit_time",
72 FirstLimitTime => "first_limit_time",
73 LastPrice => "last_price",
74 PriceChangeRatio => "price_change_ratio_pct",
75 TurnoverRatio => "turnover_ratio_pct",
76 }
77}
78
79wire_enum! {
80 pub enum LimitBreakSortField {
82 PriceChangeRatio => "price_change_ratio_pct",
83 OpenTimes => "open_times",
84 LastPrice => "last_price",
85 TurnoverRatio => "turnover_ratio_pct",
86 Turnover => "turnover",
87 }
88}
89
90#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
92pub struct Page {
93 number: u32,
94 size: u16,
95}
96
97impl Page {
98 pub const fn new(number: u32, size: u16) -> Result<Self, ValidationError> {
99 if number == 0 {
100 return Err(ValidationError::new("page", "must be at least 1"));
101 }
102 if size == 0 || size > 200 {
103 return Err(ValidationError::new("size", "must be in the range 1..=200"));
104 }
105 Ok(Self { number, size })
106 }
107
108 #[must_use]
109 pub const fn number(self) -> u32 {
110 self.number
111 }
112
113 #[must_use]
114 pub const fn size(self) -> u16 {
115 self.size
116 }
117}
118
119impl Default for Page {
120 fn default() -> Self {
121 Self {
122 number: 1,
123 size: 50,
124 }
125 }
126}
127
128wire_enum! {
129 pub enum RankTrend {
131 Up => "up",
132 Down => "down",
133 Flat => "flat",
134 Unknown => "unknown",
135 }
136}
137
138#[cfg(test)]
139mod tests {
140 use super::Page;
141
142 #[test]
143 fn special_data_page_bounds_are_enforced() {
144 assert!(Page::new(0, 50).is_err());
145 assert!(Page::new(1, 0).is_err());
146 assert!(Page::new(1, 1).is_ok());
147 assert!(Page::new(u32::MAX, 200).is_ok());
148 assert!(Page::new(1, 201).is_err());
149 }
150}