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