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
Alice sends an order: BUY 2@9652

Her bid "crosses" the top-level offer (OFFER 1@9651), aka beats the lowest price an existing market maker is willing to sell at.

So Alice takes 1.

But she wanted 2. Her limit order isn't completely filled.
The remainder bid gets added to ToB.
Any order that crosses the spread & “takes” liquidity from the order book can sweep through multiple price levels on a thin book.

e.g. if Bob puts in “SELL 4@9649” he sweeps the top 3 bid levels & gets fulfilled at:
1@9652
2@9650
1@9649

Post-trade, the CLOB becomes 1-line deep.
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:
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! 🥳

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Ming Zhao

Ming Zhao Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @FabiusMercurius

17 Oct
Crypto Market Map 101
(aka a hierarchical DeFi-TradFi mapping)

If ur a:
- crypto newbie
- confused by who's who & what they all do
- dying for someone to draw parallels btw defi & tradfi infra
- crypto entrepreneur looking for opps

I made this map for u:
docs.google.com/spreadsheets/d…
DeFi vs Traditional Finance Infrastructural Comparison

from @mccannatron

i highly suggest you read Chris's whole blog post:
medium.com/racecapital/de…
Eth to Solana Mapping

also from @mccannatron
Read 6 tweets
2 Oct
🇺🇸🏦 America's Shadow Banks

With all this Debt Ceiling talk, here's another throwback:

What are shadow banks?
How did they spur the 2008 financial crisis?

"But shadow banks aren't a thing anymore, right?"
Wrong.

Today they underwrite more debt than regular banks.

Thread👇
1/ If it looks like a duck & quacks like a duck...

Is it a 🦆?

If a company moves money around and lends to other companies even (especially) when real banks refuse, then is it a bank?

In 2007, economist Paul McCulley named these things "shadow banks."

The name stuck around.
2/ What do they do?

4 things.

- Transfer credit risk: from loan originator to 3rd party
- Lever up: borrow $ to invest & make more $
- Transform liquidity: use cash-like liabilities to buy hard-to-sell assets
- Transform maturity: use short-term deposits to fund long term loans
Read 19 tweets
21 Sep
Post-Evergrande: China's Waterfall of Pain

China itself is one big Evergrande.
One big debt crisis.

For years massively over-levered shadow banks masqueraded as propcos, got drunk on credit, flirted w/ default & called for bailout like a late-night uber.

Contagion has begun
👇 https://twitter.com/rosetechnology_/status/14328496098613534
1/ How Evergrande is Actually a (Shadow) Bank

On the surface Evergrande is a propco. It has insatiable demand for capital cuz it needs to buy land. That's what propcos do.

But then Evergrande started stuffing its commercial paper into WMPs & selling it off to its own employees.
Let's be more explicit.

In June 2019, Evergrande plowed 13.2B¥ into Shengjing Bank, acquiring 36% stake in a literal lender.
Shengjing was on the brink of default. Tier 1 capital adequacy ratio was 8.52%, barely above regulatory req.

Now why would a propco bail out a bank? 🤔 https://www.wsj.com/articles/why-the-worlds-biggest-property
Read 16 tweets
18 Sep
🇨🇳Evergrande's Backstory🇨🇳

🌎 The world demands answers.

From Fortune 500 to 1.95 Trillion in debt: How did China's #2 real estate giant get to this point?

How much cash does it *actually* have?
Will there be a bailout?
Who's gonna get f*cked?

Here goes. Story time.
👇
1/ First, how bad is the current situation?

There's not much info on Evergrande's finances on the Western web (aka Google) so I had to dig through the Chinese web (aka Baidu).

This poster shows China's top 3 most indebted real estate co's in 2020:

#1 is Evergrande (@ 1.95T ¥!) #2 is Country Garden #3 is Vanke
2/ According to the company's 2020 annual report, 674B ¥ (35%) is interest-bearing debt, which means it incurs new interest liability of 180+M ¥ every day!

Comparatively, it only has 158B in cash to repay all its short term debt + interest which means...

Major defaults to come.
Read 15 tweets
13 Sep
Met a guy at a party this weekend.

He was fine until,
Guy: "U were Columbia 2016? What was ur 5-Year reunion like?

Did y'all sit around figuring out who's the most successful?"

My stomach dropped. Something vile was bubbling in my throat-- the toxicity dizzying.

Story time 👇
He was a Columbia 2019 so maybe it was self-deprecating humor?

Well not funny. A revolving door of emotions passed between us.

First, disgust. Why the fuck would we come all this way just to whip out our dicks & size each other up?

Second, denial. Dude musta had no friends.
People like him were the exception, not the rule.

Third, sympathy. Should I feel bad for him?

Fourth, realization. Damn, this guy... was all of us.

Fifth, disgust. Why the fuck did we come all this way just to whip out our dicks and size each other up?
Read 11 tweets
11 Sep
🥬Kimchi Premium & Hidden Arbitrage🥬

On Jan 8, 2018, a man made $1.5B trading BTC in Korea.

BTC price was $25K in Korea.
But $16K elsewhere in the world.

57% arbitrage opportunity! WHAT?! This trade became infamously known as the Kimchi Premium.

Here's the full story:
👇
1/ How it started

It was not always this way.

Back in Jan 2017, BTC hovered at $2K. Crypto prices between Korea & elsewhere was not that different.

By Dec 2017, BTC had soared 10x to $20K. Unknown to most of us, there was an even madder dash to panic buy in Korea than the US.
Suddenly S. Korea was trading 20% of all global BTC volumes on any given day. The "Korean Housewife Trader" became a meme.

Such localized trading frenzy caused local BTC prices to diverge from 1% premium to 10% to 30%...

At 30%, (even) CNN took notice:
money.cnn.com/2017/12/12/tec…
Read 11 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!

Follow Us on Twitter!

:(