1use serde::{Deserialize, Serialize};
2use chrono::{DateTime, Utc};
3use crate::snapshot::MDSnapshot;
4
5#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
7pub struct Tick {
8 pub instrument_id: String,
10
11 pub last_price: f64,
13
14 pub volume: i64,
16
17 pub amount: f64,
19
20 pub datetime: DateTime<Utc>,
22}
23
24impl Tick {
25 pub fn new(
27 instrument_id: String,
28 last_price: f64,
29 volume: i64,
30 amount: f64,
31 datetime: DateTime<Utc>
32 ) -> Self {
33 Self {
34 instrument_id,
35 last_price,
36 volume,
37 amount,
38 datetime,
39 }
40 }
41
42 pub fn from_snapshot(snapshot: &MDSnapshot) -> Self {
44 Self {
45 instrument_id: snapshot.instrument_id.clone(),
46 last_price: snapshot.last_price,
47 volume: snapshot.volume,
48 amount: snapshot.amount,
49 datetime: snapshot.datetime,
50 }
51 }
52}