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 using the token's contract address.
- Python
- JavaScript
import os, requests
from dotenv import load_dotenv
load_dotenv()
token_price_base_url = "https://enterprise-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
headers = { "x-api-key": os.getenv("ODOS_API_KEY") }
response = requests.get(f"{token_price_base_url}/{chain_id}/{token_address}", headers=headers)
if response.status_code == 200:
token_price = response.json()
print(token_price)
else:
print(f"Error getting token price: {response.json()}")
import 'dotenv/config';
import fetch from 'node-fetch';
const tokenPriceBaseUrl = 'https://enterprise-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}`, {
headers: { 'x-api-key': process.env.ODOS_API_KEY }
});
if (response.status === 200) {
const tokenPrice = await response.json();
console.log(tokenPrice);
} else {
console.error('Error getting token price:', await response.json());
}
Getting price of multiple tokens (using tokens_addresses)
You can retrieve pricing data for multiple tokens in a single call using the tokens_addresses query parameter.
Pass a comma-separated list of token addresses (checksummed) to /pricing/tokens.
- Python
- JavaScript
import os, requests
from dotenv import load_dotenv
load_dotenv()
token_prices_url = "https://enterprise-api.odos.xyz/pricing/tokens"
chain_id = 1
token_addresses = [
"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", # USDC
"0xdAC17F958D2ee523a2206206994597C13D831ec7", # USDT
"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2" # WETH
]
params = { "chainId": chain_id, "tokens_addresses": ",".join(token_addresses) }
headers = { "x-api-key": os.getenv("ODOS_API_KEY") }
response = requests.get(token_prices_url, headers=headers, params=params)
if response.status_code == 200:
prices = response.json()
for token, data in prices.items():
print(token, "→", data["price"])
else:
print(f"Error getting token prices: {response.json()}")
import 'dotenv/config';
import fetch from 'node-fetch';
const tokenPricesUrl = 'https://enterprise-api.odos.xyz/pricing/tokens';
const chainId = 1;
const tokensAddresses = [
'0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', // USDC
'0xdAC17F958D2ee523a2206206994597C13D831ec7', // USDT
'0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2' // WETH
].join(',');
const queryParams = new URLSearchParams({ chainId, tokens_addresses: tokensAddresses });
const response = await fetch(`${tokenPricesUrl}?${queryParams}`, {
headers: { 'x-api-key': process.env.ODOS_API_KEY }
});
if (response.status === 200) {
const prices = await response.json();
Object.entries(prices).forEach(([token, data]) => {
console.log(`${token} → ${data.price}`);
});
} else {
console.error('Error getting token prices:', await response.json());
}
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 a currency besides USD.
- Python
- JavaScript
import os, requests
from dotenv import load_dotenv
load_dotenv()
pricing_currencies_url = "https://enterprise-api.odos.xyz/pricing/currencies"
headers = { "x-api-key": os.getenv("ODOS_API_KEY") }
response = requests.get(pricing_currencies_url, headers=headers)
if response.status_code == 200:
pricing_currencies = response.json()
print(pricing_currencies)
else:
print(f"Error getting token pricing currencies: {response.json()}")
import 'dotenv/config';
import fetch from 'node-fetch';
const pricingCurrenciesUrl = 'https://enterprise-api.odos.xyz/pricing/currencies';
const response = await fetch(pricingCurrenciesUrl, {
headers: { 'x-api-key': process.env.ODOS_API_KEY }
});
if (response.status === 200) {
const pricingCurrencies = await response.json();
console.log(pricingCurrencies);
} else {
console.error('Error getting token pricing currencies:', await response.json());
}
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 /pricing/currencies.
- Python
- JavaScript
import os, requests
from dotenv import load_dotenv
load_dotenv()
token_price_base_url = "https://enterprise-api.odos.xyz/pricing/token"
chain_id = 1
token_address = "0x..." # checksummed address
currency_id = "EUR" # some currency id from /pricing/currencies
headers = { "x-api-key": os.getenv("ODOS_API_KEY") }
response = requests.get(
f"{token_price_base_url}/{chain_id}/{token_address}",
headers=headers,
params={ "currencyId": currency_id }
)
if response.status_code == 200:
token_price = response.json()
print(token_price)
else:
print(f"Error getting token price: {response.json()}")
import 'dotenv/config';
import fetch from 'node-fetch';
const tokenPriceBaseUrl = 'https://enterprise-api.odos.xyz/pricing/token';
const chainId = 1;
const tokenAddress = '0x...';
const currencyId = 'EUR';
const queryParams = new URLSearchParams({ currencyId });
const response = await fetch(`${tokenPriceBaseUrl}/${chainId}/${tokenAddress}?${queryParams}`, {
headers: { 'x-api-key': process.env.ODOS_API_KEY }
});
if (response.status === 200) {
const tokenPrice = await response.json();
console.log(tokenPrice);
} else {
console.error('Error getting token price:', await response.json());
}
Need Help?
- For a deeper dive, see the API Endpoints page for complete parameter details.
- For technical assistance, visit our Support Page.
- Join the Odos Discord Community to connect with other developers and our team.