Implement a simplified Voleon order book matcher. Orders arrive in the given sequence and are either limit or market orders, creating four combinations: buy limit, sell limit, buy market, and sell market.
Each order has a unique ID, side, type, and quantity. A limit order also has a price. Match every incoming order against resting orders on the opposite side using price-time priority. A buy limit can trade with the lowest-priced sell limit whose price is at most the buy price. A sell limit can trade with the highest-priced buy limit whose price is at least the sell price. Market orders trade at the best available opposite-side limit price. Market orders that cannot be fully executed are canceled and never rest in the book. A trade executes at the resting order's price.
Write match_orders(orders). orders is a list of dictionaries in arrival order:
id: unique stringside: either buy or selltype: either limit or marketprice: integer for limit orders, and null for market ordersquantity: positive integerReturn a list of arrays in execution order. Each array is [buy_id, sell_id, quantity, price]. Partial fills must be emitted as separate trades when an incoming order matches multiple resting orders.
def match_orders(orders):