-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Description
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: booltoBacktestVenueConfig(high-level API) - Add
publish_synthetic_ticks: boolparameter toBacktestEngine.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