nautilus_common/messages/data/
subscribe.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::num::NonZeroUsize;
17
18use indexmap::IndexMap;
19use nautilus_core::{UUID4, UnixNanos};
20use nautilus_model::{
21    data::{BarType, DataType},
22    enums::BookType,
23    identifiers::{ClientId, InstrumentId, Venue},
24};
25
26use super::check_client_id_or_venue;
27
28#[derive(Clone, Debug)]
29pub struct SubscribeCustomData {
30    pub client_id: Option<ClientId>,
31    pub venue: Option<Venue>,
32    pub data_type: DataType,
33    pub command_id: UUID4,
34    pub ts_init: UnixNanos,
35    pub correlation_id: Option<UUID4>,
36    pub params: Option<IndexMap<String, String>>,
37}
38
39impl SubscribeCustomData {
40    /// Creates a new [`SubscribeCustomData`] instance.
41    #[allow(clippy::too_many_arguments)]
42    pub fn new(
43        client_id: Option<ClientId>,
44        venue: Option<Venue>,
45        data_type: DataType,
46        command_id: UUID4,
47        ts_init: UnixNanos,
48        correlation_id: Option<UUID4>,
49        params: Option<IndexMap<String, String>>,
50    ) -> Self {
51        check_client_id_or_venue(&client_id, &venue);
52        Self {
53            client_id,
54            venue,
55            data_type,
56            command_id,
57            ts_init,
58            correlation_id,
59            params,
60        }
61    }
62}
63
64#[derive(Clone, Debug)]
65pub struct SubscribeInstrument {
66    pub instrument_id: InstrumentId,
67    pub client_id: Option<ClientId>,
68    pub venue: Option<Venue>,
69    pub command_id: UUID4,
70    pub ts_init: UnixNanos,
71    pub correlation_id: Option<UUID4>,
72    pub params: Option<IndexMap<String, String>>,
73}
74
75impl SubscribeInstrument {
76    /// Creates a new [`SubscribeInstrument`] instance.
77    #[allow(clippy::too_many_arguments)]
78    pub fn new(
79        instrument_id: InstrumentId,
80        client_id: Option<ClientId>,
81        venue: Option<Venue>,
82        command_id: UUID4,
83        ts_init: UnixNanos,
84        correlation_id: Option<UUID4>,
85        params: Option<IndexMap<String, String>>,
86    ) -> Self {
87        check_client_id_or_venue(&client_id, &venue);
88        Self {
89            instrument_id,
90            client_id,
91            venue,
92            command_id,
93            ts_init,
94            correlation_id,
95            params,
96        }
97    }
98}
99
100#[derive(Clone, Debug)]
101pub struct SubscribeInstruments {
102    pub client_id: Option<ClientId>,
103    pub venue: Venue,
104    pub command_id: UUID4,
105    pub ts_init: UnixNanos,
106    pub correlation_id: Option<UUID4>,
107    pub params: Option<IndexMap<String, String>>,
108}
109
110impl SubscribeInstruments {
111    /// Creates a new [`SubscribeInstruments`] instance.
112    pub fn new(
113        client_id: Option<ClientId>,
114        venue: Venue,
115        command_id: UUID4,
116        ts_init: UnixNanos,
117        correlation_id: Option<UUID4>,
118        params: Option<IndexMap<String, String>>,
119    ) -> Self {
120        Self {
121            client_id,
122            venue,
123            command_id,
124            ts_init,
125            correlation_id,
126            params,
127        }
128    }
129}
130
131#[derive(Clone, Debug)]
132pub struct SubscribeBookDeltas {
133    pub instrument_id: InstrumentId,
134    pub book_type: BookType,
135    pub client_id: Option<ClientId>,
136    pub venue: Option<Venue>,
137    pub command_id: UUID4,
138    pub ts_init: UnixNanos,
139    pub depth: Option<NonZeroUsize>,
140    pub managed: bool,
141    pub correlation_id: Option<UUID4>,
142    pub params: Option<IndexMap<String, String>>,
143}
144
145impl SubscribeBookDeltas {
146    /// Creates a new [`SubscribeBookDeltas`] instance.
147    #[allow(clippy::too_many_arguments)]
148    pub fn new(
149        instrument_id: InstrumentId,
150        book_type: BookType,
151        client_id: Option<ClientId>,
152        venue: Option<Venue>,
153        command_id: UUID4,
154        ts_init: UnixNanos,
155        depth: Option<NonZeroUsize>,
156        managed: bool,
157        correlation_id: Option<UUID4>,
158        params: Option<IndexMap<String, String>>,
159    ) -> Self {
160        check_client_id_or_venue(&client_id, &venue);
161        Self {
162            instrument_id,
163            book_type,
164            client_id,
165            venue,
166            command_id,
167            ts_init,
168            depth,
169            managed,
170            correlation_id,
171            params,
172        }
173    }
174}
175
176#[derive(Clone, Debug)]
177pub struct SubscribeBookDepth10 {
178    pub instrument_id: InstrumentId,
179    pub book_type: BookType,
180    pub client_id: Option<ClientId>,
181    pub venue: Option<Venue>,
182    pub command_id: UUID4,
183    pub ts_init: UnixNanos,
184    pub depth: Option<NonZeroUsize>,
185    pub managed: bool,
186    pub correlation_id: Option<UUID4>,
187    pub params: Option<IndexMap<String, String>>,
188}
189
190impl SubscribeBookDepth10 {
191    /// Creates a new [`SubscribeBookDepth10`] instance.
192    #[allow(clippy::too_many_arguments)]
193    pub fn new(
194        instrument_id: InstrumentId,
195        book_type: BookType,
196        client_id: Option<ClientId>,
197        venue: Option<Venue>,
198        command_id: UUID4,
199        ts_init: UnixNanos,
200        depth: Option<NonZeroUsize>,
201        managed: bool,
202        correlation_id: Option<UUID4>,
203        params: Option<IndexMap<String, String>>,
204    ) -> Self {
205        check_client_id_or_venue(&client_id, &venue);
206        Self {
207            instrument_id,
208            book_type,
209            client_id,
210            venue,
211            command_id,
212            ts_init,
213            depth,
214            managed,
215            correlation_id,
216            params,
217        }
218    }
219}
220
221#[derive(Clone, Debug)]
222pub struct SubscribeBookSnapshots {
223    pub instrument_id: InstrumentId,
224    pub book_type: BookType,
225    pub client_id: Option<ClientId>,
226    pub venue: Option<Venue>,
227    pub command_id: UUID4,
228    pub ts_init: UnixNanos,
229    pub depth: Option<NonZeroUsize>,
230    pub interval_ms: NonZeroUsize,
231    pub correlation_id: Option<UUID4>,
232    pub params: Option<IndexMap<String, String>>,
233}
234
235impl SubscribeBookSnapshots {
236    /// Creates a new [`SubscribeBookSnapshots`] instance.
237    #[allow(clippy::too_many_arguments)]
238    pub fn new(
239        instrument_id: InstrumentId,
240        book_type: BookType,
241        client_id: Option<ClientId>,
242        venue: Option<Venue>,
243        command_id: UUID4,
244        ts_init: UnixNanos,
245        depth: Option<NonZeroUsize>,
246        interval_ms: NonZeroUsize,
247        correlation_id: Option<UUID4>,
248        params: Option<IndexMap<String, String>>,
249    ) -> Self {
250        check_client_id_or_venue(&client_id, &venue);
251        Self {
252            instrument_id,
253            book_type,
254            client_id,
255            venue,
256            command_id,
257            ts_init,
258            depth,
259            interval_ms,
260            correlation_id,
261            params,
262        }
263    }
264}
265
266#[derive(Clone, Debug)]
267pub struct SubscribeQuotes {
268    pub instrument_id: InstrumentId,
269    pub client_id: Option<ClientId>,
270    pub venue: Option<Venue>,
271    pub command_id: UUID4,
272    pub ts_init: UnixNanos,
273    pub correlation_id: Option<UUID4>,
274    pub params: Option<IndexMap<String, String>>,
275}
276
277impl SubscribeQuotes {
278    /// Creates a new [`SubscribeQuotes`] instance.
279    #[allow(clippy::too_many_arguments)]
280    pub fn new(
281        instrument_id: InstrumentId,
282        client_id: Option<ClientId>,
283        venue: Option<Venue>,
284        command_id: UUID4,
285        ts_init: UnixNanos,
286        correlation_id: Option<UUID4>,
287        params: Option<IndexMap<String, String>>,
288    ) -> Self {
289        check_client_id_or_venue(&client_id, &venue);
290        Self {
291            instrument_id,
292            client_id,
293            venue,
294            command_id,
295            ts_init,
296            correlation_id,
297            params,
298        }
299    }
300}
301
302#[derive(Clone, Debug)]
303pub struct SubscribeTrades {
304    pub instrument_id: InstrumentId,
305    pub client_id: Option<ClientId>,
306    pub venue: Option<Venue>,
307    pub command_id: UUID4,
308    pub ts_init: UnixNanos,
309    pub correlation_id: Option<UUID4>,
310    pub params: Option<IndexMap<String, String>>,
311}
312
313impl SubscribeTrades {
314    /// Creates a new [`SubscribeTrades`] instance.
315    #[allow(clippy::too_many_arguments)]
316    pub fn new(
317        instrument_id: InstrumentId,
318        client_id: Option<ClientId>,
319        venue: Option<Venue>,
320        command_id: UUID4,
321        ts_init: UnixNanos,
322        correlation_id: Option<UUID4>,
323        params: Option<IndexMap<String, String>>,
324    ) -> Self {
325        check_client_id_or_venue(&client_id, &venue);
326        Self {
327            instrument_id,
328            client_id,
329            venue,
330            command_id,
331            ts_init,
332            correlation_id,
333            params,
334        }
335    }
336}
337
338#[derive(Clone, Debug)]
339pub struct SubscribeBars {
340    pub bar_type: BarType,
341    pub client_id: Option<ClientId>,
342    pub venue: Option<Venue>,
343    pub command_id: UUID4,
344    pub ts_init: UnixNanos,
345    pub correlation_id: Option<UUID4>,
346    pub params: Option<IndexMap<String, String>>,
347}
348
349impl SubscribeBars {
350    /// Creates a new [`SubscribeBars`] instance.
351    #[allow(clippy::too_many_arguments)]
352    pub fn new(
353        bar_type: BarType,
354        client_id: Option<ClientId>,
355        venue: Option<Venue>,
356        command_id: UUID4,
357        ts_init: UnixNanos,
358        correlation_id: Option<UUID4>,
359        params: Option<IndexMap<String, String>>,
360    ) -> Self {
361        check_client_id_or_venue(&client_id, &venue);
362        Self {
363            bar_type,
364            client_id,
365            venue,
366            command_id,
367            ts_init,
368            correlation_id,
369            params,
370        }
371    }
372}
373
374#[derive(Clone, Debug)]
375pub struct SubscribeMarkPrices {
376    pub instrument_id: InstrumentId,
377    pub client_id: Option<ClientId>,
378    pub venue: Option<Venue>,
379    pub command_id: UUID4,
380    pub ts_init: UnixNanos,
381    pub correlation_id: Option<UUID4>,
382    pub params: Option<IndexMap<String, String>>,
383}
384
385impl SubscribeMarkPrices {
386    /// Creates a new [`SubscribeMarkPrices`] instance.
387    #[allow(clippy::too_many_arguments)]
388    pub fn new(
389        instrument_id: InstrumentId,
390        client_id: Option<ClientId>,
391        venue: Option<Venue>,
392        command_id: UUID4,
393        ts_init: UnixNanos,
394        correlation_id: Option<UUID4>,
395        params: Option<IndexMap<String, String>>,
396    ) -> Self {
397        check_client_id_or_venue(&client_id, &venue);
398        Self {
399            instrument_id,
400            client_id,
401            venue,
402            command_id,
403            ts_init,
404            correlation_id,
405            params,
406        }
407    }
408}
409
410#[derive(Clone, Debug)]
411pub struct SubscribeIndexPrices {
412    pub instrument_id: InstrumentId,
413    pub client_id: Option<ClientId>,
414    pub venue: Option<Venue>,
415    pub command_id: UUID4,
416    pub ts_init: UnixNanos,
417    pub correlation_id: Option<UUID4>,
418    pub params: Option<IndexMap<String, String>>,
419}
420
421impl SubscribeIndexPrices {
422    /// Creates a new [`SubscribeIndexPrices`] instance.
423    #[allow(clippy::too_many_arguments)]
424    pub fn new(
425        instrument_id: InstrumentId,
426        client_id: Option<ClientId>,
427        venue: Option<Venue>,
428        command_id: UUID4,
429        ts_init: UnixNanos,
430        correlation_id: Option<UUID4>,
431        params: Option<IndexMap<String, String>>,
432    ) -> Self {
433        check_client_id_or_venue(&client_id, &venue);
434        Self {
435            instrument_id,
436            client_id,
437            venue,
438            command_id,
439            ts_init,
440            correlation_id,
441            params,
442        }
443    }
444}
445
446#[derive(Clone, Debug)]
447pub struct SubscribeFundingRates {
448    pub instrument_id: InstrumentId,
449    pub client_id: Option<ClientId>,
450    pub venue: Option<Venue>,
451    pub command_id: UUID4,
452    pub ts_init: UnixNanos,
453    pub correlation_id: Option<UUID4>,
454    pub params: Option<IndexMap<String, String>>,
455}
456
457impl SubscribeFundingRates {
458    /// Creates a new [`SubscribeFundingRates`] instance.
459    #[allow(clippy::too_many_arguments)]
460    pub fn new(
461        instrument_id: InstrumentId,
462        client_id: Option<ClientId>,
463        venue: Option<Venue>,
464        command_id: UUID4,
465        ts_init: UnixNanos,
466        correlation_id: Option<UUID4>,
467        params: Option<IndexMap<String, String>>,
468    ) -> Self {
469        check_client_id_or_venue(&client_id, &venue);
470        Self {
471            instrument_id,
472            client_id,
473            venue,
474            command_id,
475            ts_init,
476            correlation_id,
477            params,
478        }
479    }
480}
481
482#[derive(Clone, Debug)]
483pub struct SubscribeInstrumentStatus {
484    pub instrument_id: InstrumentId,
485    pub client_id: Option<ClientId>,
486    pub venue: Option<Venue>,
487    pub command_id: UUID4,
488    pub ts_init: UnixNanos,
489    pub correlation_id: Option<UUID4>,
490    pub params: Option<IndexMap<String, String>>,
491}
492
493impl SubscribeInstrumentStatus {
494    /// Creates a new [`SubscribeInstrumentStatus`] instance.
495    #[allow(clippy::too_many_arguments)]
496    pub fn new(
497        instrument_id: InstrumentId,
498        client_id: Option<ClientId>,
499        venue: Option<Venue>,
500        command_id: UUID4,
501        ts_init: UnixNanos,
502        correlation_id: Option<UUID4>,
503        params: Option<IndexMap<String, String>>,
504    ) -> Self {
505        check_client_id_or_venue(&client_id, &venue);
506        Self {
507            instrument_id,
508            client_id,
509            venue,
510            command_id,
511            ts_init,
512            correlation_id,
513            params,
514        }
515    }
516}
517
518#[derive(Clone, Debug)]
519pub struct SubscribeInstrumentClose {
520    pub instrument_id: InstrumentId,
521    pub client_id: Option<ClientId>,
522    pub venue: Option<Venue>,
523    pub command_id: UUID4,
524    pub ts_init: UnixNanos,
525    pub correlation_id: Option<UUID4>,
526    pub params: Option<IndexMap<String, String>>,
527}
528
529impl SubscribeInstrumentClose {
530    /// Creates a new [`SubscribeInstrumentClose`] instance.
531    #[allow(clippy::too_many_arguments)]
532    pub fn new(
533        instrument_id: InstrumentId,
534        client_id: Option<ClientId>,
535        venue: Option<Venue>,
536        command_id: UUID4,
537        ts_init: UnixNanos,
538        correlation_id: Option<UUID4>,
539        params: Option<IndexMap<String, String>>,
540    ) -> Self {
541        check_client_id_or_venue(&client_id, &venue);
542        Self {
543            instrument_id,
544            client_id,
545            venue,
546            command_id,
547            ts_init,
548            correlation_id,
549            params,
550        }
551    }
552}