While we went into the basics of matching orders in our previous article, this article will go a step deeper into the orderbook. Going deeper down the rabbit hole will slowly help us understand how basics become the smartest algorithms.
How does an order get resolved and completed? An orderbook will keep on refreshing and find new matches. So, every match made, and trade completed, will ‘eat’ the orderbook. In a healthy market, there is always an orderbook with some ‘open’ trades on the ‘DEMAND’ and ‘SUPPLY’ side. And every trade that meets a match will be written out of the orderbook, refreshing and deciding upon its new market value to be sold or bought on.
To put it visually:
1. An order of ‘[email protected]’comes in; it goes into the ‘Matching Machine’ below to find a match with the existing orderbook.
2. In the orderbook, there is an open ‘[email protected]’ which it is matched with.
3. The buy order is fulfilled, and it can ‘leave’ the matching engine to the new owner.
4. The new owner is in possession of his asset.
5. The unmatched ‘[email protected]’ order returns to the top of the orderbook.
6. This makes a new orderbook and the algorithm repeats itself to find new matches.
A ‘buy’ like you see in the visual presentation is called an ‘aggressor order’. It basically eats the open order in the orderbook and creates a rise in price since there are no more available ‘[email protected]’ and the next is only at 201.
The opposite of the ‘aggressor order’ is the ‘resting order’. This is an order LOWER than the available price match in the orderbook. A visual representation of such an order is shown below:
Step 7 is added: ‘Order is not fulfilled’ and will return to the DEMAND side of the Orders until it finds a match. The orderbook is not changed or moved and is thus called a ‘resting order’.
It is also considered a resting order if there are partially filled orders under (3) but the supply is staying steady at a set price, not influencing any movement in the orderbook on the assets pricing. For example, ordering [email protected], but available are [email protected] There will still be [email protected] left in the orderbook and is thus not moving the price.
Two Popular Matching Order Algorithms
There are two matching orders which are most used. We will finish this article with those and see what is the difference between them. These are implemented when ‘questions arise’ with orders packed in the Matching Engine.
FiFo: We touched base on FiFo in the earlier ‘Order Matching 101’ article. It is called a ‘time/price priority’ putting the oldest order in front in matching with a buy/sell.
Tim puts in the order for ‘[email protected]’, Jack puts in the order for ‘[email protected]’. The orderbook contained ‘3 on offer @199’. Tim buys 2 and Jack buys 1, leaving [email protected] open at no.7 in the diagram above. They go back into the orderbook until they find the next match.
Pure Pro-Rata: Pro-Rata is Latin for ‘in proportion’ and means that everything that will be allocated as per their share of the whole. It is important to understand that things will get divided proportionally. The most honest way to calculate this is to count all the (used) assets and look at how many people own a certain percentage of this asset, and then divide the profit or distribution as per how much they invested or have.
A short example: Jack owns 30% of a company, Jill owns 30% of the same company and Ed owns 40%. They give 10 lollipops as a bonus which will be divided pro-rata.
Just like the saying “There are many roads that lead to Rome'', a combination of these allocations and selections can also be mixed, creating their own ‘Matching Engine’. The Mandala Exchange, backed by Binance Cloud, uses a combination of these methods in their state-of-the-art order matching system. As technology and understanding improve, both Mandala and Binance will upgrade their systems to provide the best in user experience, security, and fairness.