Prices and Swaps (Prebuilt APIs)
Access real-time price feeds and 24-hour swap activity with our prebuilt API.
About Prices and Swaps Prebuilt APIs
Accessing real-time data on asset prices and swaps is crucial for developers aiming to build dynamic and responsive dApps, yet it is a challenging process.
ZettaBlock's prebuilt APIs are engineered to streamline this process, offering a robust and efficient solution for integrating comprehensive price and swap data into your dApps.
Using Prebuilt APIs for Prices and Swaps
To leverage the prebuilt APIs for fetching prices, balances and swaps, follow the example below. This example demonstrates how to use the API to retrieve the current user balance with one API call.
Table of Contents
- Token Prices API:
- Token Price Data for the Last 24h Hours
- Real Time Token Price Data for the Last 24h Hours
- Swaps API
- Get Top 100 Pools Ordered by Swap Count in the Last 24 h
To run all these GraphQL endpoints, go here.
1. Token Prices APIs
Token Price Data for the Last 24h Hours
The Prices API provides access price data of tokens over the last 24 hours, allowing developers to track market movements with precision.
Key Use:
Retrieve the latest price data for a specific token, with updates every 10 minutes.
Customization:
You can specify the price interval (10m, 5m, 2m) by using the parameters is_10m, is_5m, and is_2m. If these parameters are not provided, the system will return the price of the token for every minute over the past 24 hours.
Sample Query:
To fetch the price data of a particular token from the last 24 hours and sort them by time in descending order:
query {
records(contract_address: "0xc944E90C64B2c07662A292be6244BDf05Cda44a7", is_10m: 1, orderBy: minute, orderDirection: desc) {
price
minute
}
}
Real Time Token Price Data for the Last 24h Hours
This API provides real-time token price data, ensuring your application or service has the most current information on token valuations.
Key Use:
Obtain up-to-the-minute price data for a list of tokens, allowing for real-time market analysis and decision-making.
Sample Query:
To retrieve real-time price data for a specified list of tokens over the last 24 hours:
query Prices {
token_prices_24h(
where: {contract_address: {in: ["0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "0x9be89d2a4cd102d8fecc6bf9da793be995c22541"]}}
is10Minutes: true
) {
contract_address
records {
price
date_time
}
}
}
2. Swaps API
The Swaps API delivers detailed information on swap transactions, enabling users to analyze liquidity and trading activities across various pools.
Key Use:
Access data on the top 100 pools ordered by swap count in the last 24 hours.
Sample Query:
To retrieve information on the top 100 pools by swap count over the past 24 hours:
query {
records(limit: 100, orderBy: swap_count_24h, orderDirection: desc) {
symbol_1
symbol_2
pair_address
swap_count_24h
swap_amount_24h
swap_amount
swap_count
liquidity_amount_usd
}
}
Updated 9 months ago