DEX API
Get quotes

Get quotes#

Get the best quote for a swap through OKX DEX.

Request address#

GET https://www.okx.com/api/v5/dex/aggregator/quote

Request param#

ParameterTypeRequiredDescription
chainIdStringYesChain ID (e.g., 1 for Ethereum. See Chain IDs)
amountStringYesThe input amount of a token to be sold (set in minimal divisible units, e.g., 1.00 USDT set as 1000000, 1.00 DAI set as 1000000000000000000)
fromTokenAddressStringYesThe contract address of a token to be sold (e.g., 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee)
toTokenAddressStringYesThe contract address of a token to be bought (e.g., 0xa892e1fef8b31acc44ce78e7db0a2dc610f92d00)
dexIdsStringNoDexId of the liquidity pool for limited quotes, multiple combinations separated by , (e.g.,1,50,180, see liquidity list for more)
priceImpactProtectionPercentageStringNo(Optional. The default is 90%.) The percentage (between 0 - 1.0) of the price impact allowed.

When the priceImpactProtectionPercentage is set, if the estimated price impact is above the percentage indicated, an error will be returned. For example, if PriceImpactProtectionPercentage = .25 (25%), any quote with a price impact higher than 25% will return an error.

This is an optional feature, and the default value is 0.9. When it’s set to 1.0 (100%), the feature will be disabled, which means that every transaction will be allowed to pass.

Note: If we’re unable to calculate the price impact, we’ll return null, and the price impact protection will be disabled.
feePercentStringNoThe percentage of fromTokenAmount will be sent to the referrer's address, the rest will be set as the input amount to be sold. min percentage:0 max percentage:3

Response param#

ParameterTypeDescription
chainIdStringChain ID (e.g., 1 for Ethereum. See Chain IDs)
dexRouterListObject[]Quote path data set
fromTokenAmountStringThe input amount of a token to be sold (e.g., 500000000000000000000000)
toTokenAmountStringThe resulting amount of a token to be bought (e.g., 168611907733361)
routerStringOne of the main paths for the token swap
routerPercentStringThe percentage of assets handled by the main path (e.g., 5)
subRouterListObject[]DEX Router information
dexProtocolObject[]Liquidity protocols used on the main path (e.g., Verse)
percentStringThe percentage of assets handled by the protocol (e.g., 100)
dexNameStringThe name of the liquidity protocol
fromTokenObjectThe information of a token to be sold
tokenContractAddressStringToken contract address (e.g., 0xa892e1fef8b31acc44ce78e7db0a2dc610f92d00)
tokenSymbolStringToken symbol (e.g., 0xa892e1fef8b31acc44ce78e7db0a2dc610f92d00)
tokenUnitPriceStringThe token unit price returned by this interface is a general USD price based on data from on-chain, exchange, and other third-party sources. Note: This price is only a recommended price. For some special cases, the token unit price may be 'null'
decimalStringThe decimal number defines the smallest unit into which a single currency token can be divided. For example, if the decimal number of a token is 8, it means that a single such token can be divided into 100,000,000 of its smallest units. Note: This parameter is for reference only. It may change due to reasons such as settings adjustments by the contract owner.
toTokenObjectThe information of a token to be bought
quoteCompareListObject[]Comparison of quote routes
dexNameStringDEX name of the quote route
dexLogoStringDEX logo of the quote route
tradeFeeStringEstimated network fee (USD) of the quote route
receiveAmountStringReceived amount of the quote route

Request example#

shell
curl --location --request GET 'https://www.okx.com/api/v5/dex/aggregator/quote?amount=10000000000000000000&chainId=1&toTokenAddress=0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48&fromTokenAddress=0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee' \
--header 'OK-ACCESS-PROJECT: 86af********d1bc' \
--header 'OK-ACCESS-KEY: 37c541a1-****-****-****-10fe7a038418' \
--header 'OK-ACCESS-SIGN: leaV********3uw=' \
--header 'OK-ACCESS-PASSPHRASE: 1****6' \
--header 'OK-ACCESS-TIMESTAMP: 2023-10-18T12:21:41.274Z'

Response example#

200
{
      "code": "0",
      "data": [
            {
                  "chainId": "1",
                  "dexRouterList": [
                        {
                              "router": "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee--0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
                              "routerPercent": "100",
                              "subRouterList": [
                                    {
                                          "dexProtocol": [
                                                {
                                                      "dexName": "Uniswap V3",
                                                      "percent": "100"
                                                }
                                          ],
                                          "fromToken": {
                                                "decimal": "18",
                                                "tokenContractAddress": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
                                                "tokenSymbol": "WETH",
                                                "tokenUnitPrice": "3083.47233955226"
                                          },
                                          "toToken": {
                                                "decimal": "6",
                                                "tokenContractAddress": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
                                                "tokenSymbol": "USDC",
                                                "tokenUnitPrice": "0.9998542668416743"
                                          }
                                    }
                              ]
                        }
                  ],
                  "estimateGasFee": "135000",
                  "fromToken": {
                        "decimal": "18",
                        "tokenContractAddress": "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
                        "tokenSymbol": "ETH",
                        "tokenUnitPrice": "3083.47233955226"
                  },
                  "fromTokenAmount": "10000000000000000000",
                  "quoteCompareList": [
                        {
                              "amountOut": "30765.431033",
                              "dexLogo": "https://static.okx.com/cdn/wallet/logo/Curve.png",
                              "dexName": "Curve TNG",
                              "tradeFee": "13.883083203"
                        },
                        {
                              "amountOut": "30718.488726",
                              "dexLogo": "https://static.okx.com/cdn/wallet/logo/pancake.png",
                              "dexName": "PancakeSwap V3",
                              "tradeFee": "9.452311968"
                        },
                        {
                              "amountOut": "30712.217539",
                              "dexLogo": "https://static.okx.com/cdn/wallet/logo/UNI.png",
                              "dexName": "Uniswap V2",
                              "tradeFee": "9.452311968"
                        },
                        {
                              "amountOut": "30587.988076",
                              "dexLogo": "https://static.okx.com/cdn/wallet/logo/SUSHI.png",
                              "dexName": "SushiSwap",
                              "tradeFee": "9.452311968"
                        },
                        {
                              "amountOut": "30542.173078",
                              "dexLogo": "https://static.okx.com/cdn/wallet/logo/UNI.png",
                              "dexName": "Uniswap V3",
                              "tradeFee": "9.452311968"
                        }
                  ],
                  "toToken": {
                        "decimal": "6",
                        "tokenContractAddress": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
                        "tokenSymbol": "USDC",
                        "tokenUnitPrice": "0.9998542668416743"
                  },
                  "toTokenAmount": "30794623157"
            }
      ],
      "msg": ""
}