File size: 834 Bytes
59da845
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
use crate::data::parser::{Ohlcv, Tick};

pub enum DataRow {
    Ohlc(Ohlcv),
    TickData(Tick),
}

pub struct DataFeed {
    pub symbol: String,
    pub data: Vec<DataRow>,
    cursor: usize,
}

impl DataFeed {
    pub fn new(symbol: &str, data: Vec<DataRow>) -> Self {
        Self {
            symbol: symbol.to_string(),
            data,
            cursor: 0,
        }
    }

    pub fn reset(&mut self) {
        self.cursor = 0;
    }

    pub fn next(&mut self) -> Option<&DataRow> {
        if self.cursor < self.data.len() {
            let row = &self.data[self.cursor];
            self.cursor += 1;
            Some(row)
        } else {
            None
        }
    }
    
    pub fn len(&self) -> usize {
        self.data.len()
    }
    
    pub fn is_empty(&self) -> bool {
        self.data.is_empty()
    }
}