pub trait FillModel {
// Required method
fn fill_price(&self, fill: &FillContext<'_>) -> Option<Decimal>;
}Expand description
Prices a fill the venue has already decided will happen.
§Backtest-only
Only simulated execution consults a FillModel. Live execution clients receive real fill
prices from the venue.
§Called only for a taker
A market order, or a limit order that is marketable when it arrives. A resting order matched later fills at its own limit price and never reaches a fill model: a maker is paid the price it quoted, and price improvement accrues to the aggressor that crossed it.
§This model does not see the limit price, and must not
A limit constrains the result, not the pricing. The venue clamps whatever is returned to the order’s limit — never above a buy’s, never below a sell’s — so an implementation models slippage and spread and cannot produce a fill outside the order’s terms.
Reading the limit here is how two of the three models this crate ships came to return the limit itself for a marketable order: a buy limit of 51,000 arriving against an ask of 50,000 filled at 51,000 — a worse price than a market order got under the same configuration. The third returned the midpoint even when it sat above a buy’s limit. Removing the parameter is what makes that class of error unwritable rather than merely documented.
§Extensibility
Implement this to model slippage, market impact, or other execution dynamics. The built-in
models (LastPriceFillModel, BidAskFillModel, MidpointFillModel) are baselines.
§Returns
None when the context carries nothing this model can price from — no prices at all on the
first ticks of a backtest, say. The venue turns that into a rejection naming the instrument
rather than a panic.
Required Methods§
fn fill_price(&self, fill: &FillContext<'_>) -> Option<Decimal>
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".