Trade API

Get Quotes#

Get the best quote for a swap through OKX DEX.

Request URL#

GET https://web3.okx.com/api/v6/dex/aggregator/quote

Request Parameters#

ParameterTypeRequiredDescription
chainIndexStringYesUnique identifier for the chain.
e.g., 1: Ethereum.
See more here.
amountStringYesThe input amount of a token to be sold (if swapMode=exactIn) or buy (if swapMode=exactOut), set in minimal divisible units, e.g., 1.00 USDT set as 1000000, 1.00 DAI set as 1000000000000000000, you could get the minimal divisible units from Tokenlist.
swapModeStringYesPossible values: [exactIn, exactOut].
Default: exactIn.
exactOut is for supporting use cases where you need an exact output amount.

Note:
1.ExactOut feature currently only support Ethereum、Base、BSC 、Arbitrum chain.
2.ExactOut feature currently support only Uni v2 and v3 protocols
3. In this case the slippage is on the input token.
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)
directRouteBooleanNoThe default setting is false. When enabled, Direct Routes restrict our routing to a single liquidity pool only. Currently, this feature is only active for Solana swaps.
priceImpactProtectionPercentStringNoThis is an optional feature. The default value is 90 (representing 90%). The priceImpactProtectionPercent parameter can be set between 0 and 100.
When it’s set to 100, the feature is disabled and every transaction will be allowed to pass.
If the estimated price impact is above the percentage indicated, an error will be returned. For example, if priceImpactProtectionPercent = 25 (25%), any quote with a price impact higher than 25% will return an error.
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: 10 for Solana, 3 for all other chains.
By configuring this parameter, you can obtain the final amount of totoken provided to the user after deducting the commission from fromtoken.
A maximum of nine decimal places is allowed.
If more decimals are entered, the system will automatically round up.

Response Parameters#

ParameterTypeDescription
chainIndexStringUnique identifier for the chain.
swapModeStringSwap mode of this quote.
dexRouterListArrayQuote 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)
tradeFeeStringEstimated network fee (USD) of the quote route
estimateGasFeeStringEstimated gas consumption is returned in the smallest units of each chain, such as wei.
routerStringMain path for the token swap
routerPercentStringThe percentage of assets handled by the main path (e.g., 5)
subRouterListArrayDEX Router information
dexProtocolArrayLiquidity 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
fromTokenIndexStringToken index of fromToken in the swap path.
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 real time price based on data from on-chain 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.
isHoneyPotBooleanIf the token is a honeypot token. yes:true no:false
taxRateStringToken tax rate for selling: Applicable to tokens with configurable tax mechanisms (e.g., SafeMoon, SPL2022 tokens). Returns 0 for regular tokens without tax. The value ranges from 0 to 1, where 0.01 represents 1%.
toTokenIndexStringToken index of toToken in the swap path.
toTokenObjectThe information of a token to be bought
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.
isHoneyPotBooleanIf the token is a honeypot token. yes:true no:false
taxRateStringToken tax rate for buying: Applicable to tokens with configurable tax mechanisms (e.g., SafeMoon, SPL2022 tokens). Returns 0 for regular tokens without tax. The value ranges from 0 to 1, where 0.01 represents 1%.
quoteCompareListArrayComparison of quote routes
dexNameStringDEX name of the quote route
dexLogoStringDEX logo of the quote route
tradeFeeStringEstimated network fee (USD) of the quote route
amountOutStringReceived amount of the quote route
priceImpactPercentStringPercentage = (Received value – Paid value) / Paid value. The swap amount will affect the depth of the liquidity pool, causing a value difference. This percentage can be positive if the received value exceeds the paid value, e.g., 5 represents 5%.

Request Example#

shell
curl --location --request GET 'https://web3.okx.com/api/v6/dex/aggregator/quote?amount=10000000000000000000&chainIndex=1&toTokenAddress=0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48&fromTokenAddress=0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee' \

--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": [
        {
            "chainIndex": "130",
            "contextSlot": 0,
            "dexRouterList": [
                {
                    "dexProtocol": {
                        "dexName": "Uniswap V4",
                        "percent": "30"
                    },
                    "fromToken": {
                        "decimal": "18",
                        "isHoneyPot": false,
                        "taxRate": "0",
                        "tokenContractAddress": "0x4200000000000000000000000000000000000006",
                        "tokenSymbol": "WETH",
                        "tokenUnitPrice": "4191.043356462183138854"
                    },
                    "fromTokenIndex": "0",
                    "toToken": {
                        "decimal": "6",
                        "isHoneyPot": false,
                        "taxRate": "0",
                        "tokenContractAddress": "0x078d782b760474a361dda0af3839290b0ef57ad6",
                        "tokenSymbol": "USDC",
                        "tokenUnitPrice": "0.999692348812448693"
                    },
                    "toTokenIndex": "4"
                },
                {
                    "dexProtocol": {
                        "dexName": "Uniswap V4",
                        "percent": "5"
                    },
                    "fromToken": {
                        "decimal": "18",
                        "isHoneyPot": false,
                        "taxRate": "0",
                        "tokenContractAddress": "0x4200000000000000000000000000000000000006",
                        "tokenSymbol": "WETH",
                        "tokenUnitPrice": "4191.043356462183138854"
                    },
                    "fromTokenIndex": "0",
                    "toToken": {
                        "decimal": "6",
                        "isHoneyPot": false,
                        "taxRate": "0",
                        "tokenContractAddress": "0x9151434b16b9763660705744891fa906f660ecc5",
                        "tokenSymbol": "USDT",
                        "tokenUnitPrice": "1.000313193103130296"
                    },
                    "toTokenIndex": "3"
                },
                {
                    "dexProtocol": {
                        "dexName": "Uniswap V4",
                        "percent": "5"
                    },
                    "fromToken": {
                        "decimal": "18",
                        "isHoneyPot": false,
                        "taxRate": "0",
                        "tokenContractAddress": "0x4200000000000000000000000000000000000006",
                        "tokenSymbol": "WETH",
                        "tokenUnitPrice": "4191.043356462183138854"
                    },
                    "fromTokenIndex": "0",
                    "toToken": {
                        "decimal": "8",
                        "isHoneyPot": false,
                        "taxRate": "0",
                        "tokenContractAddress": "0x0555e30da8f98308edb960aa94c0db47230d2b9c",
                        "tokenSymbol": "WBTC",
                        "tokenUnitPrice": "112879.983830393508167243"
                    },
                    "toTokenIndex": "2"
                },
                {
                    "dexProtocol": {
                        "dexName": "Uniswap V4",
                        "percent": "5"
                    },
                    "fromToken": {
                        "decimal": "18",
                        "isHoneyPot": false,
                        "taxRate": "0",
                        "tokenContractAddress": "0x4200000000000000000000000000000000000006",
                        "tokenSymbol": "WETH",
                        "tokenUnitPrice": "4191.043356462183138854"
                    },
                    "fromTokenIndex": "0",
                    "toToken": {
                        "decimal": "8",
                        "isHoneyPot": false,
                        "taxRate": "0",
                        "tokenContractAddress": "0x927b51f251480a681271180da4de28d44ec4afb8",
                        "tokenSymbol": "WBTC",
                        "tokenUnitPrice": "112634.107075070841530997"
                    },
                    "toTokenIndex": "1"
                },
                {
                    "dexProtocol": {
                        "dexName": "Uniswap V4",
                        "percent": "55"
                    },
                    "fromToken": {
                        "decimal": "18",
                        "isHoneyPot": false,
                        "taxRate": "0",
                        "tokenContractAddress": "0x4200000000000000000000000000000000000006",
                        "tokenSymbol": "WETH",
                        "tokenUnitPrice": "4191.043356462183138854"
                    },
                    "fromTokenIndex": "0",
                    "toToken": {
                        "decimal": "8",
                        "isHoneyPot": false,
                        "taxRate": "0",
                        "tokenContractAddress": "0x927b51f251480a681271180da4de28d44ec4afb8",
                        "tokenSymbol": "WBTC",
                        "tokenUnitPrice": "112634.107075070841530997"
                    },
                    "toTokenIndex": "1"
                },
                {
                    "dexProtocol": {
                        "dexName": "Uniswap V4",
                        "percent": "3"
                    },
                    "fromToken": {
                        "decimal": "8",
                        "isHoneyPot": false,
                        "taxRate": "0",
                        "tokenContractAddress": "0x927b51f251480a681271180da4de28d44ec4afb8",
                        "tokenSymbol": "WBTC",
                        "tokenUnitPrice": "112634.107075070841530997"
                    },
                    "fromTokenIndex": "1",
                    "toToken": {
                        "decimal": "6",
                        "isHoneyPot": false,
                        "taxRate": "0",
                        "tokenContractAddress": "0x9151434b16b9763660705744891fa906f660ecc5",
                        "tokenSymbol": "USDT",
                        "tokenUnitPrice": "1.000313193103130296"
                    },
                    "toTokenIndex": "3"
                },
                {
                    "dexProtocol": {
                        "dexName": "Uniswap V4",
                        "percent": "97"
                    },
                    "fromToken": {
                        "decimal": "8",
                        "isHoneyPot": false,
                        "taxRate": "0",
                        "tokenContractAddress": "0x927b51f251480a681271180da4de28d44ec4afb8",
                        "tokenSymbol": "WBTC",
                        "tokenUnitPrice": "112634.107075070841530997"
                    },
                    "fromTokenIndex": "1",
                    "toToken": {
                        "decimal": "8",
                        "isHoneyPot": false,
                        "taxRate": "0",
                        "tokenContractAddress": "0x0555e30da8f98308edb960aa94c0db47230d2b9c",
                        "tokenSymbol": "WBTC",
                        "tokenUnitPrice": "112879.983830393508167243"
                    },
                    "toTokenIndex": "2"
                },
                {
                    "dexProtocol": {
                        "dexName": "Uniswap V4",
                        "percent": "48"
                    },
                    "fromToken": {
                        "decimal": "8",
                        "isHoneyPot": false,
                        "taxRate": "0",
                        "tokenContractAddress": "0x0555e30da8f98308edb960aa94c0db47230d2b9c",
                        "tokenSymbol": "WBTC",
                        "tokenUnitPrice": "112879.983830393508167243"
                    },
                    "fromTokenIndex": "2",
                    "toToken": {
                        "decimal": "6",
                        "isHoneyPot": false,
                        "taxRate": "0",
                        "tokenContractAddress": "0x078d782b760474a361dda0af3839290b0ef57ad6",
                        "tokenSymbol": "USDC",
                        "tokenUnitPrice": "0.999692348812448693"
                    },
                    "toTokenIndex": "4"
                },
                {
                    "dexProtocol": {
                        "dexName": "Uniswap V4",
                        "percent": "52"
                    },
                    "fromToken": {
                        "decimal": "8",
                        "isHoneyPot": false,
                        "taxRate": "0",
                        "tokenContractAddress": "0x0555e30da8f98308edb960aa94c0db47230d2b9c",
                        "tokenSymbol": "WBTC",
                        "tokenUnitPrice": "112879.983830393508167243"
                    },
                    "fromTokenIndex": "2",
                    "toToken": {
                        "decimal": "6",
                        "isHoneyPot": false,
                        "taxRate": "0",
                        "tokenContractAddress": "0x9151434b16b9763660705744891fa906f660ecc5",
                        "tokenSymbol": "USDT",
                        "tokenUnitPrice": "1.000313193103130296"
                    },
                    "toTokenIndex": "3"
                },
                {
                    "dexProtocol": {
                        "dexName": "Euler",
                        "percent": "73"
                    },
                    "fromToken": {
                        "decimal": "6",
                        "isHoneyPot": false,
                        "taxRate": "0",
                        "tokenContractAddress": "0x9151434b16b9763660705744891fa906f660ecc5",
                        "tokenSymbol": "USDT",
                        "tokenUnitPrice": "1.000313193103130296"
                    },
                    "fromTokenIndex": "3",
                    "toToken": {
                        "decimal": "6",
                        "isHoneyPot": false,
                        "taxRate": "0",
                        "tokenContractAddress": "0x078d782b760474a361dda0af3839290b0ef57ad6",
                        "tokenSymbol": "USDC",
                        "tokenUnitPrice": "0.999692348812448693"
                    },
                    "toTokenIndex": "4"
                },
                {
                    "dexProtocol": {
                        "dexName": "Euler",
                        "percent": "26"
                    },
                    "fromToken": {
                        "decimal": "6",
                        "isHoneyPot": false,
                        "taxRate": "0",
                        "tokenContractAddress": "0x9151434b16b9763660705744891fa906f660ecc5",
                        "tokenSymbol": "USDT",
                        "tokenUnitPrice": "1.000313193103130296"
                    },
                    "fromTokenIndex": "3",
                    "toToken": {
                        "decimal": "6",
                        "isHoneyPot": false,
                        "taxRate": "0",
                        "tokenContractAddress": "0x078d782b760474a361dda0af3839290b0ef57ad6",
                        "tokenSymbol": "USDC",
                        "tokenUnitPrice": "0.999692348812448693"
                    },
                    "toTokenIndex": "4"
                },
                {
                    "dexProtocol": {
                        "dexName": "Uniswap V4",
                        "percent": "1"
                    },
                    "fromToken": {
                        "decimal": "6",
                        "isHoneyPot": false,
                        "taxRate": "0",
                        "tokenContractAddress": "0x9151434b16b9763660705744891fa906f660ecc5",
                        "tokenSymbol": "USDT",
                        "tokenUnitPrice": "1.000313193103130296"
                    },
                    "fromTokenIndex": "3",
                    "toToken": {
                        "decimal": "6",
                        "isHoneyPot": false,
                        "taxRate": "0",
                        "tokenContractAddress": "0x078d782b760474a361dda0af3839290b0ef57ad6",
                        "tokenSymbol": "USDC",
                        "tokenUnitPrice": "0.999692348812448693"
                    },
                    "toTokenIndex": "4"
                }
            ],
            "estimateGasFee": "1002000",
            "fromToken": {
                "decimal": "18",
                "isHoneyPot": false,
                "taxRate": "0",
                "tokenContractAddress": "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee",
                "tokenSymbol": "UNICHAIN_ETH",
                "tokenUnitPrice": "4191.043356462183138854"
            },
            "fromTokenAmount": "10000000000000000000000",
            "priceImpactPercent": "-67.53",
            "router": "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee--0x927b51f251480a681271180da4de28d44ec4afb8--0x0555e30da8f98308edb960aa94c0db47230d2b9c--0x9151434b16b9763660705744891fa906f660ecc5--0x078d782b760474a361dda0af3839290b0ef57ad6",
            "swapMode": "exactIn",
            "toToken": {
                "decimal": "6",
                "isHoneyPot": false,
                "taxRate": "0",
                "tokenContractAddress": "0x078d782b760474a361dda0af3839290b0ef57ad6",
                "tokenSymbol": "USDC",
                "tokenUnitPrice": "0.999692348812448693"
            },
            "toTokenAmount": "13614286937853",
            "tradeFee": "0.00001607688116316"
        }
    ],
    "msg": ""
}