nautilus_common/messages/data/
response.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
16use std::{any::Any, sync::Arc};
17
18use indexmap::IndexMap;
19use nautilus_core::{UUID4, UnixNanos};
20use nautilus_model::{
21    data::{Bar, BarType, DataType, QuoteTick, TradeTick},
22    identifiers::{ClientId, InstrumentId, Venue},
23    instruments::InstrumentAny,
24    orderbook::OrderBook,
25};
26
27use super::Payload;
28
29#[derive(Clone, Debug)]
30pub struct CustomDataResponse {
31    pub correlation_id: UUID4,
32    pub client_id: ClientId,
33    pub venue: Option<Venue>,
34    pub data_type: DataType,
35    pub data: Payload,
36    pub ts_init: UnixNanos,
37    pub params: Option<IndexMap<String, String>>,
38}
39
40impl CustomDataResponse {
41    /// Creates a new [`CustomDataResponse`] instance.
42    pub fn new<T: Any + Send + Sync>(
43        correlation_id: UUID4,
44        client_id: ClientId,
45        venue: Option<Venue>,
46        data_type: DataType,
47        data: T,
48        ts_init: UnixNanos,
49        params: Option<IndexMap<String, String>>,
50    ) -> Self {
51        Self {
52            correlation_id,
53            client_id,
54            venue,
55            data_type,
56            data: Arc::new(data),
57            ts_init,
58            params,
59        }
60    }
61
62    /// Converts the response to a dyn Any trait object for messaging.
63    pub fn as_any(&self) -> &dyn Any {
64        self
65    }
66}
67
68#[derive(Clone, Debug)]
69pub struct InstrumentResponse {
70    pub correlation_id: UUID4,
71    pub client_id: ClientId,
72    pub instrument_id: InstrumentId,
73    pub data: InstrumentAny,
74    pub ts_init: UnixNanos,
75    pub params: Option<IndexMap<String, String>>,
76}
77
78impl InstrumentResponse {
79    /// Converts to a dyn Any trait object for messaging.
80    pub fn as_any(&self) -> &dyn Any {
81        self
82    }
83
84    /// Creates a new [`InstrumentResponse`] instance.
85    pub fn new(
86        correlation_id: UUID4,
87        client_id: ClientId,
88        instrument_id: InstrumentId,
89        data: InstrumentAny,
90        ts_init: UnixNanos,
91        params: Option<IndexMap<String, String>>,
92    ) -> Self {
93        Self {
94            correlation_id,
95            client_id,
96            instrument_id,
97            data,
98            ts_init,
99            params,
100        }
101    }
102}
103
104#[derive(Clone, Debug)]
105pub struct InstrumentsResponse {
106    pub correlation_id: UUID4,
107    pub client_id: ClientId,
108    pub venue: Venue,
109    pub data: Vec<InstrumentAny>,
110    pub ts_init: UnixNanos,
111    pub params: Option<IndexMap<String, String>>,
112}
113
114impl InstrumentsResponse {
115    /// Converts to a dyn Any trait object for messaging.
116    pub fn as_any(&self) -> &dyn Any {
117        self
118    }
119
120    /// Creates a new [`InstrumentsResponse`] instance.
121    pub fn new(
122        correlation_id: UUID4,
123        client_id: ClientId,
124        venue: Venue,
125        data: Vec<InstrumentAny>,
126        ts_init: UnixNanos,
127        params: Option<IndexMap<String, String>>,
128    ) -> Self {
129        Self {
130            correlation_id,
131            client_id,
132            venue,
133            data,
134            ts_init,
135            params,
136        }
137    }
138}
139
140#[derive(Clone, Debug)]
141pub struct BookResponse {
142    pub correlation_id: UUID4,
143    pub client_id: ClientId,
144    pub instrument_id: InstrumentId,
145    pub data: OrderBook,
146    pub ts_init: UnixNanos,
147    pub params: Option<IndexMap<String, String>>,
148}
149
150impl BookResponse {
151    /// Converts to a dyn Any trait object for messaging.
152    pub fn as_any(&self) -> &dyn Any {
153        self
154    }
155
156    /// Creates a new [`BookResponse`] instance.
157    pub fn new(
158        correlation_id: UUID4,
159        client_id: ClientId,
160        instrument_id: InstrumentId,
161        data: OrderBook,
162        ts_init: UnixNanos,
163        params: Option<IndexMap<String, String>>,
164    ) -> Self {
165        Self {
166            correlation_id,
167            client_id,
168            instrument_id,
169            data,
170            ts_init,
171            params,
172        }
173    }
174}
175
176#[derive(Clone, Debug)]
177pub struct QuotesResponse {
178    pub correlation_id: UUID4,
179    pub client_id: ClientId,
180    pub instrument_id: InstrumentId,
181    pub data: Vec<QuoteTick>,
182    pub ts_init: UnixNanos,
183    pub params: Option<IndexMap<String, String>>,
184}
185
186impl QuotesResponse {
187    /// Converts to a dyn Any trait object for messaging.
188    pub fn as_any(&self) -> &dyn Any {
189        self
190    }
191
192    /// Creates a new [`QuotesResponse`] instance.
193    pub fn new(
194        correlation_id: UUID4,
195        client_id: ClientId,
196        instrument_id: InstrumentId,
197        data: Vec<QuoteTick>,
198        ts_init: UnixNanos,
199        params: Option<IndexMap<String, String>>,
200    ) -> Self {
201        Self {
202            correlation_id,
203            client_id,
204            instrument_id,
205            data,
206            ts_init,
207            params,
208        }
209    }
210}
211
212#[derive(Clone, Debug)]
213pub struct TradesResponse {
214    pub correlation_id: UUID4,
215    pub client_id: ClientId,
216    pub instrument_id: InstrumentId,
217    pub data: Vec<TradeTick>,
218    pub ts_init: UnixNanos,
219    pub params: Option<IndexMap<String, String>>,
220}
221
222impl TradesResponse {
223    /// Converts to a dyn Any trait object for messaging.
224    pub fn as_any(&self) -> &dyn Any {
225        self
226    }
227
228    /// Creates a new [`TradesResponse`] instance.
229    pub fn new(
230        correlation_id: UUID4,
231        client_id: ClientId,
232        instrument_id: InstrumentId,
233        data: Vec<TradeTick>,
234        ts_init: UnixNanos,
235        params: Option<IndexMap<String, String>>,
236    ) -> Self {
237        Self {
238            correlation_id,
239            client_id,
240            instrument_id,
241            data,
242            ts_init,
243            params,
244        }
245    }
246}
247
248#[derive(Clone, Debug)]
249pub struct BarsResponse {
250    pub correlation_id: UUID4,
251    pub client_id: ClientId,
252    pub bar_type: BarType,
253    pub data: Vec<Bar>,
254    pub ts_init: UnixNanos,
255    pub params: Option<IndexMap<String, String>>,
256}
257
258impl BarsResponse {
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 [`BarsResponse`] instance.
265    pub fn new(
266        correlation_id: UUID4,
267        client_id: ClientId,
268        bar_type: BarType,
269        data: Vec<Bar>,
270        ts_init: UnixNanos,
271        params: Option<IndexMap<String, String>>,
272    ) -> Self {
273        Self {
274            correlation_id,
275            client_id,
276            bar_type,
277            data,
278            ts_init,
279            params,
280        }
281    }
282}