Get latest transactions and aggregate to get sell and buy amounts

Description
I would love to:

  • Extract the transactions in the last 15 mins on pancakeswap
  • Aggregrate these per token/contract
  • Get the number of buys and sells for that token - so I can check if there are more buys than sells

What I have now
I can retrieve the last transactions and aggregate them for the “BNB > token” pair, however, this only gives me the number of tokens bought, not the number of tokens sold since I would need the “token > BNB” pair for this too. Obviously, I could run the query below twice, once with BNB as buy and once with BNB as sell currency but this is rather tedious, perhaps there is a much easier way for this?

{
  ethereum(network: bsc) {
    dexTrades(
      time: {since: "2021-06-09T19:00:00"}
      sellCurrency: {is: "0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c"}
      exchangeName: {in: ["Pancake", "Pancake v2"]}
      options: {limit: 10000}
    ) {
      baseCurrency {
        symbol
        address
      }
      baseAmount
      quoteCurrency {
        symbol
        address
      }
      baseCurrency {
        symbol
      }
      buyCurrency {
        symbol
      }
      sellCurrency {
        symbol
      }
      buyAmount(calculate: sum)
      sellAmount(calculate: sum)
      trades: count(uniq: txs)
      uniqueSenders: count(uniq: senders)
      maximum_price: quotePrice(calculate: maximum)
      minimum_price: quotePrice(calculate: minimum)
    }
  }
}

Thanks in advance!

Is this what you are looking for?

{
  ethereum(network: bsc) {
    dexTrades(
      time: {since: "2021-06-12T19:00:00"}
      quoteCurrency: {is: "0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c"}
      exchangeName: {in: ["Pancake", "Pancake v2"]}
      options: {limit: 10000 , desc : "tradeAmount"}
    ) {
      baseCurrency {
        symbol
        address
      }
      baseAmount
      quoteCurrency {
        symbol
        address
      }
  		tradeAmount(calculate:sum in: USD)
      trades: count(uniq: txs)
      takers: count (uniq: takers)
      makers: count (uniq: makers)
      uniqueSenders: count(uniq: senders)
      maximum_price: quotePrice(calculate: maximum)
      minimum_price: quotePrice(calculate: minimum)
    }
  }
}

Thanks for looking with me!
What I actually meant is:

  • Get the transactions for the latest 15 minutes
  • Check how many of these were buys/sells grouped by token

So let’s say token $X, I want to know how many tokens were bought and how many were sold. Since we have pairs, lets always ook at BNB. I think takers/makers tells us how many “people” bought right not how many tokens were involved. In other words, I think I could rephrase it, the trade amount tells us how much was traded, I want to know how many tokens were bought and how many were sold there.

So that we get something like:
token - address - tokens sold - tokens bought

That would be amazing :innocent:

I’m just thinking, we could use the candle data for this instead (like you proposed here), and look at the open and close for each token. This does not give the exact amounts but it does tell me whether there were more buys than sells. Although I’m not entirely sure what the exact query would have to look like, since:

  • I don’t need all tokens just those traded recently
  • that query does not always seem to return the last candle

Basically, I’m trying to use the query to find tokens that are getting more buys than sells in the last X minutes

is this what you are looking for?

{
  ethereum(network: bsc) {
    dexTrades(
      sellCurrency: {is: "0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c"}
      time: {since: "2021-06-12T19:00:00"}
      exchangeName: {in: ["Pancake", "Pancake v2"]}
      options: {limit: 10, desc: "sellAmount"}
    ) {
      buyCurrency {
        name
        symbol
        address
      }
      buyAmount
      sellAmount
    }
  }
}

Hey Gaurav sorry for the late reply! Some personal stuff going on… :frowning:
I looked into this one, but it appears that the buy and sell amount are not both in BNB?
For example if I run it for today (“2021-08-13T00:00:00”) it, for example, gives (slightly modified it to include more info):

      {
        "buyCurrency": {
          "address": "0x609d183fb91a0fce59550b62ab7d2c931b0bb1be",
          "symbol": "PkMon"
        },
        "sellCurrency": {
          "address": "0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c",
          "symbol": "WBNB"
        },
        "trades": 21008,
        "tradeAmount": 6094125.3570813155,
        "buyAmount": 677944564.571495,
        "sellAmount": 15242.647860307368
      },

This gives me the impression there were more buys than sells, but this is not the case, looking at the chart: PooCoin BSC Charts. I suppose this is because buyAmount and sellAmount are in different currencies - buy being the amount of the token and sell the amount of BNB.

Is there any way to make the buy and sell amount comparable such that I can see if a token went up?

You can convert them into USD and check their values.

{
  ethereum(network: bsc) {
    dexTrades(
      sellCurrency: {is: "0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c"}
      time: {since: "2021-06-12T19:00:00"}
      exchangeName: {in: ["Pancake", "Pancake v2"]}
      options: {limit: 10, desc: "sellAmount"}
    ) {
      buyCurrency {
        name
        symbol
        address
      }
      buyAmount(in: USD)
      sellAmount(in: USD)
    }
  }
}

Thanks! I just tried this but for some reason most of the “buyamount” now become 0, any idea why that is?

Any idea about the above?

No idea why the buy amounts become 0 when using the conversion? It makes it quite useless…

Hi @CodeGod sorry to keep you waiting but we do not have USD data for buyAmount.