Skip to content

RFC: Support emulated orders in backtests with only bar data #3517

@HaakonFlaaronning

Description

@HaakonFlaaronning

I will work on a solution for this over the coming days. It would be nice to get some input on the best approach.

Context

Emulated orders (using emulation_trigger) fail in backtests that only have bar data. The OrderEmulator subscribes to ticks via the message bus, but when backtesting with only bars available, no ticks are published - the synthetic ticks created by OrderMatchingEngine.process_bar() are only used internally.

This prevents users from validating emulated order behavior in backtests without tick data, creating inconsistency
between backtest and live trading results.

How native orders work with bars: When backtesting with bar data, OrderMatchingEngine.process_bar() generates synthetic ticks internally at Open→High→Low→Close prices and uses them to evaluate triggers and fill orders. This happens transparently - the matching engine processes whatever data it receives.

Desired outcome: Emulated orders should work seamlessly in bar-only backtests, using the same O→H→L→C price iteration that native orders use.

Proposed Solutions

Publish synthetic ticks from OrderMatchingEngine

Add an opt-in config flag that publishes internally-generated synthetic ticks to the DataEngine, making them available to OrderEmulator via the message bus.

  • Add publish_synthetic_ticks: bool to BacktestVenueConfig (high-level API)
  • Add publish_synthetic_ticks: bool parameter to BacktestEngine.add_venue() (low-level API)
  • Pass flag through to OrderMatchingEngine
  • In _process_trade_bar_* and _process_quote_bar_* methods, call _data_engine.process(tick) when enabled

Metadata

Metadata

Assignees

No one assigned

    Labels

    RFCA request for comment

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions