nautilus_common/cache/
error.rs1use nautilus_model::identifiers::{
17 AccountId, ClientOrderId, InstrumentId, OrderListId, PositionId,
18};
19use thiserror::Error;
20use ustr::Ustr;
21
22pub const ACCOUNT_NOT_FOUND: &str = "account not found in cache";
24
25pub const CURRENCY_NOT_FOUND: &str = "currency not found in cache";
27
28pub const INSTRUMENT_NOT_FOUND: &str = "instrument not found in cache";
30
31pub const ORDER_BOOK_NOT_FOUND: &str = "order book not found in cache";
33
34pub const OWN_ORDER_BOOK_NOT_FOUND: &str = "own order book not found in cache";
36
37pub const SYNTHETIC_INSTRUMENT_NOT_FOUND: &str = "synthetic instrument not found in cache";
39
40pub const ORDER_NOT_FOUND: &str = "order not found in cache";
42
43pub const ORDER_LIST_NOT_FOUND: &str = "order list not found in cache";
45
46pub const POSITION_NOT_FOUND: &str = "position not found in cache";
48
49#[derive(Debug, Clone, Copy, PartialEq, Eq, Error)]
51pub enum AccountLookupError {
52 #[error("{message}: {account_id}", message = ACCOUNT_NOT_FOUND)]
54 NotFound {
55 account_id: AccountId,
57 },
58}
59
60impl AccountLookupError {
61 #[must_use]
63 pub const fn not_found(account_id: AccountId) -> Self {
64 Self::NotFound { account_id }
65 }
66}
67
68#[derive(Debug, Clone, Copy, PartialEq, Eq, Error)]
70pub enum CurrencyLookupError {
71 #[error("{message}: {code}", message = CURRENCY_NOT_FOUND)]
73 NotFound {
74 code: Ustr,
76 },
77}
78
79impl CurrencyLookupError {
80 #[must_use]
82 pub const fn not_found(code: Ustr) -> Self {
83 Self::NotFound { code }
84 }
85}
86
87#[derive(Debug, Clone, Copy, PartialEq, Eq, Error)]
89pub enum InstrumentLookupError {
90 #[error("{message}: {instrument_id}", message = INSTRUMENT_NOT_FOUND)]
92 NotFound {
93 instrument_id: InstrumentId,
95 },
96}
97
98impl InstrumentLookupError {
99 #[must_use]
101 pub const fn not_found(instrument_id: InstrumentId) -> Self {
102 Self::NotFound { instrument_id }
103 }
104}
105
106#[derive(Debug, Clone, Copy, PartialEq, Eq, Error)]
108pub enum SyntheticInstrumentLookupError {
109 #[error("{message}: {instrument_id}", message = SYNTHETIC_INSTRUMENT_NOT_FOUND)]
111 NotFound {
112 instrument_id: InstrumentId,
114 },
115}
116
117impl SyntheticInstrumentLookupError {
118 #[must_use]
120 pub const fn not_found(instrument_id: InstrumentId) -> Self {
121 Self::NotFound { instrument_id }
122 }
123}
124
125#[derive(Debug, Clone, Copy, PartialEq, Eq, Error)]
127pub enum OrderBookLookupError {
128 #[error("{message}: {instrument_id}", message = ORDER_BOOK_NOT_FOUND)]
130 NotFound {
131 instrument_id: InstrumentId,
133 },
134}
135
136impl OrderBookLookupError {
137 #[must_use]
139 pub const fn not_found(instrument_id: InstrumentId) -> Self {
140 Self::NotFound { instrument_id }
141 }
142}
143
144#[derive(Debug, Clone, Copy, PartialEq, Eq, Error)]
146pub enum OwnOrderBookLookupError {
147 #[error("{message}: {instrument_id}", message = OWN_ORDER_BOOK_NOT_FOUND)]
149 NotFound {
150 instrument_id: InstrumentId,
152 },
153}
154
155impl OwnOrderBookLookupError {
156 #[must_use]
158 pub const fn not_found(instrument_id: InstrumentId) -> Self {
159 Self::NotFound { instrument_id }
160 }
161}
162
163#[derive(Debug, Clone, Copy, PartialEq, Eq, Error)]
165pub enum OrderLookupError {
166 #[error("{message}: {client_order_id}", message = ORDER_NOT_FOUND)]
168 NotFound {
169 client_order_id: ClientOrderId,
171 },
172}
173
174impl OrderLookupError {
175 #[must_use]
177 pub const fn not_found(client_order_id: ClientOrderId) -> Self {
178 Self::NotFound { client_order_id }
179 }
180}
181
182#[derive(Debug, Clone, Copy, PartialEq, Eq, Error)]
184pub enum OrderListLookupError {
185 #[error("{message}: {order_list_id}", message = ORDER_LIST_NOT_FOUND)]
187 NotFound {
188 order_list_id: OrderListId,
190 },
191}
192
193impl OrderListLookupError {
194 #[must_use]
196 pub const fn not_found(order_list_id: OrderListId) -> Self {
197 Self::NotFound { order_list_id }
198 }
199}
200
201#[derive(Debug, Clone, Copy, PartialEq, Eq, Error)]
203pub enum PositionLookupError {
204 #[error("{message}: {position_id}", message = POSITION_NOT_FOUND)]
206 NotFound {
207 position_id: PositionId,
209 },
210}
211
212impl PositionLookupError {
213 #[must_use]
215 pub const fn not_found(position_id: PositionId) -> Self {
216 Self::NotFound { position_id }
217 }
218}