pub trait SimulationModule {
// Required methods
fn pre_process(&self, data: &Data) -> Result<()>;
fn process(
&self,
ts_now: UnixNanos,
ctx: &ExchangeContext<'_>,
) -> Result<SimulationModuleResult>;
fn acknowledge(&self, outcomes: &[AccountAdjustmentOutcome]) -> Result<()>;
fn log_diagnostics(&self) -> Result<()>;
fn reset(&self) -> Result<()>;
}Expand description
Trait for custom simulation modules that extend backtesting functionality.
Implementations can add specialized behavior such as rollover interest, market makers, price impact models, or other venue-specific simulation logic that runs alongside the core backtesting engine.
Modules use interior mutability (Cell/RefCell) for state since they
are stored inside SimulatedExchange and invoked through shared references.
Required Methods§
Sourcefn pre_process(&self, data: &Data) -> Result<()>
fn pre_process(&self, data: &Data) -> Result<()>
Pre-processes market data before matching engine processing.
§Errors
Returns an error if the module cannot accept the data.
Sourcefn process(
&self,
ts_now: UnixNanos,
ctx: &ExchangeContext<'_>,
) -> Result<SimulationModuleResult>
fn process( &self, ts_now: UnixNanos, ctx: &ExchangeContext<'_>, ) -> Result<SimulationModuleResult>
Processes simulation logic at the given timestamp.
Returns a complete batch of account balance adjustments, or indicates that the module is not ready.
§Errors
Returns an error if the module cannot process the exchange state.
Sourcefn acknowledge(&self, outcomes: &[AccountAdjustmentOutcome]) -> Result<()>
fn acknowledge(&self, outcomes: &[AccountAdjustmentOutcome]) -> Result<()>
Acknowledges the ordered application outcomes for a completed batch.
This is called exactly once for every SimulationModuleResult::Completed,
including an empty batch.
§Errors
Returns an error if the outcomes do not match the pending completed batch or the module cannot record them. The exchange treats an acknowledgement failure as terminal until reset because account adjustments may already have been applied.
Sourcefn log_diagnostics(&self) -> Result<()>
fn log_diagnostics(&self) -> Result<()>
Logs diagnostic information about the module’s state.
§Errors
Returns an error if the module cannot produce its diagnostics.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".