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:Complete TWAP Setup
Here’s a complete example of creating and activating a TWAP order:Order Lifecycle
TWAP Execution Flow
- Creation: TWAP order is created with all parameters
- Merkle Root: Root is set on ComposableCoW contract
- Proof Storage: Proofs stored off-chain for watchtowers
- Monitoring: Watchtowers monitor for execution conditions
- Part Execution: Each part executes at its scheduled time
- 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 theCurrentBlockTimestampFactory when starting at mining time:
Serialization
Human-Readable Output
Best Practices
Choose appropriate intervals
Choose appropriate intervals
Set
timeBetweenParts based on:- Token liquidity (higher liquidity = shorter intervals)
- Market volatility (higher volatility = shorter intervals)
- Total execution time preference
Set reasonable numberOfParts
Set reasonable numberOfParts
- 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
Consider part duration
Consider part duration
- Use AUTO for maximum flexibility
- Use LIMIT_DURATION to ensure timely execution
- Set duration to 50-80% of interval for safety margin
Monitor execution
Monitor execution
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