Get Pools Created Between Time

Query pools created between a time range.

Here we see how we can apply filter on number fields. We are searching for pools created within an hour. For that we check for poolOpenTime to between a start and end range using _gte (greater than equal to) and _lte (less than equal to). Moreover, we sort them based on lpReserve field.

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,
  },
});

function queryLpsBetween(start: number, end: number) {

  const query = gql`
    query MyQuery {
  Raydium_LiquidityPoolv4(
    where: {poolOpenTime: {_gte: ${start}}, _and: {poolOpenTime: {_lte: ${end}}}}
    order_by: {lpReserve: desc}
  ) {
    _updatedAt
    amountWaveRatio
    baseDecimal
    baseLotSize
    baseMint
    baseNeedTakePnl
    baseTotalPnl
    baseVault
    depth
    lpMint
    lpReserve
    lpVault
    marketId
    marketProgramId
    maxOrder
    maxPriceMultiplier
    minPriceMultiplier
    minSeparateDenominator
    minSeparateNumerator
    minSize
    nonce
    openOrders
    orderbookToInitTime
    owner
    pnlDenominator
    pnlNumerator
    poolOpenTime
    punishCoinAmount
    punishPcAmount
    quoteDecimal
    quoteLotSize
    quoteMint
    quoteNeedTakePnl
    quoteTotalPnl
    quoteVault
    resetFlag
    state
    status
    swapBase2QuoteFee
    swapBaseInAmount
    swapBaseOutAmount
    swapFeeDenominator
    swapFeeNumerator
    swapQuote2BaseFee
    swapQuoteInAmount
    swapQuoteOutAmount
    systemDecimalValue
    targetOrders
    tradeFeeDenominator
    tradeFeeNumerator
    volMaxCutRatio
    withdrawQueue
  }
}`;

  graphQLClient.request(query).then(console.log);
}

//Querying between an hour
queryLpsBetween(1708702200, 1708705800);

Last updated