How to Use CoinGecko’s Free API to Get Digital Asset Data: Just the Basics (2024)

Software developers talk about APIs a lot. What is an API? API stands for an application programming interface. I wanted to gather specific market data on Bitcoin, Ethereum and other digital assets for a JavaScript project I was working on. My first stop was CoinGecko.

How to Use CoinGecko’s Free API to Get Digital Asset Data: Just the Basics (3)

I chose CoinGecko’s API because the other major digital asset information site, CoinMarketCap, is notorious for publishing fake volume data on coins.

  1. Decide what data you want to get. My application required current market price for a given coin, and the market price of a coin on a certain historical date, and a snapshot of the current market.

a. Go to https://www.coingecko.com/en/api and scroll about halfway down. There, you’ll see the types of requests you can make. Since my application needs to bring in some data from CoinGecko, I want to make a GET request. That’s exactly what CoinGecko enables. Wicked.

How to Use CoinGecko’s Free API to Get Digital Asset Data: Just the Basics (4)

b. I will use /simple/price to get current market prices of coins X, Y, and Z. I will use /coins/{id}/history to get the price of a coin at some previous date.

2. Test how the data will be sent to your application. The testing environment on CoinGecko was excellent. It gives you an example of exactly how the information will pass to my application when I make a request. Let’s say I want to get the current market prices of Bitcoin and Ether. I can input these parameters right in the browser. Be sure to separate the ids of coins only with a comma, and no spaces, or you will hit a problem.

How to Use CoinGecko’s Free API to Get Digital Asset Data: Just the Basics (5)

Click execute.

CoinGecko spits out the response it will send when your application makes this same request.

How to Use CoinGecko’s Free API to Get Digital Asset Data: Just the Basics (6)

Great, so now we know that bitcoin.usd will bring out 9627.02 as a number from this object. Check it out by going to the API, copying that data structure, pasting it in your console, and testing out how to get the information you need.

How to Use CoinGecko’s Free API to Get Digital Asset Data: Just the Basics (7)

3. Import the dependencies in JavaScript

All you need is to run from the terminal:

npm install 'coingecko-api'

You may want to double check this lands in your package.json file like so:

"coingecko-api": "^1.0.10"

Nice and easy!

You only need the dependency to use the node.js wrapper, or else you can just hit the URL directly. (See the implementation below.)

4. Make your requests.

Lesson learned #1: If you need to get data for multiple coins, put them in an array when sending your fetch request to get the data.

Lesson learned #2: If the fetch request throws an error on historical queries, it may be because the data is only served from since the time CoinGecko started tracking that coin.

Lesson learned #3: Don’t forget that await functions (like this API query) must be conducted inside an async function. Here’s an implementation using the node.js wrapper inside a React class component:

async componentDidMount() {await this.CoinGeckoClient.coins.markets(
{ vs_currency: "usd",
order: "market_cap_desc",
per_page: 100,
page: 1,
sparkline: false,
price_change_percentage: "24h"})
.then(data => console.log(data))}

Lesson learned #4: Running your requests in a JS file that is separate from your application can help avoid headaches. Just use that environment to practice how you’ll consume the data, and where you’ll send it. I spent half-a-day practicing requests in a coin-gecko-api.js file and rendering them in a simple react app just to get a feel for making the different requests. Time well-spent.

Here’s how an implementation of a historical request might look:

const getHistoricalPrice = async event => {let currency1API= "bitcoin";
let indexDate="01-01-2020";
let
string = "https://api.coingecko.com/api/v3/coins/" + currency1API +"/history?date="+indexDate+"&localization=false";
await fetch(string)
.then(resp => resp.json())
.then(data => console.log(data.market_data.current_price.usd))}
//=> 7195.15

5. Do what you want with the data!

Now you’ve got the data all ready to go. Who dares wins!

Also Read: 10 Best Crypto APIs for Developers

Join Coinmonks Telegram Channel and Youtube Channel get daily Crypto News

Also, Read

How to Use CoinGecko’s Free API to Get Digital Asset Data: Just the Basics (2024)
Top Articles
How To Invest in Your 30s (It's Not Too Late!) - Bravely Go
Alina Zöller on LinkedIn: Did you know that Trader Joe's is actually owned by the German discount…
Omega Pizza-Roast Beef -Seafood Middleton Menu
Artem The Gambler
123 Movies Black Adam
O'reilly's Auto Parts Closest To My Location
855-392-7812
Napa Autocare Locator
Readyset Ochsner.org
Google Jobs Denver
Wausau Marketplace
Ub Civil Engineering Flowsheet
THE 10 BEST River Retreats for 2024/2025
Becky Hudson Free
12 Best Craigslist Apps for Android and iOS (2024)
Enterprise Car Sales Jacksonville Used Cars
Farmer's Almanac 2 Month Free Forecast
2020 Military Pay Charts – Officer & Enlisted Pay Scales (3.1% Raise)
Persona 5 Royal Fusion Calculator (Fusion list with guide)
Air Quality Index Endicott Ny
Engineering Beauties Chapter 1
Cb2 South Coast Plaza
Xxn Abbreviation List 2017 Pdf
Jurassic World Exhibition Discount Code
Xxn Abbreviation List 2023
60 Second Burger Run Unblocked
Sf Bay Area Craigslist Com
Craigslist Gigs Norfolk
Six Flags Employee Pay Stubs
How to Get Into UCLA: Admissions Stats + Tips
Ark Unlock All Skins Command
Cruise Ships Archives
AsROck Q1900B ITX und Ramverträglichkeit
Build-A-Team: Putting together the best Cathedral basketball team
Greater Keene Men's Softball
Jail View Sumter
Winco Money Order Hours
Craigslist Mexicali Cars And Trucks - By Owner
968 woorden beginnen met kruis
How Does The Common App Work? A Guide To The Common App
Patricia And Aaron Toro
844 386 9815
Ts In Baton Rouge
Sapphire Pine Grove
UNC Charlotte Admission Requirements
Muni Metro Schedule
Latina Webcam Lesbian
Razor Edge Gotti Pitbull Price
Aaca Not Mine
Latest Posts
Article information

Author: Errol Quitzon

Last Updated:

Views: 5876

Rating: 4.9 / 5 (79 voted)

Reviews: 94% of readers found this page helpful

Author information

Name: Errol Quitzon

Birthday: 1993-04-02

Address: 70604 Haley Lane, Port Weldonside, TN 99233-0942

Phone: +9665282866296

Job: Product Retail Agent

Hobby: Computer programming, Horseback riding, Hooping, Dance, Ice skating, Backpacking, Rafting

Introduction: My name is Errol Quitzon, I am a fair, cute, fancy, clean, attractive, sparkling, kind person who loves writing and wants to share my knowledge and understanding with you.