-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathxangle.py
More file actions
184 lines (172 loc) · 6.15 KB
/
xangle.py
File metadata and controls
184 lines (172 loc) · 6.15 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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
import os
from typing import Dict, List
import requests
class Xangle(object):
def __init__(self, api_key: str = os.environ.get("XANGLE_API_KEY", None)) -> None:
super().__init__()
if api_key is None:
raise ValueError(
"An API key is required to interact with the Xangle API.\nProvide one to the api_key parameter or by setting the environment variable 'XANGLE_API_KEY'."
)
# self.api_key = api_key
self.headers = {"X-XANGLE_API_KEY": api_key}
self.baseurl = "https://pro-api.xangle.io/v1/"
# https://pro-api.xangle.io/#operation/project-list
def get_project_list(
self,
page: int = 0
) -> Dict:
try:
response = requests.get(
"https://pro-api.xangle.io/v1/project/list",
headers=self.headers,
params={"page": page},
)
return response.json()
except requests.exceptions.ConnectionError as e:
return {"error": f"{e}"}
# https://pro-api.xangle.io/#operation/project-list
def search_project(
self,
search_type: str,
symbol: str = None,
token_address: str = None,
) -> Dict:
try:
response = requests.get(
"https://pro-api.xangle.io/v1/project/search",
headers=self.headers,
params={"search_type": search_type, "symbol": symbol, "token_address": token_address},
)
return response.json()
except requests.exceptions.ConnectionError as e:
return {"error": f"{e}"}
# https://pro-api.xangle.io/#operation/disclosure-detail
def get_disclosure_detail(
self,
disclosure_id: str,
lang: str = "en"
) -> Dict:
try:
response = requests.get(
"https://pro-api.xangle.io/v1/disclosure/detail",
headers=self.headers,
params={"disclosure_id": disclosure_id, "lang": lang},
)
return response.json()
except requests.exceptions.ConnectionError as e:
return {"error": f"{e}"}
# https://pro-api.xangle.io/#operation/disclosure-list-all
def get_disclosure_list_all(
self,
lang: str = "en",
page: int = 0,
project_ids: List[str] = [],
exchange: str = None,
exclude_types: List[str] = [],
) -> Dict:
try:
response = requests.get(
"https://pro-api.xangle.io/v1/disclosure/list/all",
headers=self.headers,
params={
"lang": lang,
"page": page,
"project_ids": project_ids,
"exchange": exchange,
"exclude_types": exclude_types,
},
)
return response.json()
except requests.exceptions.ConnectionError as e:
return {"error": f"{e}"}
# https://pro-api.xangle.io/#operation/disclosure-list-project
def get_disclosure_list_project(
self,
project_ids: str,
lang: str = "en",
page: int = 0,
exclude_types: List[str] = [],
) -> Dict:
try:
response = requests.get(
"https://pro-api.xangle.io/v1/disclosure/list/project",
headers=self.headers,
params={
"project_ids": project_ids,
"lang": lang,
"page": page,
"exclude_types": exclude_types,
},
)
return response.json()
except requests.exceptions.ConnectionError as e:
return {"error": f"{e}"}
# https://pro-api.xangle.io/v1/index/xangle-bluechip
def get_xangle_bluechip(
self,
reference_timestamp: str
) -> Dict:
try:
response = requests.get(
"https://pro-api.xangle.io/v1/index/xangle-bluechip",
headers=self.headers,
params={
"reference_timestamp": reference_timestamp
},
)
return response.json()
except requests.exceptions.ConnectionError as e:
return {"error": f"{e}"}
# https://pro-api.xangle.io/v1/index/xangle-bluechip-batch
def get_xangle_bluechip_batch(
self,
start_timestamp: str,
end_timestamp: str
) -> Dict:
try:
response = requests.get(
"https://pro-api.xangle.io/v1/index/xangle-bluechip-batch",
headers=self.headers,
params={
"start_timestamp": start_timestamp,
"end_timestamp": end_timestamp
},
)
return response.json()
except requests.exceptions.ConnectionError as e:
return {"error": f"{e}"}
# https://pro-api.xangle.io/v1/index/xangle-bluechip-batch
def get_xangle_bluechip_batch(
self,
start_timestamp: str,
end_timestamp: str
) -> Dict:
try:
response = requests.get(
"https://pro-api.xangle.io/v1/index/xangle-bluechip-batch",
headers=self.headers,
params={
"start_timestamp": start_timestamp,
"end_timestamp": end_timestamp
},
)
return response.json()
except requests.exceptions.ConnectionError as e:
return {"error": f"{e}"}
# https://pro-api.xangle.io/v1/index/xangle-largecap
def get_xangle_largecap(
self,
reference_timestamp: str
) -> Dict:
try:
response = requests.get(
"https://pro-api.xangle.io/v1/index/xangle-largecap",
headers=self.headers,
params={
"reference_timestamp": reference_timestamp
},
)
return response.json()
except requests.exceptions.ConnectionError as e:
return {"error": f"{e}"}