How to get over the limit of OpenSea Api?
Asked Answered
S

1

6

I am trying to use OpenSea API and I noticed that I need to set a limit before retrieving assets https://docs.opensea.io/reference/getting-assets

I figured I can use the offset to navigate through all the items, even though that's tedious. But the problem is offset itself has a limit, so are assets beyond the max offset inaccessible ?

I read that you that the API is "rate-limited" without an API key, so I assume that related to the number of requests you can make in a certain time period, am I correct about that? Or does it lift the limit of returned assets ? The documentation isn't clear about that https://docs.opensea.io/reference/api-overview

What can I do to navigate through all the assets ?

Smutch answered 31/8, 2021 at 22:16 Comment(0)
M
5

May be late answering this one, but I had a similar problem. You can only access a limited number (50) assets if using the API.

Using the API referenced on the page you linked to, you could do a for loop to grab assets of a collection in a range. For example, using Python:

import requests


def get_asset(collection_address:str, asset_id:str) ->str: 

        url = "https://api.opensea.io/api/v1/assets?token_ids="+asset_id+"&asset_contract_address="+collection_address+"&order_direction=desc&offset=0&limit=20"
        response = requests.request("GET", url)
        asset_details = response.text
        return asset_details
    
    #using the Dogepound collection with address 0x73883743dd9894bd2d43e975465b50df8d3af3b2
    collection_address = '0x73883743dd9894bd2d43e975465b50df8d3af3b2'
    asset_ids = [i for i in range(10)]
    assets = [get_asset(collection_address, str(i)) for i in asset_ids]
    print(assets)

For me, I actually used Typescript because that's what opensea use for their SDK (https://github.com/ProjectOpenSea/opensea-js). It's a bit more versatile and allows you to automate making offers, purchases and sales on assets. Anyway here's how you can get all of those assets in Typescript (you may need a few more dependencies than those referenced below):

    import * as Web3 from 'web3'
    import { OpenSeaPort, Network } from 'opensea-js'
    
    // This example provider won't let you make transactions, only read-only calls:
    const provider = new Web3.providers.HttpProvider('https://mainnet.infura.io')
    
    const seaport = new OpenSeaPort(provider, {
      networkName: Network.Main
    })


    async function getAssets(seaport: OpenSeaPort, collectionAddress: string, tokenIDRange:number) {
      let assets:Array<any> = []
      for (let i=0; i<tokenIDRange; i++) {
          try {
            let results = await client.api.getAsset({'collectionAddress':collectionAddress, 'tokenId': i,})
            assets = [...assets, results ]
          } catch (err) {
            console.log(err)
          }
          
      } 
  return Promise.all(assets)
}


(async () => {
  const seaport = connectToOpenSea();
  const assets = await getAssets(seaport, collectionAddress, 10);
  //Do something with assets 
 
})();

The final thing to be aware of is that their API is rate limited, like you said. So you can only make a certain number of calls to their API within a time frame before you get a pesky 429 error. So either find a way of bypassing rate limits or put a timer on your requests.

Martguerita answered 14/10, 2021 at 16:13 Comment(3)
Have you got an idea of the number of request/mn allowed by the API ?Palikar
@JeremLachkar From my experience, it changes regularly and isn't especially clear from their SDK. I have an API key and I can do one request every three seconds, sometimes every two before I get a 429 error message to say my request has been throttled. That said, I've seen people who are making one a second. If you want to keep up to speed with what's going on with OpenSea, from a developer's perspective, their discord channel (the dev section) is active with fellow devs and bot builders. These kind of topics are regularly spoken about, so I found it useful.Martguerita
hey @Martguerita do you mind posting a link to your github with the bot ?Sibilla

© 2022 - 2024 — McMap. All rights reserved.