exchange.IO("route", ...)
Requests quotes for a swap: lists the quote on each candidate route and the best route, without placing an order.
exchange.IO(k, symbol, side, qty)Examples
Compare the quotes on each route for selling 1 ETH.
javascript
function main() {
var r = exchange.IO("route", "ETH_USDC", "sell", 1)
if (!r) {
Log("Quote failed:", GetLastError())
return
}
if (r.best === null) {
Log("No usable pool")
return
}
Log("Best route:", r.best, "receive:", r.quote, "USDC")
r.candidates.forEach(function (c) {
Log(c.route, c.quote)
})
}Returns
| Type | Description |
object / null value | Returns |
Arguments
| Name | Type | Required | Description |
k | string | Yes | Always |
symbol | string | Yes | Trading pair, for example |
side | string | Yes | Trade direction: |
qty | number | Yes | Amount of the base currency. |
See Also
Uniswap / PancakeSwap Aerodrome / Velodrome KyberSwap 1inch exchange.IO exchange.IO("simulate") exchange.IO("slippage") exchange.IO("token") exchange.CreateOrder
Remarks
Candidate routes include the exchange's direct pools and two-hop routes through the wrapped token or USDC/USDT. The pools used depend on the exchange. Uniswap uses V3 pools at each fee tier, V2 pools and V4 pools without hooks. For V4 this means pools with common fee combinations, plus custom-fee pools found through GeckoTerminal (see the Uniswap / PancakeSwap page), and V4 routes go through the native coin or USDC/USDT. PancakeSwap uses V3, V2 and Infinity CL pools. Aerodrome and Velodrome use both generations of Slipstream pools and the basic pools. Example route notations: v3:WETH-500-USDC (V3, fee 500, i.e. 0.05%), v2:WETH-USDC, v3:UNI-3000-USDT-100-USDC (two hops), v4:ETH-500/10-USDC (Uniswap V4, fee 500, tick spacing 10, ETH is the native coin), infinity:BNB-67/1-USDT (PancakeSwap Infinity CL), cl:WETH-100-USDC (first-generation Slipstream on Aerodrome and Velodrome, where the number is the tick spacing), cl2:WETH-500-USDC (second-generation Slipstream), volatile:AERO-USDC and stable:USDC-USDbC (basic pools).
V3 routes are quoted on-chain through QuoterV2, which simulates the whole swap. V2 routes are calculated locally from the pool reserves. No quote includes gas fees.
Fields of the returned object: best is the best route. quote is the best quote: for a sell, the amount of quote currency you receive, and for a buy, the amount of quote currency you spend. price is the matching average price. candidates is a list of {route, quote} for each candidate route, and a route that cannot be quoted has a quote of null. When no pool is available, an object is still returned: best, quote and price are all null, and candidates is an empty array. When pools exist but none of them can be quoted, the quote of every item in candidates is null. If an error occurs, for example a token in the pair cannot be recognized or the node's chain does not match the configuration, a null value is returned, and GetLastError() gives the reason.
KyberSwap and 1inch exchange objects (aggregators) have only one candidate route: the quote from the aggregator. These routes are written as kyberswap:ETH-USDC and 1inch:ETH-USDC. For a buy they are written as kyberswap:USDC-ETH, with the token you pay first. For buy, the quote is for receiving qty units of the base currency, and it is approximated through several exact-input quotes. If PancakeSwap cannot fetch on-chain trade records for Infinity CL pools because the node does not support eth_getLogs, the result includes a warning that explains why. If Uniswap temporarily cannot get V4 pools beyond the common combinations from GeckoTerminal, for example because of rate limiting, the result also includes a warning. During that time only V4 pools with common combinations are used, and the query is retried after 5 minutes.