nautilus_model/defi/data/
mod.rs1use std::fmt::Display;
22
23use serde::{Deserialize, Serialize};
24
25use crate::{defi::Pool, identifiers::InstrumentId};
26
27pub mod block;
28pub mod collect;
29pub mod liquidity;
30pub mod swap;
31pub mod transaction;
32
33pub use block::Block;
35pub use collect::PoolFeeCollect;
36pub use liquidity::{PoolLiquidityUpdate, PoolLiquidityUpdateType};
37pub use swap::PoolSwap;
38pub use transaction::Transaction;
39
40#[cfg_attr(
42 feature = "python",
43 pyo3::pyclass(module = "nautilus_trader.core.nautilus_pyo3.model")
44)]
45#[allow(clippy::large_enum_variant)]
46#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
47pub enum DefiData {
48 Block(Block),
50 Pool(Pool),
52 PoolSwap(PoolSwap),
54 PoolLiquidityUpdate(PoolLiquidityUpdate),
56 PoolFeeCollect(PoolFeeCollect),
58}
59
60impl DefiData {
61 #[must_use]
67 pub fn instrument_id(&self) -> InstrumentId {
68 match self {
69 Self::Block(_) => panic!("`InstrumentId` not applicable to `Block`"), Self::PoolSwap(swap) => swap.instrument_id,
71 Self::PoolLiquidityUpdate(update) => update.instrument_id,
72 Self::PoolFeeCollect(collect) => collect.instrument_id,
73 Self::Pool(pool) => pool.instrument_id,
74 }
75 }
76}
77
78impl Display for DefiData {
79 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
80 match self {
81 Self::Block(b) => write!(f, "{b}"),
82 Self::PoolSwap(s) => write!(f, "{s}"),
83 Self::PoolLiquidityUpdate(u) => write!(f, "{u}"),
84 Self::PoolFeeCollect(c) => write!(f, "{c}"),
85 Self::Pool(p) => write!(f, "{p}"),
86 }
87 }
88}
89
90impl From<PoolSwap> for DefiData {
91 fn from(value: PoolSwap) -> Self {
92 Self::PoolSwap(value)
93 }
94}
95
96impl From<PoolLiquidityUpdate> for DefiData {
97 fn from(value: PoolLiquidityUpdate) -> Self {
98 Self::PoolLiquidityUpdate(value)
99 }
100}
101
102impl From<Pool> for DefiData {
103 fn from(value: Pool) -> Self {
104 Self::Pool(value)
105 }
106}
107
108impl From<PoolFeeCollect> for DefiData {
109 fn from(value: PoolFeeCollect) -> Self {
110 Self::PoolFeeCollect(value)
111 }
112}