Get Positions for a Pool

Get all positions for a liquidity pool on Orca Whirlpool.

Whenever users interact with liquidity pools, or trade financial assets, they get a position with respect to that particular pool. Once we have the pool address we can query all the positions respect to that particular pool, by filtering the position accounts data using GraphQl.

You can directly copy paste this code on replit and see it in action.

import { gql, GraphQLClient } from "graphql-request";

const endpoint = `https://programs.shyft.to/v0/graphql/?api_key=YOUR-KEY`;

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

async function getAllPositionsforWhirlpool(poolAddress) {
    //you can add more fields as per your requirements
    const query = gql`
    query MyQuery {
      ORCA_WHIRLPOOLS_position(
        where: {liquidity: {_gt: "0"}, whirlpool: {_eq: ${JSON.stringify(poolAddress)}}}
      ) {
        liquidity
        positionMint
        pubkey
        whirlpool
      }
    }
    `;

  const response = await graphQLClient.request(query);
  console.dir(response,{depth: null});
}
getAllPositionsforWhirlpool('ASdEzNQWHttmokANHz8DX2UnWsvgcVF2tN7eKe62Aj7o');
//you can enter pool address as per your requirement

Last updated