pub struct FillRoutingService { /* private fields */ }Expand description
Routes fills from a FillSource to every brain, refreshes the
position cache, and auto-feeds realised PnL into the risk state.
§PnL accounting
The service uses a weighted-average entry model (the same model
the backtest engine uses). It reads the cached Position before
refreshing it from the exchange, so the entry_price available is
the pre-fill average. From that:
- A fill in the same direction as the open position adds to it.
No realised PnL emitted; the post-refresh average from
exchange.get_positionbecomes the new entry. - A fill in the opposite direction reduces the position. Gross
PnL =
(fill_price - entry) * closed_qty * direction. The service callsBotHandle::record_trade_outcomeon the closed portion to feedSessionPnl+CircuitBreaker. - A fill that flips the position emits realised PnL for the closed portion only; the opening leg is left for the next reducing fill.
Fees come from Fill.fee. Hosts that need a different accounting
model (FIFO, LIFO, tax-lot) should compute PnL themselves and call
BotHandle::record_trade_outcome directly — but cannot also wire a
FillRoutingService, since the two would double-count.
Implementations§
Source§impl FillRoutingService
impl FillRoutingService
Sourcepub fn oco_cancels(&self) -> u64
pub fn oco_cancels(&self) -> u64
Total OCO siblings cancelled in response to a bracket leg filling.
Sourcepub fn fills_routed(&self) -> u64
pub fn fills_routed(&self) -> u64
Total fills delivered to brains since service start.
Sourcepub fn refresh_errors(&self) -> u64
pub fn refresh_errors(&self) -> u64
Total exchange.get_position failures during cache refresh.
Sourcepub fn trades_recorded(&self) -> u64
pub fn trades_recorded(&self) -> u64
Total realised-PnL closures fed into the risk state.