-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathGraphBacktest.py
78 lines (65 loc) · 1.71 KB
/
GraphBacktest.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
from gql import gql, Client
from gql.transport.requests import RequestsHTTPTransport
import pandas as pd
def graph(network,Adress,fromdate):
if network == 1:
sample_transport=RequestsHTTPTransport(
url='https://api.thegraph.com/subgraphs/name/uniswap/uniswap-v3',
verify=True,
retries=5,
)
client = Client(
transport=sample_transport
)
elif network == 2:
sample_transport=RequestsHTTPTransport(
url='https://api.thegraph.com/subgraphs/name/ianlapham/uniswap-arbitrum-one',
verify=True,
retries=5,
)
client = Client(
transport=sample_transport
)
elif network == 3:
sample_transport=RequestsHTTPTransport(
url='https://api.thegraph.com/subgraphs/name/ianlapham/uniswap-optimism-dev',
verify=True,
retries=5,
)
client = Client(
transport=sample_transport
)
print(fromdate)
query = gql('''
query ($fromdate: Int!)
{
poolHourDatas(where:{pool:"'''+str(Adress)+'''",periodStartUnix_gt:$fromdate},orderBy:periodStartUnix,orderDirection:desc,first:1000)
{
periodStartUnix
liquidity
high
low
pool{
totalValueLockedUSD
totalValueLockedToken1
totalValueLockedToken0
token0
{decimals
}
token1
{decimals
}
}
close
feeGrowthGlobal0X128
feeGrowthGlobal1X128
}
}
''')
params = {
"fromdate": fromdate
}
response = client.execute(query,variable_values=params)
dpd =pd.json_normalize(response['poolHourDatas'])
dpd=dpd.astype(float)
return dpd