DEXs also presents a unique opportunity with regard to the trade execution model. The two most prominent models of exchange design often center around the order book model and the automated market maker (AMM). This article will provide a breakdown of both of these trade execution models and explain the key differences that can impact trading experiences.
Orderbook

There are 2 types of orders in the order book: market order and limit order. When choosing a market order, traders can buy or sell for the best available price in DEXs promptly. It will match buyers and sellers with orders that are at the top of the book at that time. Meanwhile, when putting a limit order, traders choose expected prices and set the number of cryptos for buying or selling. The order will sit on the order book until a DEX system finds a suitable order and automatically matches it with yours.
AMM

Liquidity is one of the most prominent barriers in DEXs. Even though tokens are difficult to exchange efficiently, AMM designs come in handy in solving this problem. Unlike an order book that specifies prices at which buyers and sellers wish to trade, an AMM exchange aggregates liquidity for both sides of a trading pair into a pool. The AMM pool then determines a single market price according to a deterministic algorithm. The price formula is usually based on the pool’s current liquidity, or in other words the availability of an asset in the pool.
AMMs do not require market makers, but rather heavily rely on liquidity providers to join the pool and expand its size to ensure that tokens reflect a fair price.
Various AMM DEXs use different mathematical formulas to quote prices for their liquidity pools. Let us consider the XYK formula pioneered by the Position exchange as an example. The price was calculated based on the ratio of the two assets in the pool as follows:
x*y=k (constant)
The constant “k” represents the total token balances in a liquidity pool that determine the token prices, x, and y at a given time. Let us assume that x = BNB and y = POSI. Each time users buy BNB, the price of BNB increases as the quantity of BNB in the pool decreases. Conversely, the price of POSI decreases as the number of POSI increases. Liquidity pools often provide arbitrage opportunities that can be exploited for profit.
Let us assume that 1 BNB = 100 POSI at the time of the trade via a pool that has 10 BNB and 1000 POSI. If a trader wants to buy 2 BNB, they would need to swap 200 POSI for 2 BNB, leaving the pool with 8 BNB and 1200 POSI. The price of BNB is now 150 POSI causing impermanent losses (temporary losses of funds) for liquidity providers.
BNB = 1200/8 = 150 POSI

It is important to highlight arbitrage as a stabilizing mechanism, which incentivises traders to push the price determined by the AMM exchange closer to the spot price present in other exchanges. Expanding upon the example above, arbitrageurs can exploit this vulnerability and buy 2 BNB from a different market for a fair price of 200 POSI and sell them for 300 POSI in this liquidity pool. This would bring the price level of 1 BNB back to 100 POSI.
Compare Orderbook model and AMM model

POSITION EXCHANGE - DEX 2.0
