Offer your thoughts or opinion on the input financial query or topic using your financial background.

How do exchanges match limit orders?
The total limit book is a composite of all the orders on all of the exchanges. While it's uncommon for a limit order posted beyond the NBBO to fill outside of the NBBO, it does occur. For example, the best ask may be on exchange X, but for some reason the smart order routing algorithm may select exchange Y if it judges the net trade to be less costly, malfunctions, etc, and HFTs will immediately arbitrage the order between two exchanges, or the best order on exchange X disappears causing the order to fill above the NBBO. The system isn't perfect because there are multiple exchanges, but that eventuality is extremely rare with equities since nearly every exchange will have orders posted at the NBBO because exchange equity fee and rebate schedules are extremely competitive, nearly identical.  It is however more common with options since less exchanges as a percentage of the total will have orders posted at the NBBO because of very wide exchange rebate and fee schedules. How a single exchange handles a new order that crosses an existing limit order is already addressed here: How do exchanges match limit orders?