qamd_rs/
tick.rs

1use serde::{Deserialize, Serialize};
2use chrono::{DateTime, Utc};
3use crate::snapshot::MDSnapshot;
4
5/// Basic tick data representing a single price update
6#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
7pub struct Tick {
8    /// Unique identifier for the instrument (e.g., "SSE_688286")
9    pub instrument_id: String,
10    
11    /// Last traded price
12    pub last_price: f64,
13    
14    /// Total trading volume
15    pub volume: i64,
16    
17    /// Total turnover value
18    pub amount: f64,
19    
20    /// Timestamp of the tick
21    pub datetime: DateTime<Utc>,
22}
23
24impl Tick {
25    /// Create a new tick with the given values
26    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    /// Extract a tick from a market data snapshot
43    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}