`on_position_event` callback receives each event twice
dkharrat opened this issue · comments
Bug Report
The on_position_event
callback in a strategy is being called with duplicate events. It receives each PositionEvent
twice. This is using backtesting. I haven't tried testing it live mode, so not sure if this happens there too or not. On the other hand, the on_event
callback receives the event once, so this seems isolated to the on_position_event
callback.
Expected Behavior
The on_position_event
callback should receive an event once.
Actual Behavior
The on_position_event
callback receives each event twice, resulting in the strategy receiving duplicate events.
Steps to Reproduce the Problem
- Create a test strategy that submits a market order and add a print statement in the
on_position_event
callback that prints theevent.id
. You'll notice that the callback receives each event twice.
Specifications
- OS platform: Ubuntu
- Python version: 3.11
nautilus_trader
version: Develop branch (commit a29de8a)
Hi @dkharrat
This is the intended design and explained here in the docs.
You only need to handle the event in either the specific position event handler, the general on_position_event
handler, or the on_event
handler - at your choice.
This also applies to order events too, see the event handling in the base class:
https://github.com/nautechsystems/nautilus_trader/blob/develop/nautilus_trader/trading/strategy.pyx#L1533