Designing an Exchange (Order books, AMMs, RFQs) Exchanges are the market's DNA. Details of their inner workings determine all downstream trading dynamics. A 🧵 on the different exchange microstructures and their mechanisms for order matching & market-making. 👇
1/ There are 4 main ways for an exchange to provide liquidity: 1. via CLOBs, aka central limit order books 2. via bonding curve AMMs, aka automated market maker 3. via RFQs, aka requests for quote 4. via auctions Each design has its strengths and tradeoffs.
Each design reflects a relative prioritization between: - price discovery - liquidity - slippage - scalability - responsiveness to volatility - capital efficiency for market makers - manipulability - composability - defensibility
2/ CLOBs (most common type) A CLOB is a transparent ledger of bids & offers, sorted best to worst (a running tally of prices and quantities @ which someone is willing to buy & sell) All traders see it; all traders can add to it. "Top Of Book" (1st line) shows best bid & offer.
3/ Order Matching on CLOBs Consider this simple CLOB w/ 3 price levels. - all orders here are "resting orders" (not yet filled because nobody on the buy side is matchable with anybody on the sell side) - bid/offer qty is the sum of all order quantities at a given level
5/ Slippage on thin books Now let's say instead of a limit order, Bob places a 4x SELL market order. Sadly instead of 9652 (best displayed bid), his avg fulfilled sell price is (1*9652+2*9650+1*9649)/4 = 9650.25. Bob loses 1.75 per share to slippage b/c the CLOB was too thin.
6/ Exchanges designed as CLOBs: Traditional finance - NYSE - Nasdaq - CME - CBOE - LSE - HKEX Cexs (centralized crypto exchanges) - FTX - Coinbase - Binance - OKEx - Huobi Dexs (decentralized crypto exchanges) - Serum - Raydium - Dexlab - Slope - dydx (off-chain book) etc..
7/ Why use a CLOB design? Pros: - liquidity transparency - enables market asymmetries - MMs free to make or take - MMs can widen/tighten spreads on high/low vol Cons: - cold start problem (hard to bootstrap liquidity) - bad for illiquid assets - if on-chain, requires "high" TPS
8/ Why so few CLOBs on ETH? ETH TPS is too low to support on-chain order book updating (most Dexs are AMMs). An exception, dydx, keeps its book off-chain (so order matching & price updating is off-chain; settlement is on-chain) Au contraire, SOL's 60K TPS enables many CLOBs.
9/ AMMs Automated Market Makers were invented as a workaround to the low TPS problem in DeFi. Think of AMMs as a series of swap machines (e.g. ETH/USDT,MATIC/USDT, ETH/MATIC etc.) There's no order book. Just a predetermined function that sets the price on all swap pairs.
This predetermined function (e.g. x*y=k) sets prices based on the changing ratio between supplies of 2 tokens in each "liquidity pool" (pools where anyone can contribute more of both tokens at the current ratio, for a kickback). For more details on AMMs: https://www.youtube.com/watch?...
10/ Exchanges designed as AMMs: Traditional finance - none Cexs - none Dexs --- Eth --- - Uniswap - Curve - Bancor - Balancer --- Solana --- - Saber - Orca - Raydium (hybrid AMM + CLOB) etc.
11/ Why use an AMM design? Pros: - easy to bootstrap liquidity for new tokens - decentralized - composable Cons: - forced market symmetry - uniform liquidity at all price points (solved in Uni v3) - high slippage - high impermanent loss in high vol (LPs win on mean reversion)
12/ RFQs RFQs are typically used for trading in more illiquid markets (e.g. fixed income, exotic derivatives, ETFs). This model lets traders ‘request a quote’ from counterparties (participant market makers of a specific exchange) based on security and quantity.
RFQ is an "asymmetric" trade execution model: - a trader can't put up his own better bid/offer, i.e. customers can't make markets or trade w/ other customers, only the participant MMs - there's no public transparent ledger - high collusion risk Everything OTC operates on RFQ.
13/ Exchanges designed as RFQs Traditional finance - Tradeweb - any structured products desk at any bulge bracket bank (e.g. GS, JPM, Citi, Merrill, SocGen) Cexs - none Dexs --- Eth --- - 0x - Hashflow --- Solana --- - none? (if you know any, tell me)
14/ Why use an RFQ design? Pros: - makes sense for illiquid markets - socially acceptable in the DeFi community b/c few know what it is Cons: - lack of transparency - not actually decentralized (order storage & matching is done off-chain while trade settlement is done on-chain)
15/ Auction Method (aka it's all about the pre-auction) How NYSE sets stock prices each morning. 9-9:30 AM: NYSE streams historical order imbalances data to let traders adjust quotes. If there's late breaking news (aka every day) NYSE asks designated MMs for price adjustment.
A DMM (designated MM) is assigned to each security trading on the exchange. DMMs have special authority to: - make price adjustments - delay trading start time for a given security - get first dibs on a security (if needed to "maintain the smooth functioning of the market")
DMMs also get help from supplemental liquidity providers (SLPs). SLPs are HFT shops that NYSE gives aggressive rebates to & wines/dines to persuade them to inject high liquidity into the market at the open. Here are NYSE's current SLPs:
9:30 AM ET: the market finally opens & everyone else's MOOs & LOOs (market on open & limit on open) finally get the chance to get executed.
16/ Why use an auction design? Pros: - excitement (i.e. why they're good for NFTs) Cons: - highly manipulable - easy to give special treatment & incentives to specific institutions - slow & not scalable
Bottom line: There are many ways to design an exchange, each w/ different benefits & tradeoffs. Picking the right exchange design for each asset class & market is critical because it shapes all subsequent trading behavior in the ecosystem. End/ Thx for reading! Happy Sunday! 🥳
@FabiusMercurius Great thread
@ColeGotTweets Thanks!
@FabiusMercurius I'd be curious to know where you would place @DFlowProtocol's "Order Flow Markets" in your taxonomy. (https://dflow.net/blog/intro-t...
@FabiusMercurius Great job, that 🧵 is really awesome, thanks for writing it!
@FabiusMercurius @memdotai mem it
@FabiusMercurius This is great! Thank you for writing this.
@FabiusMercurius Nice Thread! I would just add that Auction mechanisms come in many shapes and are probably worth exploring more. Check out Arizona Stock Exchange for one example. Many exchanges today have open and closing auctions to help reach a "more accurate" opening or closing price.
@FabiusMercurius @readwiseio save thread
@FabiusMercurius @OolongWOOlong Plug in to WooNetwork and instantly be sorted on liquidity in the books @WOOnetwork
@FabiusMercurius Thanks for writing this and the "yield farming" - using standard finance terms makes things much clearer.
@FabiusMercurius @threadreaderapp unroll plz











