nautilus_backtest/
data_client.rs

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