Coins: 14,031
Exchanges: 1,065
Market Cap: $2.444T 2.0%
24h Vol: $74.297B
Gas: 6 GWEI
Go Ad-free
API
TABLE OF CONTENTS

How to Build an Interactive NFT Floor Price Tracker

4.0 | by Vikas Negi

Non-Fungible Tokens (NFTs) have generated a lot of excitement over the last few years. Their use cases include digital art, music, event ticketing, virtual real estate, gaming etc. NFTs are bought and sold on NFT marketplaces such as OpenSea. Just like cryptocurrencies, their prices are determined by the economics of supply and demand. The key price metric is commonly referred to as the floor price, which is the lowest price at which a NFT is listed for sale within a given collection. Floor price gives a good indication of the popularity for a given NFT, which helps estimate its market demand and guide trading strategies.

NFT floor prices fluctuate on a daily basis following market cycles. It can often become difficult to keep track of trends for popular collections. Using monitoring tools like CoinGecko’s NFT Floor Price Tracker or apps like Floor might help, but they can be limited in customizability and functionality, tailored to personal preferences. Instead, we can take a different approach and make use of Python to build our own interactive NFT price tracker.

NFT API - build an interactive NFT floor price tracker

In order to get the NFT floor price data, we will leverage the CoinGecko API and call these commonly used endpoints:

  • /nfts/list - List all supported NFT IDs    
  • /nfts/{id} - Get current data for a given NFT collection    
  • /nfts/markets - Data for all supported NFTs (paid exclusive endpoint)
  • /nfts/{id}/market_chart - Historical data of a NFT collection (paid exclusive endpoint)

We will additionally be using the /ping endpoint to test the API connection.

Here’s a sneak peek of our NFT tracker in action:

Interactive NFT Floor Price Tracker built with CoinGecko NFT API


How to Make API Calls in Python? 

The simplest way to make API calls in Python and get NFT data is through the pycoingecko package, which can be installed via pip. However, as the repository hasn't been updated in a while, it might not support the latest changes to the API. In this guide, we will therefore write our own functions to make API requests and fetch the desired data. The schema for making requests is explained in the API documentation.

Before we begin, ensure that requests and json libraries are imported.

import requests as rq
import json

Let's start with some simple examples using a Jupyter notebook. The screenshot below shows a simple function which can be used to make a HTTP request to the CoinGecko API. In this case, we simply want to ping the server and verify that everything works as expected. 

Check CoinGecko API status using the ping endpoint

We check for the response code 200, which indicates that our request was successful. 

💡 Pro-tip: Bookmark this list of response codes and corresponding statuses.

A few things are worth mentioning in the above example. PUB_URL points to the public API, which is freely available with a keyed authentication. All you need to do is sign up and create a demo account. The key can then be generated using the developer dashboard.

The demo key is passed to our response function via the use_demo header.

💡 Pro-tip: Never expose an API key directly within your code, especially when it’s publicly shared on GitHub. Instead, read it from a file which is available only to the owner locally.

Here's the code snippet you can use to retrieve your Demo API key:

 


How to Get NFT Floor Price Data with an API

The easiest way to fetch NFT floor price data via API is to use CoinGecko API’s /nfts/{id} endpoint, publicly accessible on the Demo plan.

To call this endpoint, we will require the relevant NFT ID. /nfts/list can be used to fetch a list of NFT IDs, and can be sorted according to market cap. Parse the response into a Pandas DataFrame to make it more readable. 

Example showing how to fetch a list of NFTs using CoinGecko's API and Python

Now that we know how to get the NFT ID, we can make use of the /nfts/{id} endpoint to fetch its floor price, amongst other NFT data. The following function makes this request and creates a dictionary with the relevant fields.

We can repeat this exercise for a number of NFT IDs by going through a for loop. In the end, the data can once be returned as a pandas DataFrame. The following example shows a function get_nft_floor_prices where we are able to fetch floor prices for top 10 NFTs in the descending order of market cap in USD. 

Example showing how to fetch NFT floor prices using CoinGecko's API and Python

💡 Pro-tip: If you intend to perform data analysis on a large NFT dataset (think hundreds of thousands of rows in a DataFrame), it will be beneficial to explore the polars library instead of pandas.

How to Fetch Historical NFT Price Data in an Interactive App

Similar to fetching live NFT price data, you can call the CoinGecko API to pull historical NFT price data through the /nfts/markets and /nfts/{id}/market_chart endpoints. Historical price data can help to inform market trends. As these are paid exclusive endpoints, a Pro API key needs to be passed within a request header. An example structure is shown below:

use_pro = {
"accept": "application/json",
"x-cg-pro-api-key" : get_key()
}

We will now develop an interactive app using Python along with the Dash framework, instead of having the code sit within a Jupyter notebook. Dash provides an extremely versatile toolkit, which can be used to build apps rendered in the browser. Dash HTML components also enable a high degree of customization. For this demo, however, we’ll keep the dashboard simple and focus on two things:

  1. Fetch market data where number of results can be changed interactively and visualize results in a bar plot
  2. Fetch historical price data for a selected NFT and generate an interactive chart

We will make use of the Model View Controller (MVC) pattern for structuring our code. Model contains the logic used to fetch data and generate the plots. View contains the layout of the app. Controller forms the glue between the two containing the logic for callbacks, which are responsible for interactivity.

Let's start with defining the interactive components for our webpage. A drop down list of NFT ids can be created as shown below:

Here's an example of a radio button that we shall use:

The layout of the app would be structured by the following code:

The controller file contains the following logic for setting up and executing callbacks:

The app can be accessed via a port as specified below in the file app.py:

Running the app is rather straightforward and you can access the dashboard via the browser at http://127.0.0.1:7000/

poetry run python nft_tracker/app.py

💡 Pro-tips: First, we are using poetry for dependency management. This is easier and more intuitive to use compared to pip or conda. Second, the app can easily be containerized using Docker. This makes it easier to use on a variety of platforms.

How to Set Up NFT Trading Signals & Price Alerts

Set up NFT trading signals easily by leveraging CoinGecko API’s daily NFT floor price data – by calculating the simple moving average (SMA) and exponential moving average (EMA) for a given window size (larger than a day), we can examine long term trends and smoothen out the noise. For example, given a window size of 7 days, we can add a column SMA to our DataFrame as shown below:

df_hist['SMA'] = df_hist['Price_usd'].rolling(7).mean()

EMA places a greater weight on the most recent data points. It can be calculated as follows (window size = 7 days):

df_hist['EMA'] = df_hist['Price_usd'].ewm(span = 7).mean()

If the daily price is higher than SMA or EMA, it indicates an upward market trend. The converse is true when the daily prices fall below the SMA or EMA. These signals are shown in the plots on our dashboard.

Plotting price signals alongside the daily priceWe can also set up an email alert when the daily price crosses above or below the SMA. The function send_price_alert shown below takes the receiver email address, subject and body as the input arguments. It will create and send an email on behalf of the nftdemoapp@gmail.com account. A sender password is needed, which can be set up via: Google Account settings → Security → 2-Step Verification → App passwords → Enter a name and click on Create. 

This can be used within the send_email function, where we specify the conditions under which an email alert should be triggered.

NFTs of interest can be selected from the drop down list in the app’s ‘Alert email’ mode. 

Demo showing how to select the email alert mode within the app

Email alerts should be visible in your inbox:

NFT price alerts in your gmail inbox - inbox email alerts for NFT floor prices


Subscriber Benefits: Access Additional NFT & Crypto Data Endpoints

Crypto projects and developers seeking expanded capabilities with CoinGecko API can consider subscribing to our Analyst or Lite API plans to unlock exclusive paid endpoints. Beyond the endpoints covered earlier, here are some popular coin and NFT data endpoints:

  • /nfts/{id}/tickers – Get the latest floor price and 24h volume of an NFT collection, on each NFT platform (eg. Blur, OpenSea).
  • /nfts/{asset_platform_id}/contract/{contract_address}/market_chart – Get the historical market data of an NFT collection using a contract address. Market data includes floor price, market cap and 24h volume, by N days away from now.
  • /coins/top_gainers_losers – Get the top 30 coins with largest price gain and loss within a specific duration.
  • /coins/list/new – Get the latest 200 coins (id) listed on CoinGecko.

CoinGecko API plans compare pricing


Enjoyed this tutorial? You might also appreciate this guide on building a crypto Twitter (X) bot in 4 easy steps.

CoinGecko's Content Editorial Guidelines
CoinGecko’s content aims to demystify the crypto industry. While certain posts you see may be sponsored, we strive to uphold the highest standards of editorial quality and integrity, and do not publish any content that has not been vetted by our editors.
Learn more
Tell us how much you like this article!
Vote count: 4
Vikas Negi
Vikas Negi

Vikas holds a PhD in Applied Physics. He loves to write code for applications centered around crypto data. When not tinkering with a Raspberry Pi or his home lab, he spends his time slaying demons in Diablo.

More Articles


Explore Polkadot's Ecosystem
Discover trending dApps, wallets, DeFi & more

What is Zeebu?
Learn more about the Web3 neobank


coingecko
Continue in app
Track prices in real-time
Open App
Select Currency
Suggested Currencies
USD
US Dollar
IDR
Indonesian Rupiah
TWD
New Taiwan Dollar
EUR
Euro
KRW
South Korean Won
JPY
Japanese Yen
RUB
Russian Ruble
CNY
Chinese Yuan
Fiat Currencies
AED
United Arab Emirates Dirham
ARS
Argentine Peso
AUD
Australian Dollar
BDT
Bangladeshi Taka
BHD
Bahraini Dinar
BMD
Bermudian Dollar
BRL
Brazil Real
CAD
Canadian Dollar
CHF
Swiss Franc
CLP
Chilean Peso
CZK
Czech Koruna
DKK
Danish Krone
GBP
British Pound Sterling
GEL
Georgian Lari
HKD
Hong Kong Dollar
HUF
Hungarian Forint
ILS
Israeli New Shekel
INR
Indian Rupee
KWD
Kuwaiti Dinar
LKR
Sri Lankan Rupee
MMK
Burmese Kyat
MXN
Mexican Peso
MYR
Malaysian Ringgit
NGN
Nigerian Naira
NOK
Norwegian Krone
NZD
New Zealand Dollar
PHP
Philippine Peso
PKR
Pakistani Rupee
PLN
Polish Zloty
SAR
Saudi Riyal
SEK
Swedish Krona
SGD
Singapore Dollar
THB
Thai Baht
TRY
Turkish Lira
UAH
Ukrainian hryvnia
VEF
Venezuelan bolívar fuerte
VND
Vietnamese đồng
ZAR
South African Rand
XDR
IMF Special Drawing Rights
Cryptocurrencies
BTC
Bitcoin
ETH
Ether
LTC
Litecoin
BCH
Bitcoin Cash
BNB
Binance Coin
EOS
EOS
XRP
XRP
XLM
Lumens
LINK
Chainlink
DOT
Polkadot
YFI
Yearn.finance
Bitcoin Units
BITS
Bits
SATS
Satoshi
Commodities
XAG
Silver - Troy Ounce
XAU
Gold - Troy Ounce
Select Language
Popular Languages
EN
English
RU
Русский
DE
Deutsch
PL
język polski
ES
Español
VI
Tiếng việt
FR
Français
PT
Português
All Languages
AR
العربية
BG
български
CS
čeština
DA
dansk
EL
Ελληνικά
FI
suomen kieli
HE
עִבְרִית
HI
हिंदी
HR
hrvatski
HU
Magyar nyelv
ID
Bahasa Indonesia
IT
Italiano
JA
日本語
KO
한국어
LT
lietuvių kalba
NL
Nederlands
NO
norsk
RO
Limba română
SK
slovenský jazyk
SL
slovenski jezik
SV
Svenska
TH
ภาษาไทย
TR
Türkçe
UK
украї́нська мо́ва
ZH
简体中文
ZH-TW
繁體中文
Login to track your favorite coin easily 🚀
By continuing, you agree to CoinGecko Terms of Service and acknowledge you’ve read our Privacy Policy
or
Forgot your password?
Didn't receive confirmation instructions?
Resend confirmation instructions
IT'S FREE! Track your favorite coin easily with CoinGecko 🚀
By continuing, you agree to CoinGecko Terms of Service and acknowledge you’ve read our Privacy Policy
or
Password must contain at least 8 characters including 1 uppercase letter, 1 lowercase letter, 1 number, and 1 special character
Didn't receive confirmation instructions?
Resend confirmation instructions
Forgot your password?
You will receive an email with instructions on how to reset your password in a few minutes.
Resend confirmation instructions
You will receive an email with instructions for how to confirm your email address in a few minutes.
Get the CoinGecko app.
Scan this QR code to download the app now App QR Code Or check it out in the app stores