use std::{error::Error, fmt};
#[derive(Debug, Clone, Copy, Default)]
pub enum DisplayType {
Overlay,
#[default]
Indicator,
Volume,
Price,
}
impl fmt::Display for DisplayType {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:?}", self)
}
}
#[derive(Debug, Clone, Copy)]
pub enum IndicatorType {
Trend,
Momentum,
Volume,
Volatility,
Price,
Cycle,
CandleStick,
Math,
Other,
}
impl fmt::Display for IndicatorType {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:?}", self)
}
}
#[derive(Clone, Copy)]
pub struct Info {
pub name: &'static str,
pub full_name: &'static str,
pub indicator_type: IndicatorType,
pub inputs: &'static [&'static str],
pub options: &'static [&'static str],
pub outputs: &'static [&'static str],
pub optional_outputs: &'static [&'static str],
pub display_groups: &'static [DisplayGroup],
}
#[derive(Clone, Copy, Default)]
pub struct DisplayGroup {
pub id: &'static str, pub label: &'static str, pub display_type: DisplayType, pub offset: Option<&'static str>,
pub outputs: &'static [&'static str], }
impl IndicatorError {
pub fn message(&self) -> &str {
match self {
IndicatorError::InvalidInputs => {
"Invalid inputs provided for the indicator calculation"
}
IndicatorError::NotEnoughData => "Not enough data input parameter",
IndicatorError::InvalidOptions => "Invalid options provided",
IndicatorError::InvalidIndicatorState => "Invalid state inputs provided",
}
}
}
impl fmt::Display for IndicatorError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.message())
}
}
#[derive(Debug)]
pub enum IndicatorError {
InvalidInputs,
NotEnoughData,
InvalidOptions,
InvalidIndicatorState,
}
impl Error for IndicatorError {}
pub trait IndicatorStateDeref {
fn as_any(&self) -> &dyn std::any::Any;
fn as_any_mut(&mut self) -> &mut dyn std::any::Any;
}