Skip to main content

Tutorial overview

Stream and analyze pool OHLCV in InfluxDB with hourly/minute intervals and live Grafana dashboards.

From real-time monitoring to historical analysis

While InfluxDB is a champion of real-time data, its power extends far beyond live dashboards. It provides a highly optimized engine for storing and querying massive time-series datasets, making it a perfect middle-ground between the local analytics of DuckDB and the enterprise scale of ClickHouse.
Looking for other analytics solutions? Check out our full list of API Tutorials for more step-by-step guides.
This tutorial will guide you through building a production-grade ETL pipeline to populate InfluxDB with a substantial historical dataset, enabling both high-performance queries and real-time visualization. The goal: By the end of this guide, you will have a scalable analytics pipeline that can:
  1. Ingest 1-hour OHLCV data for the top 500 Uniswap v3 pools over a 14-day period.
  2. Run complex time-series analysis using Python and the Flux language.
  3. Visualize the data in a live-updating Grafana dashboard.

Step 1: Docker Setup

Get InfluxDB and Grafana running in seconds with Docker.

Step 2: ETL Pipeline

Create a robust data pipeline for ingesting large time-series datasets.

Step 3: Programmatic Analysis

Analyze your time-series data with InfluxDB’s Python client.

Step 4: Live Dashboard

Build a real-time dashboard to monitor crypto pools.

Step 1: Setting Up InfluxDB and Grafana

We’ll use Docker Compose to spin up both services. First, create a new directory named INFLUXDB in your project root. Inside that directory, create a file named docker-compose.yml with the following content.
INFLUXDB/docker-compose.yml
Run the following command from the root of the project to start the containers:
Once running, you can access:
  • InfluxDB UI: http://localhost:8087
  • Grafana UI: http://localhost:3000 (login with admin/admin)
Use the token my-super-secret-token to connect to InfluxDB.
We use port 8087 for InfluxDB to avoid potential conflicts with other services that might be using the default port 8086.

Step 2: Build the Python ETL Pipeline

Create a new file named INFLUXDB/build_influxdb_db.py. This script is built to be robust and efficient, capable of ingesting large volumes of time-series data from the DexPaprika API into your InfluxDB instance. It leverages two key endpoints: the Top Pools on a DEX endpoint to discover pools, and the Pool OHLCV Data endpoint to fetch historical price data.
INFLUXDB/build_influxdb_db.py
This script is built for performance and reliability, using several best practices common in data pipelines:
  • Asynchronous operations: By using asyncio and aiohttp, the script can make many API requests concurrently instead of one by one.
  • Dynamic windowing: The fetch_pool_ohlcv_paginated function calculates how much data to request per API call to ensure complete history is fetched efficiently.
  • Concurrency control & throttling: An asyncio.Semaphore, combined with carefully tuned BATCH_SIZE and asyncio.sleep() calls, keeps the script under the free tier’s 15 requests a minute keyless, or 30 with a free key. Pro raises that to 300 a minute, which lets you shorten the sleeps and finish the backfill sooner.
  • Resiliency: The fetch_with_retry function automatically retries failed requests with an exponential backoff delay.
  • Data Integrity: The script automatically clears old data from the bucket before each run to ensure a clean, consistent dataset.

Setup Python Environment

Before running the ETL script, it’s a critical best practice to create an isolated Python environment to manage dependencies.
  1. Create a virtual environment: Open your terminal in the project root and run:
  2. Activate the environment:
    • On macOS and Linux:
    • On Windows:
    Your terminal prompt should now be prefixed with (venv), indicating that the virtual environment is active.
  3. Install required libraries: Now, install the necessary Python packages inside the activated environment:
Run the script to start streaming data into your InfluxDB instance. This may take several minutes.

Step 3: Programmatic Analysis with Python

While the InfluxDB UI is great for exploration, the real power comes from programmatic access. The influxdb-client library for Python allows you to run complex Flux queries and integrate the data into other tools or scripts. We’ve created a query_influxdb.py script to demonstrate how to connect to your database and perform analysis on the hourly data.
INFLUXDB/query_influxdb.py
Run the script to see how you can query your data with Python:

Step 4: Visualizing Data in Grafana

  1. Open Grafana at http://localhost:3000.
  2. Go to Connections > Add new connection > InfluxDB.
  3. Configure the connection:
    • Name: InfluxDB_Crypto
    • Query Language: Flux
    • URL: http://influxdb:8086 (use the Docker service name)
    • Under Auth, toggle Basic auth off.
    • In the Custom HTTP Headers section, add a header:
      • Header: Authorization
      • Value: Token my-super-secret-token
    • Enter your InfluxDB Organization (my-org) and default Bucket (crypto-data).
  4. Click Save & Test. You should see a “Bucket found” confirmation.
  5. Now, let’s create a dashboard. In the left-hand menu, click the + icon and select Dashboard.
  6. Click on the Add new panel button.
  7. In the new panel view, ensure your InfluxDB_Crypto data source is selected at the top.
  8. Below the graph, you’ll see a query editor. You can switch to the Script editor by clicking the pencil icon on the right.
  9. Paste the following query into the editor. This query will plot the raw closing price for the AAVE/USDC trading pair.
    Troubleshooting Tip: If you initially see “No data,” there are two common reasons:
    1. Time Range: Ensure the time picker at the top right is set to “Last 7 days” or wider, not a shorter period like “Last 6 hours.”
    2. Trading Pair: The default WETH/USDC pair used in the original tutorial may not have been in the top 500 pools fetched by the script. The query above uses AAVE/USDC, which is more likely to be present. You can find other available pairs by running the query_influxdb.py script.
  10. At the top right of the dashboard page, set the time range to Last 7 days to ensure you see all the historical data you ingested.
  11. You should now see the data appear in the panel. You can give the panel a title (e.g., “AAVE/USDC Close Price”) in the settings on the right.
  12. Click Apply to save the panel to your dashboard. You can now add more panels for other queries.

What You’ve Built

You now have a powerful, scalable analytics pipeline for time-series crypto data. You’ve combined a production-grade Python ETL script with the industry-standard tools for time-series data storage (InfluxDB) and visualization (Grafana). Key achievements:
  • Built a production-ready ETL pipeline: You have a reusable, high-performance Python script that can populate a time-series database from any supported DEX.
  • Unlocked programmatic time-series analysis: You can now perform complex analytical queries on large time-series datasets using Python and Flux.
  • Mastered a scalable analytics workflow: This pipeline provides a solid foundation for building live dashboards, conducting in-depth market research, and developing sophisticated monitoring or trading algorithms.
  • Enabled live data visualization: You’ve connected your database to Grafana, the leading open-source tool for observability and data visualization.

FAQs

InfluxDB excels at time-series ingestion and dashboards; it’s ideal for hourly/minute data with Grafana visualization.
Keep recent weeks/months for dashboards and archive older data elsewhere; adjust by bucket retention.
1h is a sensible default; lower to 15m/5m for more granularity if needed.
Schedule the ETL to append new windows, and set Grafana panels to auto-refresh.