# Get latest transactions and aggregate to get sell and buy amounts

**URL:** <https://community.bitquery.io/t/get-latest-transactions-and-aggregate-to-get-sell-and-buy-amounts/163>\
**Category:** GraphQL API\
**Tags:** closed\
**Created:** [June 12, 2021, 9:54am UTC](https://community.bitquery.io/t/get-latest-transactions-and-aggregate-to-get-sell-and-buy-amounts/163 "2021-06-12T09:54:16Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![CodeGod](https://avatars.discourse-cdn.com/v4/letter/c/ac91a4/32.png) [@CodeGod](https://community.bitquery.io/u/CodeGod)\
**Post date:** [June 12, 2021, 9:54am UTC](https://community.bitquery.io/t/get-latest-transactions-and-aggregate-to-get-sell-and-buy-amounts/163/1 "2021-06-12T09:54:16Z")

</div>

**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?

```auto
{
  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!

---

<div class="post-metadata">

**Author:** ![gaurav](https://avatars.discourse-cdn.com/v4/letter/g/b487fb/32.png) [@gaurav](https://community.bitquery.io/u/gaurav)\
**Post date:** [June 13, 2021, 6:31am UTC](https://community.bitquery.io/t/get-latest-transactions-and-aggregate-to-get-sell-and-buy-amounts/163/2 "2021-06-13T06:31:54Z")

</div>

Is this what you are looking for?

```auto
{
  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)
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![CodeGod](https://avatars.discourse-cdn.com/v4/letter/c/ac91a4/32.png) [@CodeGod](https://community.bitquery.io/u/CodeGod)\
**Post date:** [June 13, 2021, 12:02pm UTC](https://community.bitquery.io/t/get-latest-transactions-and-aggregate-to-get-sell-and-buy-amounts/163/3 "2021-06-13T12:02:28Z")

</div>

> [@gaurav](#):
>
> ```auto
> {
> 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 😇

---

<div class="post-metadata">

**Author:** ![CodeGod](https://avatars.discourse-cdn.com/v4/letter/c/ac91a4/32.png) [@CodeGod](https://community.bitquery.io/u/CodeGod)\
**Post date:** [June 13, 2021, 1:08pm UTC](https://community.bitquery.io/t/get-latest-transactions-and-aggregate-to-get-sell-and-buy-amounts/163/4 "2021-06-13T13:08:33Z")

</div>

I’m just thinking, we could use the candle data for this instead (like you proposed [here](https://community.bitquery.io/t/get-price-trading-volume-trade-count-of-all-tokens-in-a-single-api/106)), 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

---

<div class="post-metadata">

**Author:** ![gaurav](https://avatars.discourse-cdn.com/v4/letter/g/b487fb/32.png) [@gaurav](https://community.bitquery.io/u/gaurav)\
**Post date:** [June 14, 2021, 6:34am UTC](https://community.bitquery.io/t/get-latest-transactions-and-aggregate-to-get-sell-and-buy-amounts/163/5 "2021-06-14T06:34:44Z")

</div>

is this what you are looking for?

```auto
{
  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
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![CodeGod](https://avatars.discourse-cdn.com/v4/letter/c/ac91a4/32.png) [@CodeGod](https://community.bitquery.io/u/CodeGod)\
**Post date:** [August 14, 2021, 2:56pm UTC](https://community.bitquery.io/t/get-latest-transactions-and-aggregate-to-get-sell-and-buy-amounts/163/6 "2021-08-14T14:56:25Z")

</div>

> [@gaurav](#):
>
> `"2021-06-12T19:00:00"`

Hey Gaurav sorry for the late reply! Some personal stuff going on… ☹  
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):

```auto
      {
        "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](https://poocoin.app/tokens/0x609d183fb91a0fce59550b62ab7d2c931b0bb1be). 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?

---

<div class="post-metadata">

**Author:** ![sayon](https://avatars.discourse-cdn.com/v4/letter/s/b2d939/32.png) [@sayon](https://community.bitquery.io/u/sayon)\
**Post date:** [August 16, 2021, 3:42am UTC](https://community.bitquery.io/t/get-latest-transactions-and-aggregate-to-get-sell-and-buy-amounts/163/7 "2021-08-16T03:42:34Z")

</div>

You can convert them into USD and check their values.

```auto
{
  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)
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![CodeGod](https://avatars.discourse-cdn.com/v4/letter/c/ac91a4/32.png) [@CodeGod](https://community.bitquery.io/u/CodeGod)\
**Post date:** [August 20, 2021, 10:18am UTC](https://community.bitquery.io/t/get-latest-transactions-and-aggregate-to-get-sell-and-buy-amounts/163/8 "2021-08-20T10:18:03Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![CodeGod](https://avatars.discourse-cdn.com/v4/letter/c/ac91a4/32.png) [@CodeGod](https://community.bitquery.io/u/CodeGod)\
**Post date:** [August 26, 2021, 4:55pm UTC](https://community.bitquery.io/t/get-latest-transactions-and-aggregate-to-get-sell-and-buy-amounts/163/9 "2021-08-26T16:55:18Z")

</div>

Any idea about the above?

---

<div class="post-metadata">

**Author:** ![CodeGod](https://avatars.discourse-cdn.com/v4/letter/c/ac91a4/32.png) [@CodeGod](https://community.bitquery.io/u/CodeGod)\
**Post date:** [September 3, 2021, 12:39pm UTC](https://community.bitquery.io/t/get-latest-transactions-and-aggregate-to-get-sell-and-buy-amounts/163/10 "2021-09-03T12:39:52Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![sayon](https://avatars.discourse-cdn.com/v4/letter/s/b2d939/32.png) [@sayon](https://community.bitquery.io/u/sayon)\
**Post date:** [September 4, 2021, 9:27am UTC](https://community.bitquery.io/t/get-latest-transactions-and-aggregate-to-get-sell-and-buy-amounts/163/11 "2021-09-04T09:27:19Z")

</div>

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