nautilus_common/messages/
data.rs1use std::{any::Any, collections::HashMap, sync::Arc};
17
18use nautilus_core::{UUID4, UnixNanos};
19use nautilus_model::{
20 data::{Data, DataType},
21 identifiers::{ClientId, Venue},
22};
23
24#[derive(Debug)]
26pub struct DataRequest {
27 pub correlation_id: UUID4,
28 pub client_id: ClientId,
29 pub venue: Venue,
30 pub data_type: DataType,
31 pub ts_init: UnixNanos,
32 pub params: Option<HashMap<String, String>>,
33}
34
35pub type Payload = Arc<dyn Any + Send + Sync>;
36
37#[derive(Debug)]
38pub struct DataResponse {
39 pub correlation_id: UUID4,
40 pub client_id: ClientId,
41 pub venue: Venue,
42 pub data_type: DataType,
43 pub data: Payload,
44 pub ts_init: UnixNanos,
45 pub params: Option<HashMap<String, String>>,
46}
47
48impl DataResponse {
49 pub fn new<T: Any + Send + Sync>(
50 correlation_id: UUID4,
51 client_id: ClientId,
52 venue: Venue,
53 data_type: DataType,
54 data: T,
55 ts_init: UnixNanos,
56 params: Option<HashMap<String, String>>,
57 ) -> Self {
58 Self {
59 correlation_id,
60 client_id,
61 venue,
62 data_type,
63 data: Arc::new(data),
64 ts_init,
65 params,
66 }
67 }
68}
69
70#[derive(Debug, Clone, Copy)]
71pub enum Action {
72 Subscribe,
73 Unsubscribe,
74}
75
76#[derive(Debug, Clone)]
77pub struct SubscriptionCommand {
78 pub client_id: ClientId,
79 pub venue: Venue,
80 pub data_type: DataType,
81 pub action: Action,
82 pub command_id: UUID4,
83 pub ts_init: UnixNanos,
84 pub params: Option<HashMap<String, String>>,
85}
86
87impl SubscriptionCommand {
88 #[must_use]
90 pub const fn new(
91 client_id: ClientId,
92 venue: Venue,
93 data_type: DataType,
94 action: Action,
95 command_id: UUID4,
96 ts_init: UnixNanos,
97 params: Option<HashMap<String, String>>,
98 ) -> Self {
99 Self {
100 client_id,
101 venue,
102 data_type,
103 action,
104 command_id,
105 ts_init,
106 params,
107 }
108 }
109}
110
111pub enum DataCommand {
112 Request(DataRequest),
113 Subscribe(SubscriptionCommand),
114}
115
116#[allow(clippy::large_enum_variant)]
118pub enum DataEvent {
119 Response(DataResponse),
120 Data(Data),
121}