Skip to main content

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 nautilus_core::{Params, UUID4, UnixNanos};
19use nautilus_model::{
20    data::{BarType, DataType, option_chain::StrikeRange},
21    enums::BookType,
22    identifiers::{ClientId, InstrumentId, OptionSeriesId, Venue},
23};
24use serde::{Deserialize, Serialize};
25
26use super::check_client_id_or_venue;
27
28#[derive(Clone, Debug, Serialize, Deserialize)]
29#[cfg_attr(
30    feature = "python",
31    pyo3::pyclass(module = "nautilus_trader.live", frozen, skip_from_py_object)
32)]
33#[cfg_attr(
34    feature = "python",
35    pyo3_stub_gen::derive::gen_stub_pyclass(module = "nautilus_trader.live")
36)]
37pub struct SubscribeCustomData {
38    pub client_id: Option<ClientId>,
39    pub venue: Option<Venue>,
40    pub data_type: DataType,
41    pub command_id: UUID4,
42    pub ts_init: UnixNanos,
43    pub correlation_id: Option<UUID4>,
44    pub params: Option<Params>,
45}
46
47impl SubscribeCustomData {
48    /// Creates a new [`SubscribeCustomData`] instance.
49    pub fn new(
50        client_id: Option<ClientId>,
51        venue: Option<Venue>,
52        data_type: DataType,
53        command_id: UUID4,
54        ts_init: UnixNanos,
55        correlation_id: Option<UUID4>,
56        params: Option<Params>,
57    ) -> Self {
58        check_client_id_or_venue(&client_id, &venue);
59        Self {
60            client_id,
61            venue,
62            data_type,
63            command_id,
64            ts_init,
65            correlation_id,
66            params,
67        }
68    }
69}
70
71#[derive(Clone, Debug, Serialize, Deserialize)]
72#[cfg_attr(
73    feature = "python",
74    pyo3::pyclass(module = "nautilus_trader.live", frozen, skip_from_py_object)
75)]
76#[cfg_attr(
77    feature = "python",
78    pyo3_stub_gen::derive::gen_stub_pyclass(module = "nautilus_trader.live")
79)]
80pub struct SubscribeInstrument {
81    pub instrument_id: InstrumentId,
82    pub client_id: Option<ClientId>,
83    pub venue: Option<Venue>,
84    pub command_id: UUID4,
85    pub ts_init: UnixNanos,
86    pub correlation_id: Option<UUID4>,
87    pub params: Option<Params>,
88}
89
90impl SubscribeInstrument {
91    /// Creates a new [`SubscribeInstrument`] instance.
92    pub fn new(
93        instrument_id: InstrumentId,
94        client_id: Option<ClientId>,
95        venue: Option<Venue>,
96        command_id: UUID4,
97        ts_init: UnixNanos,
98        correlation_id: Option<UUID4>,
99        params: Option<Params>,
100    ) -> Self {
101        check_client_id_or_venue(&client_id, &venue);
102        Self {
103            instrument_id,
104            client_id,
105            venue,
106            command_id,
107            ts_init,
108            correlation_id,
109            params,
110        }
111    }
112}
113
114#[derive(Clone, Debug, Serialize, Deserialize)]
115#[cfg_attr(
116    feature = "python",
117    pyo3::pyclass(module = "nautilus_trader.live", frozen, skip_from_py_object)
118)]
119#[cfg_attr(
120    feature = "python",
121    pyo3_stub_gen::derive::gen_stub_pyclass(module = "nautilus_trader.live")
122)]
123pub struct SubscribeInstruments {
124    pub client_id: Option<ClientId>,
125    pub venue: Venue,
126    pub command_id: UUID4,
127    pub ts_init: UnixNanos,
128    pub correlation_id: Option<UUID4>,
129    pub params: Option<Params>,
130}
131
132impl SubscribeInstruments {
133    /// Creates a new [`SubscribeInstruments`] instance.
134    pub fn new(
135        client_id: Option<ClientId>,
136        venue: Venue,
137        command_id: UUID4,
138        ts_init: UnixNanos,
139        correlation_id: Option<UUID4>,
140        params: Option<Params>,
141    ) -> Self {
142        Self {
143            client_id,
144            venue,
145            command_id,
146            ts_init,
147            correlation_id,
148            params,
149        }
150    }
151}
152
153#[derive(Clone, Debug, Serialize, Deserialize)]
154#[cfg_attr(
155    feature = "python",
156    pyo3::pyclass(module = "nautilus_trader.live", frozen, skip_from_py_object)
157)]
158#[cfg_attr(
159    feature = "python",
160    pyo3_stub_gen::derive::gen_stub_pyclass(module = "nautilus_trader.live")
161)]
162pub struct SubscribeBookDeltas {
163    pub instrument_id: InstrumentId,
164    pub book_type: BookType,
165    pub client_id: Option<ClientId>,
166    pub venue: Option<Venue>,
167    pub command_id: UUID4,
168    pub ts_init: UnixNanos,
169    pub depth: Option<NonZeroUsize>,
170    pub managed: bool,
171    pub correlation_id: Option<UUID4>,
172    pub params: Option<Params>,
173}
174
175impl SubscribeBookDeltas {
176    /// Creates a new [`SubscribeBookDeltas`] instance.
177    #[expect(clippy::too_many_arguments)]
178    pub fn new(
179        instrument_id: InstrumentId,
180        book_type: BookType,
181        client_id: Option<ClientId>,
182        venue: Option<Venue>,
183        command_id: UUID4,
184        ts_init: UnixNanos,
185        depth: Option<NonZeroUsize>,
186        managed: bool,
187        correlation_id: Option<UUID4>,
188        params: Option<Params>,
189    ) -> Self {
190        check_client_id_or_venue(&client_id, &venue);
191        Self {
192            instrument_id,
193            book_type,
194            client_id,
195            venue,
196            command_id,
197            ts_init,
198            depth,
199            managed,
200            correlation_id,
201            params,
202        }
203    }
204}
205
206#[derive(Clone, Debug, Serialize, Deserialize)]
207#[cfg_attr(
208    feature = "python",
209    pyo3::pyclass(module = "nautilus_trader.live", frozen, skip_from_py_object)
210)]
211#[cfg_attr(
212    feature = "python",
213    pyo3_stub_gen::derive::gen_stub_pyclass(module = "nautilus_trader.live")
214)]
215pub struct SubscribeBookDepth {
216    pub instrument_id: InstrumentId,
217    pub book_type: BookType,
218    pub client_id: Option<ClientId>,
219    pub venue: Option<Venue>,
220    pub command_id: UUID4,
221    pub ts_init: UnixNanos,
222    pub depth: Option<NonZeroUsize>,
223    pub managed: bool,
224    pub correlation_id: Option<UUID4>,
225    pub params: Option<Params>,
226}
227
228impl SubscribeBookDepth {
229    /// Creates a new [`SubscribeBookDepth`] instance.
230    #[expect(clippy::too_many_arguments)]
231    pub fn new(
232        instrument_id: InstrumentId,
233        book_type: BookType,
234        client_id: Option<ClientId>,
235        venue: Option<Venue>,
236        command_id: UUID4,
237        ts_init: UnixNanos,
238        depth: Option<NonZeroUsize>,
239        managed: bool,
240        correlation_id: Option<UUID4>,
241        params: Option<Params>,
242    ) -> Self {
243        check_client_id_or_venue(&client_id, &venue);
244        Self {
245            instrument_id,
246            book_type,
247            client_id,
248            venue,
249            command_id,
250            ts_init,
251            depth,
252            managed,
253            correlation_id,
254            params,
255        }
256    }
257}
258
259#[derive(Clone, Debug, Serialize, Deserialize)]
260pub struct SubscribeBookSnapshots {
261    pub instrument_id: InstrumentId,
262    pub book_type: BookType,
263    pub client_id: Option<ClientId>,
264    pub venue: Option<Venue>,
265    pub command_id: UUID4,
266    pub ts_init: UnixNanos,
267    pub depth: Option<NonZeroUsize>,
268    pub interval_ms: NonZeroUsize,
269    pub correlation_id: Option<UUID4>,
270    pub params: Option<Params>,
271}
272
273impl SubscribeBookSnapshots {
274    /// Creates a new [`SubscribeBookSnapshots`] instance.
275    #[expect(clippy::too_many_arguments)]
276    pub fn new(
277        instrument_id: InstrumentId,
278        book_type: BookType,
279        client_id: Option<ClientId>,
280        venue: Option<Venue>,
281        command_id: UUID4,
282        ts_init: UnixNanos,
283        depth: Option<NonZeroUsize>,
284        interval_ms: NonZeroUsize,
285        correlation_id: Option<UUID4>,
286        params: Option<Params>,
287    ) -> Self {
288        check_client_id_or_venue(&client_id, &venue);
289        Self {
290            instrument_id,
291            book_type,
292            client_id,
293            venue,
294            command_id,
295            ts_init,
296            depth,
297            interval_ms,
298            correlation_id,
299            params,
300        }
301    }
302}
303
304#[derive(Clone, Debug, Serialize, Deserialize)]
305#[cfg_attr(
306    feature = "python",
307    pyo3::pyclass(module = "nautilus_trader.live", frozen, skip_from_py_object)
308)]
309#[cfg_attr(
310    feature = "python",
311    pyo3_stub_gen::derive::gen_stub_pyclass(module = "nautilus_trader.live")
312)]
313pub struct SubscribeQuotes {
314    pub instrument_id: InstrumentId,
315    pub client_id: Option<ClientId>,
316    pub venue: Option<Venue>,
317    pub command_id: UUID4,
318    pub ts_init: UnixNanos,
319    pub correlation_id: Option<UUID4>,
320    pub params: Option<Params>,
321}
322
323impl SubscribeQuotes {
324    /// Creates a new [`SubscribeQuotes`] instance.
325    pub fn new(
326        instrument_id: InstrumentId,
327        client_id: Option<ClientId>,
328        venue: Option<Venue>,
329        command_id: UUID4,
330        ts_init: UnixNanos,
331        correlation_id: Option<UUID4>,
332        params: Option<Params>,
333    ) -> Self {
334        check_client_id_or_venue(&client_id, &venue);
335        Self {
336            instrument_id,
337            client_id,
338            venue,
339            command_id,
340            ts_init,
341            correlation_id,
342            params,
343        }
344    }
345}
346
347#[derive(Clone, Debug, Serialize, Deserialize)]
348#[cfg_attr(
349    feature = "python",
350    pyo3::pyclass(module = "nautilus_trader.live", frozen, skip_from_py_object)
351)]
352#[cfg_attr(
353    feature = "python",
354    pyo3_stub_gen::derive::gen_stub_pyclass(module = "nautilus_trader.live")
355)]
356pub struct SubscribeTrades {
357    pub instrument_id: InstrumentId,
358    pub client_id: Option<ClientId>,
359    pub venue: Option<Venue>,
360    pub command_id: UUID4,
361    pub ts_init: UnixNanos,
362    pub correlation_id: Option<UUID4>,
363    pub params: Option<Params>,
364}
365
366impl SubscribeTrades {
367    /// Creates a new [`SubscribeTrades`] instance.
368    pub fn new(
369        instrument_id: InstrumentId,
370        client_id: Option<ClientId>,
371        venue: Option<Venue>,
372        command_id: UUID4,
373        ts_init: UnixNanos,
374        correlation_id: Option<UUID4>,
375        params: Option<Params>,
376    ) -> Self {
377        check_client_id_or_venue(&client_id, &venue);
378        Self {
379            instrument_id,
380            client_id,
381            venue,
382            command_id,
383            ts_init,
384            correlation_id,
385            params,
386        }
387    }
388}
389
390#[derive(Clone, Debug, Serialize, Deserialize)]
391#[cfg_attr(
392    feature = "python",
393    pyo3::pyclass(module = "nautilus_trader.live", frozen, skip_from_py_object)
394)]
395#[cfg_attr(
396    feature = "python",
397    pyo3_stub_gen::derive::gen_stub_pyclass(module = "nautilus_trader.live")
398)]
399pub struct SubscribeBars {
400    pub bar_type: BarType,
401    pub client_id: Option<ClientId>,
402    pub venue: Option<Venue>,
403    pub command_id: UUID4,
404    pub ts_init: UnixNanos,
405    pub correlation_id: Option<UUID4>,
406    pub params: Option<Params>,
407}
408
409impl SubscribeBars {
410    /// Creates a new [`SubscribeBars`] instance.
411    pub fn new(
412        bar_type: BarType,
413        client_id: Option<ClientId>,
414        venue: Option<Venue>,
415        command_id: UUID4,
416        ts_init: UnixNanos,
417        correlation_id: Option<UUID4>,
418        params: Option<Params>,
419    ) -> Self {
420        check_client_id_or_venue(&client_id, &venue);
421        Self {
422            bar_type,
423            client_id,
424            venue,
425            command_id,
426            ts_init,
427            correlation_id,
428            params,
429        }
430    }
431}
432
433#[derive(Clone, Debug, Serialize, Deserialize)]
434#[cfg_attr(
435    feature = "python",
436    pyo3::pyclass(module = "nautilus_trader.live", frozen, skip_from_py_object)
437)]
438#[cfg_attr(
439    feature = "python",
440    pyo3_stub_gen::derive::gen_stub_pyclass(module = "nautilus_trader.live")
441)]
442pub struct SubscribeMarkPrices {
443    pub instrument_id: InstrumentId,
444    pub client_id: Option<ClientId>,
445    pub venue: Option<Venue>,
446    pub command_id: UUID4,
447    pub ts_init: UnixNanos,
448    pub correlation_id: Option<UUID4>,
449    pub params: Option<Params>,
450}
451
452impl SubscribeMarkPrices {
453    /// Creates a new [`SubscribeMarkPrices`] instance.
454    pub fn new(
455        instrument_id: InstrumentId,
456        client_id: Option<ClientId>,
457        venue: Option<Venue>,
458        command_id: UUID4,
459        ts_init: UnixNanos,
460        correlation_id: Option<UUID4>,
461        params: Option<Params>,
462    ) -> Self {
463        check_client_id_or_venue(&client_id, &venue);
464        Self {
465            instrument_id,
466            client_id,
467            venue,
468            command_id,
469            ts_init,
470            correlation_id,
471            params,
472        }
473    }
474}
475
476#[derive(Clone, Debug, Serialize, Deserialize)]
477#[cfg_attr(
478    feature = "python",
479    pyo3::pyclass(module = "nautilus_trader.live", frozen, skip_from_py_object)
480)]
481#[cfg_attr(
482    feature = "python",
483    pyo3_stub_gen::derive::gen_stub_pyclass(module = "nautilus_trader.live")
484)]
485pub struct SubscribeIndexPrices {
486    pub instrument_id: InstrumentId,
487    pub client_id: Option<ClientId>,
488    pub venue: Option<Venue>,
489    pub command_id: UUID4,
490    pub ts_init: UnixNanos,
491    pub correlation_id: Option<UUID4>,
492    pub params: Option<Params>,
493}
494
495impl SubscribeIndexPrices {
496    /// Creates a new [`SubscribeIndexPrices`] instance.
497    pub fn new(
498        instrument_id: InstrumentId,
499        client_id: Option<ClientId>,
500        venue: Option<Venue>,
501        command_id: UUID4,
502        ts_init: UnixNanos,
503        correlation_id: Option<UUID4>,
504        params: Option<Params>,
505    ) -> Self {
506        check_client_id_or_venue(&client_id, &venue);
507        Self {
508            instrument_id,
509            client_id,
510            venue,
511            command_id,
512            ts_init,
513            correlation_id,
514            params,
515        }
516    }
517}
518
519#[derive(Clone, Debug, Serialize, Deserialize)]
520#[cfg_attr(
521    feature = "python",
522    pyo3::pyclass(module = "nautilus_trader.live", frozen, skip_from_py_object)
523)]
524#[cfg_attr(
525    feature = "python",
526    pyo3_stub_gen::derive::gen_stub_pyclass(module = "nautilus_trader.live")
527)]
528pub struct SubscribeFundingRates {
529    pub instrument_id: InstrumentId,
530    pub client_id: Option<ClientId>,
531    pub venue: Option<Venue>,
532    pub command_id: UUID4,
533    pub ts_init: UnixNanos,
534    pub correlation_id: Option<UUID4>,
535    pub params: Option<Params>,
536}
537
538impl SubscribeFundingRates {
539    /// Creates a new [`SubscribeFundingRates`] instance.
540    pub fn new(
541        instrument_id: InstrumentId,
542        client_id: Option<ClientId>,
543        venue: Option<Venue>,
544        command_id: UUID4,
545        ts_init: UnixNanos,
546        correlation_id: Option<UUID4>,
547        params: Option<Params>,
548    ) -> Self {
549        check_client_id_or_venue(&client_id, &venue);
550        Self {
551            instrument_id,
552            client_id,
553            venue,
554            command_id,
555            ts_init,
556            correlation_id,
557            params,
558        }
559    }
560}
561
562#[derive(Clone, Debug, Serialize, Deserialize)]
563#[cfg_attr(
564    feature = "python",
565    pyo3::pyclass(module = "nautilus_trader.live", frozen, skip_from_py_object)
566)]
567#[cfg_attr(
568    feature = "python",
569    pyo3_stub_gen::derive::gen_stub_pyclass(module = "nautilus_trader.live")
570)]
571pub struct SubscribeInstrumentStatus {
572    pub instrument_id: InstrumentId,
573    pub client_id: Option<ClientId>,
574    pub venue: Option<Venue>,
575    pub command_id: UUID4,
576    pub ts_init: UnixNanos,
577    pub correlation_id: Option<UUID4>,
578    pub params: Option<Params>,
579}
580
581impl SubscribeInstrumentStatus {
582    /// Creates a new [`SubscribeInstrumentStatus`] instance.
583    pub fn new(
584        instrument_id: InstrumentId,
585        client_id: Option<ClientId>,
586        venue: Option<Venue>,
587        command_id: UUID4,
588        ts_init: UnixNanos,
589        correlation_id: Option<UUID4>,
590        params: Option<Params>,
591    ) -> Self {
592        check_client_id_or_venue(&client_id, &venue);
593        Self {
594            instrument_id,
595            client_id,
596            venue,
597            command_id,
598            ts_init,
599            correlation_id,
600            params,
601        }
602    }
603}
604
605#[derive(Clone, Debug, Serialize, Deserialize)]
606#[cfg_attr(
607    feature = "python",
608    pyo3::pyclass(module = "nautilus_trader.live", frozen, skip_from_py_object)
609)]
610#[cfg_attr(
611    feature = "python",
612    pyo3_stub_gen::derive::gen_stub_pyclass(module = "nautilus_trader.live")
613)]
614pub struct SubscribeOptionGreeks {
615    pub instrument_id: InstrumentId,
616    pub client_id: Option<ClientId>,
617    pub venue: Option<Venue>,
618    pub command_id: UUID4,
619    pub ts_init: UnixNanos,
620    pub correlation_id: Option<UUID4>,
621    pub params: Option<Params>,
622}
623
624impl SubscribeOptionGreeks {
625    /// Creates a new [`SubscribeOptionGreeks`] instance.
626    pub fn new(
627        instrument_id: InstrumentId,
628        client_id: Option<ClientId>,
629        venue: Option<Venue>,
630        command_id: UUID4,
631        ts_init: UnixNanos,
632        correlation_id: Option<UUID4>,
633        params: Option<Params>,
634    ) -> Self {
635        check_client_id_or_venue(&client_id, &venue);
636        Self {
637            instrument_id,
638            client_id,
639            venue,
640            command_id,
641            ts_init,
642            correlation_id,
643            params,
644        }
645    }
646}
647
648#[derive(Clone, Debug, Serialize, Deserialize)]
649#[cfg_attr(
650    feature = "python",
651    pyo3::pyclass(module = "nautilus_trader.live", frozen, skip_from_py_object)
652)]
653#[cfg_attr(
654    feature = "python",
655    pyo3_stub_gen::derive::gen_stub_pyclass(module = "nautilus_trader.live")
656)]
657pub struct SubscribeInstrumentClose {
658    pub instrument_id: InstrumentId,
659    pub client_id: Option<ClientId>,
660    pub venue: Option<Venue>,
661    pub command_id: UUID4,
662    pub ts_init: UnixNanos,
663    pub correlation_id: Option<UUID4>,
664    pub params: Option<Params>,
665}
666
667impl SubscribeInstrumentClose {
668    /// Creates a new [`SubscribeInstrumentClose`] instance.
669    pub fn new(
670        instrument_id: InstrumentId,
671        client_id: Option<ClientId>,
672        venue: Option<Venue>,
673        command_id: UUID4,
674        ts_init: UnixNanos,
675        correlation_id: Option<UUID4>,
676        params: Option<Params>,
677    ) -> Self {
678        check_client_id_or_venue(&client_id, &venue);
679        Self {
680            instrument_id,
681            client_id,
682            venue,
683            command_id,
684            ts_init,
685            correlation_id,
686            params,
687        }
688    }
689}
690
691#[derive(Clone, Debug, Serialize, Deserialize)]
692pub struct SubscribeOptionChain {
693    pub series_id: OptionSeriesId,
694    pub strike_range: StrikeRange,
695    pub snapshot_interval_ms: Option<u64>,
696    pub command_id: UUID4,
697    pub ts_init: UnixNanos,
698    pub client_id: Option<ClientId>,
699    pub venue: Option<Venue>,
700    #[serde(default)]
701    pub correlation_id: Option<UUID4>,
702    pub params: Option<Params>,
703}
704
705impl SubscribeOptionChain {
706    /// Creates a new [`SubscribeOptionChain`] instance.
707    #[expect(
708        clippy::too_many_arguments,
709        reason = "constructor exposes the option chain subscription fields"
710    )]
711    pub fn new(
712        series_id: OptionSeriesId,
713        strike_range: StrikeRange,
714        snapshot_interval_ms: Option<u64>,
715        command_id: UUID4,
716        ts_init: UnixNanos,
717        client_id: Option<ClientId>,
718        venue: Option<Venue>,
719        params: Option<Params>,
720    ) -> Self {
721        check_client_id_or_venue(&client_id, &venue);
722        Self {
723            series_id,
724            strike_range,
725            snapshot_interval_ms,
726            command_id,
727            ts_init,
728            client_id,
729            venue,
730            correlation_id: None,
731            params,
732        }
733    }
734}