1#[cfg(feature = "python")]
6use pyo3::prelude::*;
7use thiserror::Error;
8
9#[derive(Error, Debug)]
11pub enum ProcessingError {
12 #[error(
13 "Trades not sorted at index {index}: prev=({prev_time}, {prev_id}), curr=({curr_time}, {curr_id})"
14 )]
15 UnsortedTrades {
16 index: usize,
17 prev_time: i64,
18 prev_id: i64,
19 curr_time: i64,
20 curr_id: i64,
21 },
22
23 #[error("Empty trade data")]
24 EmptyData,
25
26 #[error(
27 "Invalid threshold: {threshold_decimal_bps} dbps. Valid range: 1-100,000 dbps (0.001%-100%)"
28 )]
29 InvalidThreshold { threshold_decimal_bps: u32 },
30}
31
32#[cfg(feature = "python")]
33impl From<ProcessingError> for PyErr {
34 fn from(err: ProcessingError) -> PyErr {
35 match err {
36 ProcessingError::UnsortedTrades {
37 index,
38 prev_time,
39 prev_id,
40 curr_time,
41 curr_id,
42 } => pyo3::exceptions::PyValueError::new_err(format!(
43 "Trades not sorted at index {}: prev=({}, {}), curr=({}, {})",
44 index, prev_time, prev_id, curr_time, curr_id
45 )),
46 ProcessingError::EmptyData => {
47 pyo3::exceptions::PyValueError::new_err("Empty trade data")
48 }
49 ProcessingError::InvalidThreshold {
50 threshold_decimal_bps,
51 } => pyo3::exceptions::PyValueError::new_err(format!(
52 "Invalid threshold: {} dbps. Valid range: 1-100,000 dbps (0.001%-100%)",
53 threshold_decimal_bps
54 )),
55 }
56 }
57}