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.
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
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:Comparing Swap vs Limit Orders
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
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