[Community puzzle] Wall Street

Send your feedback or ask for help here!

Consider test case “Multiple trades”, given the following rule:
-A trade cannot be concluded between orders that aren’t on top of the book: the best price is always traded first.
-For a buy order the best price is the highest; for a sell order the best price is the lowest.

And the input:

11
ABC BUY 10 23.50
BBC BUY 10 13.50
ABC SELL 8 23.50
ABC SELL 5 23.50
BBC BUY 8 13.50
BBC BUY 12 13.50
ABC BUY 10 23.50
ABC SELL 10 23.45
ABC BUY 3 23.45
BBC BUY 10 13.50
BBC SELL 100 13.45

for ABC, we have
The best ABC BUY is 10 23.50 (highest buy)
The best ABC SELL is 10 23.45 (lowest sell)

hence the buyer will pay at least the amount the seller asks, and we have a trade.
But the testcase says:

Found: ABC 10 23.50…
Expected: ABC 8 23.50

Btw, if the buyers price is higher than the sellers price, and there is no previous price in the system (no prior sale) it is unclear what the price will be.
There could be a new rule ala: If the buyers price are higher than the seller price, and there are no prior trades, the price will be the asking (sellers) price.