# Get active listings across marketplaces for a wallet

In an NFT marketplace, users list their NFTs for sale, setting prices or initiating auctions. Let’s see how we can query data from some of the top marketplaces such as <mark style="color:yellow;">Tensor</mark>, <mark style="color:yellow;">Sniper</mark> and <mark style="color:yellow;">Magic Eden</mark>.

{% hint style="success" %}
Cross program query in action. You can query multiple marketplaces in a single call.
{% endhint %}

* In Magic Eden, user listings are stored in the <mark style="color:yellow;">SellerTradeStateV2</mark> and <mark style="color:yellow;">SellerTradeState</mark> account
* For Sniper, we have the <mark style="color:yellow;">SOLNFTOrderV1</mark> account for listings
* Tensor Swap stores active listings in <mark style="color:yellow;">SingleListing</mark> account

With the power of Shyft’s GraphQL APIs, you can query all three marketplaces in a single call.

You can directly copy paste this code on <mark style="color:yellow;">replit</mark> and see it in action.

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

```typescript
async function fetchGraphQL(operationsDoc, operationName, variables) {
    const result = await fetch(
      "https://programs.shyft.to/v0/graphql?api_key=YOUR-API-KEY&network=mainnet-beta",
      {
        method: "POST",
        body: JSON.stringify({
          query: operationsDoc,
          variables: variables,
          operationName: operationName
        })
      }
    );
    //network is an optional param, which can be devnet also, defaults to mainnet-beta
    return await result.json();
  }
  
  const listingsforWallet = '8pvTRunAQghgWE3sinNxqCUULaxhvXhyEknf5AQe29rB';
  //wallet address for which we are fetching the listings
  const operationsDoc = `
    query MyQuery {
      MAGIC_EDEN_V2_SellerTradeStateV2(
        where: {seller: {_eq: ${JSON.stringify(listingsforWallet)}}}
      ) {
        tokenMint
        pubkey
        seller
        buyerPrice
        expiry
      }
      Tensor_SingleListing(
        where: {owner: {_eq: ${JSON.stringify(listingsforWallet)}}}
      ) {
        owner
        nftMint
        price
      }
      SNIPER_MARKET_SOLNFTOrderV1(
        where: {owner: {_eq: ${JSON.stringify(listingsforWallet)}}}
      ) {
        nftMint
        price
        owner
      }
    }
  `; //querying multiple marketplaces with one query
  
  function fetchMyQuery() {
    return fetchGraphQL(
      operationsDoc,
      "MyQuery",
      {}
    );
  }
  
  async function startFetchMyQuery() {
    const { errors, data } = await fetchMyQuery();
  
    if (errors) {
      // handle those errors like a pro
      console.error(errors);
    }
  
    // do something great with this precious data
    console.log(data);
  }
  
  startFetchMyQuery();
```

{% endcode %}
{% endtab %}

{% tab title="Response" %}

```json
{
  "data": {
    "MAGIC_EDEN_V2_SellerTradeStateV2": [
      {
        "tokenMint": "CVUcF5VUWhvQ9wywpTAgqPpv29dMRXCvGj3XhWvGa4V9",
        "pubkey": "Dy1Rywt4rRqxMF8FchgReanfQhMLLTB32mXbdZger5Q7",
        "seller": "8pvTRunAQghgWE3sinNxqCUULaxhvXhyEknf5AQe29rB",
        "buyerPrice": 391000000
      }
    ],
    "Tensor_SingleListing": [
      {
        "owner": "8pvTRunAQghgWE3sinNxqCUULaxhvXhyEknf5AQe29rB",
        "nftMint": "HS64b6CofJYWuVYsAkHn9bjfPjAq3HMAb5sQpG8ouzpA",
        "price": 294910000
      }
    ],
    "SNIPER_MARKET_SOLNFTOrderV1": [
      {
        "nftMint": "8j2JhrB7ab7CvpxvX7MYWkzDVVFYrpjs1ydPKTi66P6D",
        "price": 174000000,
        "owner": "8pvTRunAQghgWE3sinNxqCUULaxhvXhyEknf5AQe29rB"
      }
    ]
  }
} //response shortened for visibilty
```

{% endtab %}
{% endtabs %}

Please note that the responses are sample responses, and are shortened for visibility. We can also add more accounts in the response for each program, like for example, the <mark style="color:yellow;">SellerTradeState</mark> account for Magic Eden and tensor cNFTs <mark style="color:yellow;">listState</mark> has been omitted in the above example, but they can also be added.

Moreover, a single GraphQL call returns 1000 items in response. You would also need to paginate in some cases.


---

# Agent Instructions: 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:

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

The question should be specific, self-contained, and written in natural language.
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.
