Creating Limit Orders
Limit orders allow you to specify both the sell and buy amounts, creating an order that will only execute at your desired price or better.Overview
Unlike swap orders that execute at market price, limit orders give you precise control over the exchange rate. The order will only be filled when the market price reaches your specified rate.Limit orders are “good-til-cancelled” by default and remain in the order book until filled or cancelled.
Prerequisites
Before creating a limit order, make sure:- Token approval: The sell token must be approved to the CoW Protocol Vault Relayer contract. Without this, the protocol cannot move your tokens when the order fills. See Token Approvals for full details.
-
Sufficient balance: Your wallet must hold enough of the sell token to cover the
sellAmount. The order will fail at submission if balance is insufficient. -
For buy limit orders: The
sellAmountyou specify is the maximum you will pay. You may end up paying less if solvers find a better route.
Check and Set Approval
Pre-Flight Checklist
Before submitting your limit order, verify:- Sell token approved to Vault Relayer
- Wallet has sufficient sell token balance
- Token addresses are correct for the target chain
- Amounts are in token atoms (smallest unit) — watch decimal differences (USDC = 6 decimals, WETH = 18 decimals)
- Limit price is reasonable relative to the current market
validTogives enough time for the market to reach your price
Using postLimitOrder
ThepostLimitOrder method creates a limit order with your specified amounts.
Required Parameters
kind- The order kind (OrderKind.SELLorOrderKind.BUY)sellToken- The sell token addresssellTokenDecimals- The sell token decimalsbuyToken- The buy token addressbuyTokenDecimals- The buy token decimalssellAmount- The amount to sell in atomsbuyAmount- The amount to buy in atoms
Basic Example
Optional Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
quoteId | number | - | ID of a quote from the Quote API to use as reference |
validTo | number | - | Order expiration timestamp in seconds since epoch |
env | Env | prod | The environment to use (prod or staging) |
partiallyFillable | boolean | false | Whether the order can be partially filled |
receiver | string | order creator | The address that will receive the tokens |
partnerFee | PartnerFee | - | Partner fee configuration |
Example with Optional Parameters
Calculating Limit Price
The limit price is determined by the ratio ofsellAmount to buyAmount.
Example: Setting a Limit Price
Price calculation:
- Limit price = buyAmount / sellAmount (in token units)
- In this example: 3000 USDC / 1 WETH = 3000 USDC per WETH
Using Quote ID
You can reference a previous quote when creating a limit order:Advanced Settings
Customize limit order behavior withLimitOrderAdvancedSettings:
Order Kinds for Limit Orders
- 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”
buyAmount for your sellAmount:Partially Fillable Orders
By default, limit orders are “fill-or-kill” (must be completely filled). 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. Unlike swap orders that execute immediately, limit orders may take hours, days, or never fill depending on market conditions. Here is what happens after you submit:- Your order enters the order book. CoW Protocol solvers continuously scan the book for profitable orders to execute.
- Solvers evaluate your order each batch. If your limit price is at or better than the current market price, solvers will include it in the next settlement.
- If your price is far from market, the order sits in the book waiting for the market to move to your price.
- When conditions are met, a solver executes your order on-chain. You may even receive surplus (a better price than you specified).
Use
sdk.getQuote() to check the current market price before setting your limit. This helps you understand how far your limit is from the market and set realistic expectations for fill time.Monitoring Your Order
After creating a limit order, you will want to track its status.Check Order Status
Track Partial Fill Progress
For partially fillable orders, inspect how much has been executed so far:Cancel an Order
If you want to cancel an open limit order:Comparing Swap vs Limit Orders
| Feature | Swap Orders | Limit Orders |
|---|---|---|
| Price | Current market price | Your specified price |
| Amount | One amount (sell OR buy) | Both amounts (sell AND buy) |
| Execution | Immediate (if liquidity exists) | When price target is reached |
| Slippage | Applies automatically | Controlled by your price |
| Use Case | Quick trades at market price | Price-specific trades |
Best Practices
- Set realistic prices: Orders too far from market price may never fill
- Use validTo wisely: Set appropriate expiration times for your strategy
- Consider partial fills: For large orders, partial fills can improve execution
- Monitor order status: Check if your order has been filled or partially filled
- Handle slippage: Limit orders typically use 0 slippage since price is explicit
Troubleshooting
| Problem | Likely Cause | Fix |
|---|---|---|
InsufficientAllowance error | Sell token not approved to Vault Relayer | Call sdk.approveCowProtocol() before placing the order |
InsufficientBalance error | Wallet does not hold enough sell token | Verify your balance covers sellAmount |
| Order never fills | Limit price is too far from the current market | Check current market price with sdk.getQuote() and adjust |
| Order fills at a different price than expected | Solvers found a better execution route | This is expected — CoW Protocol gives you surplus (better than your limit) |
TooManyLimitOrders error | Too many open limit orders | Cancel old or stale orders first |
| Partial fill stuck at partial | Remaining amount is too small for solvers to profitably execute | Cancel the order and create a new one for the remainder |
Next Steps
- Learn about Order Management to track and cancel limit orders
- See Token Approvals for managing ERC-20 approvals
- Explore Smart Contract Wallets for advanced signing