nautilus_common/messages/defi/
mod.rs1use std::any::Any;
19
20use nautilus_core::{UUID4, UnixNanos};
21use nautilus_model::identifiers::{ClientId, Venue};
22
23pub mod subscribe;
24pub mod unsubscribe;
25
26pub use subscribe::{
28 SubscribeBlocks, SubscribePool, SubscribePoolLiquidityUpdates, SubscribePoolSwaps,
29};
30pub use unsubscribe::{
31 UnsubscribeBlocks, UnsubscribePool, UnsubscribePoolLiquidityUpdates, UnsubscribePoolSwaps,
32};
33
34#[derive(Clone, Debug)]
35pub enum DefiDataCommand {
36 Subscribe(DefiSubscribeCommand),
37 Unsubscribe(DefiUnsubscribeCommand),
38}
39
40impl PartialEq for DefiDataCommand {
41 fn eq(&self, other: &Self) -> bool {
42 self.command_id() == other.command_id()
43 }
44}
45
46impl DefiDataCommand {
47 pub fn as_any(&self) -> &dyn Any {
49 self
50 }
51
52 pub fn command_id(&self) -> UUID4 {
53 match self {
54 Self::Subscribe(cmd) => cmd.command_id(),
55 Self::Unsubscribe(cmd) => cmd.command_id(),
56 }
57 }
58
59 pub fn client_id(&self) -> Option<&ClientId> {
60 match self {
61 Self::Subscribe(cmd) => cmd.client_id(),
62 Self::Unsubscribe(cmd) => cmd.client_id(),
63 }
64 }
65
66 pub fn venue(&self) -> Option<&Venue> {
67 match self {
68 Self::Subscribe(cmd) => cmd.venue(),
69 Self::Unsubscribe(cmd) => cmd.venue(),
70 }
71 }
72
73 pub fn ts_init(&self) -> UnixNanos {
74 match self {
75 Self::Subscribe(cmd) => cmd.ts_init(),
76 Self::Unsubscribe(cmd) => cmd.ts_init(),
77 }
78 }
79}
80
81#[derive(Clone, Debug)]
82pub enum DefiSubscribeCommand {
83 Blocks(SubscribeBlocks),
84 Pool(SubscribePool),
85 PoolSwaps(SubscribePoolSwaps),
86 PoolLiquidityUpdates(SubscribePoolLiquidityUpdates),
87}
88
89impl PartialEq for DefiSubscribeCommand {
90 fn eq(&self, other: &Self) -> bool {
91 self.command_id() == other.command_id()
92 }
93}
94
95impl DefiSubscribeCommand {
96 pub fn as_any(&self) -> &dyn Any {
98 self
99 }
100
101 pub fn command_id(&self) -> UUID4 {
102 match self {
103 Self::Blocks(cmd) => cmd.command_id,
104 Self::Pool(cmd) => cmd.command_id,
105 Self::PoolSwaps(cmd) => cmd.command_id,
106 Self::PoolLiquidityUpdates(cmd) => cmd.command_id,
107 }
108 }
109
110 pub fn client_id(&self) -> Option<&ClientId> {
111 match self {
112 Self::Blocks(cmd) => cmd.client_id.as_ref(),
113 Self::Pool(cmd) => cmd.client_id.as_ref(),
114 Self::PoolSwaps(cmd) => cmd.client_id.as_ref(),
115 Self::PoolLiquidityUpdates(cmd) => cmd.client_id.as_ref(),
116 }
117 }
118
119 pub fn venue(&self) -> Option<&Venue> {
121 match self {
122 Self::Blocks(_) => None,
123 Self::Pool(_) => None,
124 Self::PoolSwaps(_) => None,
125 Self::PoolLiquidityUpdates(_) => None,
126 }
127 }
128
129 pub fn ts_init(&self) -> UnixNanos {
130 match self {
131 Self::Blocks(cmd) => cmd.ts_init,
132 Self::PoolSwaps(cmd) => cmd.ts_init,
133 Self::PoolLiquidityUpdates(cmd) => cmd.ts_init,
134 Self::Pool(cmd) => cmd.ts_init,
135 }
136 }
137}
138
139#[derive(Clone, Debug)]
140pub enum DefiUnsubscribeCommand {
141 Blocks(UnsubscribeBlocks),
142 Pool(UnsubscribePool),
143 PoolSwaps(UnsubscribePoolSwaps),
144 PoolLiquidityUpdates(UnsubscribePoolLiquidityUpdates),
145}
146
147impl PartialEq for DefiUnsubscribeCommand {
148 fn eq(&self, other: &Self) -> bool {
149 self.command_id() == other.command_id()
150 }
151}
152
153impl DefiUnsubscribeCommand {
154 pub fn as_any(&self) -> &dyn Any {
156 self
157 }
158
159 pub fn command_id(&self) -> UUID4 {
160 match self {
161 Self::Blocks(cmd) => cmd.command_id,
162 Self::Pool(cmd) => cmd.command_id,
163 Self::PoolSwaps(cmd) => cmd.command_id,
164 Self::PoolLiquidityUpdates(cmd) => cmd.command_id,
165 }
166 }
167
168 pub fn client_id(&self) -> Option<&ClientId> {
169 match self {
170 Self::Blocks(cmd) => cmd.client_id.as_ref(),
171 Self::Pool(cmd) => cmd.client_id.as_ref(),
172 Self::PoolSwaps(cmd) => cmd.client_id.as_ref(),
173 Self::PoolLiquidityUpdates(cmd) => cmd.client_id.as_ref(),
174 }
175 }
176
177 pub fn venue(&self) -> Option<&Venue> {
179 match self {
180 Self::Blocks(_) => None,
181 Self::Pool(_) => None,
182 Self::PoolSwaps(_) => None,
183 Self::PoolLiquidityUpdates(_) => None,
184 }
185 }
186
187 pub fn ts_init(&self) -> UnixNanos {
188 match self {
189 Self::Blocks(cmd) => cmd.ts_init,
190 Self::Pool(cmd) => cmd.ts_init,
191 Self::PoolSwaps(cmd) => cmd.ts_init,
192 Self::PoolLiquidityUpdates(cmd) => cmd.ts_init,
193 }
194 }
195}