4

Is there a way to get the floor price thats displayed on the main page of an NFT collection?

enter image description here

Here you see the floor price is 5.75 but if I query the contract using the Opensea api:

url = "https://api.opensea.io/api/v1/asset/0x1cb1a5e65610aeff2551a50f76a87a7d3fb649c6/1/"

response = requests.request("GET", url)

print(response.text)

I get a floor of:

enter image description here

So it seems as though the api is a little off. Was just curious if anyone here knows of a better way to get a more accurate floor price?

William
  • 429
  • 3
  • 5
  • 16
  • what about scrapping the webpage? – Mayeul sgc Sep 30 '21 at 02:48
  • 1
    You're querying the wrong API. If you look at the response, it's for Cryptoadz #1. I'm not familiar with this api in particular, but I think you want to query for the [bundle](https://docs.opensea.io/reference/retrieving-bundles). – Roddy of the Frozen Peas Sep 30 '21 at 02:56
  • 1
    Are you talking about the collection floor price? – pguardiario Oct 06 '21 at 10:11
  • Did you manage to find a way? I have the same issue where the floor price of the api sometimes does not much the floor price on their website or app? – makis.k Oct 20 '21 at 18:54
  • @makis.k hey sorry for the late reply, but in case you were still looking it looks like OpenSea added an endpoint for this: https://docs.opensea.io/reference/retrieving-collection-stats – William Jan 05 '22 at 22:19

6 Answers6

13

I have no idea why this works, but...

https://api.opensea.io/collection/${slug}

slug = the collection slug (name in URL).

For reference, I found this in some random other library's documentation... But it seems to work

Roxkstar74
  • 171
  • 5
1

Floor price is for collections (contracts). Opensea api does have a collections endpoint but it can't filter by anything except owner address. So you have to know the address of someone why owns a token I guess, which seems pretty retarded.

Also you can get the owner of a token from the assets endpoint which can filter by contract address and token id.

pguardiario
  • 53,827
  • 19
  • 119
  • 159
0

In case anyone was still looking, it looks like OpenSea added a new endpoint that more accurately tracks floor price:

https://docs.opensea.io/reference/retrieving-collection-stats

William
  • 429
  • 3
  • 5
  • 16
0

In the documentation it shows how the API works

https://api.opensea.io/api/v1/collection/doodles-official/stats

This returns all the stats. So change the name of the collection to the one you want and that's it.

msqar
  • 2,940
  • 5
  • 44
  • 90
0

I've managed to make it work by fetching different data from my collection on OpenSea and showing them on my website.

app.js:

function fetchData() {
// Using the OpenSea API's direct URL of the .json file from the collection
// Change the "OpenSeaCollectionNameSlug" in the URL to your collection's slug
    fetch('https://api.opensea.io/api/v1/collection/OpenSeaCollectionNameSlug/stats?format=json')
      .then(response => {
// If the data doesn't load properly from the URL, show a custom error message on the HTML file
        if (!response.ok) {
          throw Error('X');
        }
        return response.json();
      })
      .then(data => {
// Creating one or more const to put data inside
        const floorprice = data.stats.floor_price
        const owners = data.stats.num_owners
// Using id inside different span to add the content on the HTML file
// Using toFixed and toPrecision to round the output
        document.querySelector('#floorprice').innerHTML = (floorprice).toFixed(3);
        document.querySelector('#owners').innerHTML = Math.round(owners).toPrecision(2) / 1000;
// Keeping this console.log to see which other data stats can be fetched
        console.log(data.stats);
      });
  }
fetchData();

index.html:

<div>
 <h1>OWNERS</h1>
 <h3><span id="owners"></span></h3>
</div>

<div>
 <h1>FLOOR PRICE</h1>
 <h3><span id="floorprice"></span> Ξ</h3>
</div>
0
const collectionSlug = 'm4rabbit';//opensea tag of m4rabbit.io collection
const apiUrl = `https://api.opensea.io/api/v1/collection/${collectionSlug}/stats?format=json`;

fetch(apiUrl)
  .then(response => response.json())
  .then(data => {
    const floorPrice = parseFloat(data.stats.floor_price).toFixed(3);
    const owners = (Math.round(data.stats.num_owners) / 1000).toPrecision(2);

    document.querySelector('#floorprice').innerHTML = floorPrice;
    document.querySelector('#owners').innerHTML = owners;
  })
  .catch(error => {
    console.error('Error fetching data:', error);
    document.querySelector('#error').innerHTML = 'Error fetching data';
  });

failed many times then realised it was v1 i had to adjust and add a header X-API-KEY and use a key from opensea along with this code https://docs.opensea.io/reference/api-overview to get it to work after being dormant a few months

ace
  • 1