Skip to main content

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

The postLimitOrder method creates a limit order with your specified amounts.

Required Parameters

  • kind - The order kind (OrderKind.SELL or OrderKind.BUY)
  • sellToken - The sell token address
  • sellTokenDecimals - The sell token decimals
  • buyToken - The buy token address
  • buyTokenDecimals - The buy token decimals
  • sellAmount - The amount to sell in atoms
  • buyAmount - 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 of sellAmount 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 with LimitOrderAdvancedSettings:

Order Kinds for Limit Orders

Sell orders guarantee you receive at least the specified buyAmount for your sellAmount:
Use case: “I want to sell 1 WETH and receive at least 3000 USDC”

Partially Fillable Orders

By default, limit orders are “fill-or-kill” (must be completely filled). Enable partial fills to allow incremental execution:
Partially fillable orders may be executed in multiple transactions over time. Monitor the order status to track fills.

Comparing Swap vs Limit Orders

Best Practices

  1. Set realistic prices: Orders too far from market price may never fill
  2. Use validTo wisely: Set appropriate expiration times for your strategy
  3. Consider partial fills: For large orders, partial fills can improve execution
  4. Monitor order status: Check if your order has been filled or partially filled
  5. Handle slippage: Limit orders typically use 0 slippage since price is explicit

Next Steps