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, num::NonZeroUsize, rc::Rc};
23
24use nautilus_common::{
25    cache::Cache,
26    messages::data::{
27        DataRequest, Payload, SubscribeBars, SubscribeBookDeltas, SubscribeBookDepth10,
28        SubscribeBookSnapshots, SubscribeData, SubscribeIndexPrices, SubscribeInstrument,
29        SubscribeInstrumentClose, SubscribeInstrumentStatus, SubscribeInstruments,
30        SubscribeMarkPrices, SubscribeQuotes, SubscribeTrades, UnsubscribeBars,
31        UnsubscribeBookDeltas, UnsubscribeBookDepth10, UnsubscribeBookSnapshots, UnsubscribeData,
32        UnsubscribeIndexPrices, UnsubscribeInstrument, UnsubscribeInstrumentClose,
33        UnsubscribeInstrumentStatus, UnsubscribeInstruments, UnsubscribeMarkPrices,
34        UnsubscribeQuotes, UnsubscribeTrades,
35    },
36};
37use nautilus_core::{UUID4, UnixNanos};
38use nautilus_data::client::DataClient;
39use nautilus_model::{
40    data::{Bar, BarType, QuoteTick, TradeTick},
41    identifiers::{ClientId, InstrumentId, Venue},
42    instruments::InstrumentAny,
43};
44
45pub struct BacktestDataClient {
46    pub client_id: ClientId,
47    pub venue: Venue,
48    cache: Rc<RefCell<Cache>>,
49}
50
51impl BacktestDataClient {
52    pub fn new(client_id: ClientId, venue: Venue, cache: Rc<RefCell<Cache>>) -> Self {
53        Self {
54            client_id,
55            venue,
56            cache,
57        }
58    }
59}
60
61impl DataClient for BacktestDataClient {
62    fn client_id(&self) -> ClientId {
63        self.client_id
64    }
65    fn venue(&self) -> Option<Venue> {
66        Some(self.venue)
67    }
68
69    fn start(&self) {}
70    fn stop(&self) {}
71    fn reset(&self) {}
72    fn dispose(&self) {}
73    fn is_connected(&self) -> bool {
74        true
75    }
76    fn is_disconnected(&self) -> bool {
77        false
78    }
79
80    // -- COMMAND HANDLERS ---------------------------------------------------------------------------
81
82    fn subscribe(&mut self, _cmd: SubscribeData) -> anyhow::Result<()> {
83        Ok(())
84    }
85
86    fn subscribe_instruments(&mut self, _cmd: SubscribeInstruments) -> anyhow::Result<()> {
87        Ok(())
88    }
89
90    fn subscribe_instrument(&mut self, _cmd: SubscribeInstrument) -> anyhow::Result<()> {
91        Ok(())
92    }
93
94    fn subscribe_book_deltas(&mut self, _cmd: SubscribeBookDeltas) -> anyhow::Result<()> {
95        Ok(())
96    }
97
98    fn subscribe_book_depth10(&mut self, _cmd: SubscribeBookDepth10) -> anyhow::Result<()> {
99        Ok(())
100    }
101
102    fn subscribe_book_snapshots(&mut self, _cmd: SubscribeBookSnapshots) -> anyhow::Result<()> {
103        Ok(())
104    }
105
106    fn subscribe_quotes(&mut self, _cmd: SubscribeQuotes) -> anyhow::Result<()> {
107        Ok(())
108    }
109
110    fn subscribe_trades(&mut self, _cmd: SubscribeTrades) -> anyhow::Result<()> {
111        Ok(())
112    }
113
114    fn subscribe_bars(&mut self, _cmd: SubscribeBars) -> anyhow::Result<()> {
115        Ok(())
116    }
117
118    fn subscribe_instrument_status(
119        &mut self,
120        _cmd: SubscribeInstrumentStatus,
121    ) -> anyhow::Result<()> {
122        Ok(())
123    }
124
125    fn subscribe_instrument_close(&mut self, _cmd: SubscribeInstrumentClose) -> anyhow::Result<()> {
126        Ok(())
127    }
128
129    fn subscribe_mark_prices(&mut self, _cmd: SubscribeMarkPrices) -> anyhow::Result<()> {
130        Ok(())
131    }
132
133    fn subscribe_index_prices(&mut self, _cmd: SubscribeIndexPrices) -> anyhow::Result<()> {
134        Ok(())
135    }
136
137    fn unsubscribe(&mut self, _cmd: UnsubscribeData) -> anyhow::Result<()> {
138        Ok(())
139    }
140
141    fn unsubscribe_instruments(&mut self, _cmd: UnsubscribeInstruments) -> anyhow::Result<()> {
142        Ok(())
143    }
144
145    fn unsubscribe_instrument(&mut self, _cmd: UnsubscribeInstrument) -> anyhow::Result<()> {
146        Ok(())
147    }
148
149    fn unsubscribe_book_deltas(&mut self, _cmd: UnsubscribeBookDeltas) -> anyhow::Result<()> {
150        Ok(())
151    }
152
153    fn unsubscribe_book_depth10(&mut self, _cmd: UnsubscribeBookDepth10) -> anyhow::Result<()> {
154        Ok(())
155    }
156
157    fn unsubscribe_book_snapshots(&mut self, _cmd: UnsubscribeBookSnapshots) -> anyhow::Result<()> {
158        Ok(())
159    }
160
161    fn unsubscribe_quotes(&mut self, _cmd: UnsubscribeQuotes) -> anyhow::Result<()> {
162        Ok(())
163    }
164
165    fn unsubscribe_trades(&mut self, _cmd: UnsubscribeTrades) -> anyhow::Result<()> {
166        Ok(())
167    }
168
169    fn unsubscribe_bars(&mut self, _cmd: UnsubscribeBars) -> anyhow::Result<()> {
170        Ok(())
171    }
172
173    fn unsubscribe_instrument_status(
174        &mut self,
175        _cmd: UnsubscribeInstrumentStatus,
176    ) -> anyhow::Result<()> {
177        Ok(())
178    }
179
180    fn unsubscribe_instrument_close(
181        &mut self,
182        _cmd: UnsubscribeInstrumentClose,
183    ) -> anyhow::Result<()> {
184        Ok(())
185    }
186
187    fn unsubscribe_mark_prices(&mut self, _cmd: UnsubscribeMarkPrices) -> anyhow::Result<()> {
188        Ok(())
189    }
190
191    fn unsubscribe_index_prices(&mut self, _cmd: UnsubscribeIndexPrices) -> anyhow::Result<()> {
192        Ok(())
193    }
194
195    // -- DATA REQUEST HANDLERS ---------------------------------------------------------------------------
196
197    fn request_data(&self, request: DataRequest) {
198        todo!()
199    }
200
201    fn request_instruments(
202        &self,
203        correlation_id: UUID4,
204        venue: Venue,
205        start: Option<UnixNanos>,
206        end: Option<UnixNanos>,
207        params: &Option<HashMap<String, String>>,
208    ) -> Vec<InstrumentAny> {
209        todo!()
210    }
211
212    fn request_instrument(
213        &self,
214        correlation_id: UUID4,
215        instrument_id: InstrumentId,
216        start: Option<UnixNanos>,
217        end: Option<UnixNanos>,
218        params: &Option<HashMap<String, String>>,
219    ) -> InstrumentAny {
220        todo!()
221    }
222
223    // TODO: figure out where to call this and it's return type
224    fn request_order_book_snapshot(
225        &self,
226        correlation_id: UUID4,
227        instrument_id: InstrumentId,
228        depth: Option<NonZeroUsize>,
229        params: &Option<HashMap<String, String>>,
230    ) -> Payload {
231        todo!()
232    }
233
234    fn request_quote_ticks(
235        &self,
236        correlation_id: UUID4,
237        instrument_id: InstrumentId,
238        start: Option<UnixNanos>,
239        end: Option<UnixNanos>,
240        limit: Option<NonZeroUsize>,
241        params: &Option<HashMap<String, String>>,
242    ) -> Vec<QuoteTick> {
243        todo!()
244    }
245
246    fn request_trade_ticks(
247        &self,
248        correlation_id: UUID4,
249        instrument_id: InstrumentId,
250        start: Option<UnixNanos>,
251        end: Option<UnixNanos>,
252        limit: Option<NonZeroUsize>,
253        params: &Option<HashMap<String, String>>,
254    ) -> Vec<TradeTick> {
255        todo!()
256    }
257
258    fn request_bars(
259        &self,
260        correlation_id: UUID4,
261        bar_type: BarType,
262        start: Option<UnixNanos>,
263        end: Option<UnixNanos>,
264        limit: Option<NonZeroUsize>,
265        params: &Option<HashMap<String, String>>,
266    ) -> Vec<Bar> {
267        todo!()
268    }
269}