barter_execution/model/
trade.rs

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
46
47
48
49
50
51
52
53
54
use super::order::OrderId;
use barter_integration::model::{
    instrument::{symbol::Symbol, Instrument},
    Side,
};
use serde::{Deserialize, Serialize};

/// Normalised Barter private [`Trade`] model.
#[derive(Clone, PartialEq, PartialOrd, Debug, Deserialize, Serialize)]
pub struct Trade {
    pub id: TradeId,
    pub order_id: OrderId,
    pub instrument: Instrument,
    pub side: Side,
    pub price: f64,
    pub quantity: f64,
    pub fees: SymbolFees,
}

/// Private [`Trade`] identifier generated by an exchange. Cannot assume this is unique across each
/// [`Exchange`](barter_integration::model::Exchange),
/// [`Market`](barter_integration::model::Market), or
/// [`Instrument`](barter_integration::model::Instrument).
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Deserialize, Serialize)]
pub struct TradeId(pub String);

impl<S> From<S> for TradeId
where
    S: Into<String>,
{
    fn from(id: S) -> Self {
        Self(id.into())
    }
}

/// [`Trade`] fees denominated in a [`Symbol`].
#[derive(Clone, PartialEq, PartialOrd, Debug, Deserialize, Serialize)]
pub struct SymbolFees {
    pub symbol: Symbol,
    pub fees: f64,
}

impl SymbolFees {
    /// Construct a new [`SymbolFees`].
    pub fn new<S>(symbol: S, fees: f64) -> Self
    where
        S: Into<Symbol>,
    {
        Self {
            symbol: symbol.into(),
            fees,
        }
    }
}