Order Matching with Mulltta

3 22
Avatar for mulltta
4 years ago

When matching buyers and sellers, an exchange uses an order matching system to make sure that trades are executed in a fair and consistent manner. Centralised cryptocurrency exchanges typically use a time priority algorithm to ensure fair matching occurs for all users.

Two orders matching to produce an Execution

All open orders are held in orderbooks, and sorted firstly by:

  • Price

and then by:

  • Time (First in - First out)

That is to say that everyone gets the closest price in the orderbook, and for any group of orders at exactly the same price, the oldest order gets executed first.

When orders are modified, a number of different things can happen:

Cancelling Orders:

If a user cancels their order, then it is removed from the orderbook, and can no longer be matched against.

Changing Order Price:

If a user updates an order to change the price, then the old order must be removed from the orderbook, and re-inserted at the new price location with the current time. The updated order does not keep it's old time priority as this would be unfair and break the first in - first out principle.

If the matching engine allowed the price to be changed without updating the time, then this would allow users to game the system and get an unfair advantage over other users.

Changing Order Quantity:

If a user updates an order to change the quantity, then we have to consider two separate cases:

  • Increase order quantity

  • Decrease order quantity

If the order quantity is increased, then depending on the matching engine logic, one of the following will happen:

  • Quantity increased whilst keeping the same time priority as the original quantity.

  • Quantity increased and the time priority is reset to the current time for the entire quantity.

  • The order is now composed of two sub-orders, the original order with the quantity and time priority, and a new order with the quantity and new time priority.

If the order quantity is decreased, then the time priority can be maintained and the quantity simply reduced. If this is considered undesirable, then the time priority can also be reset to the current time.

Many decisions need to be made when building a matching engine for a cryptocurrency exchange, and the exact matching logic should be publicly available for all users to see.

Mulltta is a fintech company which builds scalable solutions for the cryptocurrency and regular markets. Check out the official Mulltta website for more information about order matching, and their performance testing article for an in depth view into their system.

6
$ 0.10
$ 0.10 from @richardamullens
Avatar for mulltta
4 years ago

Comments

Interesting! But I think it misses the introduction or at least a link to what Mulltta is.

$ 0.00
4 years ago

Thanks for the feedback, we will update it.

$ 0.00
4 years ago

Interesting article

$ 0.00
4 years ago