-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmain.py
62 lines (55 loc) · 2 KB
/
main.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
# https://thegraph.com/hosted-service/subgraph/uniswap/uniswap-v3
import requests
import json
import functions
"""
Retrieve GraphQL mid prices for uniswap
API result sample: [
{
"id": "0x277667eb3e34f134adf870be9550e9f323d0dc24",
"totalValueLockedETH": "834419413.0127326409251168468344917",
"token0Price": "10201983.52821130596040573863212092",
"token1Price": "0.00000009802015433907763482013950488687576",
"feeTier": "100",
"token0": {
"id": "0x160de4468586b6b2f8a92feb0c260fc6cfc743b1",
"symbol": "ease.org",
"name": "Ease Fun Token",
"decimals": "18"
},
"token1": {
"id": "0xea5edef1c6ed1be1bcba4617a1c5a994e9018a43",
"symbol": "ez-cvxsteCRV",
"name": "cvxsteCRV Ease Vault",
"decimals": "18"
}
}
...
]
"""
def retrieve_uniswap_information():
url = "https://api.thegraph.com/subgraphs/name/uniswap/uniswap-v3"
query = """query {
pools(orderBy: totalValueLockedETH, orderDirection: desc, first: 500) {
id totalValueLockedETH token0Price token1Price feeTier
token0 { id symbol name decimals }
token1 { id symbol name decimals }
}
}"""
req = requests.post(url, json={'query': query})
json_dictionary = json.loads(req.text)
return json_dictionary
if __name__ == '__main__':
pairs = retrieve_uniswap_information()['data']['pools']
structured_pairs = functions.structure_trading_pairs(pairs, limit=500)
# Get surface rates
surface_rate_list = []
for t_pair in structured_pairs:
surface_rate = functions.calculate_triangular_arbitrage_surface_rate(t_pair, min_rate=1.5)
if len(surface_rate) > 0:
surface_rate_list.append(surface_rate)
# Save to JSON file
if len(surface_rate_list) > 0:
with open('uniswap_surface_rates.json', 'w') as fp:
json.dump(surface_rate_list, fp)
print('file saved')