Skip to main content

Don't have an API key yet?

Sign-up to Moralis to get your free API key and start building today.

Get Your Free API Key
Version: 2.2

Get Token Pairs & Liquidity Data with 1 API Call Using Moralis

In this tutorial, we’ll show you how to use the Moralis Token Pairs API to fetch token pairs and liquidity data in a single API call. This API is perfect for developers building DeFi applications, liquidity trackers, and analytics dashboards who need real-time data on decentralized exchanges (DEXes).

Watch the Full Video Tutorial

To see a full walkthrough of fetching token pairs and liquidity data using Moralis, check out the video tutorial below:

Key Features of the Moralis Token Pairs API

  • Fetch Token Pairs Across All DEXes: The API fetches token pairs from various decentralized exchanges (DEXes) such as Uniswap, Sushiswap, and more.
  • Real-Time Data: Get the latest data on token pairs and liquidity directly from decentralized exchanges.
  • Exchange Information: Retrieve the exchange name, address, and logo for the token pair.
  • Token Pair Details: Get the token pair label (e.g., USDC/WETH) and the pair's contract address.
  • USD Price: Fetch the current price of the token in USD.
  • Price Changes: See the 24-hour percentage price change and USD value change.
  • Liquidity Data: Get liquidity in USD for the token pair as well as for each individual token in the pair.
  • Token Information: Retrieve details about both tokens in the pair, such as token name, symbol, decimals, and more.
  • Pagination: Supports pagination with cursors for handling large datasets.

Step 1: Setting Up Moralis

First, you need to set up Moralis to start using the Token API. If you haven't done so yet, follow the Getting Started with Moralis API guide to get your API key.

Once you're ready, you can proceed to fetch the token pairs and liquidity data.

Step 2: Fetching Token Pairs & Liquidity Data with Moralis Token Pairs API

Moralis allows you to fetch token pairs and liquidity data from decentralized exchanges (DEXes) like Uniswap and Sushiswap using the Token Pairs API. By making a single API call, you can get real-time data on token pairs, including the current liquidity, price in USD, and 24-hour price changes.

Example JavaScript Code

// Dependencies to install:
// $ npm install node-fetch --save
// add "type": "module" to package.json

import fetch from "node-fetch";

const options = {
method: "GET",
headers: {
accept: "application/json",
"X-API-Key": "YOUR_API_KEY",
},
};

fetch(
"https://deep-index.moralis.io/api/v2.2/erc20/0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48/pairs?chain=eth",
options
)
.then((response) => response.json())
.then((response) => console.log(response))
.catch((err) => console.error(err));

In this example:

  • Chain: Set to "0x1" for Ethereum Mainnet.
  • TokenAddress: The contract address for the token (in this case, USDC).

Example API Response

{
"cursor": "eyJhbGciOiJIUzI1NiJ9.IjEi.sFnyj-BnyhcH3SQSzsLZZLfxNst7s7LO2BtW70G2ggk",
"page_size": 50,
"page": 1,
"pairs": [
{
"exchange_address": "0x1f98431c8ad98523631ae4a59f267346ea31f984",
"exchange_name": "Uniswap v3",
"exchange_logo": "https://entities-logos.s3.us-east-1.amazonaws.com/uniswap.png",
"pair_label": "USDC/WETH",
"pair_address": "0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640",
"usd_price": 0.9990729133416532,
"usd_price_24hr_percent_change": -0.11184241399839524,
"usd_price_24hr_usd_change": -0.001118638376049086,
"liquidity_usd": 151579536.54,
"base_token": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
"quote_token": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
"pair": [
{
"token_address": "0xa0b86991c6218b36c1d19D4a2e9eb0cE3606eB48",
"token_name": "USD Coin",
"token_symbol": "USDC",
"token_logo": "https://logo.moralis.io/0x1_0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48_d021d841dc113e213b32a0cb11ec2f86",
"token_decimals": "6",
"pair_token_type": "token0",
"liquidity_usd": 99513339.77
},
{
"token_address": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
"token_name": "Wrapped Ether",
"token_symbol": "WETH",
"token_logo": "https://logo.moralis.io/0x1_0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2_894ddd91dd6b3f3f3c278629a4e481d6",
"token_decimals": "18",
"pair_token_type": "token1",
"liquidity_usd": 52066196.77
}
]
}
]
}

Explanation of the Response

  • exchange_address: The contract address of the exchange where the token pair is traded.
  • exchange_name: The name of the exchange (e.g., Uniswap v3).
  • pair_label: The token pair label (e.g., USDC/WETH).
  • usd_price: The current price of the token in USD.
  • usd_price_24hr_percent_change: The percentage price change over the last 24 hours.
  • liquidity_usd: The total liquidity of the token pair in USD.
  • base_token: The contract address of the base token (in this case, USDC).
  • quote_token: The contract address of the quote token (in this case, WETH).
  • pair: A list containing details of both tokens in the pair, including token name, symbol, decimals, and liquidity in USD.

Use Cases for Moralis Token Pairs & Liquidity API

The Moralis Token Pairs API and Liquidity API are ideal for:

  • Building DeFi Tools: Track token pairs, liquidity pools, and price changes in real-time.
  • DEX Analytics: Analyze token pairs and liquidity data across decentralized exchanges.
  • Liquidity Trackers: Build dashboards that monitor liquidity in various liquidity pools.
  • DeFi Portfolio Trackers: Get token pair details and liquidity data to track the performance of decentralized portfolios.

Conclusion

Moralis simplifies the process of tracking token pairs and liquidity data with its powerful API. With just one API call, you can retrieve all the essential information about token pairs, making it easy to integrate this data into your dApps or analytics tools.