# dexTrades time filter and data aggregation question

**URL:** <https://community.bitquery.io/t/dextrades-time-filter-and-data-aggregation-question/66>\
**Category:** GraphQL API\
**Tags:** closed\
**Created:** [May 25, 2021, 6:09am UTC](https://community.bitquery.io/t/dextrades-time-filter-and-data-aggregation-question/66 "2021-05-25T06:09:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![kfish](https://sea2.discourse-cdn.com/flex016/user_avatar/community.bitquery.io/kfish/32/21_2.png) [@kfish](https://community.bitquery.io/u/kfish)\
**Post date:** [May 25, 2021, 6:09am UTC](https://community.bitquery.io/t/dextrades-time-filter-and-data-aggregation-question/66/1 "2021-05-25T06:09:36Z")

</div>

Love bitquery, been playing around with this for a while and learned a lot. I’m stuck with something though, I’m trying to aggregate data of dex trades for different time ranges and I’m not sure how to achieve this. For example, I’d like to get the sum of tradeAmount, buyAmount, sellAmount, trades, sum of unique senders for the past 7 minutes. I have tried setting the time (now - 7 minutes for in format YYY-MM-DDTHH:MM:SSZ example) filter but the results are not what I expected 🤔 any help would be greatly appreciated.

Here is my current query, it’s basically the same query but with different times ( time: {since: “2021-05-24T22:17Z”}, time: {since: “2021-05-24T22:24Z”}, time: {since: “2021-05-24T21:24Z”}). All three queries are returning the same data.

```
{
  ethereum(network: bsc) {
    test1:dexTrades(
      time: {since: "2021-05-24T22:17Z"}
      options: {limitBy: {each: "baseCurrency.symbol", limit: 1}}
      exchangeName: {in: ["Pancake", "Pancake v2"]}
      baseCurrency: {is: "0xe9e7cea3dedca5984780bafc599bd69add087d56"}
      quoteCurrency: {is: "0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c"}
      tradeAmountUsd: {gt: 1}
    ) {
      baseCurrency {
        symbol
      }
      buyCurrency {
        symbol
      }
      sellCurrency {
        symbol
      }
      tradeAmount(calculate: sum, in: USD)
      buyAmount(calculate: sum)
      sellAmount(calculate: sum)
      trades: count(uniq: txs)
      uniqueSenders: count(uniq: senders)
      maximum_price: quotePrice(calculate: maximum)
      minimum_price: quotePrice(calculate: minimum)
      open_price: minimum(of: block, get: quote_price)
      close_price: maximum(of: block, get: quote_price)
    }
    test2:dexTrades(
      time: {since: "2021-05-24T22:24Z"}
      options: {limitBy: {each: "baseCurrency.symbol", limit: 1}}
      exchangeName: {in: ["Pancake", "Pancake v2"]}
      baseCurrency: {is: "0xe9e7cea3dedca5984780bafc599bd69add087d56"}
      quoteCurrency: {is: "0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c"}
      tradeAmountUsd: {gt: 1}
    ) {
      baseCurrency {
        symbol
      }
      buyCurrency {
        symbol
      }
      sellCurrency {
        symbol
      }
      tradeAmount(calculate: sum, in: USD)
      buyAmount(calculate: sum)
      sellAmount(calculate: sum)
      trades: count(uniq: txs)
      uniqueSenders: count(uniq: senders)
      maximum_price: quotePrice(calculate: maximum)
      minimum_price: quotePrice(calculate: minimum)
      open_price: minimum(of: block, get: quote_price)
      close_price: maximum(of: block, get: quote_price)
    }
    test3:dexTrades(
      time: {since: "2021-05-24T21:24Z"}
      options: {limitBy: {each: "baseCurrency.symbol", limit: 1}}
      exchangeName: {in: ["Pancake", "Pancake v2"]}
      baseCurrency: {is: "0xe9e7cea3dedca5984780bafc599bd69add087d56"}
      quoteCurrency: {is: "0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c"}
      tradeAmountUsd: {gt: 1}
    ) {
      baseCurrency {
        symbol
      }
      buyCurrency {
        symbol
      }
      sellCurrency {
        symbol
      }
      tradeAmount(calculate: sum, in: USD)
      buyAmount(calculate: sum)
      sellAmount(calculate: sum)
      trades: count(uniq: txs)
      uniqueSenders: count(uniq: senders)
      maximum_price: quotePrice(calculate: maximum)
      minimum_price: quotePrice(calculate: minimum)
      open_price: minimum(of: block, get: quote_price)
      close_price: maximum(of: block, get: quote_price)
    }
  }
}
```

---

<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:** [May 25, 2021, 7:57am UTC](https://community.bitquery.io/t/dextrades-time-filter-and-data-aggregation-question/66/2 "2021-05-25T07:57:06Z")

</div>

Try following query

```
{
  ethereum(network: bsc) {
    test1:dexTrades(
      time: {between: ["2021-05-24T01:00:00Z","2021-05-24T01:07:00Z"]}
      options: {limitBy: {each: "baseCurrency.symbol", limit: 1}}
      exchangeName: {in: ["Pancake", "Pancake v2"]}
      baseCurrency: {is: "0xe9e7cea3dedca5984780bafc599bd69add087d56"}
      quoteCurrency: {is: "0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c"}
      tradeAmountUsd: {gt: 1}
    ) {
      baseCurrency {
        symbol
      }
      buyCurrency {
        symbol
      }
      sellCurrency {
        symbol
      }
      tradeAmount(calculate: sum, in: USD)
      buyAmount(calculate: sum)
      sellAmount(calculate: sum)
      trades: count(uniq: txs)
      uniqueSenders: count(uniq: senders)
      maximum_price: quotePrice(calculate: maximum)
      minimum_price: quotePrice(calculate: minimum)
      open_price: minimum(of: block, get: quote_price)
      close_price: maximum(of: block, get: quote_price)
    }
  }
}
```

---

<div class="post-metadata">

**Author:** ![kfish](https://sea2.discourse-cdn.com/flex016/user_avatar/community.bitquery.io/kfish/32/21_2.png) [@kfish](https://community.bitquery.io/u/kfish)\
**Post date:** [May 25, 2021, 8:02am UTC](https://community.bitquery.io/t/dextrades-time-filter-and-data-aggregation-question/66/3 "2021-05-25T08:02:57Z")

</div>

The between did the trick! Thank you very much. Any resources or documentation available where I can find these little but impactful details? 🙂

---

<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:** [May 25, 2021, 9:11am UTC](https://community.bitquery.io/t/dextrades-time-filter-and-data-aggregation-question/66/4 "2021-05-25T09:11:50Z")

</div>

Just check the example APIs and the schema on our [GraphQL IDE](http://graphql.bitquery.io/)
