TWAP (Time-Weighted Average Price)
Splits a large order into equal-sized slices submitted at regular time intervals:How TWAP works
- Divides
duration_secsbynum_slicesto get the interval (6 seconds above). - On each
on_tick()call, checks if enough time has passed for the next slice. - Submits a child order of
total_size / num_slicescontracts. - Tracks total filled across all children and marks complete when the target is reached.
When to use TWAP
- Low-urgency fills where minimizing market impact matters more than speed.
- Markets with thin books where placing the full size at once would walk the book.
- Predictable scheduling: TWAP gives you even participation over the time window.
VWAP (Volume-Weighted Average Price)
Slices the order proportionally to a volume profile, concentrating execution during high-volume periods:How VWAP works
The volume profile determines how much of the total order goes into each time slice:duration_secs.
When to use VWAP
- Benchmarking against market VWAP: your fills will match the volume pattern.
- High-volume windows: concentrate execution when liquidity is deepest.
- Relative value strategies where you want to match the market’s natural flow.
Building a volume profile
You can construct volume profiles from historical data or use common patterns:Iceberg (Hidden Size)
Shows only a small visible portion of the total order. When the visible slice fills, a new one is placed:How Iceberg works
- Places a limit order for
show_sizecontracts. - On each
on_tick(), checks whether the visible order is still open. - When the visible order fills, calculates remaining size and places a new visible slice.
- Repeats until the full target size is filled.
When to use Iceberg
- Avoid signaling: other market participants cannot see your true order size.
- Thin prediction markets where showing 100 contracts would discourage counterparty flow.
- Passive fills: each slice rests at your limit price, earning the spread.
Running an Algo in a Loop
All three algorithms follow the sameExecAlgo interface. Here is a complete example driving TWAP inside a loop:
Comparison
| Feature | TWAP | VWAP | Iceberg |
|---|---|---|---|
| Slicing | Equal time intervals | Volume-weighted intervals | On-fill replacement |
| Market impact | Low (spread out) | Lowest (follows liquidity) | Low (small visible) |
| Speed | Fixed duration | Fixed duration | Depends on fill rate |
| Best for | Low urgency, even execution | Matching market flow | Hiding order size |
| Inputs | duration_secs, num_slices | duration_secs, volume_profile | show_size |
API Reference
All algorithms inherit fromExecAlgo and share these properties and methods:
| Member | Type | Description |
|---|---|---|
start(request) | Method | Begin execution of a parent order. |
on_tick(current_price, timestamp) | Method | Called each cycle to manage child orders. |
is_complete | Property | True when the target size has been fully filled. |
child_order_ids | Property | List of all child order IDs submitted so far. |
total_filled | Property | Total contracts filled across all children. |