kiteticker_async_manager/models/
ohlc.rs

1use crate::Exchange;
2
3use crate::parser::price;
4
5#[derive(Debug, Clone, Default, PartialEq)]
6///
7/// OHLC packet structure
8///
9pub struct OHLC {
10  pub open: f64,
11  pub high: f64,
12  pub low: f64,
13  pub close: f64,
14}
15
16impl OHLC {
17  pub(crate) fn from(value: &[u8], exchange: &Exchange) -> Option<Self> {
18    if let Some(bs) = value.get(0..16) {
19      Some(OHLC {
20        open: price(&bs[0..=3], exchange).unwrap(),
21        high: price(&bs[4..=7], exchange).unwrap(),
22        low: price(&bs[8..=11], exchange).unwrap(),
23        close: price(&bs[12..=15], exchange).unwrap(),
24      })
25    } else {
26      None
27    }
28  }
29}