Trait rustdx::tcp::Tdx

source ·
pub trait Tdx {
    type Item: ?Sized;

    const SEND: &'static [u8];
    const TAG: &'static str;
    const LEN: usize = _;

    // Required methods
    fn send(&mut self) -> &[u8] ;
    fn parse(&mut self, response: Vec<u8>);
    fn result(&self) -> &Self::Item;

    // Provided methods
    fn recv(&mut self, tcp: &mut Tcp) -> Result<Vec<u8>> { ... }
    fn recv_parsed(&mut self, tcp: &mut Tcp) -> Result<&Self::Item> { ... }
}

Required Associated Types§

Required Associated Constants§

source

const SEND: &'static [u8]

待发送的字节。所有发送请求的字节由两部分组成:

  1. 固定的默认字节(基本为前半段字节)
  2. 查询所需的变化的字节(基本为后半段字节)

Tdx::SEND 的作用为默认有效的字节,即发送字节之后会正常响应且数据可以解析, 但是并不保证每次响应的数据完全一致。 比如请求日线时发送字节在当天收盘后是不变的,次日交易日请求得到的数据则可能改变。

如果发送请求的字节有误,则无法得到响应 (比如设置了读取超时,无响应情况下会得到: WouldBlock error)。

字节具体的含义见 Implementor 的 Tdx trait 部分的 SEND 文档。

source

const TAG: &'static str

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

Provided Associated Constants§

source

const LEN: usize = _

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

Required Methods§

source

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

真正发送的字节。

source

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

解析响应的字节。

source

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

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

Provided Methods§

source

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

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

source

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

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

Object Safety§

This trait is not object safe.

Implementors§

source§

impl Tdx for SecurityCount

§

type Item = u16

source§

const SEND: &'static [u8] = _

source§

const TAG: &'static str = "heartbeat"

source§

impl Tdx for SecurityList

§

type Item = [SecurityListData]

source§

const SEND: &'static [u8] = _

source§

const TAG: &'static str = "股票、指数列表"

source§

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

§

type Item = [KlineData<'a>]

source§

const SEND: &'static [u8] = _

source§

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

source§

impl<'a> Tdx for Xdxr<'a>

§

type Item = [XdxrData]

source§

const SEND: &'static [u8] = _

source§

const TAG: &'static str = "除权除息"