cxmr_exchanges/
trade.rs

1//! Crypto-bank trade structure.
2
3use std::cmp::Ordering;
4
5use super::Order;
6
7/// Currency trade details.
8#[derive(Serialize, Deserialize, PartialEq, Clone, Debug)]
9pub struct Trade {
10    /// Trade ID, unique only for a market.
11    #[serde(skip_serializing_if = "Option::is_none")]
12    pub id: Option<i64>,
13    /// Trade order.
14    pub order: Order,
15    /// Trade timestamp.
16    pub timestamp: u64,
17}
18
19impl PartialOrd for Trade {
20    fn partial_cmp(&self, other: &Trade) -> Option<Ordering> {
21        if self.timestamp > other.timestamp {
22            Some(Ordering::Greater)
23        } else if self.timestamp == other.timestamp {
24            Some(Ordering::Equal)
25        } else {
26            Some(Ordering::Less)
27        }
28    }
29}
30
31impl Ord for Trade {
32    fn cmp(&self, other: &Trade) -> Ordering {
33        self.partial_cmp(other).unwrap()
34    }
35}
36
37impl Eq for Trade {}