nautilus_common/messages/data/
subscribe.rs

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