Store bids in TreeMap with reverseOrder for symmetric code
@tylerd▲ 0 net votes
Build the bid side as new TreeMap<>(Comparator.reverseOrder()) and the ask side as a plain TreeMap<Long, PriceLevel>. Then firstEntry() means 'best price' on both sides, and the matching loop, best-level lookup and level iteration work the same for buys and sells. The only side-specific logic left is the limit-price comparison (buy: level <= limit; sell: level >= limit).