-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added tutorials for token pairs apis
- Loading branch information
1 parent
49fe34a
commit e9691ab
Showing
2 changed files
with
278 additions
and
0 deletions.
There are no files selected for viewing
127 changes: 127 additions & 0 deletions
127
...pi/evm/token-api/05-Pairs & Liquidity/how-to-get-aggregated-token-pair-stats.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
--- | ||
title: "How to Get Aggregated Token Pair Stats with Moralis" | ||
slug: "../how-to-get-aggregated-token-pair-stats" | ||
description: "Learn how to fetch aggregated token pair stats including liquidity, active pairs, and DEX coverage using Moralis' powerful API. Ideal for developers building DeFi dashboards and liquidity trackers." | ||
sidebar_label: "Get Aggregated Token Pair Stats" | ||
sidebar_position: 1 | ||
tags: | ||
[ | ||
"Aggregated Token Pair Stats API", | ||
"Liquidity API", | ||
"DeFi API", | ||
"Moralis API", | ||
"Crypto API", | ||
] | ||
keywords: | ||
[ | ||
"aggregated token pair stats", | ||
"liquidity API", | ||
"fetch token pairs", | ||
"Moralis API", | ||
"DEX stats", | ||
"crypto liquidity data", | ||
] | ||
--- | ||
|
||
# Get Aggregated Token Pair Stats with Moralis API - Full Tutorial | ||
|
||
In this tutorial, we'll guide you through how to use the **Moralis Aggregated Token Pair Stats API** to fetch aggregated statistics for a specific ERC20 token. This is ideal for developers looking to retrieve liquidity, active pairs, and DEX (decentralized exchange) stats in one API call. Whether you’re building DeFi dashboards, liquidity trackers, or analytics tools, this tutorial will help you get started quickly. | ||
|
||
## Watch the Full Video Tutorial | ||
|
||
To see a complete walkthrough of how to fetch aggregated token pair statistics using the Moralis API, check out the video below: | ||
|
||
[![Watch the video](https://img.youtube.com/vi/djoAlbLOsks/0.jpg)](https://youtu.be/djoAlbLOsks) | ||
|
||
## Key Features of the Aggregated Token Pair Stats API | ||
|
||
- **Real-Time Liquidity Data**: Get the total liquidity for a given ERC20 token in USD, aggregated across multiple decentralized exchanges (DEXes). | ||
- **Active Token Pairs**: Fetch the total number of active trading pairs for a specified token, providing insights into token activity across platforms. | ||
- **DEX Coverage**: Retrieve the number of decentralized exchanges where the token is actively traded, helping track token distribution across various DEXes. | ||
- **Cross-Chain Support**: Supports multiple blockchain networks such as Ethereum, Binance Smart Chain, and more, allowing you to retrieve token pair data across different ecosystems. | ||
- **Efficient Data Retrieval**: Fetch all relevant token stats in one API call, making it simpler and faster to develop DeFi applications, liquidity trackers, or dashboards. | ||
- **Comprehensive Analytics**: Get detailed stats on liquidity and pair activity for improved token analysis and market insights. | ||
|
||
## Step 1: Set Up the Moralis API | ||
|
||
To get started, you'll need to set up Moralis and obtain your API key. If you haven't done so yet, follow the [Getting Started with Moralis API](https://docs.moralis.io/docs/getting-started) guide. | ||
|
||
Once you have your API key, you can start making requests to fetch aggregated token pair stats. | ||
|
||
## Step 2: Install Dependencies | ||
|
||
Before we begin, make sure you have the necessary dependencies installed. Run the following command to install `node-fetch`, which we'll use for making HTTP requests: | ||
|
||
```bash | ||
$ npm install node-fetch --save | ||
``` | ||
|
||
Additionally, add `"type": "module"` to your `package.json` file to enable ES module support. | ||
|
||
### Example package.json | ||
|
||
```json | ||
{ | ||
"name": "aggregated-token-pair-stats", | ||
"version": "1.0.0", | ||
"type": "module", | ||
"dependencies": { | ||
"node-fetch": "^3.0.0" | ||
} | ||
} | ||
``` | ||
|
||
## Step 3: Fetch Aggregated Token Pair Stats | ||
|
||
Now you can use the following JavaScript code to fetch aggregated stats for a specific token. In this example, we’ll retrieve stats for the USDC token on the Ethereum network. | ||
|
||
### Example JavaScript Code | ||
|
||
```javascript | ||
import fetch from "node-fetch"; | ||
|
||
const options = { | ||
method: "GET", | ||
headers: { | ||
accept: "application/json", | ||
"X-API-Key": "YOUR_API_KEY", // Replace with your actual API key | ||
}, | ||
}; | ||
|
||
fetch( | ||
"https://deep-index.moralis.io/api/v2.2/erc20/0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48/pairs/stats?chain=eth", | ||
options | ||
) | ||
.then((response) => response.json()) | ||
.then((response) => console.log(response)) | ||
.catch((err) => console.error(err)); | ||
``` | ||
|
||
In this example: | ||
|
||
- chain: Set to eth for the Ethereum network. | ||
- token address: The contract address for USDC (0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48). | ||
|
||
### Example API Response | ||
|
||
```json | ||
{ | ||
"total_liquidity_usd": 1184543489313.2297, | ||
"total_active_pairs": 217, | ||
"total_active_dexes": 163 | ||
} | ||
``` | ||
|
||
## Use Cases for the Aggregated Token Pair Stats API | ||
|
||
The **Aggregated Token Pair Stats API** is perfect for the following use cases: | ||
|
||
- **DeFi Dashboards**: Track total liquidity, active pairs, and DEX activity for specific tokens in real-time. | ||
- **Liquidity Trackers**: Monitor liquidity across decentralized exchanges to inform trading and investment strategies. | ||
- **Token Analytics**: Analyze the performance, trading volume, and liquidity of a token across multiple decentralized exchanges. | ||
- **Portfolio Monitoring**: Use aggregated data to track how tokens in a portfolio are performing in terms of liquidity and pair activity, giving users a comprehensive view of their assets. | ||
- **Market Insights**: Provide insights into token liquidity trends, helping users identify potential opportunities and risks in the DeFi ecosystem. | ||
|
||
## Conclusion | ||
|
||
With the **Moralis Aggregated Token Pair Stats API**, you can easily access real-time liquidity and token pair statistics across decentralized exchanges. This API provides a powerful tool for developers building **DeFi applications**, **analytics dashboards**, and **liquidity trackers**. By aggregating key token data across multiple DEXes, you can create more efficient and informative tools for your users. |
151 changes: 151 additions & 0 deletions
151
...evm/token-api/05-Pairs & Liquidity/how-to-get-token-pairs-and-liquidity-data.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
--- | ||
title: "How to Get Token Pairs & Liquidity Data with 1 API Call Using Moralis" | ||
slug: "../how-to-get-token-pairs-liquidity" | ||
description: "Learn how to fetch token pairs and liquidity data in a single API call using Moralis' powerful Token API. Perfect for developers building DeFi tools, liquidity trackers, and analytics dashboards." | ||
sidebar_label: "Get Token Pairs & Liquidity" | ||
sidebar_position: 0 | ||
tags: | ||
["Token Pairs API", "Liquidity API", "Moralis API", "DeFi API", "Crypto API"] | ||
keywords: | ||
[ | ||
"token pairs API", | ||
"liquidity API", | ||
"fetch token pairs", | ||
"Moralis liquidity API", | ||
"crypto liquidity data", | ||
"DEX token pairs", | ||
] | ||
--- | ||
|
||
# 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: | ||
|
||
[![Watch the video](https://img.youtube.com/vi/djoAlbLOsks/0.jpg)](https://youtu.be/djoAlbLOsks) | ||
|
||
## 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](https://docs.moralis.io/docs/getting-started) 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 | ||
|
||
```javascript | ||
// 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 | ||
|
||
```json | ||
{ | ||
"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. |