# Exchanges: CEX vs. DEX

> Centralized vs. decentralized trading.

Module: Crypto — Deep Dive — Finotaur Academy (free lesson)
Source: https://www.finotaur.com/academy/crypto/exchanges-cex-vs-dex

## You'll be able to

Compare centralized and decentralized exchanges by how they match trades, who holds your funds and what a trade really costs, and calculate slippage on both an order book and an automated market maker.

## In plain words

A centralized exchange (CEX) is a company that holds customers' funds and matches buy and sell orders on its own internal order book, while a decentralized exchange (DEX) is a set of smart contracts that lets you trade directly from your own wallet, usually against a pool of tokens priced by a formula. A CEX gives you deep liquidity, fiat on-ramps and familiar order types in exchange for trusting the company. A DEX removes that custodial trust but exposes you to smart-contract risk, on-chain fees and price impact that depends entirely on pool size.

```takeaways
- **CEX**: company custody, internal order book, fast matching, fiat access, counterparty risk.
- **DEX**: self-custody, on-chain settlement, usually an **automated market maker (AMM)** pricing trades with a formula such as **x × y = k**.
- Real cost = **fees + spread + slippage (price impact)**, plus network gas on a DEX.
- On an AMM, price impact grows quickly as your trade becomes a larger share of the pool.
```

## Quick demo

**Order book slippage (hypothetical CEX).** You want to buy 10 BTC at market. The ask side shows: 5 BTC at $60,000, 3 BTC at $60,010, 4 BTC at $60,025.

- You fill 5 × $60,000 + 3 × $60,010 + 2 × $60,025 = **$600,080**.
- Average price = $600,080 ÷ 10 = **$60,008**, which is **0.013%** above the best ask.

On a deep book, a large order barely moves the price.

**AMM slippage (hypothetical DEX pool).** A constant-product pool holds **100 ETH** and **300,000 USDC**, so its spot price is 300,000 ÷ 100 = **$3,000**, and k = 100 × 300,000 = 30,000,000. You sell 30,000 USDC for ETH, with a 0.3% pool fee.

- USDC that counts toward the swap: 30,000 × 0.997 = 29,910 (the $90 fee stays in the pool for liquidity providers).
- ETH out = 100 − (100 × 300,000) ÷ (300,000 + 29,910) = **9.066 ETH**.
- Average price paid = 30,000 ÷ 9.066 = **$3,309**, about **10.3% worse** than the $3,000 spot price.
- After the trade the pool holds about 90.93 ETH and 330,000 USDC, so the new spot price is about **$3,629**.

Your trade was 10% of the pool's USDC, and it cost you roughly 10% in price impact. Arbitrage traders will now sell ETH into the pool until its price lines up with other markets again.

```chart
{
  "type": "bar",
  "title": "Average fill vs. reference price in the two demos (%)",
  "data": [["CEX order book, 10 BTC", 0.013], ["AMM pool, 30,000 USDC", 10.3]],
  "unit": "%",
  "unitPosition": "suffix",
  "caption": "Exact arithmetic on the hypothetical order book and pool above. Real depth varies by market and moment."
}
```

## Full explanation

### How a centralized exchange works

When you deposit to a CEX, your coins move to wallets the exchange controls and your account is credited internally. Trades between customers are just database updates, which is why they are fast and free of network fees. The **central limit order book** ranks bids and asks by price and time. Market makers post both sides and earn the spread; takers cross it. Exchanges typically charge lower **maker** fees (for adding liquidity with limit orders) and higher **taker** fees (for removing it). Withdrawals to the blockchain incur a network fee and sometimes a minimum.

What you get: deep liquidity on major pairs, fiat deposits and withdrawals, advanced order types (stop, OCO, post-only), derivatives such as perpetual futures, and customer support. What you accept: custody risk, account freezes, KYC data exposure, and the possibility that the venue's own internal practices (rehypothecation, conflicts of interest, wash trading) are opaque. The FTX collapse in November 2022 showed how quickly an apparently healthy exchange can halt withdrawals.

### How a decentralized exchange works

A DEX runs as smart contracts. You connect a wallet, approve the contract to spend a token, and submit a swap transaction. Settlement is atomic: either you receive the output in the same transaction or nothing happens. Nobody can freeze your account because there is no account; your wallet is your identity.

Most DEXs are **AMMs**. Liquidity providers (LPs) deposit two tokens into a pool, and a formula sets the price. In the constant-product design, the product of the two balances stays constant (before fees): x × y = k. Buying one token makes it scarcer in the pool, so its price rises along a curve. Newer designs use **concentrated liquidity**, letting LPs place capital in chosen price ranges, which makes pools deeper near the current price but thinner further away. Some DEXs use on-chain order books or aggregators that split orders across many pools.

### The full cost of a trade

- **Explicit fees**: CEX maker/taker fees; DEX pool fees (commonly fractions of a percent).
- **Spread**: the gap between best bid and best ask.
- **Slippage or price impact**: how far your own order moves the price.
- **Gas**: on a DEX, the network fee, which can exceed the trade's value for small swaps on a busy chain.
- **MEV**: on public chains, bots can see pending swaps and "sandwich" them, buying just before you and selling just after. A tight **slippage tolerance** limits how much they can extract; too tight and your transaction fails.

### Risks specific to each venue

| | CEX | DEX |
|---|---|---|
| Custody | Company holds funds | You hold funds |
| Main failure mode | Insolvency, hack, freeze | Contract bug, malicious token, phishing site |
| Listing standard | Exchange decides | Anyone can create a pool |
| Recourse | Support, regulators, courts | Usually none |
| Privacy | KYC required in most jurisdictions | Wallet-based, but transactions are public |

Because anyone can create a DEX pool, fake tokens with the same name and ticker as real ones are common. Always trade by **contract address**, not ticker.

### How professionals use both

Active traders often keep working capital on one or two liquid CEXs for speed and derivatives, hold reserves in self-custody, and use DEXs for tokens not yet listed elsewhere or to avoid moving funds through a custodian. They compare quotes across venues, split large orders, use limit orders where possible and check pool depth before swapping. Arbitrage between CEX and DEX prices is one of the forces that keeps crypto prices consistent across venues.

### Common mistakes

- **Market-ordering into a thin book or small pool** without checking depth.
- **Setting slippage tolerance very high** to "make it go through", inviting sandwich attacks.
- **Buying a token by ticker on a DEX** and receiving a copycat.
- **Leaving large balances on a CEX** between trades.

```tip
Before any DEX swap, divide your trade size by the pool's liquidity on the side you are paying in. If the answer is more than a percent or two, expect meaningful price impact and consider splitting the order, using an aggregator or trading on a deeper venue.
```

```checklist
title: Choosing where to place a trade
- Compare total cost: fees, spread, expected slippage and gas.
- Check order book depth or pool size relative to your trade.
- On a DEX, verify the token contract address from an official source.
- Set a slippage tolerance that is realistic but not loose.
- Withdraw profits you are not actively trading from the CEX.
- Record the venue, fees and fill price in your journal for review.
```

```quiz
[
  {
    "q": "A pool holds 50 ETH and 150,000 USDC. What is its spot price for ETH?",
    "options": ["$300", "$3,000", "$1,500", "$30,000"],
    "answer": 1,
    "why": "Spot price = 150,000 ÷ 50 = $3,000 per ETH."
  },
  {
    "q": "Why did the 30,000 USDC AMM trade in the demo pay about 10% above spot?",
    "options": ["The pool fee was 10%", "The trade was large relative to the pool, so it moved along the price curve", "Gas costs", "The exchange added a markup"],
    "answer": 1,
    "why": "The fee was only 0.3%; most of the cost was price impact from taking a large share of the pool."
  },
  {
    "q": "Which risk is greatest for funds held on a centralized exchange?",
    "options": ["Sandwich attacks", "Smart-contract bugs in the pool", "The company becoming insolvent or freezing withdrawals", "Impermanent loss"],
    "answer": 2,
    "why": "CEX customers hold a claim on the company, so its solvency and conduct are the key risk."
  },
  {
    "q": "What is the safest way to identify a token on a DEX?",
    "options": ["By its ticker", "By its logo", "By its contract address from an official source", "By the largest pool"],
    "answer": 2,
    "why": "Tickers and logos can be copied; the contract address is unique."
  }
]
```
