Write the core logic of a matching engine