Orders are matched according to price-time priority, e.g. orders with more aggressive price (higher for buy, lower for sell) have higher priority for matching, and for orders with the same price, their priorities are sorted by submission time ascending.
Matching happens when the highest bid price is higher than or equal to the lowest offer price.