DataManager

Struct DataManager 

Source
pub struct DataManager { /* private fields */ }
Expand description

数据管理器

管理所有 DIFF 协议数据,支持:

  • 递归合并
  • 版本追踪
  • 路径监听

Implementations§

Source§

impl DataManager

Source

pub fn new( initial_data: HashMap<String, Value>, config: DataManagerConfig, ) -> Self

创建新的数据管理器

Source

pub fn on_data<F>(&self, callback: F)
where F: Fn() + Send + Sync + 'static,

注册数据更新回调

Source

pub fn merge_data(&self, source: Value, epoch_increase: bool, delete_null: bool)

合并数据(DIFF 协议核心)

§参数
  • source - 源数据(可以是单个对象或数组)
  • epoch_increase - 是否增加版本号
  • delete_null - 是否删除 null 对象
Source

pub fn get_by_path(&self, path: &[&str]) -> Option<Value>

根据路径获取数据

Source

pub fn is_changing(&self, path: &[&str]) -> bool

判断指定路径的数据是否在最近一次更新中发生了变化

Source

pub fn get_epoch(&self) -> i64

获取当前版本号

Source

pub fn set_default(&self, path: &[&str], default_value: Value) -> Option<Value>

设置默认值

Source

pub fn watch(&self, path: Vec<String>) -> Receiver<Value>

监听指定路径的数据变化

返回一个 receiver,数据变化时会推送到这个 channel

Source

pub fn unwatch(&self, path: &[String]) -> Result<()>

取消路径监听

Source

pub fn convert_to_struct<T: DeserializeOwned>(&self, data: &Value) -> Result<T>

转换为结构体

Source

pub fn get_quote_data(&self, symbol: &str) -> Result<Quote>

获取 Quote 数据

Source

pub fn get_klines_data( &self, symbol: &str, duration: i64, view_width: usize, right_id: i64, ) -> Result<KlineSeriesData>

获取 K线数据

Source

pub fn get_multi_klines_data( &self, symbols: &[String], duration: i64, chart_id: &str, view_width: usize, ) -> Result<MultiKlineSeriesData>

获取多合约对齐的 K线数据

Source

pub fn get_ticks_data( &self, symbol: &str, view_width: usize, right_id: i64, ) -> Result<TickSeriesData>

获取 Tick 数据

Source

pub fn get_account_data(&self, user_id: &str, currency: &str) -> Result<Account>

获取账户数据

Source

pub fn get_position_data(&self, user_id: &str, symbol: &str) -> Result<Position>

获取持仓数据

Source

pub fn get_order_data(&self, user_id: &str, order_id: &str) -> Result<Order>

获取委托单数据

Source

pub fn get_trade_data(&self, user_id: &str, trade_id: &str) -> Result<Trade>

获取成交数据

Auto Trait Implementations§

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more