Skip to content
IntermediateLook up a term

What is TWAP (time-weighted average price)?

Author
CRYPTO PORT Editorial
Published
Updated
Reading time
4 min

In short

TWAP is a price averaged over a window of time. Because a momentary distortion is diluted across the window, it is much harder to manipulate. The cost is lag: in a fast-moving market it reports a price the market has already left behind. Manipulation resistance and immediacy pull against each other.

Key points

  • A price averaged over a defined time window
  • Momentary manipulation is diluted by the average
  • A longer window resists manipulation but reacts slower
  • In fast markets it drifts far from the live price

Definition

A price computed by weighting observed prices by how long they held over a given window, used by oracles and large-order execution to damp the effect of momentary price swings.

The idea is to weight each observed price by how long it held. If a price sat at 100 for 59 minutes of an hour and jumped to 200 for the final minute, the latest price is 200 but the TWAP is only about 102. Moving the price for an instant barely moves the average — that is the whole property.

It is used in oracles for exactly that reason. A flash loan that spikes a pool's price leaves collateral valuations based on TWAP almost untouched. To move the average, an attacker must hold the price distorted for a sustained period, and arbitrageurs make that expensive enough to stop being worthwhile.

The weakness is lag. When the market genuinely crashes, TWAP keeps reporting a higher price for a while. During that window, loans that should be liquidated are not, and the protocol can end up with bad debt. In a rally the same lag undervalues collateral. Choosing the window length is therefore a straight trade-off between manipulation resistance and responsiveness.

Watch out for

  • · In fast markets it diverges from reality, delaying liquidations and creating bad debt
  • · In very thin pools an attacker can hold a distorted price long enough to move the average, so the resistance is not absolute
  • · Shortening the window weakens manipulation resistance; lengthening it increases the lag

Related coins

Read next

Crypto quizzes

Answer a few questions and get your result instantly.

Start