nautilus_backtest/
data_client.rs

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