Skip to main content

TWAP Execution

What It Does

TWAP (Time-Weighted Average Price) splits a large order into smaller slices executed over time. Instead of placing one big order that moves the market, TWAP places many small orders at regular intervals.

How It Works

  1. You specify a total size and duration (e.g., $5,000 over 10 minutes)
  2. The engine calculates slice count dynamically — targeting 15-30 second intervals
  3. Each slice is placed as a post_only limit order (maker, 0% fee)
  4. Between slices, the engine checks if the current price is favorable
  5. If price is unfavorable, it waits (up to 10 minutes max) for a better entry

Dynamic Slicing

DurationSlicesInterval
5 min2015s
10 min3020s
30 min6030s
60 min12030s

Shorter TWAPs use more frequent, smaller slices. Longer TWAPs cap at 30-second intervals.

Favorable Entry Detection

For buy TWAPs, the engine tracks a 2-minute rolling average and only executes slices when the current price is below average (buying dips). For sell TWAPs, it waits for price to be above average (selling rips).

If the price stays unfavorable for more than 10 minutes, the engine executes anyway to stay on schedule.

Stealth Randomization

Slice intervals are randomized by +/-30% to prevent detection. A 20-second base interval might execute at 14s or 26s.

Parameters

ParameterDefaultDescription
DurationvariesTotal time window for execution
Drawdown threshold0.1%How much dip/rip counts as "favorable"
Randomization30%Interval variation for stealth
Max wait per chunk10 minHard fallback if price stays unfavorable

When to Use

  • Entering or exiting large positions ($1K+) on thin DEX books
  • Copy trade entries where you want to minimize impact
  • Any time you want to avoid moving the price against yourself

When Not to Use

  • Fast-moving markets where you need immediate execution
  • Very small orders ($50 or less) where splitting adds no benefit
  • When the spread is already tight and a single limit fills instantly