pub enum MarketEvent {
Tick {
symbol: String,
ts: NaiveDateTime,
bid: f64,
ask: f64,
},
Bar {
symbol: String,
ts: NaiveDateTime,
open: f64,
high: f64,
low: f64,
close: f64,
volume: i64,
spread: Option<f64>,
timeframe_seconds: Option<u64>,
tick_count: Option<u64>,
},
}Expand description
A single market data event consumed by the backtest runner.
Variants§
Tick
A bid/ask tick.
Bar
An OHLCV bar.
Fields
ts: NaiveDateTimespread: Option<f64>Symmetric bid/ask spread in price units observed while the bar formed.
None means the spread is unknown, which keeps the historical zero-spread approximation for feeds that cannot supply it.
Implementations§
Source§impl MarketEvent
impl MarketEvent
Sourcepub fn ts(&self) -> NaiveDateTime
pub fn ts(&self) -> NaiveDateTime
Timestamp of the event.
Sourcepub fn to_quote(&self) -> PriceQuote
pub fn to_quote(&self) -> PriceQuote
Convert the event into a PriceQuote suitable for the trade engine.
A tick carries its own two-sided quote. A bar yields its closing quote, with its recorded spread applied symmetrically around the close; FutureQuote replay executes a bar through MarketEvent::bar_execution_prices instead, over its open, range, and close. A bar without a recorded spread keeps the zero-spread approximation; use MarketEvent::to_quote_with_spread_fallback to supply one.
Sourcepub fn to_quote_with_spread_fallback(&self, fallback: Option<f64>) -> PriceQuote
pub fn to_quote_with_spread_fallback(&self, fallback: Option<f64>) -> PriceQuote
Convert the event into a PriceQuote, applying fallback when a bar has no recorded spread.
fallback is expressed in price units and applied symmetrically around the bar close. It is ignored for ticks and for bars that already carry a spread.
Sourcepub fn bar_execution_prices(
&self,
fallback: Option<f64>,
) -> Option<BarExecutionPrices>
pub fn bar_execution_prices( &self, fallback: Option<f64>, ) -> Option<BarExecutionPrices>
The execution view of a bar: its prices and half of the spread applied around each of them, using fallback when the bar records no spread. None for a tick.
Sourcepub fn is_zero_spread_bar(&self) -> bool
pub fn is_zero_spread_bar(&self) -> bool
Whether this event is a bar that carries no usable spread.
Sourcepub fn to_valid_quote(&self) -> Option<PriceQuote>
pub fn to_valid_quote(&self) -> Option<PriceQuote>
Convert this event into a quote only when its executable bid/ask view is finite, positive, and not crossed.