Skip to main content

Tick

Struct Tick 

Source
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: Symbol

The traded instrument.

§price: Price

The trade price (positive).

§quantity: Quantity

The trade quantity (non-negative).

§side: Side

Whether this was a bid-side or ask-side aggressor.

§timestamp: NanoTimestamp

Exchange timestamp in nanoseconds.

Implementations§

Source§

impl Tick

Source

pub fn new( symbol: Symbol, price: Price, quantity: Quantity, side: Side, timestamp: NanoTimestamp, ) -> Self

Constructs a new Tick.

Source

pub fn notional(&self) -> Decimal

Returns the notional value of this tick: price * quantity.

Source

pub fn notional_checked(&self) -> Option<Decimal>

Returns the notional value using checked arithmetic, or None on overflow.

Source

pub fn is_buy_aggressor(&self) -> bool

Returns true if this tick represents an aggressive buy (bid-side aggressor).

Source

pub fn is_sell_aggressor(&self) -> bool

Returns true if this tick represents an aggressive sell (ask-side aggressor).

Source

pub fn is_buy(&self) -> bool

Returns true if this tick is on the buy (bid) side.

Source

pub fn is_sell(&self) -> bool

Returns true if this tick is on the sell (ask) side.

Source

pub fn is_uptick(&self, prev: &Tick) -> bool

Returns true if this tick’s price is strictly higher than prev.

Source

pub fn is_downtick(&self, prev: &Tick) -> bool

Returns true if this tick’s price is strictly lower than prev.

Source

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.

Source

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.

Source

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.

Source

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).

Source

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).

Source

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.

Source

pub fn max_price(ticks: &[Tick]) -> Option<Price>

Returns the highest traded price in the slice, or None if empty.

Source

pub fn min_price(ticks: &[Tick]) -> Option<Price>

Returns the lowest traded price in the slice, or None if empty.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn notional_volume(ticks: &[Tick]) -> Decimal

Returns the total notional value: Σ(price × quantity) across all ticks.

Zero when the slice is empty.

Source

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.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Clone for Tick

Source§

fn clone(&self) -> Tick

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Tick

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Tick

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for Tick

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl Freeze for Tick

§

impl RefUnwindSafe for Tick

§

impl Send for Tick

§

impl Sync for Tick

§

impl Unpin for Tick

§

impl UnsafeUnpin for Tick

§

impl UnwindSafe for Tick

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,