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
//! Crypto-bank trade structure.

use std::cmp::Ordering;

use super::Order;

/// Currency trade details.
#[derive(Serialize, Deserialize, PartialEq, Clone, Debug)]
pub struct Trade {
    /// Trade ID, unique only for a market.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub id: Option<i64>,
    /// Trade order.
    pub order: Order,
    /// Trade timestamp.
    pub timestamp: u64,
}

impl PartialOrd for Trade {
    fn partial_cmp(&self, other: &Trade) -> Option<Ordering> {
        if self.timestamp > other.timestamp {
            Some(Ordering::Greater)
        } else if self.timestamp == other.timestamp {
            Some(Ordering::Equal)
        } else {
            Some(Ordering::Less)
        }
    }
}

impl Ord for Trade {
    fn cmp(&self, other: &Trade) -> Ordering {
        self.partial_cmp(other).unwrap()
    }
}

impl Eq for Trade {}