Token Pricing Integration Guide
Welcome to the Odos Quick Start Guide for integrating our Token Pricing API! This guide will help you get started with the API endpoints for utilizing Odos pricing data.
Overview
Our Token Pricing API offers an essential tool for your DeFi operations - precise, real-time on-chain pricing data. It brings to your fingertips the most accurate information about any asset on the supported chains, aiding in crucial trading decisions. Integrating this into your application means equipping your users with reliable, up-to-the-minute pricing data - a key ingredient for success in the DeFi marketplace.
We meticulously monitor and evaluate an extensive network of over 900 diverse sources of liquidity. This includes decentralized exchanges, lending protocols, yield optimizers, collateralized debt positions (CDPs), and numerous others. Although our principal attention is on Smart Order Routing (SOR), our services extend to providing a comprehensive pricing service that encapsulates the entire DeFi ecosystem.
Our distinctive pricing service operates by calculating the starting buy and sell prices for each pool across every liquidity source we track. This information, along with additional pool data, helps us pinpoint an aggregate buy, sell, and midpoint price for any token that has on-chain liquidity.
Our Distinctive Features
We have several unique aspects that set us apart from other offerings:
- Our ability to furnish block-specific pricing information, tailored to individual customer preferences
- A focus on DeFi-centric pricing, meticulously calibrated for the decentralized finance ecosystem
- We offer pricing information for less commonly traded assets, utilizing only their contract address. If it’s present in a pool we track, we can provide its price.
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
- Python
- JavaScript
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.
- Python
- JavaScript
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.
- Python
- JavaScript
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
}
Need Help?
- For a deeper dive, the API Endpoints page is your go-to resource, providing an extensive look at all available endpoints, parameters, and more.
- For technical assistance, visit our Support Page.
- Join the Odos Discord Community to connect with other developers and our team.