> 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/tensor/get-all-pools-of-a-margin-account.md).

# 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 %}
