pub struct Trade {
pub id: TradeId,
pub price: Price,
pub quantity: Quantity,
pub aggressor_order_id: OrderId,
pub passive_order_id: OrderId,
pub aggressor_side: Side,
pub timestamp: Timestamp,
}Expand description
A completed trade between two orders.
Trades are created when an incoming (aggressor) order matches against a resting (passive) order on the book.
Fields§
§id: TradeIdUnique identifier assigned by exchange
price: PriceExecution price (always the resting order’s price)
quantity: QuantityQuantity executed
aggressor_order_id: OrderIdOrder that initiated the trade (taker)
passive_order_id: OrderIdOrder that was resting on the book (maker)
aggressor_side: SideSide of the aggressor order
timestamp: TimestampWhen the trade occurred
Implementations§
Source§impl Trade
impl Trade
Sourcepub fn new(
id: TradeId,
price: Price,
quantity: Quantity,
aggressor_order_id: OrderId,
passive_order_id: OrderId,
aggressor_side: Side,
timestamp: Timestamp,
) -> Self
pub fn new( id: TradeId, price: Price, quantity: Quantity, aggressor_order_id: OrderId, passive_order_id: OrderId, aggressor_side: Side, timestamp: Timestamp, ) -> Self
Create a new trade.
Sourcepub fn passive_side(&self) -> Side
pub fn passive_side(&self) -> Side
Returns the side of the passive (maker) order.
Sourcepub fn notional(&self) -> i64
pub fn notional(&self) -> i64
Returns the notional value (price × quantity).
Note: This returns the raw product of price units × quantity. Interpretation depends on your price unit convention.
Sourcepub fn vwap(trades: &[Trade]) -> Option<Price>
pub fn vwap(trades: &[Trade]) -> Option<Price>
Compute the volume-weighted average price (VWAP) of a trade series.
Returns None if the slice is empty or total quantity is zero.
use nanobook::{Trade, Price, TradeId, OrderId, Side};
let trades = vec![
Trade::new(TradeId(1), Price(100_00), 50, OrderId(1), OrderId(2), Side::Buy, 1),
Trade::new(TradeId(2), Price(102_00), 150, OrderId(3), OrderId(4), Side::Buy, 2),
];
let vwap = Trade::vwap(&trades).unwrap();
// (100_00 * 50 + 102_00 * 150) / 200 = 101_50
assert_eq!(vwap, Price(101_50));Trait Implementations§
impl Eq for Trade
impl StructuralPartialEq for Trade
Auto Trait Implementations§
impl Freeze for Trade
impl RefUnwindSafe for Trade
impl Send for Trade
impl Sync for Trade
impl Unpin for Trade
impl UnwindSafe for Trade
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more