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 55 56 57 58 59 60 61 62 63 64 65 66 67
use crate::TimestampResolution;
#[derive(Default, Debug, Clone, Copy, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
/// Defines a taker trade
pub struct Trade {
/// Timestamp, assumed to be in milliseconds
pub timestamp: i64,
/// Price of the asset
pub price: f64,
/// Size of the trade
/// negative values indicate a taker Sell order
pub size: f64,
}
impl TakerTrade for Trade {
#[inline(always)]
fn timestamp(&self) -> i64 {
self.timestamp
}
#[inline(always)]
fn price(&self) -> f64 {
self.price
}
#[inline(always)]
fn size(&self) -> f64 {
self.size
}
}
/// Defines how to aggregate trade size
/// either by Base currency or Quote Currency
/// assumes trades sizes are denoted in Quote
/// e.g.: buy 10 contracts of BTC would be trade size of 10
#[derive(Debug, Clone, Copy)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum By {
/// when aggregating by Base, divide size by price for volume sum
Base,
/// when aggregating by Quote, take the raw trade size for volume sum
/// as the assumption is that Trade size is denoted in Quote
Quote,
}
/// Trait to enable third party types to be passed into aggregators.
pub trait TakerTrade {
/// The timestamp of a trade,
fn timestamp(&self) -> i64;
/// units for the timestamp integer returned by [TakerTrade.timestamp()] method
/// A default implementation is included and assumes milliseconds
fn timestamp_resolution(&self) -> TimestampResolution {
TimestampResolution::Millisecond
}
/// Fill price of the transaction
fn price(&self) -> f64;
/// Number of shares or contracts in this trade.
/// A negative value indicates
/// that the trade was executed on the bid (market sell order).
fn size(&self) -> f64;
}