Skip to main content

CryptoExchangeCache

Struct CryptoExchangeCache 

Source
pub struct CryptoExchangeCache {
    pub by_broker: DashMap<BrokerExchangeKey, Vec<CryptoExchangeInfo>>,
    pub lv2_exchange_cache: DashMap<ExchangeCacheKey, CachedOrderBook>,
    pub lv2_prob_to_brokers: DashMap<ExchangeCacheKey, HashSet<u32>>,
    /* private fields */
}
Expand description

Crypto LV2 多交易所缓存. 包装 3 个 DashMap + 反向索引重建逻辑.

线程安全: 内部全用 DashMap, 任意线程可同时 read/write. lifecycle: 整个 daemon lifetime, 由 GatewayBridge::crypto_exchange_cache 持有 Arc.

Fields§

§by_broker: DashMap<BrokerExchangeKey, Vec<CryptoExchangeInfo>>

(stock_id, broker_id) → exchange list (from CMD18012 response).

§lv2_exchange_cache: DashMap<ExchangeCacheKey, CachedOrderBook>

(stock_id, lv2_prob) → orderbook (exchange-level, raw from push).

§lv2_prob_to_brokers: DashMap<ExchangeCacheKey, HashSet<u32>>

(stock_id, lv2_prob) → set<broker_id> — 反向索引, O(1) 查询受 exchange-level push 影响的 broker 集.

Implementations§

Source§

impl CryptoExchangeCache

Source

pub fn new() -> Arc<Self>

设置 (stock_id, broker_id) 对应的 exchange 列表 (CMD18012 response).

副作用:

  1. 更新 by_broker[(stock_id, broker_id)] = exchanges
  2. 重建 lv2_prob_to_brokers[(stock_id, *)] 该 stock 的反向索引 (先清旧 entries 该 stock 的所有 prob → 再按本次 + 其他 broker 重建)

对齐 C++ INNData_Qot_CryptoExchange::SetLv2RelatedExchange(stKey, vExchanges) + UpdateLv2ProbToBrokersIndex(nStockID).

Source

pub fn exchanges_for_broker( &self, stock_id: u64, broker_id: u32, ) -> Option<Vec<CryptoExchangeInfo>>

取某 broker 看某 stock 的 exchange 列表.

Source

pub fn set_lv2_exchange_cache( &self, stock_id: u64, lv2_prob: i32, orderbook: CachedOrderBook, )

写 exchange-level cache (单个 exchange 的原始 LV2 摆盘). 对齐 C++ m_mapLv2ExchangeCache[cacheKey] = pbOrderBook (QotRealTimeData.cpp:938).

Source

pub fn get_lv2_exchange_cache( &self, stock_id: u64, lv2_prob: i32, ) -> Option<CachedOrderBook>

取 exchange-level cache.

Source

pub fn get_brokers_affected_by_lv2_prob( &self, stock_id: u64, lv2_prob: i32, ) -> HashSet<u32>

反向索引查询: (stock_id, lv2_prob) 影响哪些 broker. 对齐 C++ setBrokerIDs = m_mapLv2ProbToBrokers[cacheKey] (QotRealTimeData.cpp:941-944).

Source

pub fn collect_exchange_caches_for_broker( &self, stock_id: u64, broker_id: u32, ) -> Vec<CachedOrderBook>

给定 (stock_id, broker_id), 收集该 broker 的所有 exchange 对应的 exchange-level cache 列表 (用作 merge 输入).

对齐 C++ MergeCryptoExchangesToBrokerCache 内部逻辑 (line 987-1022).

Source

pub fn clear_stock(&self, stock_id: u64)

清除某 stock 的所有 cache (退订 / reset 时调). 对齐 C++ ClearStockData(nStockID).

Source

pub fn clear_stock_broker(&self, stock_id: u64, broker_id: u32)

v1.4.110 R6-8: 清除某 (stock_id, broker_id)by_broker entry + 重建该 stock 反向索引. 用于 部分 broker 退订 —— stock 还有别的 broker 在订 (clear_stock 整 stock 清不适用), 但本 broker 已全局无订阅, 其 by_broker[(stock, broker)] 会 stale 滞留 → by_broker 慢漏累积死 entry.

移除本 broker 后该 stock 已无任何 broker → 连 lv2_exchange_cache 一并清 (无 broker 引用的 exchange-level cache 也是 stale).

Source

pub fn brokers_for_stock(&self, stock_id: u64) -> Vec<u32>

v1.4.110 R6-8: 列出 by_broker 里某 stock 当前缓存的所有 broker_id. 退订路径用它枚举该 stock 的 broker, 逐个判是否已全局无订阅 → clear.

Source

pub fn rebuild_broker_cache( &self, qot_cache: &QotCache, stock_id: u64, broker_id: u32, broker_cache_key: &str, ) -> Option<CachedOrderBook>

v1.4.110 R6-2 + R6-4: 重建某 (stock_id, broker_id) 的 broker-level 摆盘缓存 —— 收集该 broker 所有 exchange 的 LV2 cache → merge 40 档 → 写 qot_cache.order_books[broker_cache_key] → 唤醒 cold-cache waiter.

对齐 C++ QotRealTimeData::RebuildCryptoBrokerCache (line 960-985). parse_crypto_lv2_order_book_to_push (push 路径, 每个 affected broker 调 一次) 与 maybe_fetch_crypto_exchanges (CMD18012 完成后补 merge, R6-4) 共用本 fn.

Some(merged) 供 caller 构造 PushEvent; 该 broker 当前无任何 exchange cache (collect 空) → None (无数据可 merge, 不动 qot_cache).

broker_cache_key 由 caller 传 (= QotSecurityKey::cache_key(), "{public}@b{broker_id}") —— public sec_key 构造需要 market/code 上下文, 不在本 cache 持有.

Trait Implementations§

Source§

impl Debug for CryptoExchangeCache

Source§

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

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

impl Default for CryptoExchangeCache

Source§

fn default() -> CryptoExchangeCache

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

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.

§

impl<T> Instrument for T

§

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

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

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

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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