pub struct ReplayClock { /* private fields */ }Expand description
A deterministic clock merging all instruments by time, sequence, then symbol. Advancing uses wall-clock elapsed time times the speed, never a bar index. Hosts own the input and scheduling. Seek rebuilds trades from the start and depth from the latest preceding snapshot per symbol.
use egui_charts::data::{MarketEvent, ReplayClock, ReplayEvent};
use egui_charts::model::Tick;
use std::time::Duration;
let time = chrono::Utc::now();
let event = ReplayEvent::new("A", time, 0,
MarketEvent::Trade(Tick::new(time, 100.0, 2.0, None)));
let mut clock = ReplayClock::new(vec![event]).unwrap();
clock.set_speed(2.0).unwrap();
assert_eq!(clock.advance(Duration::ZERO).unwrap().len(), 1);
assert!(clock.is_finished());Implementations§
Source§impl ReplayClock
impl ReplayClock
Sourcepub fn new(events: Vec<ReplayEvent>) -> Result<Self, FeedError>
pub fn new(events: Vec<ReplayEvent>) -> Result<Self, FeedError>
Sorts events into deterministic replay order. Duplicate time/sequence keys within one symbol or disagreeing payload timestamps/symbols are invalid; equal keys across symbols are ordered by symbol. Start at the first event, with no events consumed yet.
Sourcepub fn set_speed(&mut self, speed: f64) -> Result<(), FeedError>
pub fn set_speed(&mut self, speed: f64) -> Result<(), FeedError>
Sets a finite non-negative multiplier, preserving sub-nanosecond elapsed time.
Sourcepub fn is_finished(&self) -> bool
pub fn is_finished(&self) -> bool
Whether every recorded event has been consumed.
Sourcepub fn advance(
&mut self,
elapsed: Duration,
) -> Result<&[ReplayEvent], FeedError>
pub fn advance( &mut self, elapsed: Duration, ) -> Result<&[ReplayEvent], FeedError>
Advances by real elapsed time at the selected speed, returning newly due events once, including events at the new time. A paused clock consumes nothing. Overflow is an error without changing the cursor or time. Sub-nanosecond progress is retained between calls.
Sourcepub fn seek(&mut self, time: DateTime<Utc>) -> impl Iterator<Item = ReplayEvent>
pub fn seek(&mut self, time: DateTime<Utc>) -> impl Iterator<Item = ReplayEvent>
Seeks inclusively to time. Before pushing these events, call Sink::reset_replay on
every participating sink. Trades rebuild bars from the beginning; book messages before
each symbol’s latest snapshot are skipped. A symbol without a snapshot starts empty and
follows normal gap/resync rules. Subsequent advance returns only events after the seek.
Trait Implementations§
Source§impl Clone for ReplayClock
impl Clone for ReplayClock
Source§fn clone(&self) -> ReplayClock
fn clone(&self) -> ReplayClock
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for ReplayClock
impl RefUnwindSafe for ReplayClock
impl Send for ReplayClock
impl Sync for ReplayClock
impl Unpin for ReplayClock
impl UnsafeUnpin for ReplayClock
impl UnwindSafe for ReplayClock
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more