Skip to Content
RatesGet rates for a pair

Get rates for a pair

GET/v3/pairs/:pairId/rates

Description

This endpoint retrieves a list of exchange rates for a specific assets pair. Considering that the exchange rates are constantly changing, the endpoint returns a list of rates sorted by the best rate.

The best rate is determined by maximizing the toAmount, which can be calculated using the following formula:

const toAmount = fromAmount * rate.amount.value - rate.minerFee.value;

Where the rate.amount.value is the multiplier for the exchange rate and rate.minerFee.value is the fee that is subtracted from the toAmount.

A rate can be used if it’s within the limits (rate.min.value <= fromAmount and rate.max.value >= fromAmount) and hasn’t expired (rate.expiry < Date.now())

How to calculate the best rate

Here is a JavaScript code snippet for how to get the best rate based on the user input:

best rate calculation
const pairId = "BTC_ETH"; // The pair the user wants to exchange.
 
const rates = await fetch(
  `https://exchange.exodus.io/v3/pairs/${pairId}/rates`,
).then((res) => res.json());
 
// The amount that the user wants to exchange, in this example this means '0.002 BTC'.
const userInput = 0.002;
 
const bestRate = rates.reduce((bestRate, rate) => {
  // Check if the user amount is within the rate's limits.
  if (userInput >= rate.min.value && userInput <= rate.max.value) {
    // Calculate the new rate output amount to see if it's better than the previous one.
    const outputAmount = userInput * rate.amount.value - rate.minerFee.value;
    const bestRateAmount =
      userInput * bestRate.amount.value - bestRate.minerFee.value;
 
    // Select the best rate between the best and the current rate.
    return outputAmount > bestRateAmount ? rate : bestRate;
  }
 
  return bestRate;
});

How to calculate the minimums and maximums

Here is a JavaScript code snippet for how to get absolute minimums and maximums for a pair:

min max calculation
const pairId = "BTC_ETH"; // The pair the user wants to exchange.
 
const rates = await fetch(
  `https://exchange.exodus.io/v3/pairs/${pairId}/rates`,
).then((res) => res.json());
 
const { min, max } = rates.reduce(
  (acc, rate) => {
    if (rate.min.value < acc.min) {
      acc.min = rate.min.value;
    }
    if (rate.max.value > acc.max) {
      acc.max = rate.max.value;
    }
    return acc;
  },
  { min: Infinity, max: -Infinity },
);

Why not using a quote endpoint instead of rates?

The reason why XO Swap API returns all the rates for a pair instead of one single quote, is to reduce network latencies when calculating the output. So the user can type the amount without having to wait for what the rate would be.

Header Parameters

NameDescriptionRequired
App-NameApp-Name for the authorizationyes
App-VersionApp-Version for the authorizationno
ForwardedIf you are proxying requests to the API, you must include the "Forwarded" header with the original request IP address. This is used for geolocation availability purposes.no

Path Parameters

NameDescriptionRequired
pairIdPair id from the list of pairsyes

Try it

https://exchange.exodus.io/v3/pairs//rates
Press on the 'Send' button to try this request.
Last updated on