nautilus_backtest/
data_client.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//! Provides a `BacktestDataClient` implementation for backtesting.
17
18// Under development
19#![allow(dead_code)]
20#![allow(unused_variables)]
21
22use std::{cell::RefCell, rc::Rc};
23
24use nautilus_common::{
25    cache::Cache,
26    clients::DataClient,
27    messages::data::{
28        RequestBars, RequestBookSnapshot, RequestCustomData, RequestInstrument, RequestInstruments,
29        RequestQuotes, RequestTrades, SubscribeBars, SubscribeBookDeltas, SubscribeBookDepth10,
30        SubscribeCustomData, SubscribeIndexPrices, SubscribeInstrument, SubscribeInstrumentClose,
31        SubscribeInstrumentStatus, SubscribeInstruments, SubscribeMarkPrices, SubscribeQuotes,
32        SubscribeTrades, UnsubscribeBars, UnsubscribeBookDeltas, UnsubscribeBookDepth10,
33        UnsubscribeCustomData, UnsubscribeIndexPrices, UnsubscribeInstrument,
34        UnsubscribeInstrumentClose, UnsubscribeInstrumentStatus, UnsubscribeInstruments,
35        UnsubscribeMarkPrices, UnsubscribeQuotes, UnsubscribeTrades,
36    },
37};
38use nautilus_model::identifiers::{ClientId, Venue};
39
40#[derive(Debug)]
41/// Data client implementation for backtesting market data operations.
42///
43/// The `BacktestDataClient` provides a data client interface specifically designed
44/// for backtesting environments. It handles market data subscriptions and requests
45/// during backtesting, coordinating with the backtesting engine to provide
46/// historical data replay functionality.
47pub struct BacktestDataClient {
48    pub client_id: ClientId,
49    pub venue: Venue,
50    cache: Rc<RefCell<Cache>>,
51}
52
53impl BacktestDataClient {
54    pub const fn new(client_id: ClientId, venue: Venue, cache: Rc<RefCell<Cache>>) -> Self {
55        Self {
56            client_id,
57            venue,
58            cache,
59        }
60    }
61}
62
63#[async_trait::async_trait(?Send)]
64impl DataClient for BacktestDataClient {
65    fn client_id(&self) -> ClientId {
66        self.client_id
67    }
68
69    fn venue(&self) -> Option<Venue> {
70        Some(self.venue)
71    }
72
73    fn start(&mut self) -> anyhow::Result<()> {
74        Ok(())
75    }
76
77    fn stop(&mut self) -> anyhow::Result<()> {
78        Ok(())
79    }
80
81    fn reset(&mut self) -> anyhow::Result<()> {
82        Ok(())
83    }
84
85    fn dispose(&mut self) -> anyhow::Result<()> {
86        Ok(())
87    }
88
89    fn is_connected(&self) -> bool {
90        true
91    }
92
93    fn is_disconnected(&self) -> bool {
94        false
95    }
96
97    // -- COMMAND HANDLERS ---------------------------------------------------------------------------
98
99    fn subscribe(&mut self, _cmd: &SubscribeCustomData) -> anyhow::Result<()> {
100        Ok(())
101    }
102
103    fn subscribe_instruments(&mut self, _cmd: &SubscribeInstruments) -> anyhow::Result<()> {
104        Ok(())
105    }
106
107    fn subscribe_instrument(&mut self, _cmd: &SubscribeInstrument) -> anyhow::Result<()> {
108        Ok(())
109    }
110
111    fn subscribe_book_deltas(&mut self, _cmd: &SubscribeBookDeltas) -> anyhow::Result<()> {
112        Ok(())
113    }
114
115    fn subscribe_book_depth10(&mut self, _cmd: &SubscribeBookDepth10) -> anyhow::Result<()> {
116        Ok(())
117    }
118
119    fn subscribe_quotes(&mut self, _cmd: &SubscribeQuotes) -> anyhow::Result<()> {
120        Ok(())
121    }
122
123    fn subscribe_trades(&mut self, _cmd: &SubscribeTrades) -> anyhow::Result<()> {
124        Ok(())
125    }
126
127    fn subscribe_bars(&mut self, _cmd: &SubscribeBars) -> anyhow::Result<()> {
128        Ok(())
129    }
130
131    fn subscribe_mark_prices(&mut self, _cmd: &SubscribeMarkPrices) -> anyhow::Result<()> {
132        Ok(())
133    }
134
135    fn subscribe_index_prices(&mut self, _cmd: &SubscribeIndexPrices) -> anyhow::Result<()> {
136        Ok(())
137    }
138
139    fn subscribe_instrument_status(
140        &mut self,
141        _cmd: &SubscribeInstrumentStatus,
142    ) -> anyhow::Result<()> {
143        Ok(())
144    }
145
146    fn subscribe_instrument_close(
147        &mut self,
148        _cmd: &SubscribeInstrumentClose,
149    ) -> anyhow::Result<()> {
150        Ok(())
151    }
152
153    fn unsubscribe(&mut self, _cmd: &UnsubscribeCustomData) -> anyhow::Result<()> {
154        Ok(())
155    }
156
157    fn unsubscribe_instruments(&mut self, _cmd: &UnsubscribeInstruments) -> anyhow::Result<()> {
158        Ok(())
159    }
160
161    fn unsubscribe_instrument(&mut self, _cmd: &UnsubscribeInstrument) -> anyhow::Result<()> {
162        Ok(())
163    }
164
165    fn unsubscribe_book_deltas(&mut self, _cmd: &UnsubscribeBookDeltas) -> anyhow::Result<()> {
166        Ok(())
167    }
168
169    fn unsubscribe_book_depth10(&mut self, _cmd: &UnsubscribeBookDepth10) -> anyhow::Result<()> {
170        Ok(())
171    }
172
173    fn unsubscribe_quotes(&mut self, _cmd: &UnsubscribeQuotes) -> anyhow::Result<()> {
174        Ok(())
175    }
176
177    fn unsubscribe_trades(&mut self, _cmd: &UnsubscribeTrades) -> anyhow::Result<()> {
178        Ok(())
179    }
180
181    fn unsubscribe_bars(&mut self, _cmd: &UnsubscribeBars) -> anyhow::Result<()> {
182        Ok(())
183    }
184
185    fn unsubscribe_mark_prices(&mut self, _cmd: &UnsubscribeMarkPrices) -> anyhow::Result<()> {
186        Ok(())
187    }
188
189    fn unsubscribe_index_prices(&mut self, _cmd: &UnsubscribeIndexPrices) -> anyhow::Result<()> {
190        Ok(())
191    }
192
193    fn unsubscribe_instrument_status(
194        &mut self,
195        _cmd: &UnsubscribeInstrumentStatus,
196    ) -> anyhow::Result<()> {
197        Ok(())
198    }
199
200    fn unsubscribe_instrument_close(
201        &mut self,
202        _cmd: &UnsubscribeInstrumentClose,
203    ) -> anyhow::Result<()> {
204        Ok(())
205    }
206
207    // -- DATA REQUEST HANDLERS ---------------------------------------------------------------------------
208
209    fn request_data(&self, request: &RequestCustomData) -> anyhow::Result<()> {
210        todo!()
211    }
212
213    fn request_instruments(&self, request: &RequestInstruments) -> anyhow::Result<()> {
214        todo!()
215    }
216
217    fn request_instrument(&self, request: &RequestInstrument) -> anyhow::Result<()> {
218        todo!()
219    }
220
221    fn request_book_snapshot(&self, request: &RequestBookSnapshot) -> anyhow::Result<()> {
222        todo!()
223    }
224
225    fn request_quotes(&self, request: &RequestQuotes) -> anyhow::Result<()> {
226        todo!()
227    }
228
229    fn request_trades(&self, request: &RequestTrades) -> anyhow::Result<()> {
230        todo!()
231    }
232
233    fn request_bars(&self, request: &RequestBars) -> anyhow::Result<()> {
234        todo!()
235    }
236}