Method
async getQuote(params: QuoteParams): Promise<APIResponse<QuoteData>>
Parameters
Quote request parameters
Show properties
Show properties
Chain identifier (e.g., “1” for Ethereum, “501” for Solana)
Contract address of the token to swap from
Contract address of the token to swap to
Amount to swap (in token’s smallest unit)
Maximum acceptable slippage (0-1, e.g., “0.005” for 0.5%)
User’s wallet address
Comma-separated list of DEX IDs to route through
Whether to use direct routing only
Maximum acceptable price impact (0-1)
Referral fee percentage
Response
Response code (“0” indicates success)
Response message
Array of quote data objects
Show QuoteData properties
Show QuoteData properties
Chain identifier
Destination token information (same structure as fromToken)
Input token amount
Expected output token amount
Estimated gas fee in native token
Price impact percentage
Trading fee amount
Router information
Swap mode identifier
List of DEX routers used
Show DexRouter properties
Show DexRouter properties
Source token for this route
Destination token for this route
Source token index
Destination token index
Context slot (Solana only)
Example
import { OKXClient } from '@okxweb3/okx-api';
const client = new OKXClient({
apiKey: 'your-api-key',
secretKey: 'your-secret-key',
apiPassphrase: 'your-passphrase',
projectId: 'your-project-id'
});
const quote = await client.dex.getQuote({
chainIndex: '1',
fromTokenAddress: '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE',
toTokenAddress: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
amount: '1000000000000000000', // 1 ETH
slippagePercent: '0.005',
userWalletAddress: '0x742d35Cc6634C0532925a3b844Bc454e4438f44e'
});
console.log('Quote:', quote.data[0]);
console.log('Expected output:', quote.data[0].toTokenAmount);
console.log('Price impact:', quote.data[0].priceImpactPercent);
Response Example
{
"code": "0",
"msg": "",
"data": [{
"chainIndex": "1",
"fromToken": {
"decimal": "18",
"isHoneyPot": false,
"taxRate": "0",
"tokenContractAddress": "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
"tokenSymbol": "ETH",
"tokenUnitPrice": "2500.00"
},
"toToken": {
"decimal": "6",
"isHoneyPot": false,
"taxRate": "0",
"tokenContractAddress": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
"tokenSymbol": "USDC",
"tokenUnitPrice": "1.00"
},
"fromTokenAmount": "1000000000000000000",
"toTokenAmount": "2487500000",
"estimateGasFee": "0.002",
"priceImpactPercent": "0.15",
"tradeFee": "2500000",
"router": "aggregator",
"swapMode": "auto",
"dexRouterList": []
}]
}