use nautilus_model::identifiers::{
AccountId, ClientOrderId, InstrumentId, OrderListId, PositionId,
};
use thiserror::Error;
use ustr::Ustr;
pub const ACCOUNT_NOT_FOUND: &str = "account not found in cache";
pub const CURRENCY_NOT_FOUND: &str = "currency not found in cache";
pub const INSTRUMENT_NOT_FOUND: &str = "instrument not found in cache";
pub const ORDER_BOOK_NOT_FOUND: &str = "order book not found in cache";
pub const OWN_ORDER_BOOK_NOT_FOUND: &str = "own order book not found in cache";
pub const SYNTHETIC_INSTRUMENT_NOT_FOUND: &str = "synthetic instrument not found in cache";
pub const ORDER_NOT_FOUND: &str = "order not found in cache";
pub const ORDER_LIST_NOT_FOUND: &str = "order list not found in cache";
pub const POSITION_NOT_FOUND: &str = "position not found in cache";
#[derive(Debug, Clone, Copy, PartialEq, Eq, Error)]
pub enum AccountLookupError {
#[error("{message}: {account_id}", message = ACCOUNT_NOT_FOUND)]
NotFound {
account_id: AccountId,
},
}
impl AccountLookupError {
#[must_use]
pub const fn not_found(account_id: AccountId) -> Self {
Self::NotFound { account_id }
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Error)]
pub enum CurrencyLookupError {
#[error("{message}: {code}", message = CURRENCY_NOT_FOUND)]
NotFound {
code: Ustr,
},
}
impl CurrencyLookupError {
#[must_use]
pub const fn not_found(code: Ustr) -> Self {
Self::NotFound { code }
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Error)]
pub enum InstrumentLookupError {
#[error("{message}: {instrument_id}", message = INSTRUMENT_NOT_FOUND)]
NotFound {
instrument_id: InstrumentId,
},
}
impl InstrumentLookupError {
#[must_use]
pub const fn not_found(instrument_id: InstrumentId) -> Self {
Self::NotFound { instrument_id }
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Error)]
pub enum SyntheticInstrumentLookupError {
#[error("{message}: {instrument_id}", message = SYNTHETIC_INSTRUMENT_NOT_FOUND)]
NotFound {
instrument_id: InstrumentId,
},
}
impl SyntheticInstrumentLookupError {
#[must_use]
pub const fn not_found(instrument_id: InstrumentId) -> Self {
Self::NotFound { instrument_id }
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Error)]
pub enum OrderBookLookupError {
#[error("{message}: {instrument_id}", message = ORDER_BOOK_NOT_FOUND)]
NotFound {
instrument_id: InstrumentId,
},
}
impl OrderBookLookupError {
#[must_use]
pub const fn not_found(instrument_id: InstrumentId) -> Self {
Self::NotFound { instrument_id }
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Error)]
pub enum OwnOrderBookLookupError {
#[error("{message}: {instrument_id}", message = OWN_ORDER_BOOK_NOT_FOUND)]
NotFound {
instrument_id: InstrumentId,
},
}
impl OwnOrderBookLookupError {
#[must_use]
pub const fn not_found(instrument_id: InstrumentId) -> Self {
Self::NotFound { instrument_id }
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Error)]
pub enum OrderLookupError {
#[error("{message}: {client_order_id}", message = ORDER_NOT_FOUND)]
NotFound {
client_order_id: ClientOrderId,
},
}
impl OrderLookupError {
#[must_use]
pub const fn not_found(client_order_id: ClientOrderId) -> Self {
Self::NotFound { client_order_id }
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Error)]
pub enum OrderListLookupError {
#[error("{message}: {order_list_id}", message = ORDER_LIST_NOT_FOUND)]
NotFound {
order_list_id: OrderListId,
},
}
impl OrderListLookupError {
#[must_use]
pub const fn not_found(order_list_id: OrderListId) -> Self {
Self::NotFound { order_list_id }
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Error)]
pub enum PositionLookupError {
#[error("{message}: {position_id}", message = POSITION_NOT_FOUND)]
NotFound {
position_id: PositionId,
},
}
impl PositionLookupError {
#[must_use]
pub const fn not_found(position_id: PositionId) -> Self {
Self::NotFound { position_id }
}
}