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";constendpoint=`https://programs.shyft.to/v0/graphql/?api_key=YOUR-KEY`;constgraphQLClient=newGraphQLClient(endpoint, { method:`POST`, jsonSerializer: { parse:JSON.parse, stringify:JSON.stringify, },});asyncfunctiongetAllPositionsforWhirlpool(poolAddress) {//you can add more fields as per your requirementsconstquery=gql` query MyQuery { ORCA_WHIRLPOOLS_position( where: {liquidity: {_gt: "0"}, whirlpool: {_eq: ${JSON.stringify(poolAddress)}}} ) { liquidity positionMint pubkey whirlpool } } `;constresponse=awaitgraphQLClient.request(query);console.dir(response,{depth:null});}getAllPositionsforWhirlpool('ASdEzNQWHttmokANHz8DX2UnWsvgcVF2tN7eKe62Aj7o');//you can enter pool address as per your requirement