nautechsystems / nautilus_trader

A high-performance algorithmic trading platform and event-driven backtester
https://nautilustrader.io
GNU Lesser General Public License v3.0
1.71k stars 402 forks source link

Fix venue_order_id issue for Sandbox #1629

Closed rsmb7z closed 1 month ago

rsmb7z commented 2 months ago

Pull Request

Fixes venue_order_id error on order event.

ValueError(The 'self.venue_order_id' <class 'nautilus_trader.model.identifiers.VenueOrderId'> of PAXOS-1-001 was not equal to the 'event.venue_order_id' <class 'nautilus_trader.model.identifiers.VenueOrderId'> of PAXOS-1-002)
Traceback (most recent call last):
  File "nautilus_trader\\execution\\engine.pyx", line 1007, in nautilus_trader.execution.engine.ExecutionEngine._apply_event_to_order
  File "nautilus_trader\\model\\orders\\base.pyx", line 946, in nautilus_trader.model.orders.base.Order.apply
  File "nautilus_trader\\core\\correctness.pyx", line 306, in nautilus_trader.core.correctness.Condition.equal

Type of change

Delete options that are not relevant.

cjdsellers commented 1 month ago

I'm not sure this is the right approach to take to fix the root cause?

The venue order ID should be generated by the matching engine only from _generate_venue_position_id, potentially running in sandbox mode creates a race condition here because we have this real time element external to the matching engine or any backtest engine loop.

Needs a little more investigating.

rsmb7z commented 1 month ago

@cjdsellers Yes you are right, even though it reduced the errors in my case with above but they are still there. Will update if I find any further clue.

davidsblom commented 1 month ago

Gave it another try as well in this pull request #1635. @rsmb7z would be interesting to see if it fixes your issue as well.

rsmb7z commented 1 month ago

Fixed here.