# Get all Pools by Owner

Pool details for a wallet can be fetched by applying a where filter on the <mark style="color:yellow;">owner</mark> field in Tensor's Pool Account.

{% hint style="success" %}
Account Joins can be seen in action here! We fetch pool data joined with the associated margin account.
{% endhint %}

Natively in RPC calls, if a wallet owns 100 pools you would need to fetch margin accounts for each one separately to get the balance. But here we are <mark style="color:yellow;">joining</mark> the pool data with the associated margin account, so you get everything 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
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

async function getAllPoolsByUser(walletAddr) {
    //you can select particular fields as per your requirement
    const query = gql`
    query MyQuery {
        Tensor_Pool(
          where: {owner: {_eq: ${JSON.stringify(walletAddr)}}}
        ) {
          frozen
          createdUnixSeconds
          Margin {
            owner
            poolsAttached
            lamports
          }
          nftAuthority
          nftsHeld
          orderType
          owner
        }
      }
    `;

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

getAllPoolsByUser('9XNuYM6ktSL4KcATv3seDBVhWAmVHEU42foY4t7skygg')
//replace this address to get all Pools of one particular owner
```

{% endcode %}
{% endtab %}

{% tab title="Response" %}

```json
{
  "data": {
    "Tensor_Pool": [
      {
        "frozen": null,
        "createdUnixSeconds": 1705505122,
        "Margin": {
          "owner": "9XNuYM6ktSL4KcATv3seDBVhWAmVHEU42foY4t7skygg",
          "poolsAttached": 4
        },
        "nftAuthority": "CVeiwtnGbGcFFEs71V7DQyvbBp5cv5uaGSkvibv3jAWP",
        "nftsHeld": 0,
        "orderType": 0,
        "owner": "9XNuYM6ktSL4KcATv3seDBVhWAmVHEU42foY4t7skygg"
      },
      {
        "frozen": null,
        "createdUnixSeconds": 1705505122,
        "Margin": {
          "owner": "9XNuYM6ktSL4KcATv3seDBVhWAmVHEU42foY4t7skygg",
          "poolsAttached": 4
        },
        "nftAuthority": "CVeiwtnGbGcFFEs71V7DQyvbBp5cv5uaGSkvibv3jAWP",
        "nftsHeld": 0,
        "orderType": 0,
        "owner": "9XNuYM6ktSL4KcATv3seDBVhWAmVHEU42foY4t7skygg"
      },
      {
        "frozen": null,
        "createdUnixSeconds": 1705505122,
        "Margin": {
          "owner": "9XNuYM6ktSL4KcATv3seDBVhWAmVHEU42foY4t7skygg",
          "poolsAttached": 4
        },
        "nftAuthority": "CVeiwtnGbGcFFEs71V7DQyvbBp5cv5uaGSkvibv3jAWP",
        "nftsHeld": 0,
        "orderType": 0,
        "owner": "9XNuYM6ktSL4KcATv3seDBVhWAmVHEU42foY4t7skygg"
      }
    ]
  }
}
```

{% endtab %}
{% endtabs %}


---

# 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/tensor/get-all-pools-by-owner.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.
