Struct Lc

Source
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: u32

Implementations§

Source§

impl Lc

Source

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
Source

pub fn from_file_into_vec<P: AsRef<Path>>(code: u32, p: P) -> Result<Vec<Lc>>

一次性以同步方式读取单个 *.lc 文件所有数据,然后转化成 Vec。

Source

pub fn into_serde_type(self) -> LcSerde

转化成用于(反)序列化的数据类型: 6 位字符串的股票代码;%Y-%m-%d 字符串格式的日期;f64 类型的成交额;u64 类型的 vol 。

Source

pub fn datetime_string(&self) -> String

Source

pub fn date_string(&self) -> String

%Y-%m-%d 格式的日期

Source

pub fn ymd_arr(&self) -> [u16; 3]

[年, 月, 日] 格式的日期

Source

pub fn hm_arr(&self) -> [u16; 2]

Source

pub fn datetime(&self) -> NaiveDateTime

chrono 格式的日期:用于某些序列化或者与时间相关的计算

Trait Implementations§

Source§

impl Clone for Lc

Source§

fn clone(&self) -> Lc

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Lc

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Copy for Lc

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.