Best practices
Recommendations on how to best use the API
To maximize the effectiveness and efficiency of the API, we recommend following these best practices.
By structuring your workflow according to these guidelines, you will ensure that your application or analysis is robust, scalable, and performs optimally.
Maintain an up-to-date cache of projects and metrics
Token Terminal regularly updates the list of supported projects and metrics. To ensure your application or analysis remains current, it is best practice to maintain your own cache or index.
We recommend caching the responses from the /projects
and /metrics
endpoints. This allows you to quickly reference available projects and supported metrics without making redundant API calls.
The responses should be updated periodically based on your needs, ideally daily or weekly, depending on how frequently you expect changes in the data.
By caching responses from these endpoints, you can easily reference available projects and supported metrics.
Utilize metric endpoints for detailed data
The most flexible and powerful way to interact with Token Terminal data is via metric endpoints.
They allow you to retrieve detailed metrics for specific projects, chains, and time ranges.
The following call retrieves revenue metrics for Uniswap and Aave projects on Ethereum between specified dates:
Use breakdown aggregation API for summarized responses
Instead of fetching time series data first, and then aggregating it, you can directly request summarized data using the breakdown API. This is particularly useful for reducing the amount of data transferred and speeding up response times.
The following call retrieves the revenue breakdown aggregation for Uniswap and Aave projects for the specified date range and applying aggregations like avg, change, sum and trend:
Handling errors and missing data
Proper error handling ensures your application remains stable even when data is temporarily unavailable or incorrect parameters are provided.
Check HTTP response status codes:
- 200: Successful response
- 400: Bad request (invalid parameters)
- 404: Data not found (possibly unsupported project/metric)
- 429: Too many requests (rate limiting)
Here’s an example of how to handle errors in Python:
Managing rate limiting
Token Terminal implements rate limiting to ensure fair usage. You should handle rate limits gracefully by implementing exponential backoff or retry logic.
Rate limit recommendation: Monitor for HTTP 429 responses and implement retry logic.
Here’s an example of how to handle rate limiting in Python: