use std::fmt::{Display, Formatter};
use crate::core::Instrument;
use super::instrument_id::InstrumentId;
use super::quote::Quote;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub enum MarketDataError {
UnknownInstrument,
QuoteUnavailable,
QuoteExpired(Quote),
}
impl Display for MarketDataError {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
Self::UnknownInstrument => f.write_str("unknown instrument"),
Self::QuoteUnavailable => f.write_str("quote unavailable"),
Self::QuoteExpired(_) => f.write_str("quote expired"),
}
}
}
impl std::error::Error for MarketDataError {}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct UnknownInstrumentId {
pub instrument_id: InstrumentId,
}
impl Display for UnknownInstrumentId {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "unknown instrument id: {}", self.instrument_id.0)
}
}
impl std::error::Error for UnknownInstrumentId {}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct AlreadyRegistered {
pub instrument: Instrument,
}
impl Display for AlreadyRegistered {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "instrument {:?} is already registered", self.instrument)
}
}
impl std::error::Error for AlreadyRegistered {}
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub enum RegistrationError {
DuplicateId {
instrument_id: InstrumentId,
},
DuplicateInstrument {
instrument: Instrument,
},
}
impl Display for RegistrationError {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
Self::DuplicateId { instrument_id } => {
write!(f, "instrument id {} is already registered", instrument_id.0)
}
Self::DuplicateInstrument { instrument } => {
write!(f, "instrument {:?} is already registered", instrument)
}
}
}
}
impl std::error::Error for RegistrationError {}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub enum PushForError {
UnknownInstrument {
instrument_id: InstrumentId,
},
NoTarget,
}
impl Display for PushForError {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
Self::UnknownInstrument { instrument_id } => {
write!(f, "unknown instrument id: {}", instrument_id.0)
}
Self::NoTarget => f.write_str("push_for requires at least one account or group target"),
}
}
}
impl std::error::Error for PushForError {}