dexTrades time filter and data aggregation question

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 :thinking: 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)
    }
  }
}

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

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

Just check the example APIs and the schema on our GraphQL IDE