-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathLecture5c.py
79 lines (62 loc) · 1.14 KB
/
Lecture5c.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import pandas as pd
from gql import gql, Client
from gql.transport.requests import RequestsHTTPTransport
#---------- Extract data from Uniswap Subgraph ----------
sample_transport=RequestsHTTPTransport(
url='https://api.thegraph.com/subgraphs/name/uniswap/uniswap-v2',
verify=True,
retries=3,
)
client = Client(
transport=sample_transport
)
query = gql('''
query {
pairs (first: 5) {
token0 {
symbol
}
token1 {
symbol
}
}
}
''')
response1 = client.execute(query)
print(response1)
print(response1['pairs'])
pairs = []
for i in response1['pairs']:
pairs.append([
i['token0']['symbol'],
i['token1']['symbol'],
])
print(pairs)
df = pd.DataFrame(pairs)
print(df)
query = gql('''
query {
pairs (first: 10, where: {volumeUSD_gt: "100000" })
{
volumeUSD
token0 {
symbol
}
token1 {
symbol
}
}
}
''')
response2 = client.execute(query)
print()
print()
pairs = []
for i in response2['pairs']:
pairs.append([
i['token0']['symbol'],
i['token1']['symbol'],
i['volumeUSD']
])
df = pd.DataFrame(pairs)
print(df)