Pricing API Guide

This guide will help you get started with the API endpoints for utilizing Odos pricing data.

Setup

Firstly, you’ll need to setup your project. This involves importing the required libraries for making HTTP requests.

Recommended HTTP libraries (examples below):

  • Python: requests (Requires installation from here)
  • Javascript: fetch (natively supported in most environments)

Getting USD price of a token

Odos provides accurate defi-native pricing for every tradeable asset on each supported chain. This pricing data is available via a simple GET request provided by the Odos API

token_price_base_url = f"https://api.odos.xyz/pricing/token"

chain_id = 1 # the chain id the token/asset is from
token_address = "0x..." # the checksummed address of the token/asset to get a price for

response = requests.get(f"{token_price_base_url}/{chain_id}/{token_address}")

if response.status_code == 200:
  token_price = response.json()
  # handle token price data
else:
  print(f"Error getting token price: {response.json()}")
  # handle token price failure cases
const tokenPriceBaseUrl = 'https://api.odos.xyz/pricing/token';

const chainId = 1; // the chain id the token/asset is from
const tokenAddress = '0x...' // the checksummed address of the token/asset to get a price for

const response = await fetch(`${tokenPriceBaseUrl}/${chainId}/${tokenAddress}`);

if (response.status === 200) {
  const tokenPrice = await response.json();
  // handle token price data
} else {
  console.error('Error in Transaction Assembly:', response);
  // handle token price failure cases
}

Getting price of a token in different currencies

The Odos Pricing API supports many different currency prices besides just USD for any supported crypto asset

Checking available currency codes

A list of currency names and API codes can be retrieved from the /pricing/currencies endpoint. The id field from each currency entry is what can be used as a /pricing/token parameter for getting an asset’s price in terms of a currency besides USD.

pricing_currencies_url = f"https://api.odos.xyz/pricing/currencies"

response = requests.get(pricing_currencies_url)

if response.status_code == 200:
  pricing_currencies = response.json()
  # handle token pricing currencies data
else:
  print(f"'Error getting token pricing currencies: {response.json()}")
  # handle token pricing currencies failure cases
const pricingCurrenciesUrl = 'https://api.odos.xyz/pricing/currencies';

const response = await fetch(pricingCurrenciesUrl);

if (response.status === 200) {
  const pricingCurrencies = await response.json();
  // handle token pricing currencies data
} else {
  console.error('Error getting token pricing currencies:', response);
  // handle token pricing currencies failure cases
}

Requesting token price in a foreign currency

The main token pricing endpoint can be used to get prices in terms of any supported currency, via the optional query parameter currencyId set to an id from the /pricing/currencies mentioned above.

token_price_base_url = f"https://api.odos.xyz/pricing/token"

chain_id = 1 # the chain id the token/asset is from
token_address = "0x..." # the checksummed address of the token/asset to get a price for
currency_id = "EUR" # some currency id from the /pricing/currencies endpoint

response = requests.get(
  f"{token_price_base_url}/{chain_id}/{token_address}",
  params={
    "currencyId": currency_id
  }
)

if response.status_code == 200:
  token_price = response.json()
  # handle token price data
else:
  print(f"Error getting token price: {response.json()}")
  # handle token price failure cases
const tokenPriceBaseUrl = 'https://api.odos.xyz/pricing/token';

const chainId = 1; // the chain id the token/asset is from
const tokenAddress = '0x...'; // the checksummed address of the token/asset to get a price for
const currencyId = 'EUR'; // some currency id from the /pricing/currencies endpoint

const queryParams = new URLSearchParams({ currencyId: currencyId })
const response = await fetch(`${tokenPriceBaseUrl}/${chainId}/${tokenAddress}?${queryParams}`);

if (response.status === 200) {
  const tokenPrice = await response.json();
  // handle token price data
} else {
  console.error('Error getting token price:', response);
  // handle token price failure cases
}