> For the complete documentation index, see [llms.txt](https://docs.shyft.to/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.shyft.to/solana-indexers/case-studies/cross-marketplace-queries/get-listings-for-a-collection-across-marketplaces.md).

# Get listings for a collection across marketplaces

In order to query active listings for a collection, we would first need a mint list (list of addresses of all NFTs belonging to that collection). We can save it before hand or fetch it through DAS. For this example we will be fetching the data through DAS.

GraphQL API also allows you to add <mark style="color:yellow;">multiple filters</mark>, along with <mark style="color:yellow;">checks for a range of values</mark> for particular fields. Suppose, we are filtering the nftMint, or the owner field, we can check if the <mark style="color:yellow;">nftMint</mark> or <mark style="color:yellow;">owner</mark>, <mark style="color:yellow;">belongs to a range (array) of values</mark> instead of just one particular value.

So to achieve the above objective, we will be requiring two simple steps

* We will get a <mark style="color:yellow;">list of all mint addresses</mark> for a collection using DAS.
* We will then use the array of mint addresses to <mark style="color:yellow;">filter the listing</mark> across the three marketplaces.

{% tabs %}
{% tab title="Code Snippet" %}
{% code overflow="wrap" %}

```typescript
import { Network, ShyftSdk } from '@shyft-to/js';
import { gql, GraphQLClient } from 'graphql-request';

const endpoint = `https://programs.shyft.to/v0/graphql?api_key=YOUR-API-KEY`; //Shyft's gQl endpoint

const graphQLClient = new GraphQLClient(endpoint, {
  method: `POST`,
  jsonSerializer: {
    parse: JSON.parse,
    stringify: JSON.stringify,
  },
}); //Initialize gQL Client

const shyft = new ShyftSdk({ apiKey: "YOUR-API-KEY", network: Network.Mainnet }); //Initialize Shyft SDK

async function getAllListingsForCollection(collectionAddr:string) {

    const allNftMintsforCollection = await getAllMintsofColl(collectionAddr);
    const query = gql`
    query MyQuery {
        MAGIC_EDEN_V2_SellerTradeStateV2(
          where: {tokenMint: {_in: ${JSON.stringify(allNftMintsforCollection)}}}
        ) {
          tokenMint
          seller
          buyerPrice
        }
        Tensor_SingleListing(
          where: {nftMint: {_in: ${JSON.stringify(allNftMintsforCollection)}}}
        ) {
          owner
          nftMint
          price
        }
        SNIPER_MARKET_SOLNFTOrderV1(
          where: {nftMint: {_in: ${JSON.stringify(allNftMintsforCollection)}}}
        ) {
          nftMint
          price
          owner
        }
      }
    `;

  const response = await graphQLClient.request(query);
  console.dir(response,{depth: null});
  
}

//MadLads collection address
getAllListingsForCollection('J1S9H3QjnRtBbbuD4HjPV6RpRhwuk4zKbxsnCHuTgh9w')

async function getAllMintsofColl(collectionAddr:string) {
    //function to get all NFTs mints from a collection
    let page = 1;
    const assets = [];

    while (page > 0) {
      const assetsByGroup = await shyft.rpc.getAssetsByGroup({
        groupKey: 'collection',
        groupValue: collectionAddr,
        page,
        limit: 1000,
      });

      console.log(`fetching ${page} from DAS`);
      assets.push(...assetsByGroup.items);
      page = assetsByGroup.total !== 1000 ? -1 : page + 1;
    }

    console.log('Total NFT ', assets.length);
    const nftAddresses = assets.map((nft) => nft.id);
    return nftAddresses;
}
```

{% endcode %}
{% endtab %}

{% tab title="Response" %}

```json
{
  MAGIC_EDEN_V2_SellerTradeStateV2: [
    {
      tokenMint: 'JDZP2FipS7xDsiVYXbtqqywaAz9MkXNSgfWvFe2PL2xA',
      pubkey: 'BcxqyQ7S8ddBWo7EEMgrmFWe9HuQTELvVDyhnrF4cSnm',
      seller: '9k3Ad9uoftGYUo6UZAgEn23aqyQWGKqfycb7a8DVcCCN',
      buyerPrice: 283000000
    }
  ],
  Tensor_SingleListing: [
    {
      owner: '6CEM7ptNH2JRE2Ce2GTfNc7uroxZDghBiRj5DGEsqN7M',
      nftMint: 'JANV72ERRvo4iqEAkeqqr7quPJs9M1bDQj3XQKuJwhdV',
      price: 182400000
    }
  ],
  SNIPER_MARKET_SOLNFTOrderV1: [
    {
      nftMint: 'JArGq4iPvciyS8Ry2Qvp9ZHVHmkak3HMMFfdiZrHpqMo',
      price: 220000000,
      owner: 'FtGiXsW72evEzwQ1KBfMAraUT9WfL3rz3ciFY7yQjti5'
    }
  ]
}
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
You can also use our [<mark style="color:red;">MintList</mark>](https://airdrop.shyft.to/) tool to get a collection's mint list.
{% endhint %}

Please note that, like filtering we can also <mark style="color:yellow;">limit</mark> the number of results we want in the response. In the above case we have limited the listings from each marketplace to 1, however this can be removed to fetch more listings for that particular collection from the marketplaces.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.shyft.to/solana-indexers/case-studies/cross-marketplace-queries/get-listings-for-a-collection-across-marketplaces.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
