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