Coins: 17,794
Exchanges: 1,463
Market Cap: $2.469T 3.3%
24h Vol: $92.256B
Gas: 0.185 GWEI
Go Ad-free
API
TABLE OF CONTENTS

How to Pull Crypto Prices From DEXs

4.5
| by
Roxait
|
Edited by
Brian Lee
-

This article is for anyone who needs to get accurate cryptocurrency prices directly from decentralized exchanges (DEXs). Whether you are tracking your portfolio, analyzing market trends, or building crypto applications, reliable DEX price data is essential for making informed decisions.

How to Pull Crypto Prices From DEXs


There are several traditional methods that allow one to get crypto/token prices from DEXs:

  • Querying DEX subgraphs (e.g. Uniswap via The Graph)
  • Calling DEX smart contracts directly (via RPC/archive node)
  • Using DEX-specific SDKs

Limitations of Traditional Methods for Pulling Crypto Prices From DEXs

Traditional approaches come with significant limitations. Each DEX requires a separate, protocol-specific integration. While some methods offer partial USD conversion through stable pair routing, you often need to write custom logic to ensure accurate pricing. This complexity multiplies as you add more chains and DEXs, leaving you to manage a tangled web of RPC nodes, subgraph endpoints, and multiple SDKs, which increases both development effort and infrastructure costs.

What Is the Best Way to Pull Crypto Prices From DEXs?

The best way to pull crypto prices from DEXs is by using CoinGecko's on-chain API. It offers a unified solution for retrieving DEX price data from over 1,600 DEXs across 200+ networks and is always expanding its coverage. This includes popular DEXs like Uniswap and PancakeSwap, as well as rapidly emerging memecoin launchpads like Pump.fun and LetsBonkFun, ensuring you only need one API to get the latest on-chain data.

Quick Comparison: CoinGecko API vs Traditional Methods

Feature CoinGecko API Traditional Methods (Subgraphs, RPC, DEX SDKs)
DEX & Chain Support Unified access to 1,600+ DEXs across 200+ chains. Protocol-specific; requires separate integration for each.
Price Conversion Provides direct price conversion against 45+ fiat currencies (e.g., USD, EUR, JPY) and 15+ crypto assets (e.g., BTC, ETH, SOL). Manual conversion logic required via stablecoin pairs.
Integration Effort Fast; single API integration. Slower; requires managing multiple endpoints & libraries.
Scalability Seamless; CoinGecko manages integrations with latest DEXs and networks. High effort and cost to add new DEXs and chains.

Prerequisites

To follow this guide, you'll need a CoinGecko API Key. If you don't have one, read this guide on how to get your free Demo API key. While most examples in this article use a free Demo API key, some require exclusive endpoints that are only available with a paid API plan.

You’ll also need Python 3.7+ installed on your system, and basic Python knowledge with familiarity using the requests library and handling JSON.

Install required dependencies

pip install requests python-dotenv matplotlib pandas numpy

pip install requests python-dotenv matplotlib pandas numpy

How to Find DEX Pool Addresses

To get price data for a specific pool, you first need its address. You can use CoinGecko's API to search for pools by name or discover top pools on a specific network or DEX. The API also returns USD price data for both base and quote tokens by default, which may be all you need for many use cases.

Search for a Pool

To search for a pool, use the /onchain/search/pools API endpoint. This endpoint is useful when you know the name of the pool but don't know the exact pool address.

The code above searches for USDC pools on Ethereum, loops through the first 3 results, and prints each pool's name, address, and DEX information.

Example Output

Find DEX Pool Addresses

Get Top Pools of a Network

To get the top pools of a specified network, use the /onchain/networks/{network}/pools API endpoint. This endpoint will return the top pools by transaction volume in the last 24 hours of the specified network.

The code above fetches the top 5 pools on Ethereum  and displays their names, liquidity values, DEX names, and 24-hour trading volumes.

Example Output

Get Top Pools of a Network

Get Top Pools of a DEX

We can use the /onchain/networks/{network}/dexes/{dex}/pools to get the top pools from a specific DEX like Uniswap or PancakeSwap.

This code fetches the first page of pools from the Uniswap V3 DEX on Ethereum. It displays the names, addresses, fee percentages, and total value locked (TVL) in USD for the first 3 pools returned.

Example Output

How to Get Top Pools of a DEX

Note: If you don’t see data for newer pools, try another network or timeframe as on-chain coverage and data freshness can vary.

Other Pool Discovery Methods

CoinGecko’s On-chain API also offers several other endpoints for comprehensive pool discovery:

💡 Pro tip: For a quick, no-code way to find a specific pool address, use GeckoTerminal, our dedicated real-time DEX tracker. Simply search for the token pair on the site, and you can copy the pool address directly from the page's information section or URL.

How to Pull Current & Historical Token Price Data From DEXs

You can use CoinGecko's on-chain API to fetch real-time and historical token price data. You can get token price data in two main ways: by using the token's address or by querying a specific pool address.

Using a token address is the most convenient method. The API automatically finds the most liquid pool for that token and returns its price, so you don't need to know which specific DEX pool to query. This section covers the token address method.

The following section will cover how to get price data by querying a specific DEX pool address.

Current Token Prices by Token Address

The /onchain/simple/networks/{network}/token_price/{addresses} endpoint is the most straightforward way to get current real-time prices for one or more tokens in a single API call. It aggregates data from multiple DEXs on a given network to provide an accurate market price based on liquidity and pool activity, saving you from having to query individual DEX pools.

The response includes current USD prices, 24-hour volume, and price changes for all requested tokens on the specified network.

Example Output

Current Token Prices by Token Address

Common use cases include:

  • Portfolio tracking: Monitor multiple token prices in real-time for investment management
  • Price alerts: Set up notifications when tokens hit target prices for trading decisions
  • Trading bots: Get reliable price feeds for automated trading strategies

Historical Token Prices by Token Address

The /onchain/networks/{network}/tokens/{token_address}/ohlcv/{timeframe} endpoint can be used to retrieve historical OHLCV data using just a token's contract address. However, this is an exclusive endpoint available only on paid API plans. This quality-of-life endpoint simplifies the data retrieval process by automatically providing price data from the token's most liquid pool without the need of specifying a pool’s contract address.

Subscribe to CoinGecko API

For free Demo API users, the same historical data can be obtained by using the historical pool data endpoint, which requires a specific pool address. This alternative method is covered in the next section.

Example Output

Historical Token Prices by Token Address

Common use cases include:

  • Technical analysis: Building indicators like moving averages, RSI, and MACD for trading decisions
  • Backtesting strategies: Testing trading strategies against historical price movements
  • Risk assessment: Analyzing volatility patterns and price correlations for portfolio management

Building a Token Price Chart

Visualizing historical data is a great way to understand a token's price action. The following build_token_chart Python function takes the OHLCV data we fetched, organizes it into a pandas DataFrame, and then uses matplotlib to plot the closing price against the date. The resulting chart is saved as a PNG image, providing a clear view of the token's price trend over the selected period.

Example Chart Output

Building a Token Price Chart

How to Pull Current & Historical Token Price Data From DEX Pools

You can use CoinGecko's On-chain API to get both current and historical price data for a specific DEX pool by providing its unique contract address.

While fetching prices by token address offers convenience, this pool-based method gives you more granular control. It is ideal when you need to analyze a token's performance on a particular DEX. For free Demo API users, the historical endpoint in this section is the alternative for getting OHLCV data.

Current Pool Data by Pool Address

The /onchain/networks/{network}/pools/{address} endpoint can be used to get detailed real-time price and volume data for a single liquidity pool by specifying a unique pool address.

Example Output

Current Pool Data by Pool Address

This endpoint returns detailed pool information including base/quote tokens, current price, liquidity, and trading volume.

💡 Pro tip: You can also get data for multiple pool addresses using the /onchain/networks/{network}/pools/multi/{addresses} endpoint.

Historical Pool Data by Pool Address

The /onchain/networks/{network}/pools/{pool_address}/ohlcv/{timeframe} endpoint can be used to retrieve historical OHLCV data for a specific pool address and is available on all API plans, including the free Demo plan. It serves as the alternative for Demo API users to fetch historical token prices from a DEX.

Example Output

Historical Pool Data by Pool Address

Building a Pool Price Chart

With historical pool data, you can create more advanced visualizations. The build_pool_chart function below uses pandas and matplotlib to plot both the pool's price and its trading volume on a single chart and saves it as a PNG image, offering a more complete picture of its market activity.

Example Chart Output

Building a Pool Price Chart

Summary and Conclusion

In this guide, we demonstrated how CoinGecko’s on-chain API simplifies the process of fetching DEX price data. We walked through discovering pool and token addresses, pulling current prices with built-in USD conversion, and accessing historical OHLCV data to build price charts.

Unlike traditional methods that require protocol-specific integrations, the CoinGecko API provides unified access to thousands of DEXs and offers a scalable architecture that grows automatically with new chains and DEXs.

To access exclusive endpoints like historical token data by token address, and to benefit from higher rate limits, consider subscribing to a paid API plan.

CoinGecko's Content Editorial Guidelines
CoinGecko’s content aims to demystify the crypto industry. While certain posts you see may be sponsored, we strive to uphold the highest standards of editorial quality and integrity, and do not publish any content that has not been vetted by our editors.
Learn more
Want to be the first to know about upcoming airdrops?
Subscribe to the CoinGecko Daily Newsletter!
Join 600,000+ crypto enthusiasts, traders, and degens in getting the latest crypto news, articles, videos, and reports by subscribing to our FREE newsletter.
Tell us how much you like this article!
Vote count: 8
Roxait
Roxait
With 18 years of pioneering experience in the crypto space, Roxait excels in technical collaborations to develop cutting-edge decentralized solutions. Our commitment to innovation and expertise in blockchain technology has made us a trusted partner in driving the future of decentralized systems. Follow the author on Twitter @roxaittech

Related Articles

New Portfolio
Icon & name
Select Currency
Suggested Currencies
USD
US Dollar
IDR
Indonesian Rupiah
TWD
New Taiwan Dollar
EUR
Euro
KRW
South Korean Won
JPY
Japanese Yen
RUB
Russian Ruble
CNY
Chinese Yuan
Fiat Currencies
AED
United Arab Emirates Dirham
ARS
Argentine Peso
AUD
Australian Dollar
BDT
Bangladeshi Taka
BHD
Bahraini Dinar
BMD
Bermudian Dollar
BRL
Brazil Real
CAD
Canadian Dollar
CHF
Swiss Franc
CLP
Chilean Peso
CZK
Czech Koruna
DKK
Danish Krone
GBP
British Pound Sterling
GEL
Georgian Lari
HKD
Hong Kong Dollar
HUF
Hungarian Forint
ILS
Israeli New Shekel
INR
Indian Rupee
KWD
Kuwaiti Dinar
LKR
Sri Lankan Rupee
MMK
Burmese Kyat
MXN
Mexican Peso
MYR
Malaysian Ringgit
NGN
Nigerian Naira
NOK
Norwegian Krone
NZD
New Zealand Dollar
PHP
Philippine Peso
PKR
Pakistani Rupee
PLN
Polish Zloty
SAR
Saudi Riyal
SEK
Swedish Krona
SGD
Singapore Dollar
THB
Thai Baht
TRY
Turkish Lira
UAH
Ukrainian hryvnia
VEF
Venezuelan bolívar fuerte
VND
Vietnamese đồng
ZAR
South African Rand
XDR
IMF Special Drawing Rights
Cryptocurrencies
BTC
Bitcoin
ETH
Ether
LTC
Litecoin
BCH
Bitcoin Cash
BNB
Binance Coin
EOS
EOS
XRP
XRP
XLM
Lumens
LINK
Chainlink
DOT
Polkadot
YFI
Yearn.finance
SOL
Solana
Bitcoin Units
BITS
Bits
SATS
Satoshi
Commodities
XAG
Silver - Troy Ounce
XAU
Gold - Troy Ounce
Select Language
Popular Languages
EN
English
RU
Русский
DE
Deutsch
PL
język polski
ES
Español
VI
Tiếng việt
FR
Français
PT-BR
Português
All Languages
AR
العربية
BG
български
CS
čeština
DA
dansk
EL
Ελληνικά
FI
suomen kieli
HE
עִבְרִית
HI
हिंदी
HR
hrvatski
HU
Magyar nyelv
ID
Bahasa Indonesia
IT
Italiano
JA
日本語
KO
한국어
LT
lietuvių kalba
NL
Nederlands
NO
norsk
RO
Limba română
SK
slovenský jazyk
SL
slovenski jezik
SV
Svenska
TH
ภาษาไทย
TR
Türkçe
UK
украї́нська мо́ва
ZH
简体中文
ZH-TW
繁體中文
Welcome to CoinGecko
Welcome back!
Login or Sign up in seconds
or
Sign in with . Not you?
Forgot your password?
Didn't receive confirmation instructions?
Resend confirmation instructions
Password must contain at least 8 characters including 1 uppercase letter, 1 lowercase letter, 1 number, and 1 special character
By continuing, you acknowledge that you've read and agree fully to our Terms of Service and Privacy Policy.
Get Price Alerts with CoinGecko App
Forgot your password?
You will receive an email with instructions on how to reset your password in a few minutes.
Resend confirmation instructions
You will receive an email with instructions for how to confirm your email address in a few minutes.
Get the CoinGecko app.
Scan this QR code to download the app now App QR Code Or check it out in the app stores
Add NFT
Track wallet address
Paste
We only display assets from supported networks.
Ethereum Mainnet
Base Mainnet
BNB Smart Chain
Arbitrum
Avalanche
Fantom
Flare
Gnosis
Linea
Optimism
Polygon
Polygon zkEVM
Scroll
Stellar
Story
Syscoin
Telos
X Layer
Xai
Read-only access
We only fetch public data. No private keys, no signing, and we can't make any changes to your wallet.
Create Portfolio
Select icon
💎
🔥
👀
🚀
💰
🦍
🌱
💩
🌙
🪂
💚
CoinGecko
Better on the app
Real-time price alerts and a faster, smoother experience.
You’ve reached the limit.
Guest portfolios are limited to 10 coins. Sign up or log in to keep the coins listed below.