Skip to main content

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