Introduction
Get the best quote for your token swaps through OKX DEX API with optimized pricing and liquidity routing. This guide covers all required parameters, response formats, and best practices for integrating swap functionality.
Core Parameters
Required Fields
| Parameter | Type | Required | Description |
|---|---|---|---|
chainIndex | String | Yes | Unique chain identifier (e.g., 1 for Ethereum). Supported chains. |
chainId | String | Yes | Legacy chain ID (will be deprecated). |
amount | String | Yes | Input amount in minimal units (e.g., 1 USDT = 1000000). Get divisibility from Tokenlist. |
swapMode | String | Yes | exactIn (fixed input) or exactOut (fixed output). Default: exactIn. |
fromTokenAddress | String | Yes | Contract address of the sold token (e.g., 0xeee...eee for native tokens). |
toTokenAddress | String | Yes | Contract address of the bought token. |
Optional Fields
| Parameter | Type | Description |
|---|---|---|
dexIds | String | Limit quotes to specific liquidity pools (comma-separated, e.g., 1,50,180). |
directRoute | Boolean | Restrict routing to a single pool (Solana only). Default: false. |
priceImpactProtectionPercentage | String | Maximum allowed price impact (0β1.0). Default: 0.9 (90%). |
feePercent | String | Referrer commission (0β3%, or 10% for Solana). Deducted from fromToken. |
Response Structure
Quote Metadata
| Field | Type | Description |
|---|---|---|
chainIndex | String | Chain identifier. |
swapMode | String | Swap type (exactIn/exactOut). |
Routing Details
| Field | Type | Description |
|---|---|---|
fromTokenAmount | String | Input amount (e.g., 500000000000000000). |
toTokenAmount | String | Output amount (e.g., 168611907733361). |
tradeFee | String | Estimated network fee (USD). |
estimateGasFee | String | Gas cost in chain-native units (e.g., wei). |
Token Information
| Field | Type | Description |
|---|---|---|
tokenContractAddress | String | Token contract address. |
tokenSymbol | String | Symbol (e.g., USDT). |
decimal | String | Token divisibility. Note: May change per contract. |
isHoneyPot | Boolean | true if token has transfer restrictions. |
taxRate | String | Buy/sell tax (0β1.0, e.g., 0.05 = 5%). |
π Optimize your swaps with OKX DEX API
Quote Comparison
| Field | Type | Description |
|---|---|---|
dexName | String | DEX platform name (e.g., Uniswap). |
amountOut | String | Expected received amount. |
priceImpactPercentage | String | Estimated slippage impact (positive/negative). |
FAQs
How do I handle tokens with high price impact?
Set priceImpactProtectionPercentage to reject quotes exceeding your threshold (e.g., 0.25 for 25%).
Whatβs the difference between exactIn and exactOut?
exactIn: Fix the input amount; output varies based on liquidity.exactOut: Fix the desired output; input adjusts with slippage.
Can I restrict routes to specific DEXs?
Yes. Use dexIds to specify preferred liquidity pools (e.g., 1,50 for Uniswap and SushiSwap).
π Explore advanced DEX routing strategies
Best Practices
- Monitor Gas Fees: Use
estimateGasFeeto optimize transaction timing. - Tax Awareness: Check
taxRatefor tokens with transfer fees. - Liquidity Depth: Larger swaps may incur higher
priceImpactPercentage.
Need more liquidity options? Check OKX DEX integrations.