pub struct OrderFlowDetectors { /* private fields */ }Expand description
A Signals service that finds order-flow events in the executions and depth a host already
streams, as PaperAccount is a ready-made
Broker. It needs no egui, so a server can run the same code.
The host tracks each symbol and feeds the service the events it pushes into
the chart’s Sink, as MarketEvent values tagged with the symbol and
their feed time, so live feeds, recordings and replay share one input. Every window runs on
that feed time, never the wall clock, so replayed data gives the signals live data gave.
Trades. A trade with an id already seen is dropped, so the trade an order execution carries
counts once even when the feed also sends it as a trade. Fills group by the aggressor id on
their first copy; later copies cannot identify it retroactively. A feed that prints the tape
first must carry that id on the print or push the order execution before its tape copy.
Trades that are not finite numbers or have a negative size are ignored.
push_history runs loaded trades through the same detection.
Trade timestamps must be valid feed times, including in loaded
history: the service trusts them without a tolerance against observation time. A far-future
timestamp can end zones at that time and advance the forming bar past later prints, preventing
body and wick classification until reset. Validate times before pushing them.
Book. Depth snapshots and deltas, and order snapshots and events, keep the symbol’s book
with the sequencing rules of the Sink: a gap or an invalid event clears the book without a
signal, and the next snapshot restores it.
Signals. Each DetectionKind has its own signal category, which the user can hide.
subscribe pushes the symbol’s most recent 5,000 detections, then each
new or changed one. Evicted detections are removed from existing subscriptions too.
use std::sync::Arc;
use egui_charts::data::{ReplayEvent, Sink};
use egui_charts::model::Instrument;
use egui_charts::services::OrderFlowDetectors;
let detectors = Arc::new(OrderFlowDetectors::new());
let mut instrument = Instrument::new("ES");
instrument.tick_size = Some(0.25);
detectors.track(&instrument).unwrap();
let mut settings = detectors.settings();
settings.big_trades.enabled = true;
detectors.set_settings(settings);
// `Chart::set_signal_source(Some(detectors.clone()))` draws the detections.
/// Pushes one event of the feed into the chart and into the detectors.
fn push(sink: &Sink, detectors: &OrderFlowDetectors, event: &ReplayEvent) {
event.push_to(sink);
detectors.push(&event.symbol, event.time, &event.event);
}Implementations§
Source§impl OrderFlowDetectors
impl OrderFlowDetectors
Sourcepub fn counts(
&self,
symbol: &str,
kind: DetectionKind,
now: DateTime<Utc>,
) -> DetectionCounts
pub fn counts( &self, symbol: &str, kind: DetectionKind, now: DateTime<Utc>, ) -> DetectionCounts
Counts of kind on symbol at the current feed time, or zero for an untracked symbol.
Windows retain five minutes relative to the latest supplied feed time; queries before
that retained interval cannot restore expired detections. Wall-clock time is not used.
Sourcepub fn take_alerts(&self) -> Vec<DetectionAlert>
pub fn take_alerts(&self) -> Vec<DetectionAlert>
Drains pending live alerts once, oldest first. At most the latest 5,000 are retained between calls; draining does not remove entries from the notification log.
Source§impl OrderFlowDetectors
impl OrderFlowDetectors
Sourcepub fn track(&self, instrument: &Instrument) -> Result<(), FeedError>
pub fn track(&self, instrument: &Instrument) -> Result<(), FeedError>
Starts detecting on instrument, which needs a positive and finite tick size. Tracking a
tracked symbol starts it afresh.
Sourcepub fn untrack(&self, symbol: &str)
pub fn untrack(&self, symbol: &str)
Stops detecting on symbol and drops its state and detections.
Sourcepub fn reset(&self, symbol: &str)
pub fn reset(&self, symbol: &str)
Drops the state and detections of symbol and starts it afresh, as after a session
change or a replay seek.
Sourcepub fn settings(&self) -> DetectorSettings
pub fn settings(&self) -> DetectorSettings
The settings of every detector.
Sourcepub fn set_settings(&self, settings: DetectorSettings)
pub fn set_settings(&self, settings: DetectorSettings)
Replaces the settings of every detector from the next event on. Completed detections stay; a disabled liquidity tracker drops its unfinished zones. Panics if a fixed threshold is not positive and finite, or a refill or count-alert minimum is zero.
Sourcepub fn push(&self, symbol: &str, time: DateTime<Utc>, event: &MarketEvent)
pub fn push(&self, symbol: &str, time: DateTime<Utc>, event: &MarketEvent)
Detects on event of symbol, observed at feed time time. Events of untracked symbols
are ignored.
Sourcepub fn push_history(&self, symbol: &str, trades: &[Tick])
pub fn push_history(&self, symbol: &str, trades: &[Tick])
Detects on the loaded trade history of symbol, in time order, before the live trades
that follow it. Its detections are made and pushed like live ones and warm the automatic
thresholds and counts without raising alerts; trades with an id already seen are dropped.
Trait Implementations§
Source§impl Default for OrderFlowDetectors
impl Default for OrderFlowDetectors
Source§impl Notifications for OrderFlowDetectors
impl Notifications for OrderFlowDetectors
Source§impl Signals for OrderFlowDetectors
impl Signals for OrderFlowDetectors
Source§fn subscribe(
&self,
symbol: &str,
timeframe: Timeframe,
events: Events<SignalEvent>,
)
fn subscribe( &self, symbol: &str, timeframe: Timeframe, events: Events<SignalEvent>, )
symbol at timeframe into events until it is inactive.
Push the current signals first: each subscription starts from none. The terminal subscribes
again on every symbol or interval change and after the stream lagged, each time with a new
stream, and stops the old one. Read moreAuto Trait Implementations§
impl !Freeze for OrderFlowDetectors
impl RefUnwindSafe for OrderFlowDetectors
impl Send for OrderFlowDetectors
impl Sync for OrderFlowDetectors
impl Unpin for OrderFlowDetectors
impl UnsafeUnpin for OrderFlowDetectors
impl UnwindSafe for OrderFlowDetectors
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> 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