use thiserror::Error;
#[non_exhaustive]
#[derive(Debug, Error)]
pub enum ExchangeError {
#[error("HTTP error: {0}")]
Http(#[from] reqwest::Error),
#[error("WebSocket error: {0}")]
WebSocket(Box<tokio_tungstenite::tungstenite::Error>),
#[error("JSON error: {0}")]
Json(#[from] serde_json::Error),
#[error("Exchange API error — code: {code}, msg: {message}")]
Api {
code: String,
message: String,
},
#[error("Authentication error: {0}")]
Auth(String),
#[error("Config error: {0}")]
Config(String),
#[error("Order error: {0}")]
Order(String),
#[error("WebSocket disconnected after {attempts} reconnect attempts on {url}")]
WsDisconnected {
url: String,
attempts: u32,
},
#[error("Insufficient data: {0}")]
InsufficientData(String),
#[error(transparent)]
Other(#[from] anyhow::Error),
}
impl From<tokio_tungstenite::tungstenite::Error> for ExchangeError {
fn from(e: tokio_tungstenite::tungstenite::Error) -> Self {
Self::WebSocket(Box::new(e))
}
}
pub type Result<T> = std::result::Result<T, ExchangeError>;