# Get all Pools of a Margin Account

From Tensor, we can get all pools related to a particular margin account by filtering the <mark style="color:yellow;">margin</mark> field in <mark style="color:yellow;">Tensor\_Pool</mark> account.

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

Natively in RPC calls, you would need to fetch both pool and the margin account separately. Here we are fetching pools joined with the associated margin account.

\
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 getAllPoolsperMargin(marginAddr) {
    //fields can be selected as per requirement
    const query = gql`
    query MyQuery {
      Tensor_Pool(where: {margin: {_eq: ${JSON.stringify(marginAddr)}}}) {
        createdUnixSeconds
        Margin {
          poolsAttached
          lamports
        }
        nftAuthority
        nftsHeld
        orderType
        owner
        margin
      }
    }
    `;

  const response = await graphQLClient.request(query);
  console.dir(response,{depth: null});
}
getAllPoolsperMargin('11HQ8NxwY3A6D4WUoYcUM4KRUUVSVRRJXpCMe4oTp4H')
//replace with margin account address
```

{% endcode %}
{% endtab %}

{% tab title="Response" %}

```json
{
  Tensor_Pool: [
    {
      createdUnixSeconds: 1705985569,
      Margin: { poolsAttached: 2 },
      nftAuthority: 'BoDEyiiL3c3M3TgAViwtucaYhtcidHJakTfHH6dWDJPZ',
      nftsHeld: 0,
      orderType: 0,
      owner: 'HGXtUPqc6dCiNuD2bVzGV1A95Uo54vJ2Q2m2PTBUTxfv',
      margin: '11HQ8NxwY3A6D4WUoYcUM4KRUUVSVRRJXpCMe4oTp4H'
    },
    {
      createdUnixSeconds: 1704434659,
      Margin: { poolsAttached: 2 },
      nftAuthority: '82WQumagdRZcFFtCFpAfCzgrrKycPvjbZ3ftpSU9Zwfu',
      nftsHeld: 0,
      orderType: 0,
      owner: 'HGXtUPqc6dCiNuD2bVzGV1A95Uo54vJ2Q2m2PTBUTxfv',
      margin: '11HQ8NxwY3A6D4WUoYcUM4KRUUVSVRRJXpCMe4oTp4H'
    }
  ]
}
```

{% 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-of-a-margin-account.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.
