# Time-Weighted Average Price

A TWAP (Time-Weighted Average Price) order splits a large order into smaller chunks executed over a duration. Each chunk is a market order — individual chunks and timing are not exposed on-chain (CEX-style shielded execution).

Use `executionType: "TWAP"`. Also works for closing positions via the close API with `executionType: "TWAP"`.

```json
{
  "executionType": "TWAP",
  "leverage": 5,
  "usdValue": 5000,
  "slippage": 0.01,
  "twapDuration": 30,
  "twapIntervalSeconds": 60,
  "randomizeExecution": true,
  "longAssets": [{ "asset": "BTC", "weight": 0.5 }],
  "shortAssets": [{ "asset": "ETH", "weight": 0.5 }]
}
```

**How it works:**

* `twapDuration`: total duration in minutes (required)
* `twapIntervalSeconds`: seconds between chunks (default: 30)
* Number of chunks = `duration / interval`, capped by minimum $11 per asset per chunk
* USD value split equally across chunks
* `randomizeExecution`: adds ±10% jitter to chunk timing to reduce predictability
* Chunks queued via BullMQ and executed as individual market orders
* TP/SL intents are cached and applied after the first chunk creates a position; subsequent chunks merge into it

**Example**: $5,000 over 30 minutes at 60s intervals → 30 chunks of \~$166 each, one every \~60s (±6s with randomization).


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.pearprotocol.io/api-integration/executing-trade/order-type/time-weighted-average-price.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
