Orderbooks usually use price-time priority.
Implement sort_by_priority.
sort_by_priority
For bids:
For asks:
This is what makes matching deterministic and fair among same-price orders.