At this stage, the matching engine observes that you want to buy at $32, and someone is willing to sell at less than $32. You trade directly with that person at $32.
It's actually illegal for any matching engine to match the $31.90 bid, they must cross trades at the NBBO.
You place a limit order to buy FOO at $32
Someone else offers FOO at $31.90
That scenario would result in a locked market, which can't possibly happen under RegNMS. The exchange that saw the offer for $31.90 is required to route-out to the exchange with a bid of $32.
A HFT algorithm buys FOO at $31.90
That also can't happen. Even without RegNMS, the exchange's matching engine would have paired the value investor with the offer of $31.90, though the execution price would actually be $32. The HFT participant won't even see the ask price in this scenario.
Comments
I'm not involved in HFT, but I imagine the following scenario is plausible:
You place a limit order to buy FOO at $32
Someone else offers FOO at $31.90
A HFT algorithm buys FOO at $31.90 and immediately offers it at $32
You buy FOO at $32 from the HFT algo
So you have lost potential profit on the transaction even though you technically hit your limit price.
You place a limit order to buy FOO at $32
Someone else offers FOO at $31.90
At this stage, the matching engine observes that you want to buy at $32, and someone is willing to sell at less than $32. You trade directly with that person at $32.
It's actually illegal for any matching engine to match the $31.90 bid, they must cross trades at the NBBO.