Skip to main content

OrderFlowDetectors

Struct OrderFlowDetectors 

Source
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

Source

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.

Source

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

Source

pub fn new() -> Self

A service tracking no symbol, with detectors, alerts and sounds disabled.

Source

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.

Source

pub fn untrack(&self, symbol: &str)

Stops detecting on symbol and drops its state and detections.

Source

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.

Source

pub fn settings(&self) -> DetectorSettings

The settings of every detector.

Source

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.

Source

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.

Source

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

Source§

fn default() -> Self

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

impl Notifications for OrderFlowDetectors

Source§

fn watch(&self, events: Events<Notification>)

Pushes the recent notifications, oldest first, then each new one until events is inactive. Called when the panel starts and again after a lagged stream, each time with a new stream that starts from none. Read more
Source§

impl Signals for OrderFlowDetectors

Source§

fn subscribe( &self, symbol: &str, timeframe: Timeframe, events: Events<SignalEvent>, )

Starts pushing the signals of 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 more
Source§

fn clicked(&self, id: &SignalId)

The user clicked the signal id, which this service pushed. The default does nothing.

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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> MaybeSend for T
where T: Send + Sync + ?Sized,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

§

fn simd_from(_simd: S, value: T) -> T

§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

§

fn simd_into(self, simd: S) -> T

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.