Sub topic 1
Where a token's price comes from
Prerequisites
This chapter assumes you already know the following:
- What a cryptocurrency token or coin is, and that you can hold it in a wallet or on an exchange.
- What a spot price on an exchange looks like, for example a quote such as 2.50 USDC per token.
- Simple multiplication and percentages.
You do not need any knowledge of supply terms yet. Later chapters cover circulating, total, and maximum supply. This chapter covers the other input to every market cap figure, which is the price.
Why start with price
Market capitalisation is price multiplied by a quantity of tokens. The quantity gets most of the attention, but the price is the less obvious input. A token has no single official price. The number you see on a website is produced by a process, and that process affects how far you can trust any figure built on it.
By the end of this chapter you should be able to:
- Explain how trades on an order book and in an automated market maker (AMM) set a price.
- Separate the quoted price from the price you would actually get when trading.
- Explain why the same token can trade at different prices on different venues.
- Explain how the displayed price of a token is derived from many trades.
- Judge when a price is reliable enough to build a market cap on.
A price is the result of a trade
A token's spot price is the price at which it can be exchanged for another asset right now. Spot means immediate settlement, as opposed to futures or other contracts that settle later. The other asset is called the quote asset. It is often a stablecoin such as USDC or USDT, or a large coin such as BTC or ETH.
Nothing sets this price by decree. It comes from buyers and sellers agreeing on a trade. Two designs handle most trading in crypto:
- Order book exchanges, which match buyers and sellers.
- Automated market makers, which trade against a pool of tokens using a formula.
Order books
An order book is a list of resting orders. A bid is an offer to buy at a stated price. An ask (or offer) is an offer to sell at a stated price. Each order also states a quantity.
- The best bid is the highest price any buyer will currently pay.
- The best ask is the lowest price any seller will currently accept.
- The spread is the gap between them.
- The mid price is the average of the best bid and best ask.
A trade happens when a market order arrives. A market order says "buy or sell this quantity now at whatever the book offers". A market buy takes the lowest asks first, then moves to higher ones until the quantity is filled. The last trade price is the price of the most recent fill.
This produces a point that is easy to miss. The last trade price describes one small trade. If you wanted to buy a large amount, you would not get that price. You would walk up the book and pay progressively more.
The following code builds a small book, computes the quoted prices, and fills a market buy.
bids = [(2.49, 15_000), (2.48, 30_000), (2.45, 40_000)]
asks = [(2.51, 10_000), (2.52, 20_000), (2.55, 50_000)]
def market_buy(asks, quantity):
"""Fill a market buy against asks sorted from lowest price up.
Returns (total_cost, last_fill_price).
"""
remaining = quantity
cost = 0.0
last_price = None
for price, size in asks:
if remaining <= 0:
break
fill = min(size, remaining)
cost += fill * price
remaining -= fill
last_price = price
if remaining > 0:
raise ValueError("Not enough liquidity in the book")
return cost, last_price
best_bid = bids[0][0]
best_ask = asks[0][0]
mid = (best_bid + best_ask) / 2
spread_pct = (best_ask - best_bid) / mid
qty = 40_000
cost, last_price = market_buy(asks, qty)
avg_price = cost / qty
print(f"Mid price: {mid:.4f}")
print(f"Spread: {spread_pct:.2%}")
print(f"Cost of buying {qty:,}: {cost:,.0f}")
print(f"Average fill price: {avg_price:.4f}")
print(f"Slippage versus mid: {(avg_price - mid) / mid:.2%}")
print(f"Last trade price afterwards: {last_price}")
# Mid price: 2.5000
# Spread: 0.80%
# Cost of buying 40,000: 101,000
# Average fill price: 2.5250
# Slippage versus mid: 1.00%
# Last trade price afterwards: 2.55The quoted mid price is 2.50. Buying 40,000 tokens costs an average of 2.525, and the last trade leaves the displayed price at 2.55. Slippage is the difference between the price you expected and the average price you actually got. It grows with order size and shrinks when the book is deep. A deep book has many orders close to the mid price.
Automated market makers
Many tokens trade mainly on decentralised exchanges (DEXs) that use AMMs. An AMM holds a liquidity pool, which is a reserve of two assets deposited by liquidity providers. There is no order book. Instead a formula links the two reserves.
The simplest and best-known formula is the constant product rule. If the pool holds x tokens and y units of the quote asset, the pool keeps x * y = k constant across trades. The spot price is the ratio y / x.
When a trader buys tokens, the pool's token reserve falls and its quote reserve rises. The ratio y / x increases, so the price rises. The size of the move depends on the trade size relative to the pool.
def amm_buy(token_reserve, quote_reserve, tokens_out):
"""Buy tokens from a constant product pool. Fees are ignored."""
k = token_reserve * quote_reserve
new_token_reserve = token_reserve - tokens_out
new_quote_reserve = k / new_token_reserve
cost = new_quote_reserve - quote_reserve
return cost, new_token_reserve, new_quote_reserve
token_reserve = 1_000_000
quote_reserve = 2_500_000
spot_before = quote_reserve / token_reserve
tokens_out = 40_000
cost, new_x, new_y = amm_buy(token_reserve, quote_reserve, tokens_out)
avg_price = cost / tokens_out
spot_after = new_y / new_x
print(f"Spot before: {spot_before:.4f}")
print(f"Cost: {cost:,.2f}")
print(f"Average price paid: {avg_price:.4f}")
print(f"Spot after: {spot_after:.4f}")
print(f"Price impact: {spot_after / spot_before - 1:.2%}")
# Spot before: 2.5000
# Cost: 104,166.67
# Average price paid: 2.6042
# Spot after: 2.7127
# Price impact: 8.51%The same 40,000-token purchase moves this pool's price by 8.51%, much more than the order book example moved its price. The reason is that this pool holds 1,000,000 tokens, so 40,000 is 4% of its token reserve. Real pools charge a fee on top, which this code leaves out to keep the arithmetic visible.
Why one token has many prices
A popular token usually trades on several venues at once: centralised exchanges, DEXs, and different trading pairs such as TOKEN/USDT and TOKEN/ETH. Each venue has its own order book or pool, so each has its own price.
Small differences are normal. Arbitrageurs, traders who profit from price gaps, buy where the token is cheap and sell where it is expensive. That activity pushes prices together. Gaps can last longer when:
- Moving funds between venues is slow or costly, for example because of network fees or withdrawal limits.
- A venue is in a different jurisdiction with restricted access.
- Liquidity is thin, so a small trade moves the price a lot.
- A stablecoin on one venue trades slightly away from its peg.
Arbitrage keeps prices close only when liquidity is deep enough for it to work.
From many venues to one displayed price
Data aggregators are websites and APIs that collect market data for thousands of tokens. They show one price per token. To produce it, they combine prices from many venues, and they must decide how.
Common choices include:
- A volume-weighted average, which gives more weight to venues with more trading volume.
- A median across venues, which resists a single bad price.
- Filters that exclude venues with very low volume, stale data, or suspicious activity.
Different aggregators make different choices. Chapter 11 covers how this leads to different market cap figures. For now, note that the displayed price is an estimate drawn from several sources, not a quote you can trade at.
Thin liquidity and unreliable prices
Liquidity is how easily you can trade without moving the price. The price of a token with deep liquidity changes little when you trade. The price of a token with thin liquidity can move a lot on a small trade.
This matters for market cap, because market cap uses one price for the whole supply. Suppose only a small share of tokens ever trades. The price reflects the opinion of the few traders who are active. Multiplying it by every circulating token assumes all of them could sell at that price. In practice, selling a large share would push the price down well before it was done.
Two failure modes follow from this:
- Illiquid price distortion. A single small purchase in a thin pool can raise the displayed price sharply. The market cap then rises by the price change times the whole supply, though little money moved.
- Manipulation. Someone can trade a thin market to create a price that looks good. This is called wash trading when the same party trades with itself to inflate volume, and it makes volume figures unreliable too.
A checklist for judging a price
Before you use a token's price in any calculation, check these points:
- Which venue or venues does the price come from?
- What is the quote asset, and is it stable?
- How deep is the liquidity near the current price?
- How large is the spread or the price impact of a realistic trade size?
- Do several venues agree on the price?
- Does the aggregator state how it combines prices?
None of these checks gives certainty. They tell you how much weight a price can carry.
What you take into the next chapter
A token's price is the outcome of trades on one or more venues, and it applies exactly only to small trades. Larger trades face slippage or price impact. Aggregators then blend venue prices into one displayed figure. The next chapter turns to the other input to market cap: circulating supply, meaning which tokens count as tradable.
Exercise
A constant product pool holds 500,000 tokens and 1,000,000 USDC, ignoring fees. A trader buys 50,000 tokens. What is the spot price before the trade, what does the trader pay in total, what is the average price paid, and what is the spot price after the trade?
Show answer
The spot price before is 1,000,000 / 500,000 = 2.00. The constant is k = 500,000 × 1,000,000 = 5 × 10^11. After the purchase the token reserve is 450,000, so the USDC reserve is 5 × 10^11 / 450,000 ≈ 1,111,111.11. The trader pays 1,111,111.11 − 1,000,000 = 111,111.11 USDC. The average price is 111,111.11 / 50,000 ≈ 2.2222. The spot price after is 1,111,111.11 / 450,000 ≈ 2.4691, a rise of about 23.5%.
Exercise
A token's displayed price is 4.00, taken from the last trade on a thin order book. Why can you not safely say that selling your entire holding would earn 4.00 per token?
Show answer
The last trade price describes only one small trade. A large sell order would fill against the bids in turn, starting with the highest and moving to lower ones. The average price you received would be below 4.00, and the gap would grow with the size of the sale and the thinness of the book.