FAQ
Home
Support Center
FAQ
Trading Bots
Spot Algo Orders
How to Use TWAP Algorithm on Binance Spot

How to Use TWAP Algorithm on Binance Spot

2023-04-20 03:34
Binance Spot launched the Time-Weighted Average Price (TWAP) trading algorithm for API users. Using Binance's in-house algorithmic trading capability, users can disperse large orders into smaller quantities and execute them at regular intervals automatically to minimize price impact.

What is a TWAP algorithm?

Time-Weighted Average Price (TWAP) is an algorithmic trade execution strategy. It aims to achieve an average execution price close to the time-weighted average price of a specific period.

When to use a TWAP algorithm?

Traders usually deploy TWAP to mitigate the market impact for large orders. TWAP trading algorithms aim to optimize a trade’s average price by slicing order execution over a specific time duration.
TWAP is favored to provide a better execution price in the following scenarios:
  • When the order size is larger than the available liquidity on the order book.
  • In anticipation of a high-price volatility period with no clear up or downward trend.
Here is an example of TWAP algorithm execution patterns:

What do I need to consider when setting up a TWAP strategy?

  • Determine the trade size (the total amount of crypto you want to buy or sell). The minimum allowed TWAP strategy trade size is equivalent to 1,000 USDT on Binance. When a TWAP strategy completes all orders, the TWAP order will stop.
  • Choose the targeted TWAP execution period. You can select between 5 minutes and 24 hours on Binance Spot.

TWAP algorithm API details

New TWAP order endpoint:

POST /sapi/v1/algo/spot/newOrderTwap

Customizable execution parameters

ParametersDescription
symbolTrading symbol (e.g., BTCUSDT)
sideTrading side (e.g., BUY or SELL)
quantityTrading quantity (must be between 1,000 USDT and 100,000 USDT equivalent)
duration
TWAP order duration in seconds (300 or 86,400)
  • If the order duration is shorter than 5 minutes, it will be set to 5 minutes (300 seconds) by default;
  • If the order duration is longer than 24 hours, it will be set to 24 hours (86,400 seconds) by default.
limitPriceTWAP order’s limit price (The order will be placed at market price by default)

Other supplementary endpoints

EndpointDescriptionLink
DELETE /sapi/v1/algo/spot/orderCancel an active orderhttps://binance-docs.github.io/apidocs/spot/en/#cancel-algo-order-trade-2
GET /sapi/v1/algo/spot/openOrdersGet all running orders

https://binance-docs.github.io/apidocs/spot/en/#query-current-algo-open-orders-user_data-2
GET /sapi/v1/algo/spot/historicalOrdersGet historical ordershttps://binance-docs.github.io/apidocs/spot/en/#query-historical-algo-orders-user_data-2
GET /sapi/v1/algo/spot/subOrdersGet respective sub orders for a specified algo IDhttps://binance-docs.github.io/apidocs/spot/en/#query-sub-orders-user_data-2

Frequently Asked Questions

1. What are the order limits?

  • Open Order Limit: TWAP supports up to 20 simultaneously running orders per account. You can place multiple TWAP orders for the same symbol.
  • Notional Limit: The notional (Order Quantity * Last Price (base asset)) must be more than or equal to (≥) 1,000 USDT equivalent, and less than or equal to (≤) 100,000 USDT equivalent.
  • Duration: Duration cannot be shorter than 5 minutes (300 seconds) or longer than 24 hours (86,400 seconds).
Transaction details won’t be available until all TWAP orders are filled. Only partially completed orders will be displayed. You can view the transaction quantity, average transaction price, and trading fee.

2. What do the error responses mean?

You may receive the following error responses following an inadequate query.
External codeExternal message
0OK
-1000An unknown error occurred while processing the request
-1102A mandatory parameter was not sent, empty/null, or malformed
-20121Invalid symbol
-20130Invalid data sent for a parameter
-2013Order does not exist
-5007Quantity must be greater than zero
-20124Invalid algo ID, or the algo ID has been completed
-20132The client algo ID is duplicated
-20194Duration is too short to execute all required quantity
-20195The total size is too small
-20196The total size is too large
-20198You’ve reached the max open orders allowed

3. Do TWAP orders guarantee execution?

TWAP orders do not guarantee execution. Orders will be filled with the best effort, subject to market liquidity and volatility.
If the market price moves considerably or liquidity is insufficient during order execution, the algorithm may not be able to execute all orders fully.
Thus, execution is and will always be liquidity-dependent with no guarantee for best price execution. For example, the algorithm may fail to complete the order before the specified end time if the market becomes distressed.

4. How to check the status of my TWAP orders?

To check the status of a TWAP order, you can use the query order endpoints (GET /sapi/v1/algo/spot/openOrders or GET /sapi/v1/algo/spot/historicalOrders).
Please note:
  • You won’t receive any WebSocket notification for order filling updates.
  • Receiving ["success": true] does not mean that your order will be executed. For example, if your Spot Wallet balance is insufficient, you’ll receive ["success": true], but the order will still fail to execute.