# How do stock trades actually go through? [duplicate]

I am trying to get a handle on how stock trades actually go through practically. Let's assume a stock with only one buyer and one seller to make things easier to understand.

Scenario 1: Alice has an ASK price of \$10.00 and Bob has a BID price of \$9.00.
Scenario 2: Alice has an ASK price of \$9.50 and Bob has a BID price of \$9.50.
Scenario 3: Alice has an ASK price of \$9.00 and Bob has a BID price of \$10.00.

In scenario 1, the trade obviously doesn't happen, because they aren't compatible. The seller wants more than the buyer is willing to pay.

In scenario 2, the trade goes through because it's a match made in heaven.

In scenario 3, I am confused. I'd like to think the trade goes through, because why wouldn't it? But at what price does the trade happen? At the seller's price? Or the buyer's? Or does the stock get sold at the ASK price and bought at the BID price and the difference goes somewhere?

I wish to understand how scenario 3 works. And in general, I want to understand if I am thinking about this correctly. How do trades happen? How do buyers and sellers get matched with each other?

Typically there's more than two partners, more like 1000. The computer finds the execution price between all their bids and asks that allows the maximum volume to trade. [Edit: while - of course - still respecting everyones bid and ask price]

If this is not unique, the middle price of all equal volume options is taken.

• This answer is wrong. Matching an order in this manner would violate the SEC's requirement to respect the NBBO. See, for example, investopedia.com/terms/n/nbbo.asp – user32479 Jan 21 '16 at 0:27
• There is no contradiction; of course the max volume calculation would still respect everyone's bid and ask price. So everyone gets what he asked for? – Aganju Jan 21 '16 at 0:56
• @Agaju That's not enough. The first order must by assumption be at the NBBO (otherwise it doesn't come into play at all). The second order when entered is not entered under the same conditions since the first order is already there and incorporated into the NBBO. The second order should be executed immediately based on the NBBO at the time that it come up for execution. The first order - since it's sitting on the book in this scenario - must not have had a match when it was entered. Otherwise it would have been executed. Even with the edit this is wrong. – user32479 Jan 21 '16 at 0:59