nautechsystems / nautilus_trader

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

Fix position closing on contract expiration #1624

Closed rsmb7z closed 5 months ago

rsmb7z commented 5 months ago

Pull Request

Fixes following bug when there are only closed positions.

nautilus_trader\\backtest\\matching_engine.pyx:1261: in nautilus_trader.backtest.matching_engine.OrderMatchingEngine.iterate
    ???
nautilus_trader\\backtest\\matching_engine.pyx:1331: in nautilus_trader.backtest.matching_engine.OrderMatchingEngine.iterate
    ???
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

>   ???
E   ValueError: invalid `PositionSide`, was FLAT

nautilus_trader\\model\\orders\\base.pyx:807: ValueError

Type of change

How has this change been tested?

Added test and resolved the exception.