-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
67 lines (64 loc) · 1.64 KB
/
test.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
def lookDecimals(pool,symbol):
return pool.loc[symbol]['decimals']
class Aave:
def __init__(self,url=AAVE_API):
self.client = client(url)
query='''query{
reserves(first: 1000,subgraphError: allow) {
id
underlyingAsset
symbol
decimals
}
}'''
cli = self.client
response = cli.execute(gql(query))
data=pd.json_normalize(response['reserves'])
data=data.set_index('symbol')
self.pools=data
def getLenders(self, reserveid):
query='''query($reserveID:ID!,$lastID:ID!) {
userReserves(
first: 1000
where: {reserve_contains: $reserveID, id_gt:$lastID}
orderBy: currentATokenBalance
orderDirection: desc
) {
reserve {
id
name
symbol
aToken {
id
pool {
id
lendingPool
}
}
}
currentATokenBalance
currentStableDebt
currentTotalDebt
user {
id
}
}
}'''
cli=self.client
lastid=0
finished = 0
agg = pd.DataFrame()
while (finished == 0):
try:
params = {
"reserveID": reserveid,
"lastID":lastid
}
res = cli.execute(gql(query),variable_values=params)
res=pd.json_normalize(res['userReserves'])
if (len(res) == 0):
return agg
agg=agg.append(res)
lastid=res.iloc[-1]['id']
except:
return agg