nautilus_common/messages/data/
subscribe.rs

1// -------------------------------------------------------------------------------------------------
2//  Copyright (C) 2015-2025 Posei Systems Pty Ltd. All rights reserved.
3//  https://poseitrader.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 await_partial: bool,
318    pub params: Option<IndexMap<String, String>>,
319}
320
321impl SubscribeBars {
322    /// Creates a new [`SubscribeBars`] instance.
323    pub fn new(
324        bar_type: BarType,
325        client_id: Option<ClientId>,
326        venue: Option<Venue>,
327        command_id: UUID4,
328        ts_init: UnixNanos,
329        await_partial: bool,
330        params: Option<IndexMap<String, String>>,
331    ) -> Self {
332        check_client_id_or_venue(&client_id, &venue);
333        Self {
334            bar_type,
335            client_id,
336            venue,
337            command_id,
338            ts_init,
339            await_partial,
340            params,
341        }
342    }
343}
344
345#[derive(Clone, Debug)]
346pub struct SubscribeMarkPrices {
347    pub instrument_id: InstrumentId,
348    pub client_id: Option<ClientId>,
349    pub venue: Option<Venue>,
350    pub command_id: UUID4,
351    pub ts_init: UnixNanos,
352    pub params: Option<IndexMap<String, String>>,
353}
354
355impl SubscribeMarkPrices {
356    /// Creates a new [`SubscribeMarkPrices`] instance.
357    pub fn new(
358        instrument_id: InstrumentId,
359        client_id: Option<ClientId>,
360        venue: Option<Venue>,
361        command_id: UUID4,
362        ts_init: UnixNanos,
363        params: Option<IndexMap<String, String>>,
364    ) -> Self {
365        check_client_id_or_venue(&client_id, &venue);
366        Self {
367            instrument_id,
368            client_id,
369            venue,
370            command_id,
371            ts_init,
372            params,
373        }
374    }
375}
376
377#[derive(Clone, Debug)]
378pub struct SubscribeIndexPrices {
379    pub instrument_id: InstrumentId,
380    pub client_id: Option<ClientId>,
381    pub venue: Option<Venue>,
382    pub command_id: UUID4,
383    pub ts_init: UnixNanos,
384    pub params: Option<IndexMap<String, String>>,
385}
386
387impl SubscribeIndexPrices {
388    /// Creates a new [`SubscribeIndexPrices`] instance.
389    pub fn new(
390        instrument_id: InstrumentId,
391        client_id: Option<ClientId>,
392        venue: Option<Venue>,
393        command_id: UUID4,
394        ts_init: UnixNanos,
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            params,
405        }
406    }
407}
408
409#[derive(Clone, Debug)]
410pub struct SubscribeInstrumentStatus {
411    pub instrument_id: InstrumentId,
412    pub client_id: Option<ClientId>,
413    pub venue: Option<Venue>,
414    pub command_id: UUID4,
415    pub ts_init: UnixNanos,
416    pub params: Option<IndexMap<String, String>>,
417}
418
419impl SubscribeInstrumentStatus {
420    /// Creates a new [`SubscribeInstrumentStatus`] instance.
421    pub fn new(
422        instrument_id: InstrumentId,
423        client_id: Option<ClientId>,
424        venue: Option<Venue>,
425        command_id: UUID4,
426        ts_init: UnixNanos,
427        params: Option<IndexMap<String, String>>,
428    ) -> Self {
429        check_client_id_or_venue(&client_id, &venue);
430        Self {
431            instrument_id,
432            client_id,
433            venue,
434            command_id,
435            ts_init,
436            params,
437        }
438    }
439}
440
441#[derive(Clone, Debug)]
442pub struct SubscribeInstrumentClose {
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 params: Option<IndexMap<String, String>>,
449}
450
451impl SubscribeInstrumentClose {
452    /// Creates a new [`SubscribeInstrumentClose`] instance.
453    pub fn new(
454        instrument_id: InstrumentId,
455        client_id: Option<ClientId>,
456        venue: Option<Venue>,
457        command_id: UUID4,
458        ts_init: UnixNanos,
459        params: Option<IndexMap<String, String>>,
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            params,
469        }
470    }
471}