Skip to main content

nautilus_common/messages/data/
response.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
16use std::{any::Any, sync::Arc};
17
18use nautilus_core::{Params, UUID4, UnixNanos};
19use nautilus_model::{
20    data::{Bar, BarType, DataType, ForwardPrice, FundingRateUpdate, QuoteTick, TradeTick},
21    identifiers::{ClientId, InstrumentId, Venue},
22    instruments::InstrumentAny,
23    orderbook::OrderBook,
24};
25
26use super::Payload;
27
28#[derive(Clone, Debug)]
29pub struct CustomDataResponse {
30    pub correlation_id: UUID4,
31    pub client_id: ClientId,
32    pub venue: Option<Venue>,
33    pub data_type: DataType,
34    pub data: Payload,
35    pub start: Option<UnixNanos>,
36    pub end: Option<UnixNanos>,
37    pub ts_init: UnixNanos,
38    pub params: Option<Params>,
39}
40
41impl CustomDataResponse {
42    /// Creates a new [`CustomDataResponse`] instance.
43    #[expect(clippy::too_many_arguments)]
44    pub fn new<T: Any + Send + Sync>(
45        correlation_id: UUID4,
46        client_id: ClientId,
47        venue: Option<Venue>,
48        data_type: DataType,
49        data: T,
50        start: Option<UnixNanos>,
51        end: Option<UnixNanos>,
52        ts_init: UnixNanos,
53        params: Option<Params>,
54    ) -> Self {
55        Self {
56            correlation_id,
57            client_id,
58            venue,
59            data_type,
60            data: Arc::new(data),
61            start,
62            end,
63            ts_init,
64            params,
65        }
66    }
67
68    /// Converts the response to a dyn Any trait object for messaging.
69    pub fn as_any(&self) -> &dyn Any {
70        self
71    }
72}
73
74#[derive(Clone, Debug)]
75pub struct InstrumentResponse {
76    pub correlation_id: UUID4,
77    pub client_id: ClientId,
78    pub instrument_id: InstrumentId,
79    pub data: InstrumentAny,
80    pub start: Option<UnixNanos>,
81    pub end: Option<UnixNanos>,
82    pub ts_init: UnixNanos,
83    pub params: Option<Params>,
84}
85
86impl InstrumentResponse {
87    /// Converts to a dyn Any trait object for messaging.
88    pub fn as_any(&self) -> &dyn Any {
89        self
90    }
91
92    /// Creates a new [`InstrumentResponse`] instance.
93    #[expect(clippy::too_many_arguments)]
94    pub fn new(
95        correlation_id: UUID4,
96        client_id: ClientId,
97        instrument_id: InstrumentId,
98        data: InstrumentAny,
99        start: Option<UnixNanos>,
100        end: Option<UnixNanos>,
101        ts_init: UnixNanos,
102        params: Option<Params>,
103    ) -> Self {
104        Self {
105            correlation_id,
106            client_id,
107            instrument_id,
108            data,
109            start,
110            end,
111            ts_init,
112            params,
113        }
114    }
115}
116
117#[derive(Clone, Debug)]
118pub struct InstrumentsResponse {
119    pub correlation_id: UUID4,
120    pub client_id: ClientId,
121    pub venue: Venue,
122    pub data: Vec<InstrumentAny>,
123    pub start: Option<UnixNanos>,
124    pub end: Option<UnixNanos>,
125    pub ts_init: UnixNanos,
126    pub params: Option<Params>,
127}
128
129impl InstrumentsResponse {
130    /// Converts to a dyn Any trait object for messaging.
131    pub fn as_any(&self) -> &dyn Any {
132        self
133    }
134
135    /// Creates a new [`InstrumentsResponse`] instance.
136    #[expect(clippy::too_many_arguments)]
137    pub fn new(
138        correlation_id: UUID4,
139        client_id: ClientId,
140        venue: Venue,
141        data: Vec<InstrumentAny>,
142        start: Option<UnixNanos>,
143        end: Option<UnixNanos>,
144        ts_init: UnixNanos,
145        params: Option<Params>,
146    ) -> Self {
147        Self {
148            correlation_id,
149            client_id,
150            venue,
151            data,
152            start,
153            end,
154            ts_init,
155            params,
156        }
157    }
158}
159
160#[derive(Clone, Debug)]
161pub struct BookResponse {
162    pub correlation_id: UUID4,
163    pub client_id: ClientId,
164    pub instrument_id: InstrumentId,
165    pub data: OrderBook,
166    pub start: Option<UnixNanos>,
167    pub end: Option<UnixNanos>,
168    pub ts_init: UnixNanos,
169    pub params: Option<Params>,
170}
171
172impl BookResponse {
173    /// Converts to a dyn Any trait object for messaging.
174    pub fn as_any(&self) -> &dyn Any {
175        self
176    }
177
178    /// Creates a new [`BookResponse`] instance.
179    #[expect(clippy::too_many_arguments)]
180    pub fn new(
181        correlation_id: UUID4,
182        client_id: ClientId,
183        instrument_id: InstrumentId,
184        data: OrderBook,
185        start: Option<UnixNanos>,
186        end: Option<UnixNanos>,
187        ts_init: UnixNanos,
188        params: Option<Params>,
189    ) -> Self {
190        Self {
191            correlation_id,
192            client_id,
193            instrument_id,
194            data,
195            start,
196            end,
197            ts_init,
198            params,
199        }
200    }
201}
202
203#[derive(Clone, Debug)]
204pub struct QuotesResponse {
205    pub correlation_id: UUID4,
206    pub client_id: ClientId,
207    pub instrument_id: InstrumentId,
208    pub data: Vec<QuoteTick>,
209    pub start: Option<UnixNanos>,
210    pub end: Option<UnixNanos>,
211    pub ts_init: UnixNanos,
212    pub params: Option<Params>,
213}
214
215impl QuotesResponse {
216    /// Converts to a dyn Any trait object for messaging.
217    pub fn as_any(&self) -> &dyn Any {
218        self
219    }
220
221    /// Creates a new [`QuotesResponse`] instance.
222    #[expect(clippy::too_many_arguments)]
223    pub fn new(
224        correlation_id: UUID4,
225        client_id: ClientId,
226        instrument_id: InstrumentId,
227        data: Vec<QuoteTick>,
228        start: Option<UnixNanos>,
229        end: Option<UnixNanos>,
230        ts_init: UnixNanos,
231        params: Option<Params>,
232    ) -> Self {
233        Self {
234            correlation_id,
235            client_id,
236            instrument_id,
237            data,
238            start,
239            end,
240            ts_init,
241            params,
242        }
243    }
244}
245
246#[derive(Clone, Debug)]
247pub struct TradesResponse {
248    pub correlation_id: UUID4,
249    pub client_id: ClientId,
250    pub instrument_id: InstrumentId,
251    pub data: Vec<TradeTick>,
252    pub start: Option<UnixNanos>,
253    pub end: Option<UnixNanos>,
254    pub ts_init: UnixNanos,
255    pub params: Option<Params>,
256}
257
258impl TradesResponse {
259    /// Converts to a dyn Any trait object for messaging.
260    pub fn as_any(&self) -> &dyn Any {
261        self
262    }
263
264    /// Creates a new [`TradesResponse`] instance.
265    #[expect(clippy::too_many_arguments)]
266    pub fn new(
267        correlation_id: UUID4,
268        client_id: ClientId,
269        instrument_id: InstrumentId,
270        data: Vec<TradeTick>,
271        start: Option<UnixNanos>,
272        end: Option<UnixNanos>,
273        ts_init: UnixNanos,
274        params: Option<Params>,
275    ) -> Self {
276        Self {
277            correlation_id,
278            client_id,
279            instrument_id,
280            data,
281            start,
282            end,
283            ts_init,
284            params,
285        }
286    }
287}
288
289#[derive(Clone, Debug)]
290pub struct FundingRatesResponse {
291    pub correlation_id: UUID4,
292    pub client_id: ClientId,
293    pub instrument_id: InstrumentId,
294    pub data: Vec<FundingRateUpdate>,
295    pub start: Option<UnixNanos>,
296    pub end: Option<UnixNanos>,
297    pub ts_init: UnixNanos,
298    pub params: Option<Params>,
299}
300
301impl FundingRatesResponse {
302    /// Converts to a dyn Any trait object for messaging.
303    pub fn as_any(&self) -> &dyn Any {
304        self
305    }
306
307    /// Creates a new [`FundingRatesResponse`] instance.
308    #[expect(clippy::too_many_arguments)]
309    pub fn new(
310        correlation_id: UUID4,
311        client_id: ClientId,
312        instrument_id: InstrumentId,
313        data: Vec<FundingRateUpdate>,
314        start: Option<UnixNanos>,
315        end: Option<UnixNanos>,
316        ts_init: UnixNanos,
317        params: Option<Params>,
318    ) -> Self {
319        Self {
320            correlation_id,
321            client_id,
322            instrument_id,
323            data,
324            start,
325            end,
326            ts_init,
327            params,
328        }
329    }
330}
331
332#[derive(Clone, Debug)]
333pub struct ForwardPricesResponse {
334    pub correlation_id: UUID4,
335    pub client_id: ClientId,
336    pub venue: Venue,
337    pub data: Vec<ForwardPrice>,
338    pub ts_init: UnixNanos,
339    pub params: Option<Params>,
340}
341
342impl ForwardPricesResponse {
343    /// Creates a new [`ForwardPricesResponse`] instance.
344    pub fn new(
345        correlation_id: UUID4,
346        client_id: ClientId,
347        venue: Venue,
348        data: Vec<ForwardPrice>,
349        ts_init: UnixNanos,
350        params: Option<Params>,
351    ) -> Self {
352        Self {
353            correlation_id,
354            client_id,
355            venue,
356            data,
357            ts_init,
358            params,
359        }
360    }
361}
362
363#[derive(Clone, Debug)]
364pub struct BarsResponse {
365    pub correlation_id: UUID4,
366    pub client_id: ClientId,
367    pub bar_type: BarType,
368    pub data: Vec<Bar>,
369    pub ts_init: UnixNanos,
370    pub start: Option<UnixNanos>,
371    pub end: Option<UnixNanos>,
372    pub params: Option<Params>,
373}
374
375impl BarsResponse {
376    /// Converts to a dyn Any trait object for messaging.
377    pub fn as_any(&self) -> &dyn Any {
378        self
379    }
380
381    /// Creates a new [`BarsResponse`] instance.
382    #[expect(clippy::too_many_arguments)]
383    pub fn new(
384        correlation_id: UUID4,
385        client_id: ClientId,
386        bar_type: BarType,
387        data: Vec<Bar>,
388        start: Option<UnixNanos>,
389        end: Option<UnixNanos>,
390        ts_init: UnixNanos,
391        params: Option<Params>,
392    ) -> Self {
393        Self {
394            correlation_id,
395            client_id,
396            bar_type,
397            data,
398            ts_init,
399            start,
400            end,
401            params,
402        }
403    }
404}