use super::types::IndicatorType;
#[derive(Debug, Clone)]
pub struct IndicatorInfo {
pub id: String,
pub name: String,
pub desc: String,
pub category: String,
pub is_overlay: bool,
pub is_premium: bool,
pub indicator_type: Option<IndicatorType>,
}
impl IndicatorInfo {
pub fn new(id: impl Into<String>, name: impl Into<String>, desc: impl Into<String>) -> Self {
let id_str: String = id.into();
Self {
indicator_type: IndicatorType::from_id(&id_str),
id: id_str,
name: name.into(),
desc: desc.into(),
category: "Technical Analysis".to_string(),
is_overlay: false,
is_premium: false,
}
}
pub fn overlay(mut self) -> Self {
self.is_overlay = true;
self
}
pub fn premium(mut self) -> Self {
self.is_premium = true;
self
}
pub fn builtin_indicators() -> Vec<IndicatorInfo> {
IndicatorType::all()
.into_iter()
.map(|t| {
let mut info = IndicatorInfo::new(t.id(), t.name(), t.desc());
info.indicator_type = Some(t);
if t.is_overlay() {
info = info.overlay();
}
info
})
.collect()
}
}
#[derive(Debug, Clone)]
pub struct ConfiguredIndicator {
pub indicator_type: IndicatorType,
pub params: IndicatorParams,
}
#[derive(Debug, Clone, PartialEq)]
pub struct IndicatorParams {
pub period: usize,
pub bb_std_dev: f64,
pub macd_fast: usize,
pub macd_slow: usize,
pub macd_signal: usize,
pub stoch_k: usize,
pub stoch_d: usize,
pub supertrend_multiplier: f64,
pub ichimoku_tenkan: usize,
pub ichimoku_kijun: usize,
pub ichimoku_senkou: usize,
}
impl Default for IndicatorParams {
fn default() -> Self {
Self {
period: 14,
bb_std_dev: 2.0,
macd_fast: 12,
macd_slow: 26,
macd_signal: 9,
stoch_k: 14,
stoch_d: 3,
supertrend_multiplier: 3.0,
ichimoku_tenkan: 9,
ichimoku_kijun: 26,
ichimoku_senkou: 52,
}
}
}