qants 0.0.1

A package to get access to various exchanges and brokers. Build technical analysis statistics.
Documentation
#![allow(dead_code)]


//! # qants
//! 
//! ```qants``` is a collection of methods aimed to simplify work with crypto excahnges like ByBit and Binance;
//! crate allows: 
//! * connect directly to exchange, 
//! * get KLines. Historical and live through websocket connection 
//! * build statistics for techncial analysis. 
//!     * SMA
//!     * EMA
//!     * Stochastic


pub mod ta;


// mod oscillator;

pub use ta::moving_average::ma;



enum OHLC {
    Open(f64),
    High(f64),
    Low(f64),
    Close(f64),
    Volume(f64),
}


#[derive(Debug)]
pub struct Kline {
    values: Vec<f64>,
    start: Option<usize>,
}


impl Kline {
    /// Create Kline from `Vec<f64>` values. 
    /// Call Moving Average functions to get {EMA, SMA} - Exponential MA, Simple MA
    /// # Examples
    /// ```
    /// let values = Vec::from([1.0, 2.0, 3.0, 4.0, 5.0]);
    /// let kline_data = Kline::new(v);
    /// let sma = kline_data.rolling(window: 5).mean();
    /// assert_eq!(sma , 3.0)
    /// ```
    /// Returns SMA value 

    pub fn new(values: Vec<f64>) -> Kline {
        Kline { values, start: None }
    }    
}

pub fn sma(v: Vec<f64>) -> f64{
    let kline_data = Kline::new(v);
    let sma = kline_data.rolling(5).mean();
    sma
}

pub fn ema() {
    todo!()
}

pub fn stoch() {
    todo!()
}

#[test]
fn get_sma() {
    let v = vec![1.0, 2.0, 3.0, 4.0, 5.0];
    assert_eq!(sma(v), 3.0)
}



enum Decision {
    ShortSell,
    LongBuy,
    Reduce,
}

enum Trend {
    UpTrend,
    DownTrend
}
trait TrendState {
    fn get_240_ema_value() -> Trend {
        // if current close price > current ema_240 => uptrend
        todo!()
    }
}

enum StochSignals {
    StochUpperSignal{signal: u8},
    StochMiddleSignal{signal: u8},
    StochBottomSignal{signal: u8},
}


trait StochState {
    fn stoch();
}

struct Stoch{
    k_length: u8,
    k_smoothing: u8,
    d_smoothing: u8,
}

impl Stoch {
    pub fn new(
        k_length: u8,
        k_smoothing: u8,
        d_smoothing: u8,
    ) -> Stoch {
        Stoch { k_length, k_smoothing, d_smoothing }
    }
}