Overview
Limit orders let you specify both the sell and buy amounts, creating an order that only executes at your desired price or better. Unlike theswap_tokens function which gets a market quote, limit orders give you precise control over the exchange rate.
Limit orders remain in the order book until filled, cancelled, or expired. Set
valid_to to control how long the order stays active.Prerequisites
Before creating limit orders, ensure you have:- An Ethereum account with a private key
- Sufficient balance of the sell token
- Token approval for the CoW Protocol Vault Relayer (see Swapping Tokens — Token Approval Flow)
Basic Limit Order
To create a limit order, construct anOrder with explicit sell_amount and buy_amount, sign it, and submit it to the OrderBook API:
Calculating Limit Prices
The limit price is determined by the ratio ofsell_amount to buy_amount. You specify both amounts explicitly:
Price calculation:
- Limit price = buyAmount / sellAmount (in token units, adjusted for decimals)
- The order fills only when the market reaches your price or better
Order Kinds
- Sell Limit Orders
- Buy Limit Orders
Sell orders guarantee you receive at least the specified Use case: “I want to sell 1 WETH and receive at least 3000 USDC”
buy_amount for your sell_amount:Using a Quote as Price Reference
You can fetch a market quote first and adjust the price to set your limit:Partially Fillable Orders
For large orders, enable partial fills to allow incremental execution:When Will My Order Fill?
Limit orders fill when the market price reaches your specified rate or better. Unlikeswap_tokens which executes immediately at the current market price, limit orders may take hours, days, or never fill if the market doesn’t reach your target.
Behind the scenes, solvers continuously check whether your order is profitable to execute. Once the on-chain price moves to meet (or beat) your limit, a solver will include your order in a batch and settle it.
Monitoring Your Order
After submitting a limit order, you can check its status at any time:status field will be one of:
open— the order is active and waiting to be filledfulfilled— the order has been completely filledcancelled— the order was cancelled by the ownerexpired— the order passed itsvalid_totimestamp without being filled
executedSellAmount and executedBuyAmount to see how much has been filled so far:
Custom App Data
Add metadata to identify your application or configure partner fees:Comparing Swap vs Limit Orders
Best Practices
- Set realistic prices — orders too far from market may never fill
- Use
valid_towisely — set appropriate expiration for your strategy - Consider partial fills — for large orders, partial fills improve execution
- Monitor order status — check if your order has been filled or partially filled using Managing Orders
- Token approvals — ensure the Vault Relayer has sufficient allowance before submitting
Troubleshooting
Next Steps
- Learn about Managing Orders to track and cancel limit orders
- Explore TWAP Orders for time-weighted average price execution
- See App Data for custom metadata and partner fees