Skip to main content

nautilus_derive/websocket/
context.rs

1// -------------------------------------------------------------------------------------------------
2//  Copyright (C) 2015-2026 Nautech Systems Pty Ltd. All rights reserved.
3//  https://nautechsystems.io
4//
5//  Licensed under the GNU Lesser General Public License Version 3.0 (the "License");
6//  You may not use this file except in compliance with the License.
7//  You may obtain a copy of the License at https://www.gnu.org/licenses/lgpl-3.0.en.html
8//
9//  Unless required by applicable law or agreed to in writing, software
10//  distributed under the License is distributed on an "AS IS" BASIS,
11//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12//  See the License for the specific language governing permissions and
13//  limitations under the License.
14// -------------------------------------------------------------------------------------------------
15
16//! WebSocket message dispatch context for the Derive data client.
17
18use std::sync::Arc;
19
20use nautilus_common::{
21    cache::{fifo::FifoCache, quote::QuoteCache},
22    live::sender::EventSender,
23    messages::DataEvent,
24};
25use nautilus_core::{AtomicMap, AtomicSet, time::AtomicTime};
26use nautilus_model::{
27    identifiers::{InstrumentId, TradeId},
28    instruments::InstrumentAny,
29};
30use parking_lot::Mutex;
31
32use super::dispatch::TRADE_DEDUP_CAPACITY;
33use crate::book::sync::BookSyncTracker;
34
35pub(crate) struct WsMessageContext {
36    pub(crate) clock: &'static AtomicTime,
37    pub(crate) data_sender: EventSender<DataEvent>,
38    pub(crate) instruments: Arc<AtomicMap<InstrumentId, InstrumentAny>>,
39    pub(crate) active_book_delta_channels: Arc<AtomicMap<InstrumentId, String>>,
40    pub(crate) active_book_depth_channels: Arc<AtomicMap<InstrumentId, String>>,
41    pub(crate) active_ticker_channels: Arc<AtomicMap<InstrumentId, String>>,
42    pub(crate) active_quote_subs: Arc<AtomicSet<InstrumentId>>,
43    pub(crate) active_trade_subs: Arc<AtomicSet<InstrumentId>>,
44    pub(crate) active_mark_subs: Arc<AtomicSet<InstrumentId>>,
45    pub(crate) active_index_subs: Arc<AtomicSet<InstrumentId>>,
46    pub(crate) active_funding_subs: Arc<AtomicSet<InstrumentId>>,
47    pub(crate) active_greeks_subs: Arc<AtomicSet<InstrumentId>>,
48    pub(crate) subscription_lock: Arc<Mutex<()>>,
49    pub(crate) book_sync: BookSyncTracker,
50    pub(crate) trades_emitted: Arc<Mutex<FifoCache<TradeId, TRADE_DEDUP_CAPACITY>>>,
51    pub(crate) quote_cache: Arc<Mutex<QuoteCache>>,
52}