Skip to main content

futu_gateway_core/bridge/
qot_runtime.rs

1//! QOT runtime state boundary for [`super::GatewayBridge`].
2//!
3//! This bundle owns QOT-specific mutable runtime state that does not belong in
4//! the bridge facade: history K-line quota counters and main-broker snapshots.
5
6use std::sync::Arc;
7use std::sync::atomic::AtomicU32;
8
9use arc_swap::ArcSwap;
10
11pub type MainBrokerCache = Arc<ArcSwap<futu_backend::main_broker_svr::MainBrokerSnapshot>>;
12
13#[derive(Clone)]
14pub struct QotRuntime {
15    kl_quota_counter: Arc<AtomicU32>,
16    main_broker_cache: MainBrokerCache,
17}
18
19impl QotRuntime {
20    pub fn new() -> Self {
21        Self {
22            kl_quota_counter: Arc::new(AtomicU32::new(0)),
23            main_broker_cache: Arc::new(ArcSwap::new(Arc::new(
24                futu_backend::main_broker_svr::MainBrokerSnapshot::default(),
25            ))),
26        }
27    }
28
29    pub fn kl_quota_counter(&self) -> Arc<AtomicU32> {
30        Arc::clone(&self.kl_quota_counter)
31    }
32
33    pub fn main_broker_cache(&self) -> MainBrokerCache {
34        Arc::clone(&self.main_broker_cache)
35    }
36
37    pub fn store_main_broker_snapshot(
38        &self,
39        snapshot: futu_backend::main_broker_svr::MainBrokerSnapshot,
40    ) {
41        self.main_broker_cache.store(Arc::new(snapshot));
42    }
43}
44
45impl Default for QotRuntime {
46    fn default() -> Self {
47        Self::new()
48    }
49}