Struct rustdx::tcp::stock::Kline

source ·
pub struct Kline<'d> {
    pub send: Box<[u8]>,
    pub market: u16,
    pub code: &'d str,
    pub category: u16,
    pub start: u16,
    pub count: u16,
    pub response: Vec<u8>,
    pub data: Vec<KlineData<'d>>,
}
Expand description

查询股票日线。对应于 pytdx 中的 hq.get_security_bars、GetSecurityBarsCmd。

§注意

只修改字段并不会更改待发送字节的内容。 如果你需要修改查询条件,请使用相应的方法。 比如修改股票代码调用 Kline::code,修改查询数量调用 Kline::count

Fields§

§send: Box<[u8]>§market: u16§code: &'d str§category: u16§start: u16§count: u16§response: Vec<u8>§data: Vec<KlineData<'d>>

Implementations§

source§

impl<'d> Kline<'d>

source

pub fn new( market: u16, code: &'d str, category: u16, start: u16, count: u16 ) -> Self

0 代表深市;1 代表沪市。

§panic

当 code 的字节长度不是 6 时,程序会 panic。

source

pub fn market(&mut self, market: u16) -> &mut Self

修改市场。

source

pub fn code(&mut self, code: &'d str) -> &mut Self

修改股票。当代码不正确时,不能正常得到响应。

§panic

当 code 的字节长度不是 6 时,程序会 panic。

source

pub fn category(&mut self, category: u16) -> &mut Self

修改 K 线类型。

source

pub fn start(&mut self, start: u16) -> &mut Self

修改起始位置。

source

pub fn count(&mut self, count: u16) -> &mut Self

修改查询数量。

注意:此方法调用了 Vec::resize_with

  1. 如果此次修改的查询数量大于修改前的查询数量, 则 data 字段除了保持已有的数据,还会会增加默认值。
  2. 如果此次修改的查询数量小于或等于修改前的查询数量, 则 data 字段截断已有的数据。
  3. 无论以上哪种情况,目的都是保证查询数量与 data 字段的 Vec 长度一致。

Trait Implementations§

source§

impl<'d> Clone for Kline<'d>

source§

fn clone(&self) -> Kline<'d>

Returns a copy 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<'d> Debug for Kline<'d>

source§

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

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

impl<'d> Default for Kline<'d>

为了对应 Kline::SEND 的含义,以下默认值值得注意:

  1. category 默认为 9 (日线);
  2. code 默认为 000001
  3. count 默认为 3;
  4. KlineData.dt.hour 默认小时数为 15。
source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<'a> Tdx for Kline<'a>

source§

const SEND: &'static [u8] = _

#sz000001# 最近三天日线的请求字节。长度为 38。

struct.pack("<HIHHHH6sHHHHIIH", bytes) # python 中的解读方式
§

type Item = [KlineData<'a>]

source§

const TAG: &'static str = "日线"

描述此次 tcp 连接的用途,目前用于记录日志。
source§

fn send(&mut self) -> &[u8]

真正发送的字节。
source§

fn parse(&mut self, v: Vec<u8>)

解析响应的字节。
source§

fn result(&self) -> &Self::Item

解析后的结果。可以是引用,也可以是 owned type 。
source§

const LEN: usize = _

发送的字节的长度。每种请求所发送的字节长度是已知的。默认为 Tdx::SEND 的长度。
source§

fn recv(&mut self, tcp: &mut Tcp) -> Result<Vec<u8>>

得到响应的字节。响应的字节长度无法预测。
source§

fn recv_parsed(&mut self, tcp: &mut Tcp) -> Result<&Self::Item>

得到和解析响应的字节,并返回解析的数据。

Auto Trait Implementations§

§

impl<'d> Freeze for Kline<'d>

§

impl<'d> RefUnwindSafe for Kline<'d>

§

impl<'d> Send for Kline<'d>

§

impl<'d> Sync for Kline<'d>

§

impl<'d> Unpin for Kline<'d>

§

impl<'d> UnwindSafe for Kline<'d>

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> 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,

§

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>,

§

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>,

§

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.