nautechsystems / nautilus_trader

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

Limit order fill behavior incorrect for multiple level books #1733

Closed cjdsellers closed 6 days ago

cjdsellers commented 1 week ago

Bug Report

Per #1730 the OrderMatchingEngine is not correctly handling limit order fills when a data point moves past the order price and there is more than one level on that side of the book.

Expected Behavior

Resting limit orders should fill at their limit price, especially when post_only.

Actual Behavior

Only the top level of the book will "honor" the orders limit price, subsequent levels may move "through" the orders limit price.

Steps to Reproduce the Problem

  1. Setup an OrderBook with a book_type of L2_MBP and market-by-price order book data (multi-level)
  2. Setup a resting limit order
  3. Process the book with updates which move partial fills through the limit price

Specifications

cjdsellers commented 6 days ago

Now fixed from 1c9f48567a09d42400a8d85fc248d9916edd4001.