What Is a TWAP Algorithm?
When to Use a TWAP Algorithm?
- Order size larger than available liquidity on the order book.
- Anticipation of high price volatility period with no clear up or downward trend.
- Determine the trade size, which is the total size of the contract you choose to buy or sell. The minimum allowed TWAP strategy trade size is equivalent to 1,000 USDT. When a TWAP strategy completes all orders, the TWAP order will stop.
- Select the duration, which is the targeted TWAP execution period. The minimum duration is 5 minutes, and the maximum is 24 hours.
TWAP Algorithm API Details
Customizable Execution Parameters
Parameters | Description |
Duration | Duration for TWAP orders in seconds. [300, 86400] less than 5min => defaults to 5 min greater than 24h => defaults to 24h |
Quantity | Trading quantity (must be more than the equivalent of 1,000 USDT and less than the equivalent of 1,000,000 USDT) |
limitPrice | Order’s limit price if unspecified, the order will be placed at market price by default |
Other Supplementary Endpoints
Endpoint | Description | Link |
DELETE sapi/v1/algo/futures/order | Cancel an active order | https://binance-docs.github.io/apidocs/spot/en/#cancel-algo-order-trade |
GET sapi/v1/algo/futures/openOrders | Get all running orders | https://binance-docs.github.io/apidocs/spot/en/#query-current-algo-open-orders-user_data |
GET sapi/v1/algo/futures/historicalOrders | Get historical orders | https://binance-docs.github.io/apidocs/spot/en/#query-historical-algo-orders-user_data |
GET sapi/v1/algo/futures/subOrders | Get respective sub orders for a specified algo ID | https://binance-docs.github.io/apidocs/spot/en/#query-sub-orders-user_data |
Additional Notes on TWAP Algorithm
1. What Are the Order Limitations When Using the TWAP Algorithm?
- Open Order Limit - TWAP supports up to 10 simultaneously running orders per account. You can place multiple TWAP orders for the same symbol
- Notional Limit - The notional (Order Quantity * `Mark Price (base asset)`) must be higher than the equivalent of 1,000 USDT and lower than the equivalent of 1,000,000 USDT.
- Duration - Duration cannot be less than 5 min (300sec) or more than 24 hours (86,400 sec)
- End Time (Delivery) - For quarterly contracts, TWAP orders must end one hour before the contract’s settlement time. For example, if you create a TWAP order at 7:00 AM with a 4-hour duration, the TWAP order will end at 11:00 AM.
- Eligible Contract Type - TWAP supports USDⓈ-M contracts and can be used with Multi-Assets Mode.
2. What Are the Expected Error Responses From the TWAP Order Endpoint?
External code | External msg |
0 | OK |
-1000 | An unknown error occurred while processing the request. |
-1102 | A mandatory parameter was not sent, empty/null, or malformed. |
-20121 | Invalid symbol. |
-20130 | Invalid data sent for a parameter. |
-2013 | Order does not exist. |
-5007 | Quantity must be greater than zero. |
-20124 | Invalid algo id or it has been completed. |
-20132 | The client algo id is duplicated. |
-20194 | Duration is too short to execute all required quantity. |
-20195 | The total size is too small. |
-20196 | The total size is too large. |
-20198 | Reach the max open orders allowed. |