Get Exchange Rate via DEX Aggregator API

ยท

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

Request Parameters

ParameterTypeRequiredDescription
chainIndexStringYesBlockchain identifier (e.g., "1" for Ethereum)
amountStringYesTrade amount including decimals
swapModeStringYesexactIn (fixed input) or exactOut (fixed output)
fromTokenAddressStringYesSeller token contract address
toTokenAddressStringYesBuyer token contract address
dexIdsStringNoComma-separated list of specific DEX IDs
priceImpactProtectionPercentageStringNo0-1.0 value (default 0.9)

Response Parameters

ParameterDescription
fromTokenAmountInput token quantity
toTokenAmountOutput token quantity
tradeFeeEstimated network fee (USD)
routerPercentRoute's share of total liquidity
priceImpactPercentageValue 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

  1. Always verify token addresses
  2. Implement price impact protection
  3. Compare multiple routes for optimal pricing
  4. Monitor gas fees for cost-efficient transactions