Skip to main content

OrderLatencyTracker

Struct OrderLatencyTracker 

Source
pub struct OrderLatencyTracker { /* private fields */ }
Expand description

Records open orders and accumulates latency samples for each lifecycle phase.

§Example

use fin_primitives::latency::{OrderLatencyTracker, LatencyPhase};
use fin_primitives::types::NanoTimestamp;

let mut tracker = OrderLatencyTracker::new();
let t0 = NanoTimestamp::new(1_000_000_000);
let t1 = NanoTimestamp::new(1_000_001_000);
let t2 = NanoTimestamp::new(1_000_002_500);
let t3 = NanoTimestamp::new(1_000_003_000);

tracker.record_submit("ord1", t0);
tracker.record_ack("ord1", t1).unwrap();
tracker.record_fill("ord1", t2).unwrap();
tracker.record_book_update("ord1", t3).unwrap();

let stats = tracker.stats(LatencyPhase::SubmitToAck).unwrap();
assert_eq!(stats.count, 1);
assert_eq!(stats.p50_ns, 1000);

Implementations§

Source§

impl OrderLatencyTracker

Source

pub fn new() -> Self

Creates a new empty OrderLatencyTracker.

Source

pub fn record_submit(&mut self, order_id: impl Into<String>, ts: NanoTimestamp)

Records the submission timestamp of order_id.

If a record for order_id already exists it is reset.

Source

pub fn record_ack( &mut self, order_id: &str, ts: NanoTimestamp, ) -> Result<(), FinError>

Records the acknowledgement timestamp of order_id.

Stores the submit→ack latency sample.

§Errors
Source

pub fn record_fill( &mut self, order_id: &str, ts: NanoTimestamp, ) -> Result<(), FinError>

Records the fill timestamp of order_id.

Stores the ack→fill latency sample.

§Errors
Source

pub fn record_book_update( &mut self, order_id: &str, ts: NanoTimestamp, ) -> Result<(), FinError>

Records the book-update timestamp of order_id and removes it from pending.

Stores the fill→book-update latency sample.

§Errors
Source

pub fn stats(&self, phase: LatencyPhase) -> Option<PhaseStats>

Returns percentile statistics for phase, or None if no samples exist.

Source

pub fn pending_count(&self) -> usize

Returns the number of orders still awaiting lifecycle completion.

Source

pub fn samples(&self, phase: LatencyPhase) -> &[i64]

Returns all accumulated samples for phase.

Trait Implementations§

Source§

impl Debug for OrderLatencyTracker

Source§

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

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

impl Default for OrderLatencyTracker

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.