hyper-agent-core 0.1.0

Core domain logic for hyper-agent: pipeline, executor, signals, positions
Documentation
use thiserror::Error;

#[derive(Debug, Error)]
pub enum HyperAgentError {
    #[error("Strategy not found: {0}")]
    StrategyNotFound(String),
    #[error("Risk blocked: {0}")]
    RiskBlocked(String),
    #[error("Circuit breaker tripped")]
    CircuitBreakerTripped,
    #[error("Execution failed: {0}")]
    ExecutionFailed(String),
    #[error("Auth error: {0}")]
    AuthError(String),
    #[error("Config error: {0}")]
    ConfigError(String),
    #[error("Storage error: {0}")]
    StorageError(String),
    #[error("Exchange error: {0}")]
    ExchangeError(String),
    #[error("Connection error: {0}")]
    ConnectionError(String),
    #[error("{0}")]
    Other(String),
}

pub type Result<T> = std::result::Result<T, HyperAgentError>;

// Conversions
impl From<crate::pipeline::PipelineError> for HyperAgentError {
    fn from(e: crate::pipeline::PipelineError) -> Self {
        match e {
            crate::pipeline::PipelineError::RiskBlocked(msg) => Self::RiskBlocked(msg),
            crate::pipeline::PipelineError::CircuitBreakerTripped => Self::CircuitBreakerTripped,
            crate::pipeline::PipelineError::ExecutionFailed(msg) => Self::ExecutionFailed(msg),
            crate::pipeline::PipelineError::AuthError(msg) => Self::AuthError(msg),
            crate::pipeline::PipelineError::ConnectionError(msg) => Self::ConnectionError(msg),
        }
    }
}

impl From<crate::executor::ExecutorError> for HyperAgentError {
    fn from(e: crate::executor::ExecutorError) -> Self {
        Self::ExecutionFailed(e.to_string())
    }
}

impl HyperAgentError {
    pub fn exit_code(&self) -> i32 {
        match self {
            Self::RiskBlocked(_) | Self::CircuitBreakerTripped => 4,
            Self::AuthError(_) => 3,
            Self::ExecutionFailed(_) | Self::ExchangeError(_) | Self::ConnectionError(_) => 5,
            Self::StrategyNotFound(_) => 6,
            _ => 1,
        }
    }
}