SDK

Request Quotes

Get the best swap route and price using the SDK quote function.

Quote API

You can directly use the Open API to quote the token exchange amount.

  • Method: GET
  • URL: https://open-api.openocean.finance/v3/:chain/quote

Parameters

ParameterTypeExampleDescription
chainstringbsc, avax, fantomChain name
inTokenAddressstring0x9029...e10ASell token address
outTokenAddressstring0xEeee...eEEeEBuy token address
amountnumber10Sell amount
gasPricenumber5Gas price in Gwei

Using the SDK

Terminal
JS
1
async quote() {
2
let response = await api.quote({
3
chain: this.chainName,
4
inTokenAddress: this.inToken.address,
5
outTokenAddress: this.outToken.address,
6
amount: this.inAmount,
7
gasPrice: this.gasPrice
8
})
9
10
if (response.code == 200) {
11
this.outAmount = new BigNumber(response.data.outAmount)
12
.div(10 ** this.outToken.decimals)
13
.toFixed(4)
14
} else {
15
alert('Error:' + response.message)
16
}
17
}

Example Request

Terminal
HTTP
1
https://open-api.openocean.finance/v3/bsc/quote?inTokenAddress=0x55d398326f99059ff775485246999027b3197955&outTokenAddress=0xe9e7cea3dedca5984780bafc599bd69add087d56&amount=10&gasPrice=5

Example Response

Terminal
{}
1
{
2
"code": 200,
3
"data": {
4
"inToken": { "symbol": "USDT", "address": "0x55d398326f99059ff775485246999027b3197955" },
5
"outToken": { "symbol": "BUSD", "address": "0xe9e7cea3dedca5984780bafc599bd69add087d56" },
6
"inAmount": "10000000000000000000",
7
"outAmount": "9985234567890123456",
8
"estimatedGas": "250000"
9
}
10
}

Next Steps