Skip to main content

futu_gateway_core/bridge/
trade_write_runtime.rs

1//! Trade-write runtime state boundary for [`super::GatewayBridge`].
2//!
3//! This bundle owns write-path deduplication and replay protection state.
4//! Trade handlers should depend on this narrow boundary instead of cloning
5//! individual fields from the full bridge object.
6
7use std::sync::Arc;
8
9use crate::idempotency::{IdempotencyCache, TradeReplayGuard};
10
11#[derive(Clone)]
12pub struct TradeWriteRuntime {
13    idempotency: Arc<IdempotencyCache>,
14    replay_guard: Arc<TradeReplayGuard>,
15}
16
17impl TradeWriteRuntime {
18    pub fn new_default() -> Self {
19        Self::new(
20            Arc::new(IdempotencyCache::with_default_ttl()),
21            Arc::new(TradeReplayGuard::new()),
22        )
23    }
24
25    pub fn new(idempotency: Arc<IdempotencyCache>, replay_guard: Arc<TradeReplayGuard>) -> Self {
26        Self {
27            idempotency,
28            replay_guard,
29        }
30    }
31
32    pub fn idempotency(&self) -> Arc<IdempotencyCache> {
33        Arc::clone(&self.idempotency)
34    }
35
36    pub fn replay_guard(&self) -> Arc<TradeReplayGuard> {
37        Arc::clone(&self.replay_guard)
38    }
39}
40
41impl Default for TradeWriteRuntime {
42    fn default() -> Self {
43        Self::new_default()
44    }
45}