How would you implement a simple stock exchange matching engine?
Process orders in arrival order using price-time priority. Each order has a unique order_id, a side ("buy" or "sell"), an integer price, and an integer quantity.
Implement match_orders(orders). Return a dictionary containing trades, in execution order, and book, containing all remaining orders sorted by descending buy price and ascending sell price. A buy matches the lowest-priced sell when buy_price >= sell_price; a sell matches the highest-priced buy when sell_price <= buy_price. Execute each trade at the resting order's price.
def match_orders(orders):