pub struct Lc {
pub date: u16,
pub min: u16,
pub code: u32,
pub open: f32,
pub high: f32,
pub low: f32,
pub close: f32,
pub amount: f32,
pub vol: u32,
}Expand description
解析 *.lc 文件中的一条日线数据,即其 32 个字节所代表的所有信息。
注意:这个类型只对 *.lc 文件进行了初步解析,
所以日期 date 和股票代码 code 都是 u32 类型,
Fields§
§date: u16§min: u16§code: u32§open: f32§high: f32§low: f32§close: f32§amount: f32§vol: u32Implementations§
Source§impl Lc
impl Lc
Sourcepub fn from_bytes(code: u32, arr: &[u8]) -> Self
pub fn from_bytes(code: u32, arr: &[u8]) -> Self
从 *.lc 文件中获取数据,该文件中,每 32 个字节存储了一根分钟 K 线数据,
各字节存储数据如下:
| 字节位置 | 含义 | 解析方式 | 额外处理 |
|---|---|---|---|
| 00 ~ 01 字节 | 年月日 | u16 | 见下文 x |
| 02 ~ 04 字节 | 分钟数 | u16 | 见下文 y |
| 04 ~ 07 字节 | 开盘价 | u32 | / |
| 08 ~ 11 字节 | 最高价 | u32 | / |
| 12 ~ 15 字节 | 最低价 | u32 | / |
| 16 ~ 19 字节 | 收盘价 | u32 | / |
| 20 ~ 23 字节 | 成交额(元) | f32 | / |
| 24 ~ 27 字节 | 成交量(股) | u32 | / |
| 28 ~ 31 字节 | 保留字段 | / | / |
“年月日时分”处理方式:
| 单位 | 计算过程 |
|---|---|
| 年 | x / 2048 + 2004 |
| 月 | x / 2048 / 100 |
| 日 | x / 2048 % 100 |
| 时 | y / 60 |
| 分 | y % 60 |
Sourcepub fn from_file_into_vec<P: AsRef<Path>>(code: u32, p: P) -> Result<Vec<Lc>>
pub fn from_file_into_vec<P: AsRef<Path>>(code: u32, p: P) -> Result<Vec<Lc>>
一次性以同步方式读取单个 *.lc 文件所有数据,然后转化成 Vec。
Sourcepub fn into_serde_type(self) -> LcSerde
pub fn into_serde_type(self) -> LcSerde
转化成用于(反)序列化的数据类型: 6 位字符串的股票代码;%Y-%m-%d 字符串格式的日期;f64 类型的成交额;u64 类型的 vol 。
pub fn datetime_string(&self) -> String
Sourcepub fn date_string(&self) -> String
pub fn date_string(&self) -> String
%Y-%m-%d 格式的日期
pub fn hm_arr(&self) -> [u16; 2]
Sourcepub fn datetime(&self) -> NaiveDateTime
pub fn datetime(&self) -> NaiveDateTime
chrono 格式的日期:用于某些序列化或者与时间相关的计算
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Lc
impl RefUnwindSafe for Lc
impl Send for Lc
impl Sync for Lc
impl Unpin for Lc
impl UnwindSafe for Lc
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more