1use nautilus_model::identifiers::{
17 AccountId, ClientOrderId, InstrumentId, OrderListId, PositionId, VenueOrderId,
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)]
51#[error(
52 "Venue order ID {venue_order_id} is already owned by client order \
53 {existing_client_order_id} and cannot be claimed by {claimant_client_order_id}"
54)]
55pub struct VenueOrderIdOwnershipError {
56 pub venue_order_id: VenueOrderId,
58 pub existing_client_order_id: ClientOrderId,
60 pub claimant_client_order_id: ClientOrderId,
62}
63
64#[derive(Debug, Clone, Copy, PartialEq, Eq, Error)]
66pub enum AccountLookupError {
67 #[error("{message}: {account_id}", message = ACCOUNT_NOT_FOUND)]
69 NotFound {
70 account_id: AccountId,
72 },
73}
74
75impl AccountLookupError {
76 #[must_use]
78 pub const fn not_found(account_id: AccountId) -> Self {
79 Self::NotFound { account_id }
80 }
81}
82
83#[derive(Debug, Clone, Copy, PartialEq, Eq, Error)]
85pub enum CurrencyLookupError {
86 #[error("{message}: {code}", message = CURRENCY_NOT_FOUND)]
88 NotFound {
89 code: Ustr,
91 },
92}
93
94impl CurrencyLookupError {
95 #[must_use]
97 pub const fn not_found(code: Ustr) -> Self {
98 Self::NotFound { code }
99 }
100}
101
102#[derive(Debug, Clone, Copy, PartialEq, Eq, Error)]
104pub enum InstrumentLookupError {
105 #[error("{message}: {instrument_id}", message = INSTRUMENT_NOT_FOUND)]
107 NotFound {
108 instrument_id: InstrumentId,
110 },
111}
112
113impl InstrumentLookupError {
114 #[must_use]
116 pub const fn not_found(instrument_id: InstrumentId) -> Self {
117 Self::NotFound { instrument_id }
118 }
119}
120
121#[derive(Debug, Clone, Copy, PartialEq, Eq, Error)]
123pub enum SyntheticInstrumentLookupError {
124 #[error("{message}: {instrument_id}", message = SYNTHETIC_INSTRUMENT_NOT_FOUND)]
126 NotFound {
127 instrument_id: InstrumentId,
129 },
130}
131
132impl SyntheticInstrumentLookupError {
133 #[must_use]
135 pub const fn not_found(instrument_id: InstrumentId) -> Self {
136 Self::NotFound { instrument_id }
137 }
138}
139
140#[derive(Debug, Clone, Copy, PartialEq, Eq, Error)]
142pub enum OrderBookLookupError {
143 #[error("{message}: {instrument_id}", message = ORDER_BOOK_NOT_FOUND)]
145 NotFound {
146 instrument_id: InstrumentId,
148 },
149}
150
151impl OrderBookLookupError {
152 #[must_use]
154 pub const fn not_found(instrument_id: InstrumentId) -> Self {
155 Self::NotFound { instrument_id }
156 }
157}
158
159#[derive(Debug, Clone, Copy, PartialEq, Eq, Error)]
161pub enum OwnOrderBookLookupError {
162 #[error("{message}: {instrument_id}", message = OWN_ORDER_BOOK_NOT_FOUND)]
164 NotFound {
165 instrument_id: InstrumentId,
167 },
168}
169
170impl OwnOrderBookLookupError {
171 #[must_use]
173 pub const fn not_found(instrument_id: InstrumentId) -> Self {
174 Self::NotFound { instrument_id }
175 }
176}
177
178#[derive(Debug, Clone, Copy, PartialEq, Eq, Error)]
180pub enum OrderLookupError {
181 #[error("{message}: {client_order_id}", message = ORDER_NOT_FOUND)]
183 NotFound {
184 client_order_id: ClientOrderId,
186 },
187}
188
189impl OrderLookupError {
190 #[must_use]
192 pub const fn not_found(client_order_id: ClientOrderId) -> Self {
193 Self::NotFound { client_order_id }
194 }
195}
196
197#[derive(Debug, Clone, Copy, PartialEq, Eq, Error)]
199pub enum OrderListLookupError {
200 #[error("{message}: {order_list_id}", message = ORDER_LIST_NOT_FOUND)]
202 NotFound {
203 order_list_id: OrderListId,
205 },
206}
207
208impl OrderListLookupError {
209 #[must_use]
211 pub const fn not_found(order_list_id: OrderListId) -> Self {
212 Self::NotFound { order_list_id }
213 }
214}
215
216#[derive(Debug, Clone, Copy, PartialEq, Eq, Error)]
218pub enum PositionLookupError {
219 #[error("{message}: {position_id}", message = POSITION_NOT_FOUND)]
221 NotFound {
222 position_id: PositionId,
224 },
225}
226
227impl PositionLookupError {
228 #[must_use]
230 pub const fn not_found(position_id: PositionId) -> Self {
231 Self::NotFound { position_id }
232 }
233}