Skip to main content
Time-Weighted Average Price (TWAP) orders allow you to split large trades into smaller parts executed at regular intervals. This reduces price impact and helps achieve better average execution prices.

Overview

A TWAP order automatically divides your total trade amount into multiple smaller orders (called “parts”) and executes them at specified time intervals. This is particularly useful for:
  • Large trades that would cause significant price impact
  • Reducing exposure to short-term price volatility
  • Achieving a more predictable average execution price
  • Automated trading strategies that require time-based execution

Installation

TWAP functionality is included in the Composable SDK:

Creating TWAP Orders

Basic TWAP Order

TWAP with Custom Start Time

TWAP with Limited Part Duration

By default, each TWAP part is valid for the entire interval. You can limit the validity period:

TWAP Parameters

Core Parameters

Optional Parameters

Start Time Options

At Mining Time (Default)

The TWAP starts when the transaction is mined:

At Specific Epoch

The TWAP starts at a specific timestamp:

Duration Options

Auto Duration (Default)

Each part is valid for the entire interval:

Limited Duration

Each part expires after a specific duration:
The duration must be less than or equal to timeBetweenParts.

Complete TWAP Setup

Here’s a complete example of creating and activating a TWAP order:

Order Lifecycle

TWAP Execution Flow

  1. Creation: TWAP order is created with all parameters
  2. Merkle Root: Root is set on ComposableCoW contract
  3. Proof Storage: Proofs stored off-chain for watchtowers
  4. Monitoring: Watchtowers monitor for execution conditions
  5. Part Execution: Each part executes at its scheduled time
  6. Completion: All parts executed or TWAP expires

Monitoring TWAP Progress

Validation

The SDK validates TWAP orders before execution:

Advanced Features

Context Factory

TWAP orders use the CurrentBlockTimestampFactory when starting at mining time:

Serialization

Human-Readable Output

Best Practices

Set timeBetweenParts based on:
  • Token liquidity (higher liquidity = shorter intervals)
  • Market volatility (higher volatility = shorter intervals)
  • Total execution time preference
Common intervals: 5 minutes (300s), 15 minutes (900s), 1 hour (3600s), 1 day (86400s)
  • Too few parts: Reduces benefits of TWAP
  • Too many parts: Increases gas costs and complexity
  • Sweet spot: Usually 10-50 parts depending on total amount
  • Use AUTO for maximum flexibility
  • Use LIMIT_DURATION to ensure timely execution
  • Set duration to 50-80% of interval for safety margin
Set up monitoring to track:
  • Number of parts executed
  • Average execution price
  • Slippage per part
  • Any failed parts

Common Use Cases

Daily DCA with TWAP

Large Trade Execution

Next Steps

Programmatic Orders

Learn about other conditional order types

Account Abstraction

Execute orders with smart contract wallets