pub trait SimulationModule {
// Required methods
fn pre_process(&self, data: &Data);
fn process(
&self,
ts_now: UnixNanos,
ctx: &ExchangeContext<'_>,
) -> SimulationModuleResult;
fn acknowledge(&self, outcomes: &[AccountAdjustmentOutcome]);
fn log_diagnostics(&self);
fn reset(&self);
}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)
fn pre_process(&self, data: &Data)
Pre-processes market data before matching engine processing.
Sourcefn process(
&self,
ts_now: UnixNanos,
ctx: &ExchangeContext<'_>,
) -> SimulationModuleResult
fn process( &self, ts_now: UnixNanos, ctx: &ExchangeContext<'_>, ) -> SimulationModuleResult
Processes simulation logic at the given timestamp.
Returns a complete batch of account balance adjustments, or indicates that the module is not ready.
Sourcefn acknowledge(&self, outcomes: &[AccountAdjustmentOutcome])
fn acknowledge(&self, outcomes: &[AccountAdjustmentOutcome])
Acknowledges the ordered application outcomes for a completed batch.
This is called exactly once for every SimulationModuleResult::Completed,
including an empty batch.
§Panics
Implementations may panic if the outcome count does not match the completed batch or if no completed batch is awaiting acknowledgement.
Sourcefn log_diagnostics(&self)
fn log_diagnostics(&self)
Logs diagnostic information about the module’s state.
Trait Implementations§
Source§impl From<SimulationModuleAny> for Box<dyn SimulationModule>
impl From<SimulationModuleAny> for Box<dyn SimulationModule>
Source§fn from(value: SimulationModuleAny) -> Self
fn from(value: SimulationModuleAny) -> Self
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".