-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathswap_volume_since_midnight.py
35 lines (30 loc) · 3.03 KB
/
swap_volume_since_midnight.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import requests
def run_query(q):
request = requests.post(
'https://api.thegraph.com/subgraphs/name/sushiswap/exchange'
'',
json={'query': query})
if request.status_code == 200:
return request.json()
else:
raise Exception(f'Query failed. return code is {request.status_code}. {query}')
query = '''{
swaps(
where: {
pair: "0x055475920a8c93cffb64d039a8205f7acc7722d3",
timestamp_gte: 1661130000
}
orderBy: timestamp,
orderDirection: desc
) {
amountUSD
transaction {
timestamp
}
}
}'''
result = run_query(query)
n = 0
for i in result['data']['swaps']:
n += float(i['amountUSD'])
print(n)