Repository navigation
Expand file tree
/
Copy pathdextools_v2.py
More file actions
155 lines (130 loc) · 6.75 KB
/
Copy pathdextools_v2.py
File metadata and controls
155 lines (130 loc) · 6.75 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
import requests
import logging
logger = logging.getLogger(__name__)
class DextoolsAPIV2:
def __init__(self, api_key, useragent="API-Wrapper/0.3", plan="partner"):
self._api_key = api_key
self._useragent = useragent
self.plan = None
self.set_plan(plan)
def set_plan(self, plan):
# python versions older than 3.10 don't support switch/case statements, using if elif instead
plan = plan.lower()
plans = ["free", "trial", "standard", "advanced", "pro"]
if plan in plans:
self.plan = plan
self.url = f"http://public-api.dextools.io/{plan}/v2"
self._headers = {"X-API-Key": self._api_key, "accept": "application/json", "User-Agent": self._useragent}
elif plan == "partner":
self.plan = plan
self.url = f"https://api.dextools.io/v2"
self._headers = {"X-API-Key": self._api_key, "accept": "application/json", "User-Agent": self._useragent}
else:
raise Exception("Plan not found")
logger.debug(f"Plan url: {self.url}")
logger.info(f"Set up plan: {plan}")
def get_blockchain(self, chain):
endpoint = "/blockchain/"
response = requests.get(self.url + endpoint + chain, headers=self._headers)
logger.debug(response.url)
return response.json()
def get_blockchains(self, order="asc", sort="name", page=None, pageSize=None):
endpoint = "/blockchain"
response = requests.get(self.url + endpoint, params={"order": order, "sort": sort, "page": page, "pageSize": pageSize}, headers=self._headers)
logger.debug(response.url)
return response.json()
def get_dex_factory_info(self, chain, address):
endpoint = "/dex/"
response = requests.get(f"{self.url}{endpoint}{chain}/{address}", headers=self._headers)
logger.debug(response.url)
return response.json()
def get_dexes(self, chain, order="asc", sort="name", page=None, pageSize=None):
endpoint = "/dex/"
response = requests.get(self.url + endpoint + chain, params={"order": order, "sort": sort, "page": page, "pageSize": pageSize}, headers=self._headers)
logger.debug(response.url)
return response.json()
def get_pool(self, chain, address):
endpoint = "/pool/"
response = requests.get(f"{self.url}{endpoint}{chain}/{address}", headers=self._headers)
logger.debug(response.url)
return response.json()
def get_pool_liquidity(self, chain, address):
endpoint = "/pool/"
response = requests.get(f"{self.url}{endpoint}{chain}/{address}/liquidity", headers=self._headers)
logger.debug(response.url)
return response.json()
def get_pool_score(self, chain, address):
endpoint = "/pool/"
response = requests.get(f"{self.url}{endpoint}{chain}/{address}/score", headers=self._headers)
logger.debug(response.url)
return response.json()
def get_pool_price(self, chain, address):
endpoint = "/pool/"
response = requests.get(f"{self.url}{endpoint}{chain}/{address}/price", headers=self._headers)
logger.debug(response.url)
return response.json()
def get_pool_locks(self, chain, address):
endpoint = "/pool/"
response = requests.get(f"{self.url}{endpoint}{chain}/{address}/locks", headers=self._headers)
logger.debug(response.url)
return response.json()
def get_pools(self, chain, from_, to, order="asc", sort="creationTime", page=None, pageSize=None):
endpoint = "/pool/"
response = requests.get(self.url + endpoint + chain, params={"order": order, "sort": sort, "from": from_, "to": to, "page": page, "pageSize": pageSize}, headers=self._headers)
logger.debug(response.url)
return response.json()
def get_token(self, chain, address):
endpoint = "/token/"
response = requests.get(f"{self.url}{endpoint}{chain}/{address}", headers=self._headers)
logger.debug(response.url)
return response.json()
def get_token_locks(self, chain, address):
endpoint = "/token/"
response = requests.get(f"{self.url}{endpoint}{chain}/{address}/locks", headers=self._headers)
logger.debug(response.url)
return response.json()
def get_token_score(self, chain, address):
endpoint = "/token/"
response = requests.get(f"{self.url}{endpoint}{chain}/{address}/score", headers=self._headers)
logger.debug(response.url)
return response.json()
def get_token_info(self, chain, address):
endpoint = "/token/"
response = requests.get(f"{self.url}{endpoint}{chain}/{address}/info", headers=self._headers)
logger.debug(response.url)
return response.json()
def get_token_price(self, chain, address):
endpoint = "/token/"
response = requests.get(f"{self.url}{endpoint}{chain}/{address}/price", headers=self._headers)
logger.debug(response.url)
return response.json()
def get_token_audit(self, chain, address):
endpoint = "/token/"
response = requests.get(f"{self.url}{endpoint}{chain}/{address}/audit", headers=self._headers)
logger.debug(response.url)
return response.json()
def get_tokens(self, chain, from_, to, order="asc", sort="socialsInfoUpdated", page=None, pageSize=None):
endpoint = "/token/"
response = requests.get(self.url + endpoint + chain, params={"order": order, "sort": sort, "from": from_, "to": to, "page": page, "pageSize": pageSize}, headers=self._headers)
logger.debug(response.url)
return response.json()
def get_token_pools(self, chain, address, from_, to, order="asc", sort="creationTime", page=None, pageSize=None):
endpoint = "/token/"
response = requests.get(f"{self.url}{endpoint}{chain}/{address}/pools", params={"order": order, "sort": sort, "from": from_, "to": to, "page": page, "pageSize": pageSize}, headers=self._headers)
logger.debug(response.url)
return response.json()
def get_ranking_hotpools(self, chain):
endpoint = "/ranking/"
response = requests.get(f"{self.url}{endpoint}{chain}/hotpools", headers=self._headers)
logger.debug(response.url)
return response.json()
def get_ranking_gainers(self, chain):
endpoint = "/ranking/"
response = requests.get(f"{self.url}{endpoint}{chain}/gainers", headers=self._headers)
logger.debug(response.url)
return response.json()
def get_ranking_losers(self, chain):
endpoint = "/ranking/"
response = requests.get(f"{self.url}{endpoint}{chain}/losers", headers=self._headers)
logger.debug(response.url)
return response.json()