What is TWAP? Time-weighted average price, explained with code

TWAP — time-weighted average price — is one of the simplest and most widely used execution algorithms in trading. Instead of dumping a large order into the market all at once and moving the price against yourself, a TWAP algorithm chops the order into equal slices and releases them at regular time intervals. The goal is not to predict direction but to execute cleanly: get filled close to the average price over a window while minimising your footprint. This guide explains exactly how TWAP works, when to use it, and shows a real Python implementation.

On this page
  1. What TWAP is
  2. Why slice an order
  3. How the algorithm works
  4. A TWAP in code
  5. TWAP vs VWAP
  6. The limits
  7. FAQ

What TWAP is

TWAP stands for time-weighted average price — the average price of an asset over a chosen window, weighting each time interval equally. As an execution algorithm, TWAP aims to fill a large order at a price close to that time average by spreading the trade evenly across the window rather than executing it all at one moment.

Why slice an order at all

A big market order eats through the order book, filling at progressively worse prices — that gap is slippage, and it can dwarf trading fees on a thin market. By breaking the order into small child orders, TWAP keeps each fill close to the prevailing price and hides your full size from other participants, including predatory bots watching for large flow.

equal slices, evenly spaced in time
TWAP releases identically sized child orders at fixed time intervals across the execution window.

How the algorithm works

The logic is deliberately simple. Decide a total quantity and a window — say buy 10 BTC over 60 minutes. Split it into N slices (e.g. 12 slices of ~0.83 BTC every 5 minutes) and submit each on schedule, regardless of price. Because the schedule is purely time-based, TWAP is trivial to implement and hard to game on its timing — but it ignores volume, which is where VWAP differs.

A TWAP in code

python · twap.pyimport ccxt, time

ex = ccxt.binance({'apiKey': KEY, 'secret': SECRET})

def twap_buy(symbol, total, slices, interval_s):
    """Buy `total` over `slices` orders, one every interval_s seconds."""
    child = total / slices
    for i in range(slices):
        ex.create_market_buy_order(symbol, child)
        print(f"slice {i+1}/{slices} filled {child}")
        if i < slices - 1:
            time.sleep(interval_s)

# buy 10 units over 12 slices, one every 5 minutes
twap_buy('BTC/USDT', 10, 12, 300)

TWAP vs VWAP

TWAP weights every time slice equally; VWAP weights by trading volume, executing more when the market is naturally busy. TWAP is simpler and better when volume is unpredictable; VWAP tracks the market’s own activity and is the more common institutional benchmark. Neither tries to time direction — both are pure execution tools.

The limits

TWAP ignores price and volume, so in a fast trend it keeps buying into a rising market with no opportunism, and in thin overnight hours it can still move an illiquid book. It is an execution aid, not a strategy — pair it with a real entry signal from your algorithm and mind the order types you use for each child slice.

Not financial advice. This content is educational. Automated and algorithmic trading carries a real risk of financial loss. Never trade money you cannot afford to lose. Review the SEC investor.gov and CFTC resources before trading.

Frequently asked questions

What does TWAP mean in trading?

TWAP stands for time-weighted average price — the average price of an asset over a chosen window with each time interval weighted equally. As an execution algorithm, TWAP fills a large order by splitting it into equal slices released at regular time intervals, aiming to get an average price close to that window average while minimising market impact.

Why use a TWAP algorithm?

A TWAP algorithm reduces slippage and market impact when executing a large order. Dumping the whole order at once eats through the order book at worsening prices and signals your size to other traders. Slicing it into small, evenly timed child orders keeps each fill near the prevailing price and hides your full intent.

What is the difference between TWAP and VWAP?

TWAP weights every time slice equally and trades on a fixed time schedule, while VWAP weights execution by trading volume, trading more when the market is naturally busy. TWAP is simpler and useful when volume is unpredictable; VWAP tracks the market’s own activity and is the more common institutional execution benchmark.

Is TWAP a trading strategy?

No. TWAP is an execution algorithm, not a directional strategy. It decides how to fill an order you have already decided to place, not whether to buy or sell. You still need a real entry and exit signal from your trading algorithm; TWAP simply executes that decision cleanly with minimal market impact.

MB

Mustafa Bilgic

Algorithmic trading practitioner · Founder, AITradingBot.us

Mustafa builds and backtests automated trading systems and writes about them without the hype. Every tool on this site is free and runs entirely in your browser.