Creating a limit order on decentralized exchanges (DEXs) has become a fundamental function for traders and developers building on Web3. With the growing demand for seamless, secure, and programmable trading experiences, leveraging a robust limit order API is essential. This guide dives into how to use the DEX API to create a limit order through OKX’s Wallet-as-a-Service (WaaS) platform — a powerful solution for integrating decentralized trading capabilities directly into your applications.
Whether you're building a DeFi dashboard, automated trading bot, or multi-chain wallet, understanding how to interact with a limit order API will empower your project with real-time, non-custodial trading functionality.
👉 Discover how to integrate advanced trading features using Web3 APIs today.
Understanding the Limit Order API Endpoint
The core endpoint for creating a limit order is:
POST https://web3.okx.com/api/v5/dex/aggregator/limit-order/save-orderThis RESTful API allows developers to submit structured order data that represents a user's intent to trade one token for another at a specified price. The request must be signed off-chain and submitted with valid cryptographic proof to ensure authenticity and prevent tampering.
Before sending the request, ensure your application has proper authentication configured via API keys or wallet signatures, depending on the integration method supported by OKX WaaS.
Required Request Parameters
To successfully create a limit order, you must include the following parameters in the request body as JSON:
Core Order Identification
orderHash(String, required): A unique hash generated from the order data, used to identify the order across the network.signature(String, required): The cryptographic signature of the order data, proving ownership and approval from the maker wallet.chainId(String, required): The blockchain network where the order will be executed. For example:1for Ethereum137for Polygon- Refer to the official supported networks list for more.
Order Data Object (data)
This nested object contains all the details about the trade:
salt(String, required): A timestamp in seconds (e.g.,1691499249) used as an idempotency key to prevent duplicate processing.makingAmount(String, required): The amount of the token being sold, formatted with full precision. For example:- 1 USDT (6 decimals) →
"1000000" - 1 DAI (18 decimals) →
"1000000000000000000"
- 1 USDT (6 decimals) →
takingAmount(String, required): The desired amount of the token to receive, also in precise format.makerToken(String, required): Contract address of the token being sold (e.g.,0x53e0bca35ec356bd5dddfebbd1fc0fd03fabad39).takerToken(String, required): Contract address of the token being bought (e.g.,0x2791bca1f2de4661ed88a30c99a7a9449aa84174).
Wallet and Execution Settings
maker(String, required): The Ethereum-style address creating the order (e.g.,0x6f9ffea7370310cd0f890dfde5e0e061059dcfd9).deadLine(String, required): Expiration time of the order as a Unix timestamp in seconds (e.g.,1699520029). After this time, the order becomes invalid.allowedSender(String, required):- Set to
0x0000000000000000000000000000000000000000to allow anyone to execute the trade. - Or specify a single address to restrict execution rights.
- Set to
receiver(String, required): The destination address where purchased assets will be sent upon successful fill.minReturn(String, required): Minimum acceptable amount of the taker token to receive, accounting for slippage and market changes.partiallyAble(Bool, required):true: Allows partial fills (e.g., half the order executes now, half later).false: Requires full execution or none at all.
These parameters ensure flexibility, security, and precision when placing orders across various DEX aggregators.
Response Structure
After submitting the request, the server returns a standardized JSON response:
code(String): Indicates success or failure. Common values:"0": Success"51000": Missing required parameter- Additional codes documented in the error reference
msg(String): Human-readable message if an error occurs; otherwise empty on success.
A successful response confirms that the order has been registered and is now available for execution on the decentralized exchange network.
👉 Start building smarter trading workflows with powerful Web3 tools.
Practical Use Case: Building a Custom Trading Interface
Imagine developing a cross-chain portfolio manager app. Users want to set limit orders for tokens across Ethereum, Polygon, and Arbitrum without leaving your interface. By integrating this limit order API, you can:
- Collect user inputs (buy/sell amounts, prices).
- Calculate precise token values using on-chain decimals.
- Generate and sign the order off-chain using embedded wallets.
- Submit via the API endpoint securely.
- Display real-time status updates from the blockchain.
This creates a smooth, custodial-free experience aligned with Web3 principles.
Frequently Asked Questions (FAQ)
Q: What happens if my order expires?
A: Once the deadLine timestamp passes, no one can execute the order. You'll need to create a new one if market conditions still align with your strategy.
Q: Can I cancel a limit order after submission?
A: Yes. While this API creates orders, cancellation typically involves calling a separate endpoint or interacting directly with the smart contract using your private key or session signature.
Q: Why do I need to include full precision amounts?
A: Blockchains operate with fixed decimal places per token (e.g., 18 for ERC-20s like DAI). Using raw integers avoids floating-point errors and ensures accurate settlement.
Q: Is it safe to allow anyone to execute my order?
A: Setting allowedSender to zero address is standard practice for public limit orders. Just ensure your signature is secure and never exposed server-side.
Q: How does partial execution affect my trade?
A: If partiallyAble is true, takers can fulfill portions of your order. This increases fill probability but may result in multiple transactions at slightly different effective prices.
Q: Can I use this API for automated trading bots?
A: Absolutely. With proper rate limiting and error handling, this API supports algorithmic strategies like arbitrage, market making, and trend-based entries.
Final Thoughts
Integrating a DEX API like OKX’s limit order system unlocks powerful capabilities for developers in the decentralized finance space. By mastering these endpoints, you enable users to take control of their trades with precision pricing, secure execution, and flexible settlement options — all without relying on centralized intermediaries.
As Web3 continues to evolve, tools that simplify complex blockchain interactions will drive broader adoption. Whether you're enabling limit orders for retail users or building institutional-grade trading infrastructure, leveraging well-documented APIs is key to staying ahead.
👉 Unlock next-gen DeFi functionality with trusted Web3 development tools.