longport_candlesticks/
types.rs1use time::OffsetDateTime;
2
3use crate::TradeSessionType;
4
5#[derive(Debug, Copy, Clone, Eq, PartialEq)]
6#[allow(non_camel_case_types)]
7#[repr(u8)]
8pub enum Period {
9 Min_1 = 0,
10 Min_2 = 1,
11 Min_3 = 2,
12 Min_5 = 3,
13 Min_10 = 4,
14 Min_15 = 5,
15 Min_20 = 6,
16 Min_30 = 7,
17 Min_45 = 8,
18 Min_60 = 9,
19 Min_120 = 10,
20 Min_180 = 11,
21 Min_240 = 12,
22 Day = 100,
23 Week = 101,
24 Month = 102,
25 Quarter = 103,
26 Year = 104,
27}
28
29impl Period {
30 #[inline]
31 pub(crate) fn minutes(&self) -> u8 {
32 match self {
33 Period::Min_1 => 1,
34 Period::Min_2 => 2,
35 Period::Min_3 => 3,
36 Period::Min_5 => 5,
37 Period::Min_10 => 10,
38 Period::Min_15 => 15,
39 Period::Min_20 => 20,
40 Period::Min_30 => 30,
41 Period::Min_45 => 45,
42 Period::Min_60 => 60,
43 Period::Min_120 => 120,
44 Period::Min_180 => 180,
45 Period::Min_240 => 240,
46 _ => unreachable!(),
47 }
48 }
49
50 #[inline]
51 pub(crate) fn is_minute(&self) -> bool {
52 (*self as u8) < 100
53 }
54}
55
56pub trait QuoteType {
57 type PriceType;
58 type VolumeType;
59 type TurnoverType;
60 type TradeSessionType;
61
62 fn time(&self) -> OffsetDateTime;
63 fn open(&self) -> Self::PriceType;
64 fn high(&self) -> Self::PriceType;
65 fn low(&self) -> Self::PriceType;
66 fn last_done(&self) -> Self::PriceType;
67 fn volume(&self) -> Self::VolumeType;
68 fn turnover(&self) -> Self::TurnoverType;
69 fn trade_session(&self) -> Self::TradeSessionType;
70}
71
72bitflags::bitflags! {
73 #[derive(Debug, Copy, Clone, Eq, PartialEq)]
74 pub struct UpdateFields: u32 {
75 const PRICE = 0x1;
76 const VOLUME = 0x2;
77 }
78}
79
80pub trait TradeType {
81 type PriceType;
82 type VolumeType;
83 type TurnoverType;
84 type TradeSessionType: TradeSessionType;
85
86 fn time(&self) -> OffsetDateTime;
87 fn price(&self) -> Self::PriceType;
88 fn volume(&self) -> Self::VolumeType;
89 fn turnover(&self, lot_size: i32) -> Self::TurnoverType;
90 fn trade_session(&self) -> Self::TradeSessionType;
91}