Algorithm

Navigating human greed with optimal path

The matching engine algorithm initiates by meticulously pairing a user's new order with existing orders listed in the order book. Once the matching process concludes, any unfulfilled portions of the order are securely deposited into a new order stored in the order book, complete with a limit price safeguard to mitigate potential Miner Extractable Value (MEV) risks.

Taking Orders

Order Matching with the Greedy Algorithm

In the context of order matching, a Greedy Algorithm is employed to optimize trades. When dealing with bid orders, the algorithm matches buying deposits that involve quote assets with ask orders containing base assets. The objective is to maximize the acquisition of base assets while minimizing the cost associated with the transaction.

Conversely, in ask orders, the algorithm pairs selling deposits that consist of base assets with bid orders that include quote assets. The goal here is to maximize the acquisition of quote assets relative to the amount of base assets being traded. This approach ensures that each trade is executed in a manner that is most advantageous to the involved parties, whether they are buying or selling.

Making Orders

Storing order in sorted linked list for the next iteration

In a bid order, the system places and positions the order at the most competitive price point within the market's order book, striving to acquire the base asset at the lowest available price. This not only ensures cost-effectiveness for the buyer but also promotes healthy competition among market participants, ultimately leading to more efficient price discovery and improved market liquidity.

In an ask order, the system positions the order at the highest price within the order book, aiming to sell the base asset at the most favorable rate obtainable in the market. This approach helps sellers maximize their potential profits and contributes to the market's overall price stability and transparency.

Last updated