简体   繁体   中英

How to get over the limit of OpenSea Api?

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 ?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM