Skip to main content

qs_core/
error.rs

1use thiserror::Error;
2
3/// Errors produced by the core trade engine.
4#[derive(Debug, Error)]
5pub enum CoreError {
6    #[error("position not found: {0}")]
7    PositionNotFound(String),
8
9    #[error("group not found: {0}")]
10    GroupNotFound(String),
11
12    #[error("invalid action: {0}")]
13    InvalidAction(String),
14
15    #[error("take-profit target {price} not found for position {position_id}")]
16    TargetNotFound { position_id: String, price: f64 },
17
18    #[error("take-profit target {price} has already triggered for position {position_id}")]
19    TargetAlreadyTriggered { position_id: String, price: f64 },
20
21    #[error("no price available for symbol: {0}")]
22    NoPriceAvailable(String),
23
24    #[error("position not in expected state: id={id}, expected={expected}, actual={actual}")]
25    InvalidState {
26        id: String,
27        expected: String,
28        actual: String,
29    },
30
31    #[error("{0}")]
32    Other(String),
33}
34
35/// Convenience alias used throughout qs-core.
36pub type Result<T> = std::result::Result<T, CoreError>;