rusty_oms/
error.rs

1//! Error types for the Order Management System
2//!
3//! Provides structured error handling for OMS operations
4
5use rusty_common::SmartString;
6use thiserror::Error;
7
8/// Main error type for OMS operations
9#[derive(Debug, Error)]
10pub enum OmsError {
11    /// Order validation failed
12    #[error("Order validation failed: {0}")]
13    Validation(SmartString),
14
15    /// Risk check failed
16    #[error("Risk check failed: {0}")]
17    RiskViolation(SmartString),
18
19    /// Exchange-specific error
20    #[error("Exchange error: {0}")]
21    Exchange(SmartString),
22
23    /// Network or communication error
24    #[error("Network error: {0}")]
25    Network(SmartString),
26
27    /// Internal system error
28    #[error("Internal error: {0}")]
29    Internal(SmartString),
30
31    /// Order not found
32    #[error("Order not found: {0}")]
33    OrderNotFound(SmartString),
34
35    /// Operation timeout
36    #[error("Operation timeout: {0}")]
37    Timeout(SmartString),
38}
39
40/// Result type alias for OMS operations
41pub type Result<T> = std::result::Result<T, OmsError>;
42
43impl From<std::string::String> for OmsError {
44    fn from(s: std::string::String) -> Self {
45        Self::Internal(SmartString::from(s))
46    }
47}
48
49impl From<&str> for OmsError {
50    fn from(s: &str) -> Self {
51        Self::Internal(SmartString::from(s))
52    }
53}
54
55impl From<crate::risk_manager::RiskError> for OmsError {
56    fn from(err: crate::risk_manager::RiskError) -> Self {
57        match err {
58            crate::risk_manager::RiskError::QuantityTooLarge => {
59                Self::RiskViolation("QuantityTooLarge".into())
60            }
61            crate::risk_manager::RiskError::PriceOutOfRange => {
62                Self::RiskViolation("PriceOutOfRange".into())
63            }
64        }
65    }
66}