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    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(?Send)]
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    fn is_connected(&self) -> bool {
91        true
92    }
93
94    fn is_disconnected(&self) -> bool {
95        false
96    }
97
98    // -- COMMAND HANDLERS ---------------------------------------------------------------------------
99
100    fn subscribe(&mut self, _cmd: &SubscribeCustomData) -> anyhow::Result<()> {
101        Ok(())
102    }
103
104    fn subscribe_instruments(&mut self, _cmd: &SubscribeInstruments) -> anyhow::Result<()> {
105        Ok(())
106    }
107
108    fn subscribe_instrument(&mut self, _cmd: &SubscribeInstrument) -> anyhow::Result<()> {
109        Ok(())
110    }
111
112    fn subscribe_book_deltas(&mut self, _cmd: &SubscribeBookDeltas) -> anyhow::Result<()> {
113        Ok(())
114    }
115
116    fn subscribe_book_depth10(&mut self, _cmd: &SubscribeBookDepth10) -> anyhow::Result<()> {
117        Ok(())
118    }
119
120    fn subscribe_book_snapshots(&mut self, _cmd: &SubscribeBookSnapshots) -> anyhow::Result<()> {
121        Ok(())
122    }
123
124    fn subscribe_quotes(&mut self, _cmd: &SubscribeQuotes) -> anyhow::Result<()> {
125        Ok(())
126    }
127
128    fn subscribe_trades(&mut self, _cmd: &SubscribeTrades) -> anyhow::Result<()> {
129        Ok(())
130    }
131
132    fn subscribe_bars(&mut self, _cmd: &SubscribeBars) -> anyhow::Result<()> {
133        Ok(())
134    }
135
136    fn subscribe_mark_prices(&mut self, _cmd: &SubscribeMarkPrices) -> anyhow::Result<()> {
137        Ok(())
138    }
139
140    fn subscribe_index_prices(&mut self, _cmd: &SubscribeIndexPrices) -> anyhow::Result<()> {
141        Ok(())
142    }
143
144    fn subscribe_instrument_status(
145        &mut self,
146        _cmd: &SubscribeInstrumentStatus,
147    ) -> anyhow::Result<()> {
148        Ok(())
149    }
150
151    fn subscribe_instrument_close(
152        &mut self,
153        _cmd: &SubscribeInstrumentClose,
154    ) -> anyhow::Result<()> {
155        Ok(())
156    }
157
158    fn unsubscribe(&mut self, _cmd: &UnsubscribeCustomData) -> anyhow::Result<()> {
159        Ok(())
160    }
161
162    fn unsubscribe_instruments(&mut self, _cmd: &UnsubscribeInstruments) -> anyhow::Result<()> {
163        Ok(())
164    }
165
166    fn unsubscribe_instrument(&mut self, _cmd: &UnsubscribeInstrument) -> anyhow::Result<()> {
167        Ok(())
168    }
169
170    fn unsubscribe_book_deltas(&mut self, _cmd: &UnsubscribeBookDeltas) -> anyhow::Result<()> {
171        Ok(())
172    }
173
174    fn unsubscribe_book_depth10(&mut self, _cmd: &UnsubscribeBookDepth10) -> anyhow::Result<()> {
175        Ok(())
176    }
177
178    fn unsubscribe_book_snapshots(
179        &mut self,
180        _cmd: &UnsubscribeBookSnapshots,
181    ) -> anyhow::Result<()> {
182        Ok(())
183    }
184
185    fn unsubscribe_quotes(&mut self, _cmd: &UnsubscribeQuotes) -> anyhow::Result<()> {
186        Ok(())
187    }
188
189    fn unsubscribe_trades(&mut self, _cmd: &UnsubscribeTrades) -> anyhow::Result<()> {
190        Ok(())
191    }
192
193    fn unsubscribe_bars(&mut self, _cmd: &UnsubscribeBars) -> anyhow::Result<()> {
194        Ok(())
195    }
196
197    fn unsubscribe_mark_prices(&mut self, _cmd: &UnsubscribeMarkPrices) -> anyhow::Result<()> {
198        Ok(())
199    }
200
201    fn unsubscribe_index_prices(&mut self, _cmd: &UnsubscribeIndexPrices) -> anyhow::Result<()> {
202        Ok(())
203    }
204
205    fn unsubscribe_instrument_status(
206        &mut self,
207        _cmd: &UnsubscribeInstrumentStatus,
208    ) -> anyhow::Result<()> {
209        Ok(())
210    }
211
212    fn unsubscribe_instrument_close(
213        &mut self,
214        _cmd: &UnsubscribeInstrumentClose,
215    ) -> anyhow::Result<()> {
216        Ok(())
217    }
218
219    // -- DATA REQUEST HANDLERS ---------------------------------------------------------------------------
220
221    fn request_data(&self, request: &RequestCustomData) -> anyhow::Result<()> {
222        todo!()
223    }
224
225    fn request_instruments(&self, request: &RequestInstruments) -> anyhow::Result<()> {
226        todo!()
227    }
228
229    fn request_instrument(&self, request: &RequestInstrument) -> anyhow::Result<()> {
230        todo!()
231    }
232
233    fn request_book_snapshot(&self, request: &RequestBookSnapshot) -> anyhow::Result<()> {
234        todo!()
235    }
236
237    fn request_quotes(&self, request: &RequestQuotes) -> anyhow::Result<()> {
238        todo!()
239    }
240
241    fn request_trades(&self, request: &RequestTrades) -> anyhow::Result<()> {
242        todo!()
243    }
244
245    fn request_bars(&self, request: &RequestBars) -> anyhow::Result<()> {
246        todo!()
247    }
248}