Create Python Cryptocurrency Charts with CoinAPI
Here’s a step-by-step guide to creating interactive cryptocurrency charts with Python and CoinAPI. This tutorial shows how to fetch historical OHLCV data from the CoinAPI Market Data REST API, convert it into a Pandas DataFrame, and visualize it as an interactive candlestick chart with Plotly.
Step 1: Set Up Your Project and API Key
Start by setting up a new Python project. Create a directory for your project and navigate to it in your terminal or command prompt.
You’ll also need a CoinAPI API key.
Create an account in the API BRICKS Console, generate a CoinAPI Market Data API key, and use it to authenticate your requests. New users can start with $25 in free credits to test API calls.
For local development, it is better to store your API key as an environment variable instead of placing it directly in your Python source code.
For example:
Then access it in Python:
Do not commit API keys to GitHub or expose them in frontend code.
Step 2: Install Dependencies
To begin, install the packages required to retrieve, process, and visualize the data.
For this tutorial, you’ll need:
requestsfor CoinAPI REST requestspandasfor working with OHLCV dataplotlyfor interactive charts
Install them using pip:
You do not need to connect separately to individual exchanges. CoinAPI provides standardized access to supported exchange data through its Market Data API.
Step 3: Find a CoinAPI Symbol
Before requesting historical OHLCV data, you need a valid CoinAPI symbol_id.
CoinAPI uses standardized identifiers that specify the exchange, instrument type, and asset pair.
For example:
This identifies the BTC/USD spot market on Bitstamp.
You can discover supported symbols through the /v1/symbols endpoint:
You can also query a specific identifier:
Using the complete symbol_id is important. The OHLCV endpoint expects an identifier such as BITSTAMP_SPOT_BTC_USD, rather than simply BTC or BTC/USD.
Step 4: Fetch Historical OHLCV Data
Now create a file named coinapi.py.
This tutorial uses the CoinAPI Market Data REST API to retrieve historical OHLCV bars.
The request uses:
to fetch historical OHLCV bars for the selected market.
The response can include fields such as:
time_period_starttime_period_endprice_openprice_highprice_lowprice_closevolume_tradedtrades_count
When experimenting with REST requests, start with a relatively small limit. You can also inspect the x-credits-used response header when available to monitor API usage.
A Note About CoinAPI OHLCV Data
OHLCV stands for Open, High, Low, Close, and Volume.
CoinAPI's OHLCV formation can use transaction and order book activity. If no trades occur during a period but the order book remains active, a bar can still be emitted with:
This is useful to understand when interpreting periods with little or no trading activity.
Step 5: Create the Cryptocurrency Chart
Next, create a separate file named charting.py.
Because we are working with OHLCV data, a candlestick chart is more informative than plotting only price_close.
Plotly uses the CoinAPI fields price_open, price_high, price_low, and price_close to create each candle.
The result is an interactive chart that allows you to inspect historical BTC/USD price behavior directly in your browser.
Advanced Charting Techniques
Once the basic candlestick chart is working, you can extend it with additional visualizations.
For example, you could add:
- Moving averages
- Trading volume
- Relative Strength Index (RSI)
- Bollinger Bands
- Multiple symbols
- Different OHLCV periods
Advanced charting techniques can help visualize trends, volatility, volume, and historical price behavior for research and strategy analysis.
For example, a simple moving average can be calculated directly with Pandas:
You could then add it to your Plotly chart:
These indicators are analytical tools rather than predictions of future market behavior.
Step 6: Put It All Together
Now create a main.py file and import the CoinAPI and charting functions:
Run the project:
The script will:
- Authenticate using your CoinAPI key.
- Request historical OHLCV data for
BITSTAMP_SPOT_BTC_USD. - Convert the response into a Pandas DataFrame.
- Parse the CoinAPI timestamps.
- Generate an interactive Plotly candlestick chart.
You can change SYMBOL_ID, period_id, time_start, and limit to explore different markets and historical periods.
Cryptocurrency Data Charts with Python and CoinAPI
The example above demonstrates a basic way to combine Python, Pandas, Plotly, and CoinAPI.
Instead of retrieving generic “historical prices,” the application is specifically requesting historical OHLCV bars for a CoinAPI symbol_id.
This distinction becomes important as your application grows because CoinAPI provides several different types of market data, including trades, quotes, order books, OHLCV, metrics, and metadata.
For continuous real-time charts, CoinAPI WebSocket streams are more appropriate than repeatedly polling historical REST endpoints.
For large historical research datasets, CoinAPI Flat Files provides bulk access to historical trades, quotes, order books, and OHLCV.
Production Tips
The example above is intentionally simple, but a production application should include a few additional safeguards.
- Protect your API key. Store it in an environment variable or secrets manager rather than hardcoding it into your application.
- Handle API errors. Check HTTP responses and implement appropriate handling for connection problems, invalid requests, and
429responses. - Monitor usage. When available, log the
x-credits-usedresponse header and monitor your consumption in the API BRICKS Console. - Cache historical data. If the same historical period is used repeatedly, storing the result locally can prevent unnecessary API requests.
- Use the right CoinAPI interface. REST is useful for targeted historical requests. WebSocket or FIX is better suited to continuous real-time market data, while Flat Files is designed for bulk historical datasets.
Start Building Your Cryptocurrency Chart
With a few Python packages and the CoinAPI Market Data REST API, you can retrieve historical OHLCV data and turn it into an interactive cryptocurrency chart.
From there, you can extend the project with volume charts, moving averages, additional symbols, technical indicators, or real-time WebSocket data.
Remember to replace YOUR_API_KEY with your own CoinAPI key when using the command-line examples. You can review current access and pricing on the Market Data API pricing page and find endpoint details in the CoinAPI documentation.
This tutorial is for educational purposes and is not investment advice.
More to read:
How to deploy a currency alerting pipeline with Quix and CoinAPI












