1use nautilus_model::identifiers::{
17 AccountId, ClientOrderId, InstrumentId, OrderListId, PositionId, VenueOrderId,
18};
19use thiserror::Error;
20use ustr::Ustr;
21
22use crate::component::ComponentAccessError;
23
24pub const ACCOUNT_NOT_FOUND: &str = "account not found in cache";
26
27pub const CURRENCY_NOT_FOUND: &str = "currency not found in cache";
29
30pub const INSTRUMENT_NOT_FOUND: &str = "instrument not found in cache";
32
33pub const ORDER_BOOK_NOT_FOUND: &str = "order book not found in cache";
35
36pub const OWN_ORDER_BOOK_NOT_FOUND: &str = "own order book not found in cache";
38
39pub const SYNTHETIC_INSTRUMENT_NOT_FOUND: &str = "synthetic instrument not found in cache";
41
42pub const ORDER_NOT_FOUND: &str = "order not found in cache";
44
45pub const ORDER_LIST_NOT_FOUND: &str = "order list not found in cache";
47
48pub const POSITION_NOT_FOUND: &str = "position not found in cache";
50
51#[derive(Debug, Clone, Copy, PartialEq, Eq, Error)]
53#[error(
54 "Venue order ID {venue_order_id} is already owned by client order \
55 {existing_client_order_id} and cannot be claimed by {claimant_client_order_id}"
56)]
57pub struct VenueOrderIdOwnershipError {
58 pub venue_order_id: VenueOrderId,
60 pub existing_client_order_id: ClientOrderId,
62 pub claimant_client_order_id: ClientOrderId,
64}
65
66#[derive(Debug, Clone, Copy, PartialEq, Eq, Error)]
68pub enum AccountLookupError {
69 #[error(transparent)]
71 Access(#[from] ComponentAccessError),
72 #[error("{message}: {account_id}", message = ACCOUNT_NOT_FOUND)]
74 NotFound {
75 account_id: AccountId,
77 },
78}
79
80impl AccountLookupError {
81 #[must_use]
83 pub const fn not_found(account_id: AccountId) -> Self {
84 Self::NotFound { account_id }
85 }
86}
87
88#[derive(Debug, Clone, Copy, PartialEq, Eq, Error)]
90pub enum CurrencyLookupError {
91 #[error(transparent)]
93 Access(#[from] ComponentAccessError),
94 #[error("{message}: {code}", message = CURRENCY_NOT_FOUND)]
96 NotFound {
97 code: Ustr,
99 },
100}
101
102impl CurrencyLookupError {
103 #[must_use]
105 pub const fn not_found(code: Ustr) -> Self {
106 Self::NotFound { code }
107 }
108}
109
110#[derive(Debug, Clone, Copy, PartialEq, Eq, Error)]
112pub enum InstrumentLookupError {
113 #[error(transparent)]
115 Access(#[from] ComponentAccessError),
116 #[error("{message}: {instrument_id}", message = INSTRUMENT_NOT_FOUND)]
118 NotFound {
119 instrument_id: InstrumentId,
121 },
122}
123
124impl InstrumentLookupError {
125 #[must_use]
127 pub const fn not_found(instrument_id: InstrumentId) -> Self {
128 Self::NotFound { instrument_id }
129 }
130}
131
132#[derive(Debug, Clone, Copy, PartialEq, Eq, Error)]
134pub enum SyntheticInstrumentLookupError {
135 #[error(transparent)]
137 Access(#[from] ComponentAccessError),
138 #[error("{message}: {instrument_id}", message = SYNTHETIC_INSTRUMENT_NOT_FOUND)]
140 NotFound {
141 instrument_id: InstrumentId,
143 },
144}
145
146impl SyntheticInstrumentLookupError {
147 #[must_use]
149 pub const fn not_found(instrument_id: InstrumentId) -> Self {
150 Self::NotFound { instrument_id }
151 }
152}
153
154#[derive(Debug, Clone, Copy, PartialEq, Eq, Error)]
156pub enum OrderBookLookupError {
157 #[error(transparent)]
159 Access(#[from] ComponentAccessError),
160 #[error("{message}: {instrument_id}", message = ORDER_BOOK_NOT_FOUND)]
162 NotFound {
163 instrument_id: InstrumentId,
165 },
166}
167
168impl OrderBookLookupError {
169 #[must_use]
171 pub const fn not_found(instrument_id: InstrumentId) -> Self {
172 Self::NotFound { instrument_id }
173 }
174}
175
176#[derive(Debug, Clone, Copy, PartialEq, Eq, Error)]
178pub enum OwnOrderBookLookupError {
179 #[error(transparent)]
181 Access(#[from] ComponentAccessError),
182 #[error("{message}: {instrument_id}", message = OWN_ORDER_BOOK_NOT_FOUND)]
184 NotFound {
185 instrument_id: InstrumentId,
187 },
188}
189
190impl OwnOrderBookLookupError {
191 #[must_use]
193 pub const fn not_found(instrument_id: InstrumentId) -> Self {
194 Self::NotFound { instrument_id }
195 }
196}
197
198#[derive(Debug, Clone, Copy, PartialEq, Eq, Error)]
200pub enum OrderLookupError {
201 #[error(transparent)]
203 Access(#[from] ComponentAccessError),
204 #[error("{message}: {client_order_id}", message = ORDER_NOT_FOUND)]
206 NotFound {
207 client_order_id: ClientOrderId,
209 },
210}
211
212impl OrderLookupError {
213 #[must_use]
215 pub const fn not_found(client_order_id: ClientOrderId) -> Self {
216 Self::NotFound { client_order_id }
217 }
218}
219
220#[derive(Debug, Clone, Copy, PartialEq, Eq, Error)]
222pub enum OrderListLookupError {
223 #[error(transparent)]
225 Access(#[from] ComponentAccessError),
226 #[error("{message}: {order_list_id}", message = ORDER_LIST_NOT_FOUND)]
228 NotFound {
229 order_list_id: OrderListId,
231 },
232}
233
234impl OrderListLookupError {
235 #[must_use]
237 pub const fn not_found(order_list_id: OrderListId) -> Self {
238 Self::NotFound { order_list_id }
239 }
240}
241
242#[derive(Debug, Clone, Copy, PartialEq, Eq, Error)]
244pub enum PositionLookupError {
245 #[error(transparent)]
247 Access(#[from] ComponentAccessError),
248 #[error("{message}: {position_id}", message = POSITION_NOT_FOUND)]
250 NotFound {
251 position_id: PositionId,
253 },
254}
255
256impl PositionLookupError {
257 #[must_use]
259 pub const fn not_found(position_id: PositionId) -> Self {
260 Self::NotFound { position_id }
261 }
262}