Introduction
In this tutorial, you’ll learn how to retrieve historical OHLC (Open, High, Low, Close) price data for any ERC20 token using the Moralis API. This candlestick data is essential for building price charts, technical analysis tools, or trading interfaces. We’ll use the following Moralis API endpoint:- Get OHLCV Data - Fetch historical candlestick price data for token pairs
Prerequisites
- Node.js v18+ installed
- A Moralis API key (get one free)
Step 1: Set Up Your Project
Create a new directory for your project and initialize it:Step 2: Create the Script
Create a file calledindex.js and add the following code:
YOUR_API_KEY with your actual Moralis API key.
Step 3: Run the Script
Execute the script to fetch the OHLC data:Example Response
Understanding the Response
| Field | Description |
|---|---|
pair_address | The liquidity pair contract address |
token0 | First token in the pair |
token1 | Second token in the pair |
timestamp | The start time of the candle |
open | Opening price for the period |
high | Highest price during the period |
low | Lowest price during the period |
close | Closing price for the period |
volume | Trading volume in USD |
trades | Number of trades in the period |
Next Steps
- Build Price Charts - Create interactive charts
- Get Token Price - Get current prices
- Get Token Pairs - Find trading pairs
- API Reference - Full API documentation

