Skip to main content

SimulationModule

Trait SimulationModule 

Source
pub trait SimulationModule {
    // Required methods
    fn pre_process(&self, data: &Data);
    fn process(
        &self,
        ts_now: UnixNanos,
        ctx: &ExchangeContext<'_>,
    ) -> Vec<Money>;
    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§

Source

fn pre_process(&self, data: &Data)

Pre-processes market data before matching engine processing.

Source

fn process(&self, ts_now: UnixNanos, ctx: &ExchangeContext<'_>) -> Vec<Money>

Processes simulation logic at the given timestamp.

Returns account balance adjustments to be applied by the exchange.

Source

fn log_diagnostics(&self)

Logs diagnostic information about the module’s state.

Source

fn reset(&self)

Resets the module to its initial state.

Trait Implementations§

Source§

impl From<SimulationModuleAny> for Box<dyn SimulationModule>

Source§

fn from(value: SimulationModuleAny) -> Self

Converts to this type from the input type.

Implementors§