Skip to main content

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.

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()}")

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.

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()}")

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.

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()}")

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.

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()}")

Need Help?