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
impl OrderLatencyTracker
Sourcepub fn record_submit(&mut self, order_id: impl Into<String>, ts: NanoTimestamp)
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.
Sourcepub fn record_ack(
&mut self,
order_id: &str,
ts: NanoTimestamp,
) -> Result<(), FinError>
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
FinError::InvalidInputiforder_idis unknown or submit was not recorded.FinError::InvalidInputif ack timestamp is before submit timestamp.
Sourcepub fn record_fill(
&mut self,
order_id: &str,
ts: NanoTimestamp,
) -> Result<(), FinError>
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
FinError::InvalidInputiforder_idis unknown or ack was not recorded.FinError::InvalidInputif fill timestamp is before ack timestamp.
Sourcepub fn record_book_update(
&mut self,
order_id: &str,
ts: NanoTimestamp,
) -> Result<(), FinError>
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
FinError::InvalidInputiforder_idis unknown or fill was not recorded.FinError::InvalidInputif book_update timestamp is before fill timestamp.
Sourcepub fn stats(&self, phase: LatencyPhase) -> Option<PhaseStats>
pub fn stats(&self, phase: LatencyPhase) -> Option<PhaseStats>
Returns percentile statistics for phase, or None if no samples exist.
Sourcepub fn pending_count(&self) -> usize
pub fn pending_count(&self) -> usize
Returns the number of orders still awaiting lifecycle completion.
Sourcepub fn samples(&self, phase: LatencyPhase) -> &[i64]
pub fn samples(&self, phase: LatencyPhase) -> &[i64]
Returns all accumulated samples for phase.
Trait Implementations§
Source§impl Debug for OrderLatencyTracker
impl Debug for OrderLatencyTracker
Auto Trait Implementations§
impl Freeze for OrderLatencyTracker
impl RefUnwindSafe for OrderLatencyTracker
impl Send for OrderLatencyTracker
impl Sync for OrderLatencyTracker
impl Unpin for OrderLatencyTracker
impl UnsafeUnpin for OrderLatencyTracker
impl UnwindSafe for OrderLatencyTracker
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