Get Quotes: API Reference for Swap, Trade, and DEX APIs

Β·

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

ParameterTypeRequiredDescription
chainIndexStringYesUnique chain identifier (e.g., 1 for Ethereum). Supported chains.
chainIdStringYesLegacy chain ID (will be deprecated).
amountStringYesInput amount in minimal units (e.g., 1 USDT = 1000000). Get divisibility from Tokenlist.
swapModeStringYesexactIn (fixed input) or exactOut (fixed output). Default: exactIn.
fromTokenAddressStringYesContract address of the sold token (e.g., 0xeee...eee for native tokens).
toTokenAddressStringYesContract address of the bought token.

Optional Fields

ParameterTypeDescription
dexIdsStringLimit quotes to specific liquidity pools (comma-separated, e.g., 1,50,180).
directRouteBooleanRestrict routing to a single pool (Solana only). Default: false.
priceImpactProtectionPercentageStringMaximum allowed price impact (0–1.0). Default: 0.9 (90%).
feePercentStringReferrer commission (0–3%, or 10% for Solana). Deducted from fromToken.

Response Structure

Quote Metadata

FieldTypeDescription
chainIndexStringChain identifier.
swapModeStringSwap type (exactIn/exactOut).

Routing Details

FieldTypeDescription
fromTokenAmountStringInput amount (e.g., 500000000000000000).
toTokenAmountStringOutput amount (e.g., 168611907733361).
tradeFeeStringEstimated network fee (USD).
estimateGasFeeStringGas cost in chain-native units (e.g., wei).

Token Information

FieldTypeDescription
tokenContractAddressStringToken contract address.
tokenSymbolStringSymbol (e.g., USDT).
decimalStringToken divisibility. Note: May change per contract.
isHoneyPotBooleantrue if token has transfer restrictions.
taxRateStringBuy/sell tax (0–1.0, e.g., 0.05 = 5%).

πŸ‘‰ Optimize your swaps with OKX DEX API


Quote Comparison

FieldTypeDescription
dexNameStringDEX platform name (e.g., Uniswap).
amountOutStringExpected received amount.
priceImpactPercentageStringEstimated 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?

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

  1. Monitor Gas Fees: Use estimateGasFee to optimize transaction timing.
  2. Tax Awareness: Check taxRate for tokens with transfer fees.
  3. Liquidity Depth: Larger swaps may incur higher priceImpactPercentage.

Need more liquidity options? Check OKX DEX integrations.