Overview
Retrieve optimized cryptocurrency exchange rates through our decentralized exchange (DEX) aggregator. This API connects you with multiple liquidity sources to ensure the best possible pricing for your token swaps.
API Endpoint
GET https://web3.okx.com/api/v5/dex/aggregator/quote
Key Features
๐ Discover how our DEX aggregator outperforms competitors
- Multi-chain support (Ethereum, Solana, etc.)
- Price impact protection
- Route optimization across 180+ liquidity pools
- Detailed fee breakdowns
Request Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
chainIndex | String | Yes | Blockchain identifier (e.g., "1" for Ethereum) |
amount | String | Yes | Trade amount including decimals |
swapMode | String | Yes | exactIn (fixed input) or exactOut (fixed output) |
fromTokenAddress | String | Yes | Seller token contract address |
toTokenAddress | String | Yes | Buyer token contract address |
dexIds | String | No | Comma-separated list of specific DEX IDs |
priceImpactProtectionPercentage | String | No | 0-1.0 value (default 0.9) |
Response Parameters
| Parameter | Description |
|---|---|
fromTokenAmount | Input token quantity |
toTokenAmount | Output token quantity |
tradeFee | Estimated network fee (USD) |
routerPercent | Route's share of total liquidity |
priceImpactPercentage | Value difference caused by liquidity depth |
Implementation Example
// Sample API request
fetch('https://web3.okx.com/api/v5/dex/aggregator/quote?chainIndex=1&amount=1000000&fromTokenAddress=0xeeee...&toTokenAddress=0xa892...')
.then(response => response.json())
.then(data => console.log(data));FAQ Section
Q: How often are prices updated?
A: Our aggregator provides real-time quotes by continuously monitoring 180+ liquidity pools across supported blockchains.
Q: What chains are supported?
A: Ethereum, Solana, and 18 other EVM-compatible chains. ๐ Full list available here
Q: How does price impact protection work?
A: When enabled, the system will reject quotes where estimated price movement exceeds your specified percentage threshold.
Q: Can I specify which DEXs to use?
A: Yes, simply include the dexIds parameter with your preferred liquidity sources.
Q: What's the difference between exactIn and exactOut?
A: exactIn fixes your input amount while exactOut guarantees your desired output quantity.
Best Practices
- Always verify token addresses
- Implement price impact protection
- Compare multiple routes for optimal pricing
- Monitor gas fees for cost-efficient transactions