pub struct Tick {
pub symbol: Symbol,
pub price: Price,
pub quantity: Quantity,
pub side: Side,
pub timestamp: NanoTimestamp,
}Expand description
A single market trade event.
Fields§
§symbol: SymbolThe traded instrument.
price: PriceThe trade price (positive).
quantity: QuantityThe trade quantity (non-negative).
side: SideWhether this was a bid-side or ask-side aggressor.
timestamp: NanoTimestampExchange timestamp in nanoseconds.
Implementations§
Source§impl Tick
impl Tick
Sourcepub fn new(
symbol: Symbol,
price: Price,
quantity: Quantity,
side: Side,
timestamp: NanoTimestamp,
) -> Self
pub fn new( symbol: Symbol, price: Price, quantity: Quantity, side: Side, timestamp: NanoTimestamp, ) -> Self
Constructs a new Tick.
Sourcepub fn notional_checked(&self) -> Option<Decimal>
pub fn notional_checked(&self) -> Option<Decimal>
Returns the notional value using checked arithmetic, or None on overflow.
Sourcepub fn is_buy_aggressor(&self) -> bool
pub fn is_buy_aggressor(&self) -> bool
Returns true if this tick represents an aggressive buy (bid-side aggressor).
Sourcepub fn is_sell_aggressor(&self) -> bool
pub fn is_sell_aggressor(&self) -> bool
Returns true if this tick represents an aggressive sell (ask-side aggressor).
Sourcepub fn is_uptick(&self, prev: &Tick) -> bool
pub fn is_uptick(&self, prev: &Tick) -> bool
Returns true if this tick’s price is strictly higher than prev.
Sourcepub fn is_downtick(&self, prev: &Tick) -> bool
pub fn is_downtick(&self, prev: &Tick) -> bool
Returns true if this tick’s price is strictly lower than prev.
Sourcepub fn delta(ticks: &[Tick]) -> Decimal
pub fn delta(ticks: &[Tick]) -> Decimal
Returns buy volume minus sell volume for a slice of ticks.
Positive delta indicates net buying pressure; negative indicates net selling.
Equivalent to buy_volume - sell_volume.
Sourcepub fn cumulative_delta(ticks: &[Tick]) -> Vec<Decimal>
pub fn cumulative_delta(ticks: &[Tick]) -> Vec<Decimal>
Returns the running cumulative delta across a tick slice.
Each entry in the returned Vec is the running total of
buy_volume - sell_volume up to and including that tick.
An empty slice returns an empty Vec.
Sourcepub fn average_price(ticks: &[Tick]) -> Option<Decimal>
pub fn average_price(ticks: &[Tick]) -> Option<Decimal>
Returns the simple (unweighted) average price from a slice of ticks.
Returns None if the slice is empty. For volume-weighted price, use Tick::vwap_from_slice.
Sourcepub fn buy_volume(ticks: &[Tick]) -> Decimal
pub fn buy_volume(ticks: &[Tick]) -> Decimal
Returns the total bid-side (buy aggressor) volume from a slice of ticks.
Useful for computing buy pressure and delta (buy volume − sell volume).
Sourcepub fn sell_volume(ticks: &[Tick]) -> Decimal
pub fn sell_volume(ticks: &[Tick]) -> Decimal
Returns the total ask-side (sell aggressor) volume from a slice of ticks.
Useful for computing sell pressure and delta (buy volume − sell volume).
Sourcepub fn vwap_from_slice(ticks: &[Tick]) -> Option<Decimal>
pub fn vwap_from_slice(ticks: &[Tick]) -> Option<Decimal>
Computes the VWAP (volume-weighted average price) over a slice of ticks.
VWAP = Σ(price * quantity) / Σ(quantity)
Returns None when ticks is empty or total quantity is zero.
Sourcepub fn max_price(ticks: &[Tick]) -> Option<Price>
pub fn max_price(ticks: &[Tick]) -> Option<Price>
Returns the highest traded price in the slice, or None if empty.
Sourcepub fn min_price(ticks: &[Tick]) -> Option<Price>
pub fn min_price(ticks: &[Tick]) -> Option<Price>
Returns the lowest traded price in the slice, or None if empty.
Sourcepub fn time_weighted_avg_price(ticks: &[Tick]) -> Option<Decimal>
pub fn time_weighted_avg_price(ticks: &[Tick]) -> Option<Decimal>
Time-Weighted Average Price from a tick slice.
Each price is weighted by the elapsed nanoseconds since the previous tick.
The first tick receives zero weight. Returns None for slices with fewer than
2 ticks or zero total elapsed time.
Sourcepub fn largest_trade(ticks: &[Tick]) -> Option<&Tick>
pub fn largest_trade(ticks: &[Tick]) -> Option<&Tick>
Returns the tick with the highest notional value (price × quantity) in the slice.
Returns None if the slice is empty.
Sourcepub fn classify_aggressor(&self) -> &'static str
pub fn classify_aggressor(&self) -> &'static str
Returns a static label classifying the aggressor side of this tick.
"market_buy"when the aggressor is the buyer (Side::Bid)"market_sell"when the aggressor is the seller (Side::Ask)
Useful for logging, display, and building aggressor-pressure histograms.
Sourcepub fn imbalance_ratio(ticks: &[Tick]) -> Option<Decimal>
pub fn imbalance_ratio(ticks: &[Tick]) -> Option<Decimal>
Returns buy volume as a fraction of total volume: buy_vol / (buy_vol + sell_vol).
Result is in [0.0, 1.0]. Returns None when total volume is zero.
Values above 0.5 indicate net buying pressure; below 0.5 net selling pressure.
Sourcepub fn count_by_side(ticks: &[Tick]) -> (usize, usize)
pub fn count_by_side(ticks: &[Tick]) -> (usize, usize)
Returns (buy_count, sell_count) — tick counts by aggressor side.
Useful for measuring trade-frequency imbalance independently of volume.
Sourcepub fn notional_volume(ticks: &[Tick]) -> Decimal
pub fn notional_volume(ticks: &[Tick]) -> Decimal
Returns the total notional value: Σ(price × quantity) across all ticks.
Zero when the slice is empty.
Sourcepub fn tick_direction_series(ticks: &[Tick]) -> Vec<i8>
pub fn tick_direction_series(ticks: &[Tick]) -> Vec<i8>
Returns tick direction for each tick relative to the prior: +1 up, -1 down, 0 flat.
The first tick in the slice has no prior, so it is assigned 0.
Returns an empty Vec when ticks is empty.
Sourcepub fn median_price(ticks: &[Tick]) -> Option<Decimal>
pub fn median_price(ticks: &[Tick]) -> Option<Decimal>
Returns the median trade price across ticks.
Sorts prices and returns the middle value (lower-middle for even counts).
Returns None when the slice is empty.
Sourcepub fn price_impact(ticks: &[Tick], ref_price: Decimal) -> Option<Decimal>
pub fn price_impact(ticks: &[Tick], ref_price: Decimal) -> Option<Decimal>
Average signed price deviation from ref_price, weighted by trade size.
price_impact = Σ((price_i - ref_price) * qty_i) / Σ(qty_i)
Positive values indicate the flow of trades is above ref_price (buying pressure);
negative values indicate selling pressure below it.
Returns None when ticks is empty or total quantity is zero.
Sourcepub fn cluster_count(ticks: &[Tick], gap_ns: u64) -> usize
pub fn cluster_count(ticks: &[Tick], gap_ns: u64) -> usize
Counts temporal clusters in a tick slice.
A new cluster begins whenever the gap between consecutive tick timestamps
exceeds gap_ns nanoseconds. A single tick (or empty slice) counts as zero clusters.
Returns 0 for an empty slice. Returns 1 for a single tick.