-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathv2DataPull.py
More file actions
71 lines (60 loc) · 1.61 KB
/
Copy pathv2DataPull.py
File metadata and controls
71 lines (60 loc) · 1.61 KB
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
from python_graphql_client import GraphqlClient
from Tick import *
import matplotlib.pyplot as plt
from SqrtPriceMath import *
from TickList import *
import constants
client = GraphqlClient(endpoint="https://api.thegraph.com/subgraphs/name/uniswap/uniswap-v2")
usdcETH = "0xb4e16d0168e52d35cacd2c6185b44281ec28c9dc"
poolAddress = usdcETH
pairData = """
query pair($poolAddress: String!) {
pair(id: $poolAddress) {
token0 {
symbol
id
decimals
}
token1 {
symbol
id
decimals
}
reserveUSD
volumeUSD
liquidityProviderCount
}
}
"""
swapQuery = """
query swaps($poolAddress: String!) {
transactions(first: 400, orderBy: blockNumber, orderDirection: desc) {
swaps(where: {pair:"0xb4e16d0168e52d35cacd2c6185b44281ec28c9dc"} ){
amountUSD
amount0In
amount1In
amount0Out
amount0In
transaction{
blockNumber
timestamp
}
}
}
}
"""
def getReserveUSD():
pairDataQuery = client.execute(query=pairData, variables={"poolAddress": poolAddress} )
reserveUSD = float(pairDataQuery['data']['pair']['reserveUSD'])
return reserveUSD
def getSwaps():
swapsReturn = []
swapQueryData = client.execute(query=swapQuery, variables={"poolAddress": poolAddress} )
swaps = swapQueryData['data']['transactions']
for swap in swaps:
if swap != {'swaps': []}:
for s in swap['swaps']:
newSwap = Swap(0, 0, float(s['amountUSD']), 0, 0, 0, 0, int(s['transaction']['blockNumber']))
swapsReturn.append(newSwap)
return swapsReturn
getSwaps()