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, collections::HashMap, rc::Rc};
23
24use nautilus_common::{
25    cache::Cache,
26    messages::data::{DataRequest, Payload},
27    msgbus::MessageBus,
28};
29use nautilus_core::{UnixNanos, UUID4};
30use nautilus_data::client::DataClient;
31use nautilus_model::{
32    data::{Bar, BarType, DataType, QuoteTick, TradeTick},
33    enums::BookType,
34    identifiers::{ClientId, InstrumentId, Venue},
35    instruments::InstrumentAny,
36};
37
38pub struct BacktestDataClient {
39    cache: Rc<RefCell<Cache>>,
40    msgbus: Rc<RefCell<MessageBus>>,
41    pub client_id: ClientId,
42    pub venue: Venue,
43}
44
45impl DataClient for BacktestDataClient {
46    fn client_id(&self) -> ClientId {
47        self.client_id
48    }
49    fn venue(&self) -> Option<Venue> {
50        Some(self.venue)
51    }
52
53    fn start(&self) {}
54    fn stop(&self) {}
55    fn reset(&self) {}
56    fn dispose(&self) {}
57    fn is_connected(&self) -> bool {
58        true
59    }
60    fn is_disconnected(&self) -> bool {
61        false
62    }
63
64    // -- COMMAND HANDLERS ---------------------------------------------------------------------------
65
66    /// Parse command and call specific function
67    fn subscribe(
68        &mut self,
69        _data_type: &DataType,
70        _params: &Option<HashMap<String, String>>,
71    ) -> anyhow::Result<()> {
72        Ok(())
73    }
74
75    fn subscribe_instruments(
76        &mut self,
77        _venue: Option<&Venue>,
78        _params: &Option<HashMap<String, String>>,
79    ) -> anyhow::Result<()> {
80        Ok(())
81    }
82
83    fn subscribe_instrument(
84        &mut self,
85        _instrument_id: &InstrumentId,
86        _params: &Option<HashMap<String, String>>,
87    ) -> anyhow::Result<()> {
88        Ok(())
89    }
90
91    fn subscribe_order_book_deltas(
92        &mut self,
93        _instrument_id: &InstrumentId,
94        _book_type: BookType,
95        _depth: Option<usize>,
96        _params: &Option<HashMap<String, String>>,
97    ) -> anyhow::Result<()> {
98        Ok(())
99    }
100
101    fn subscribe_order_book_snapshots(
102        &mut self,
103        instrument_id: &InstrumentId,
104        book_type: BookType,
105        depth: Option<usize>,
106        params: &Option<HashMap<String, String>>,
107    ) -> anyhow::Result<()> {
108        Ok(())
109    }
110
111    fn subscribe_quote_ticks(
112        &mut self,
113        instrument_id: &InstrumentId,
114        params: &Option<HashMap<String, String>>,
115    ) -> anyhow::Result<()> {
116        Ok(())
117    }
118
119    fn subscribe_trade_ticks(
120        &mut self,
121        instrument_id: &InstrumentId,
122        params: &Option<HashMap<String, String>>,
123    ) -> anyhow::Result<()> {
124        Ok(())
125    }
126
127    fn subscribe_bars(
128        &mut self,
129        bar_type: &BarType,
130        params: &Option<HashMap<String, String>>,
131    ) -> anyhow::Result<()> {
132        Ok(())
133    }
134
135    fn subscribe_instrument_status(
136        &mut self,
137        instrument_id: &InstrumentId,
138        params: &Option<HashMap<String, String>>,
139    ) -> anyhow::Result<()> {
140        Ok(())
141    }
142
143    fn subscribe_instrument_close(
144        &mut self,
145        instrument_id: &InstrumentId,
146        params: &Option<HashMap<String, String>>,
147    ) -> anyhow::Result<()> {
148        Ok(())
149    }
150
151    fn unsubscribe(
152        &mut self,
153        data_type: &DataType,
154        params: &Option<HashMap<String, String>>,
155    ) -> anyhow::Result<()> {
156        Ok(())
157    }
158
159    fn unsubscribe_instruments(
160        &mut self,
161        venue: Option<&Venue>,
162        params: &Option<HashMap<String, String>>,
163    ) -> anyhow::Result<()> {
164        Ok(())
165    }
166
167    fn unsubscribe_instrument(
168        &mut self,
169        instrument_id: &InstrumentId,
170        params: &Option<HashMap<String, String>>,
171    ) -> anyhow::Result<()> {
172        Ok(())
173    }
174
175    fn unsubscribe_order_book_deltas(
176        &mut self,
177        instrument_id: &InstrumentId,
178        params: &Option<HashMap<String, String>>,
179    ) -> anyhow::Result<()> {
180        Ok(())
181    }
182
183    fn unsubscribe_order_book_snapshots(
184        &mut self,
185        instrument_id: &InstrumentId,
186        params: &Option<HashMap<String, String>>,
187    ) -> anyhow::Result<()> {
188        Ok(())
189    }
190
191    fn unsubscribe_quote_ticks(
192        &mut self,
193        instrument_id: &InstrumentId,
194        params: &Option<HashMap<String, String>>,
195    ) -> anyhow::Result<()> {
196        Ok(())
197    }
198
199    fn unsubscribe_trade_ticks(
200        &mut self,
201        instrument_id: &InstrumentId,
202        params: &Option<HashMap<String, String>>,
203    ) -> anyhow::Result<()> {
204        Ok(())
205    }
206
207    fn unsubscribe_bars(
208        &mut self,
209        bar_type: &BarType,
210        params: &Option<HashMap<String, String>>,
211    ) -> anyhow::Result<()> {
212        Ok(())
213    }
214
215    fn unsubscribe_instrument_status(
216        &mut self,
217        instrument_id: &InstrumentId,
218        params: &Option<HashMap<String, String>>,
219    ) -> anyhow::Result<()> {
220        Ok(())
221    }
222
223    fn unsubscribe_instrument_close(
224        &mut self,
225        instrument_id: &InstrumentId,
226        params: &Option<HashMap<String, String>>,
227    ) -> anyhow::Result<()> {
228        Ok(())
229    }
230
231    // -- DATA REQUEST HANDLERS ---------------------------------------------------------------------------
232
233    fn request_data(&self, request: DataRequest) {
234        todo!()
235    }
236
237    fn request_instruments(
238        &self,
239        correlation_id: UUID4,
240        venue: Venue,
241        start: Option<UnixNanos>,
242        end: Option<UnixNanos>,
243        params: &Option<HashMap<String, String>>,
244    ) -> Vec<InstrumentAny> {
245        todo!()
246    }
247
248    fn request_instrument(
249        &self,
250        correlation_id: UUID4,
251        instrument_id: InstrumentId,
252        start: Option<UnixNanos>,
253        end: Option<UnixNanos>,
254        params: &Option<HashMap<String, String>>,
255    ) -> InstrumentAny {
256        todo!()
257    }
258
259    // TODO: figure out where to call this and it's return type
260    fn request_order_book_snapshot(
261        &self,
262        correlation_id: UUID4,
263        instrument_id: InstrumentId,
264        depth: Option<usize>,
265        params: &Option<HashMap<String, String>>,
266    ) -> Payload {
267        todo!()
268    }
269
270    fn request_quote_ticks(
271        &self,
272        correlation_id: UUID4,
273        instrument_id: InstrumentId,
274        start: Option<UnixNanos>,
275        end: Option<UnixNanos>,
276        limit: Option<usize>,
277        params: &Option<HashMap<String, String>>,
278    ) -> Vec<QuoteTick> {
279        todo!()
280    }
281
282    fn request_trade_ticks(
283        &self,
284        correlation_id: UUID4,
285        instrument_id: InstrumentId,
286        start: Option<UnixNanos>,
287        end: Option<UnixNanos>,
288        limit: Option<usize>,
289        params: &Option<HashMap<String, String>>,
290    ) -> Vec<TradeTick> {
291        todo!()
292    }
293
294    fn request_bars(
295        &self,
296        correlation_id: UUID4,
297        bar_type: BarType,
298        start: Option<UnixNanos>,
299        end: Option<UnixNanos>,
300        limit: Option<usize>,
301        params: &Option<HashMap<String, String>>,
302    ) -> Vec<Bar> {
303        todo!()
304    }
305}