# Average value of a SmartContractEvent argument, for x period

**URL:** <https://community.bitquery.io/t/average-value-of-a-smartcontractevent-argument-for-x-period/164>\
**Category:** GraphQL API\
**Tags:** closed\
**Created:** [June 12, 2021, 2:36pm UTC](https://community.bitquery.io/t/average-value-of-a-smartcontractevent-argument-for-x-period/164 "2021-06-12T14:36:01Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![chiron](https://sea2.discourse-cdn.com/flex016/user_avatar/community.bitquery.io/chiron/32/51_2.png) [@chiron](https://community.bitquery.io/u/chiron)\
**Post date:** [June 12, 2021, 2:36pm UTC](https://community.bitquery.io/t/average-value-of-a-smartcontractevent-argument-for-x-period/164/1 "2021-06-12T14:36:01Z")

</div>

hi guys, i’m trying to calculate the individual averages for 4 arguments, from a smartContractEvent, for a period (1 day). Using this formula.  
I have the actual averages of these 4 arguments, and this isn’t returning the correct numbers.  
Where am I going wrong?

```auto
query MyQuery {
  ethereum {
    arguments(
      smartContractAddress: {is: "0x0EF1B8a0E726Fc3948E15b23993015eB1627f210"}
      smartContractEvent: {is: "Sync"}
      options: {desc: "date.date"}
      date: {is: "21-06-12"}
    ) {
       date {
        date(format: "%y-%m-%d")
      }
      SwapFee: number(argument: {is: "fee"}, calculate: average)
      PriceImpactFee: number(argument: {is: "slippageFee"}, calculate: average)
      ReferralShare: number(argument: {is: "referralShare"}, calculate: average)
      GovernanceShare: number(argument: {is: "governanceShare"}, calculate: average)
      
    }
  }
}

```

---

<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:38am UTC](https://community.bitquery.io/t/average-value-of-a-smartcontractevent-argument-for-x-period/164/2 "2021-06-13T06:38:06Z")

</div>

Is this what you looking for?

```auto
{
  ethereum(network: ethereum) {
    arguments(
      smartContractAddress: {in: "0x0EF1B8a0E726Fc3948E15b23993015eB1627f210"}
      smartContractEvent: {is: "Sync"}
      date: {is: "21-06-12"}
    ) {
      SwapFee: number(argument: {is: "fee"}, calculate: average)
      PriceImpactFee: number(argument: {is: "slippageFee"}, calculate: average)
      ReferralShare: number(argument: {is: "referralShare"}, calculate: average)
      GovernanceShare: number(argument: {is: "governanceShare"}, calculate: average)
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![chiron](https://sea2.discourse-cdn.com/flex016/user_avatar/community.bitquery.io/chiron/32/51_2.png) [@chiron](https://community.bitquery.io/u/chiron)\
**Post date:** [June 13, 2021, 11:03am UTC](https://community.bitquery.io/t/average-value-of-a-smartcontractevent-argument-for-x-period/164/3 "2021-06-13T11:03:32Z")

</div>

this actually gives the same results as my the top query.  
I used the query below to get each block’s fee actual fee number, for the whole day.  
Averaged that result, and it doesn’t match to the queries above.

Code here… Which of one these queries provides the correct value?

============================================  
query MyQuery {  
ethereum {  
arguments(  
smartContractAddress: {is: “0x0EF1B8a0E726Fc3948E15b23993015eB1627f210”}  
smartContractEvent: {is: “Sync”}  
options: {desc: “block.timestamp.unixtime”}  
date: {is: “21-06-10”}  
) {  
block {  
height  
timestamp {  
unixtime  
}  
}  
index  
SwapFee: any(of: argument\_value, argument: {is: “fee”})  
PriceImpactFee: any(of: argument\_value, argument: {is: “slippageFee”})  
ReferralShare: any(of: argument\_value, argument: {is: “referralShare”})  
GovernanceShare: any(of: argument\_value, argument: {is: “governanceShare”})  
}  
}  
}

---

<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:54am UTC](https://community.bitquery.io/t/average-value-of-a-smartcontractevent-argument-for-x-period/164/4 "2021-06-14T06:54:14Z")

</div>

> [@chiron](#):
>
> this actually gives the same results as my the top query.  
> I used the query below to get each block’s fee actual fee number, for the whole day.  
> Averaged that result, and it doesn’t match to the queries above.

Date is different in the query mention.

---

<div class="post-metadata">

**Author:** ![chiron](https://sea2.discourse-cdn.com/flex016/user_avatar/community.bitquery.io/chiron/32/51_2.png) [@chiron](https://community.bitquery.io/u/chiron)\
**Post date:** [June 14, 2021, 1:30pm UTC](https://community.bitquery.io/t/average-value-of-a-smartcontractevent-argument-for-x-period/164/5 "2021-06-14T13:30:48Z")

</div>

Yes thanks. But i ran all the queries on the 10th and the numbers don’t match up.  
Just wanting to check to make sure the last formula I pasted, does what its meant to.  
So there, trying to sum all the argument values for each event for 1 day

---

<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 15, 2021, 5:26am UTC](https://community.bitquery.io/t/average-value-of-a-smartcontractevent-argument-for-x-period/164/6 "2021-06-15T05:26:17Z")

</div>

> [@chiron](#):
>
> query MyQuery {  
> ethereum {  
> arguments(  
> smartContractAddress: {is: “0x0EF1B8a0E726Fc3948E15b23993015eB1627f210”}  
> smartContractEvent: {is: “Sync”}  
> options: {desc: “block.timestamp.unixtime”}  
> date: {is: “21-06-10”}  
> ) {  
> block {  
> height  
> timestamp {  
> unixtime  
> }  
> }  
> index  
> SwapFee: any(of: argument\_value, argument: {is: “fee”})  
> PriceImpactFee: any(of: argument\_value, argument: {is: “slippageFee”})  
> ReferralShare: any(of: argument\_value, argument: {is: “referralShare”})  
> GovernanceShare: any(of: argument\_value, argument: {is: “governanceShare”})  
> }  
> }  
> }

This don’t give me any result, check here [getting events block by block](https://graphql.bitquery.io/ide/V7cWkD1p33)

---

<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 15, 2021, 5:27am UTC](https://community.bitquery.io/t/average-value-of-a-smartcontractevent-argument-for-x-period/164/7 "2021-06-15T05:27:26Z")

</div>

> [@chiron](#):
>
> Just wanting to check to make sure the last formula I pasted, does what its meant to.  
> So there, trying to sum all the argument values for each event for 1 day

I believe it will give you 1 event per block… can you confirm?

If not check it if give string or number?

---

<div class="post-metadata">

**Author:** ![chiron](https://sea2.discourse-cdn.com/flex016/user_avatar/community.bitquery.io/chiron/32/51_2.png) [@chiron](https://community.bitquery.io/u/chiron)\
**Post date:** [June 15, 2021, 12:35pm UTC](https://community.bitquery.io/t/average-value-of-a-smartcontractevent-argument-for-x-period/164/8 "2021-06-15T12:35:14Z")

</div>

from my results “block\_height”, there are no duplicates of any block in the repsonse.  
Not sure if that is conclusive.  
What code would I use to return every occurrence of an smartContractEvent?

---

<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 15, 2021, 4:21pm UTC](https://community.bitquery.io/t/average-value-of-a-smartcontractevent-argument-for-x-period/164/9 "2021-06-15T16:21:25Z")

</div>

I believe then it’s only showing 1 event per block, therefore it not taking all the events into the account, therefore you are getting different results.

---

<div class="post-metadata">

**Author:** ![chiron](https://sea2.discourse-cdn.com/flex016/user_avatar/community.bitquery.io/chiron/32/51_2.png) [@chiron](https://community.bitquery.io/u/chiron)\
**Post date:** [June 16, 2021, 3:06am UTC](https://community.bitquery.io/t/average-value-of-a-smartcontractevent-argument-for-x-period/164/10 "2021-06-16T03:06:03Z")

</div>

How would you suggest i order the results, to disregard block?  
So that multiple results from within 1 block are returned…

---

<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 16, 2021, 9:23am UTC](https://community.bitquery.io/t/average-value-of-a-smartcontractevent-argument-for-x-period/164/11 "2021-06-16T09:23:26Z")

</div>

You can either average the results Like shown in the very first answer by me…

or get all results, use query below

```auto
query MyQuery {
  ethereum {
    smartContractEvents(
      smartContractAddress: {is: "0x0EF1B8a0E726Fc3948E15b23993015eB1627f210"}
      smartContractEvent: {is: "Sync"}
      date: {is: "21-06-10"}
    ) {
      arguments {
        argument
        argumentType
        value
      }
    }
  }
}

```

However need to check how to sort it… will update on that soon

---

<div class="post-metadata">

**Author:** ![chiron](https://sea2.discourse-cdn.com/flex016/user_avatar/community.bitquery.io/chiron/32/51_2.png) [@chiron](https://community.bitquery.io/u/chiron)\
**Post date:** [June 17, 2021, 4:18pm UTC](https://community.bitquery.io/t/average-value-of-a-smartcontractevent-argument-for-x-period/164/12 "2021-06-17T16:18:18Z")

</div>

> [@gaurav](#):
>

hi Gaurav, your suggestion returns, a list of all the arguments, for a particular event. This is handy for verification purposes. However, I was after all occurrences of a particular event, on a given day. Perhaps filtered by argument (if too hard, not necessary).

---

<div class="post-metadata">

**Author:** ![chiron](https://sea2.discourse-cdn.com/flex016/user_avatar/community.bitquery.io/chiron/32/51_2.png) [@chiron](https://community.bitquery.io/u/chiron)\
**Post date:** [June 17, 2021, 4:30pm UTC](https://community.bitquery.io/t/average-value-of-a-smartcontractevent-argument-for-x-period/164/13 "2021-06-17T16:30:12Z")

</div>

think i have sorted out, all good
