How to collect NFT sales data using OpenSea API

This article shows how to collect NFT (non-fungible tokens) sales data from OpenSea, the largest market for NFT. You will see a script for ingesting historical sales data using the OpenSea API.With the data collected, you will be able to carry out your…


This content originally appeared on Level Up Coding - Medium and was authored by Francesco Falleni

This article shows how to collect NFT (non-fungible tokens) sales data from OpenSea, the largest market for NFT. You will see a script for ingesting historical sales data using the OpenSea API.

With the data collected, you will be able to carry out your analyses, build dashboards, discover new trends, and much more.

An nft transaction (called an Event) is a state change that occur for assets such as creation or transfer. According to opensea, an event is made up of the following fields:

  • event_type: Describes the event type
  • asset / asset_bundle: A subfield containing a simplified version of the Asset or Asset Bundle on which this event happened
  • created_date: When the event was recorded
  • from_account / to_account: The accounts associated with this event
  • is_private: A boolean value that is true if the sale event was a private sale
  • payment_token: The payment asset used in this transaction, such as ETH, WETH or DAI
  • quantity: The amount of the item that was sold. Applicable for semi-fungible assets
  • total_price: The total price that the asset was bought for. This includes any royalties that might have been collected

For our purposes, it will only be necessary to obtain events with a “successful” status, i.e. asset sold.

Next, we will see Step-by-Step how to get nft sales data from OpenSea API.

1. Obtain OpenSea API Key

To start making requests you will need the OpenSea API Key, which can be obtained here: https://docs.opensea.io/reference/request-an-api-key.

2. Request function

This function makes a request to the endpoint to obtain a list of events occurring between two dates:

The endpoint will return a List of Event Object and two cursors useful retrieve the next page and the previous page of results.

3. Parse Event function

This function parse Event Object:

4. Retrieve all Events between two dates

Now we can start retrieving events that occurred between two dates using the functions already defined:

At every iteration a request is made, the response is parsed and if the “next” cursor contains a value (i.e. there are other events to fetch) a request is made again by passing the cursor and so on until all results have been received.

You can find a ready-to-use script with all the functions shown here: https://github.com/Checco9811/opensea-api-nft-sales.

Run the script by passing the start date and end date as parameters, command execution example:

> python script.py -s "2022-03-25" -e "2022-03-26"

Or:

> python script.py -s "2022-03-25 01:20" -e "2022-03-26 02:30"

Help:

> python script.py -h
options:
-h, --help show this help message and exit
-s STARTDATE, --startdate STARTDATE
The Start Date (YYYY-MM-DD or YYYY-MM-DD HH:mm)
-e ENDDATE, --enddate ENDDATE
The End Date (YYYY-MM-DD or YYYY-MM-DD HH:mm)
-p PAUSE, --pause PAUSE
Seconds to wait between http requests. Default: 1
-o OUTFILE, --outfile OUTFILE
Output file path for saving nft sales record in csv format

Conclusion

We have seen how to collect events between two given dates using the OpenSea API, but it is also possible to collect data just from a single collection passing the right parameters or consider all possible types of events and not just sales events. You can find all the details in the API documentation.
I hope this article will be useful for you to build your own NFT time-series dataset and carry out your analysis.

Thank you for reading!

GitHub code

LinkedIn


How to collect NFT sales data using OpenSea API was originally published in Level Up Coding on Medium, where people are continuing the conversation by highlighting and responding to this story.


This content originally appeared on Level Up Coding - Medium and was authored by Francesco Falleni


Print Share Comment Cite Upload Translate Updates
APA

Francesco Falleni | Sciencx (2022-04-01T13:21:07+00:00) How to collect NFT sales data using OpenSea API. Retrieved from https://www.scien.cx/2022/04/01/how-to-collect-nft-sales-data-using-opensea-api/

MLA
" » How to collect NFT sales data using OpenSea API." Francesco Falleni | Sciencx - Friday April 1, 2022, https://www.scien.cx/2022/04/01/how-to-collect-nft-sales-data-using-opensea-api/
HARVARD
Francesco Falleni | Sciencx Friday April 1, 2022 » How to collect NFT sales data using OpenSea API., viewed ,<https://www.scien.cx/2022/04/01/how-to-collect-nft-sales-data-using-opensea-api/>
VANCOUVER
Francesco Falleni | Sciencx - » How to collect NFT sales data using OpenSea API. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/04/01/how-to-collect-nft-sales-data-using-opensea-api/
CHICAGO
" » How to collect NFT sales data using OpenSea API." Francesco Falleni | Sciencx - Accessed . https://www.scien.cx/2022/04/01/how-to-collect-nft-sales-data-using-opensea-api/
IEEE
" » How to collect NFT sales data using OpenSea API." Francesco Falleni | Sciencx [Online]. Available: https://www.scien.cx/2022/04/01/how-to-collect-nft-sales-data-using-opensea-api/. [Accessed: ]
rf:citation
» How to collect NFT sales data using OpenSea API | Francesco Falleni | Sciencx | https://www.scien.cx/2022/04/01/how-to-collect-nft-sales-data-using-opensea-api/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.