Fill a Limit Order

Discover open limit orders and execute a fill on-chain as a Taker using the KyberSwap Limit Order API.

Fill a Limit Order

Takers fill limit orders on-chain, earning the spread between the order rate and the current market rate. Every fill requires a KyberSwap Operator co-signature that authorises the specific fill — this prevents stale or frontrun fills.

Flow

GET /orders  →  GET /operator-signature  →  check allowance
    →  POST /encode/fill-order-to  →  send transaction

Step 1 — Get Open Orders

Query open orders for a token pair, sorted by best rate (descending):

const { data } = await axios.get(
    "https://limit-order.kyberswap.com/read-partner/api/v1/orders",
    {
        params: {
            chainId: 137,
            makerAsset: "0x2791bca1...",   // token the Maker is selling
            takerAsset: "0x1C954E8f...",   // token the Taker must provide
        }
    }
);

const orders = data.data;   // sorted best-rate first
const targetOrderId = orders[0].id;

Orders are sorted by the effective rate formula which accounts for partial fills and fees.

Step 2 — Get the Operator Signature

The Operator signature is required for every fill. It is short-lived and must be fetched immediately before building the transaction:

Step 3 — Check and Set Allowance

The Limit Order contract must be approved to spend the Taker's takerAsset:

Step 4 — Encode the Fill Calldata

Batch fills: Use POST /read-ks/api/v1/encode/fill-batch-orders-to to fill multiple orders in one transaction. Pass arrays of orderIds and operatorSignatures in matching order. See Fill Batch Orders.

Step 5 — Execute On-chain

Last updated

Was this helpful?