1use rusty_common::SmartString;
6use thiserror::Error;
7
8#[derive(Debug, Error)]
10pub enum OmsError {
11 #[error("Order validation failed: {0}")]
13 Validation(SmartString),
14
15 #[error("Risk check failed: {0}")]
17 RiskViolation(SmartString),
18
19 #[error("Exchange error: {0}")]
21 Exchange(SmartString),
22
23 #[error("Network error: {0}")]
25 Network(SmartString),
26
27 #[error("Internal error: {0}")]
29 Internal(SmartString),
30
31 #[error("Order not found: {0}")]
33 OrderNotFound(SmartString),
34
35 #[error("Operation timeout: {0}")]
37 Timeout(SmartString),
38}
39
40pub 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}