|
1
|
|
|
from typing import Union, List, Optional |
|
2
|
|
|
from tradehub.decentralized_client import NetworkCrawlerClient |
|
3
|
|
|
|
|
4
|
|
|
|
|
5
|
|
|
class PublicBlockchainClient(NetworkCrawlerClient): |
|
6
|
|
|
""" |
|
7
|
|
|
This class allows the user to interact with the TradeScan API including information |
|
8
|
|
|
available with validators, tokens, delegators, addresses, and blockchain stats. |
|
9
|
|
|
""" |
|
10
|
|
|
|
|
11
|
|
|
def __init__(self, network: str = "testnet", trusted_ips: Union[None, list] = None, trusted_uris: Union[None, list] = None, is_websocket_client: bool = False): |
|
12
|
|
|
""" |
|
13
|
|
|
Create a public client using IP:Port or URI format. |
|
14
|
|
|
|
|
15
|
|
|
Example:: |
|
16
|
|
|
public_client = PublicClient(trusted_ips=["127.0.0.1"]) |
|
17
|
|
|
|
|
18
|
|
|
# or use uri method |
|
19
|
|
|
|
|
20
|
|
|
public_client = PublicClient(trusted_uris=["https://tradehub-api-server.network/"]) |
|
21
|
|
|
|
|
22
|
|
|
:param node_ip: ip address off a tradehub node. |
|
23
|
|
|
:param node_port: prt off a tradehub node, default 5001. |
|
24
|
|
|
:param uri: URI address off tradehub node. |
|
25
|
|
|
""" |
|
26
|
|
|
if trusted_ips and trusted_uris: |
|
27
|
|
|
raise ValueError("Use IP's or URI's, not both!") |
|
28
|
|
|
|
|
29
|
|
|
NetworkCrawlerClient.__init__(self, network=network, trusted_ip_list=trusted_ips, trusted_uri_list=trusted_uris, is_websocket_client=is_websocket_client) |
|
30
|
|
|
|
|
31
|
|
|
def get_all_validators(self) -> List[dict]: |
|
32
|
|
|
""" |
|
33
|
|
|
Get all validators. This includes active, unbonding and unbonded validators. |
|
34
|
|
|
|
|
35
|
|
|
Example:: |
|
36
|
|
|
|
|
37
|
|
|
public_client.get_all_validators() |
|
38
|
|
|
|
|
39
|
|
|
The expected return result for this function is as follows:: |
|
40
|
|
|
|
|
41
|
|
|
[ |
|
42
|
|
|
{ |
|
43
|
|
|
"OperatorAddress":"swthvaloper1vwges9p847l9csj8ehrlgzajhmt4fcq4dmg8x0", |
|
44
|
|
|
"ConsPubKey":"swthvalconspub1zcjduepqcufdssqqfycjwz2srp42tytrs7gtdkkry9cpspea3zqsjzqd2tps73pr63", |
|
45
|
|
|
"Jailed":false, |
|
46
|
|
|
"Status":2, |
|
47
|
|
|
"Tokens":"22414566.55131922", |
|
48
|
|
|
"DelegatorShares":"22414566.55131922", |
|
49
|
|
|
"Description":{ |
|
50
|
|
|
"moniker":"Devel \u0026 Co", |
|
51
|
|
|
"identity":"c572aef1818379c38996878357c321398165fcf0", |
|
52
|
|
|
"website":"https://gitlab.com/switcheo-utils", |
|
53
|
|
|
"security_contact":"", |
|
54
|
|
|
"details":"..."}, |
|
55
|
|
|
"UnbondingHeight":0, |
|
56
|
|
|
"UnbondingCompletionTime":"1970-01-01T00:00:00Z", |
|
57
|
|
|
"Commission":{ |
|
58
|
|
|
"commission_rates":{ |
|
59
|
|
|
"rate":"0.004200000000000000", |
|
60
|
|
|
"max_rate":"0.200000000000000000", |
|
61
|
|
|
"max_change_rate":"0.010000000000000000" |
|
62
|
|
|
}, |
|
63
|
|
|
"update_time":"2020-11-27T20:25:33.45991154Z" |
|
64
|
|
|
}, |
|
65
|
|
|
"MinSelfDelegation":"1", |
|
66
|
|
|
"ConsAddress":"swthvalcons1pqnlj0na6k8u9y27j3elrx584mt3380dal0j9s", |
|
67
|
|
|
"ConsAddressByte":"0827F93E7DD58FC2915E9473F19A87AED7189DED", |
|
68
|
|
|
"WalletAddress":"swth1vwges9p847l9csj8ehrlgzajhmt4fcq4sd7gzl", |
|
69
|
|
|
"BondStatus":"bonded" |
|
70
|
|
|
}, |
|
71
|
|
|
... |
|
72
|
|
|
] |
|
73
|
|
|
|
|
74
|
|
|
.. warning:: |
|
75
|
|
|
The response from this endpoint uses different types off name conventions! |
|
76
|
|
|
For example 'MinSelfDelegation' and 'max_change_rate'. |
|
77
|
|
|
|
|
78
|
|
|
.. warning:: |
|
79
|
|
|
This endpoint returns numbers as string(eg. "volume":"2100") or integer(eg. "resolution":5) |
|
80
|
|
|
|
|
81
|
|
|
:return: list with validators. |
|
82
|
|
|
""" |
|
83
|
|
|
return self.tradehub_get_request(path='/get_all_validators') |
|
84
|
|
|
|
|
85
|
|
|
def get_block(self, block_nbr: int = 1): |
|
86
|
|
|
return self.tradehub_get_request(path='/blocks/{}'.format(block_nbr)) |
|
87
|
|
|
|
|
88
|
|
|
def get_block_time(self) -> str: |
|
89
|
|
|
""" |
|
90
|
|
|
Get the block time in format HH:MM:SS.ZZZZZZ. |
|
91
|
|
|
|
|
92
|
|
|
Example:: |
|
93
|
|
|
|
|
94
|
|
|
public_client.get_block_time() |
|
95
|
|
|
|
|
96
|
|
|
The expected return result for this function is as follows:: |
|
97
|
|
|
|
|
98
|
|
|
"00:00:02.190211" |
|
99
|
|
|
|
|
100
|
|
|
.. warning:: |
|
101
|
|
|
This endpoint returns only a string. |
|
102
|
|
|
|
|
103
|
|
|
:return: block time as string. |
|
104
|
|
|
""" |
|
105
|
|
|
return self.tradehub_get_request(path='/get_block_time') |
|
106
|
|
|
|
|
107
|
|
|
def get_blocks(self, before_id: Optional[int] = None, after_id: Optional[int] = None, order_by: Optional[str] = None, swth_valcons: Optional[str] = None, limit: Optional[int] = None) -> List[dict]: |
|
108
|
|
|
""" |
|
109
|
|
|
Get latest blocks or request specific blocks. |
|
110
|
|
|
|
|
111
|
|
|
Example:: |
|
112
|
|
|
|
|
113
|
|
|
public_client.get_blocks() |
|
114
|
|
|
|
|
115
|
|
|
The expected return result for this function is as follows:: |
|
116
|
|
|
|
|
117
|
|
|
[ |
|
118
|
|
|
{ |
|
119
|
|
|
"block_height":"6103923", |
|
120
|
|
|
"time":"2021-01-09T14:15:53.071509+01:00", |
|
121
|
|
|
"count":"1", |
|
122
|
|
|
"proposer_address":"swthvalcons17m2ueqqqt8u0jz4rv5kvk4kg0teel4sckytjlc" |
|
123
|
|
|
}, |
|
124
|
|
|
{ |
|
125
|
|
|
"block_height":"6103922", |
|
126
|
|
|
"time":"2021-01-09T14:15:50.824548+01:00", |
|
127
|
|
|
"count":"0", |
|
128
|
|
|
"proposer_address":"swthvalcons1zecfdrf22f6syz8xj4vn8jsvsalxdhwl9tlflk" |
|
129
|
|
|
}, |
|
130
|
|
|
... |
|
131
|
|
|
] |
|
132
|
|
|
|
|
133
|
|
|
.. warning:: This endpoint is not well documented in official documents. The parameters are NOT required. |
|
134
|
|
|
|
|
135
|
|
|
:param before_id: Before block height(exclusive). |
|
136
|
|
|
:param after_id: After block height(exclusive). |
|
137
|
|
|
:param order_by: Not specified yet. |
|
138
|
|
|
:param swth_valcons: Switcheo tradehub validator consensus starting with 'swthvalcons1' on mainnet and |
|
139
|
|
|
'tswthvalcons1' on testnet. |
|
140
|
|
|
:param limit: Limit the responded result. Values greater than 200 have no effect and a maximum off 200 |
|
141
|
|
|
results are returned. |
|
142
|
|
|
:return: List with found blocks matching the requested parameters. Can be empty list []. |
|
143
|
|
|
""" |
|
144
|
|
|
api_params = { |
|
145
|
|
|
"before_id": before_id, |
|
146
|
|
|
"after_id": after_id, |
|
147
|
|
|
"order_by": order_by, |
|
148
|
|
|
"proposer": swth_valcons, |
|
149
|
|
|
"limit": limit |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
return self.tradehub_get_request(path='/get_blocks', params=api_params) |
|
153
|
|
|
|
|
154
|
|
|
def get_commitment_curve(self): |
|
155
|
|
|
return self.tradehub_get_request(path='/get_commitment_curve') |
|
156
|
|
|
|
|
157
|
|
|
def get_distribution_parameters(self): |
|
158
|
|
|
return self.tradehub_get_request(path='/distribution/parameters') |
|
159
|
|
|
|
|
160
|
|
|
def get_inflation_start_time(self): |
|
161
|
|
|
return self.tradehub_get_request(path='/get_inflation_start_time') |
|
162
|
|
|
|
|
163
|
|
|
def get_insurance_fund_balance(self): |
|
164
|
|
|
""" |
|
165
|
|
|
|
|
166
|
|
|
.. warning:: |
|
167
|
|
|
|
|
168
|
|
|
This endpoint is not working yet. |
|
169
|
|
|
|
|
170
|
|
|
:return: |
|
171
|
|
|
""" |
|
172
|
|
|
# TODO result currently [] |
|
173
|
|
|
return self.tradehub_get_request(path='/get_insurance_balance') |
|
174
|
|
|
|
|
175
|
|
|
def get_latest_blocks(self): |
|
176
|
|
|
return self.tradehub_get_request(path='/blocks/latest') |
|
177
|
|
|
|
|
178
|
|
|
def get_liquidity_pools(self): |
|
179
|
|
|
return self.tradehub_get_request(path='/get_liquidity_pools') |
|
180
|
|
|
|
|
181
|
|
|
def get_liquidations(self, before_id: int, after_id: int, order_by: str, limit: int): |
|
182
|
|
|
""" |
|
183
|
|
|
|
|
184
|
|
|
.. warning:: |
|
185
|
|
|
|
|
186
|
|
|
This endpoint is not working yet. |
|
187
|
|
|
|
|
188
|
|
|
:param before_id: |
|
189
|
|
|
:param after_id: |
|
190
|
|
|
:param order_by: |
|
191
|
|
|
:param limit: |
|
192
|
|
|
:return: |
|
193
|
|
|
""" |
|
194
|
|
|
# TODO result currently not available |
|
195
|
|
|
api_params = { |
|
196
|
|
|
"before_id": before_id, |
|
197
|
|
|
"after_id": after_id, |
|
198
|
|
|
"order_by": order_by, |
|
199
|
|
|
"limit": limit |
|
200
|
|
|
} |
|
201
|
|
|
return self.tradehub_get_request(path='/get_liquidations', params=api_params) |
|
202
|
|
|
|
|
203
|
|
|
def get_market(self, market: str) -> dict: |
|
204
|
|
|
""" |
|
205
|
|
|
Get information about a market. |
|
206
|
|
|
|
|
207
|
|
|
Example:: |
|
208
|
|
|
|
|
209
|
|
|
public_client.get_market("swth_eth1") |
|
210
|
|
|
|
|
211
|
|
|
The expected return result for this function is as follows:: |
|
212
|
|
|
|
|
213
|
|
|
{ |
|
214
|
|
|
"type":"", |
|
215
|
|
|
"name":"swth_eth1", |
|
216
|
|
|
"display_name":"SWTH_ETH", |
|
217
|
|
|
"description":"SWTH/ETH Spot Market", |
|
218
|
|
|
"market_type":"spot", |
|
219
|
|
|
"base":"swth", |
|
220
|
|
|
"base_name":"Switcheo", |
|
221
|
|
|
"base_precision":8, |
|
222
|
|
|
"quote":"eth1", |
|
223
|
|
|
"quote_name":"Ethereum", |
|
224
|
|
|
"quote_precision":18, |
|
225
|
|
|
"lot_size":"1", |
|
226
|
|
|
"tick_size":"0.0000001", |
|
227
|
|
|
"min_quantity":"200", |
|
228
|
|
|
"maker_fee":"-0.0005", |
|
229
|
|
|
"taker_fee":"0.0025", |
|
230
|
|
|
"risk_step_size":"0", |
|
231
|
|
|
"initial_margin_base":"1", |
|
232
|
|
|
"initial_margin_step":"0", |
|
233
|
|
|
"maintenance_margin_ratio":"0", |
|
234
|
|
|
"max_liquidation_order_ticket":"0", |
|
235
|
|
|
"max_liquidation_order_duration":0, |
|
236
|
|
|
"impact_size":"0", |
|
237
|
|
|
"mark_price_band":0, |
|
238
|
|
|
"last_price_protected_band":0, |
|
239
|
|
|
"index_oracle_id":"", |
|
240
|
|
|
"expiry_time":"1970-01-01T01:00:00+01:00", |
|
241
|
|
|
"is_active":true, |
|
242
|
|
|
"is_settled":false, |
|
243
|
|
|
"closed_block_height":0, |
|
244
|
|
|
"created_block_height":0 |
|
245
|
|
|
} |
|
246
|
|
|
|
|
247
|
|
|
.. warning:: |
|
248
|
|
|
|
|
249
|
|
|
This endpoint is not well documented in official documents. |
|
250
|
|
|
The example market swth_eth does not exist on mainnet. The correct market ticker is 'swth_eth1'. |
|
251
|
|
|
See get_markets() for correct tickers. |
|
252
|
|
|
|
|
253
|
|
|
.. warning:: |
|
254
|
|
|
|
|
255
|
|
|
This endpoint returns numbers as string(eg. "lot_size":"1") or integer(eg. "base_precision":8). |
|
256
|
|
|
|
|
257
|
|
|
.. warning:: |
|
258
|
|
|
|
|
259
|
|
|
This endpoint returns the same dict structure even the market does not exist with default values! |
|
260
|
|
|
|
|
261
|
|
|
:param market: Market ticker used by blockchain (eg. swth_eth1). |
|
262
|
|
|
:return: |
|
263
|
|
|
""" |
|
264
|
|
|
api_params = { |
|
265
|
|
|
"market": market, |
|
266
|
|
|
} |
|
267
|
|
|
return self.tradehub_get_request(path='/get_market', params=api_params) |
|
268
|
|
|
|
|
269
|
|
|
def get_market_stats(self, market: Optional[str] = None) -> List[dict]: |
|
270
|
|
|
""" |
|
271
|
|
|
Get statistics about one or all markets. |
|
272
|
|
|
|
|
273
|
|
|
Example:: |
|
274
|
|
|
|
|
275
|
|
|
public_client.get_market_stats() |
|
276
|
|
|
|
|
277
|
|
|
The expected return result for this function is as follows:: |
|
278
|
|
|
|
|
279
|
|
|
[ |
|
280
|
|
|
{ |
|
281
|
|
|
"day_high":"0.0000215", |
|
282
|
|
|
"day_low":"0.000021", |
|
283
|
|
|
"day_open":"0.0000211", |
|
284
|
|
|
"day_close":"0.0000212", |
|
285
|
|
|
"day_volume":"436030", |
|
286
|
|
|
"day_quote_volume":"9.2787298", |
|
287
|
|
|
"index_price":"0", |
|
288
|
|
|
"mark_price":"0", |
|
289
|
|
|
"last_price":"0.00212000", |
|
290
|
|
|
"market":"swth_eth1", |
|
291
|
|
|
"market_type":"spot", |
|
292
|
|
|
"open_interest":"0" |
|
293
|
|
|
} |
|
294
|
|
|
... |
|
295
|
|
|
] |
|
296
|
|
|
|
|
297
|
|
|
|
|
298
|
|
|
:param market: Market ticker used by blockchain (eg. swth_eth1). |
|
299
|
|
|
:return: List with market stats as dict |
|
300
|
|
|
""" |
|
301
|
|
|
api_params = { |
|
302
|
|
|
"market": market |
|
303
|
|
|
} |
|
304
|
|
|
return self.tradehub_get_request(path='/get_market_stats', params=api_params) |
|
305
|
|
|
|
|
306
|
|
|
def get_markets(self, market_type: Optional[str] = None, is_active: Optional[bool] = None, is_settled: Optional[bool] = None) -> List[dict]: |
|
307
|
|
|
""" |
|
308
|
|
|
Get all markets or filter markets. |
|
309
|
|
|
|
|
310
|
|
|
Example:: |
|
311
|
|
|
|
|
312
|
|
|
public_client.get_markets() |
|
313
|
|
|
|
|
314
|
|
|
The expected return result for this function is as follows:: |
|
315
|
|
|
|
|
316
|
|
|
[ |
|
317
|
|
|
{ |
|
318
|
|
|
"type":"", |
|
319
|
|
|
"name":"swth_eth1", |
|
320
|
|
|
"display_name":"SWTH_ETH", |
|
321
|
|
|
"description":"SWTH/ETH Spot Market", |
|
322
|
|
|
"market_type":"spot", |
|
323
|
|
|
"base":"swth", |
|
324
|
|
|
"base_name":"Switcheo", |
|
325
|
|
|
"base_precision":8, |
|
326
|
|
|
"quote":"eth1", |
|
327
|
|
|
"quote_name":"Ethereum", |
|
328
|
|
|
"quote_precision":18, |
|
329
|
|
|
"lot_size":"1", |
|
330
|
|
|
"tick_size":"0.0000001", |
|
331
|
|
|
"min_quantity":"200", |
|
332
|
|
|
"maker_fee":"-0.0005", |
|
333
|
|
|
"taker_fee":"0.0025", |
|
334
|
|
|
"risk_step_size":"0", |
|
335
|
|
|
"initial_margin_base":"1", |
|
336
|
|
|
"initial_margin_step":"0", |
|
337
|
|
|
"maintenance_margin_ratio":"0", |
|
338
|
|
|
"max_liquidation_order_ticket":"0", |
|
339
|
|
|
"max_liquidation_order_duration":0, |
|
340
|
|
|
"impact_size":"0", |
|
341
|
|
|
"mark_price_band":0, |
|
342
|
|
|
"last_price_protected_band":0, |
|
343
|
|
|
"index_oracle_id":"", |
|
344
|
|
|
"expiry_time":"1970-01-01T01:00:00+01:00", |
|
345
|
|
|
"is_active":true, |
|
346
|
|
|
"is_settled":false, |
|
347
|
|
|
"closed_block_height":0, |
|
348
|
|
|
"created_block_height":0 |
|
349
|
|
|
}, |
|
350
|
|
|
... |
|
351
|
|
|
] |
|
352
|
|
|
|
|
353
|
|
|
.. warning:: |
|
354
|
|
|
This endpoint returns numbers as string(eg. "lot_size":"1") or integer(eg. "base_precision":8) |
|
355
|
|
|
|
|
356
|
|
|
:param market_type: type of the market can be 'futures' or 'spot' |
|
357
|
|
|
:param is_active: if only active markets should be returned |
|
358
|
|
|
:param is_settled: if only settled markets should be returned |
|
359
|
|
|
:return: List with returned market stats as dict |
|
360
|
|
|
""" |
|
361
|
|
|
|
|
362
|
|
|
if market_type and market_type not in ['futures', 'spot']: |
|
363
|
|
|
raise ValueError(f"Parameter 'market_type' only can be 'futures' or 'spot'. Got {market_type} instead.") |
|
364
|
|
|
|
|
365
|
|
|
api_params = { |
|
366
|
|
|
"market_type": market_type, |
|
367
|
|
|
"is_active": is_active, |
|
368
|
|
|
"is_settled": is_settled |
|
369
|
|
|
} |
|
370
|
|
|
|
|
371
|
|
|
return self.tradehub_get_request(path='/get_markets', params=api_params) |
|
372
|
|
|
|
|
373
|
|
|
def get_nodes(self) -> dict: |
|
374
|
|
|
""" |
|
375
|
|
|
""" |
|
376
|
|
|
# TODO no results yet available |
|
377
|
|
|
return self.tradehub_get_request(path='/monitor') |
|
378
|
|
|
|
|
379
|
|
|
def get_oracle_result(self, oracle_id: str): |
|
380
|
|
|
""" |
|
381
|
|
|
|
|
382
|
|
|
.. warning:: |
|
383
|
|
|
|
|
384
|
|
|
This endpoint is not working yet. |
|
385
|
|
|
|
|
386
|
|
|
:param oracle_id: |
|
387
|
|
|
:return: |
|
388
|
|
|
""" |
|
389
|
|
|
# TODO no results yet available |
|
390
|
|
|
api_params = { |
|
391
|
|
|
"id": oracle_id |
|
392
|
|
|
} |
|
393
|
|
|
return self.tradehub_get_request(path='/get_oracle_result', params=api_params) |
|
394
|
|
|
|
|
395
|
|
|
def get_oracle_results(self): |
|
396
|
|
|
""" |
|
397
|
|
|
|
|
398
|
|
|
.. warning:: |
|
399
|
|
|
|
|
400
|
|
|
This endpoint is not working yet. |
|
401
|
|
|
|
|
402
|
|
|
:return: |
|
403
|
|
|
""" |
|
404
|
|
|
# TODO no results yet available |
|
405
|
|
|
return self.tradehub_get_request(path='/get_oracle_results') |
|
406
|
|
|
|
|
407
|
|
|
def get_prices(self, market: Optional[str]) -> dict: |
|
408
|
|
|
""" |
|
409
|
|
|
Get prices off a market. |
|
410
|
|
|
|
|
411
|
|
|
Example:: |
|
412
|
|
|
|
|
413
|
|
|
public_client.get_prices("swth_eth1") |
|
414
|
|
|
|
|
415
|
|
|
The expected return result for this function is as follows:: |
|
416
|
|
|
|
|
417
|
|
|
{ |
|
418
|
|
|
"last":"207000", |
|
419
|
|
|
"index":"0", |
|
420
|
|
|
"fair":"0", |
|
421
|
|
|
"mark":"0", |
|
422
|
|
|
"mark_avg":"0", |
|
423
|
|
|
"settlement":"0", |
|
424
|
|
|
"fair_index_delta_avg":"0", |
|
425
|
|
|
"market":"", |
|
426
|
|
|
"marking_strategy":"", |
|
427
|
|
|
"index_updated_at":"0001-01-01T00:00:00Z", |
|
428
|
|
|
"last_updated_at":"2021-01-09T22:50:59.068526+01:00", |
|
429
|
|
|
"block_height":0 |
|
430
|
|
|
} |
|
431
|
|
|
|
|
432
|
|
|
.. warning:: |
|
433
|
|
|
|
|
434
|
|
|
This endpoint is not well documented in official documents. |
|
435
|
|
|
Parameter 'market' is NOT required, but strongly recommended. The return result has an empty 'market' field. |
|
436
|
|
|
|
|
437
|
|
|
.. warning:: |
|
438
|
|
|
|
|
439
|
|
|
This endpoint returns amounts which are NOT human readable values. Consider 'base_precision' and |
|
440
|
|
|
'quote_precision' to calculate a multiplication factor = 10 ^ ('base_precision' - 'quote_precision') |
|
441
|
|
|
|
|
442
|
|
|
.. warning:: |
|
443
|
|
|
|
|
444
|
|
|
This endpoint returns numbers as string(eg. "last":"207000") or integer(eg. "block_height":0) |
|
445
|
|
|
|
|
446
|
|
|
.. warning:: |
|
447
|
|
|
|
|
448
|
|
|
This endpoint returns a result even if the market is not known. Result contains default values. |
|
449
|
|
|
|
|
450
|
|
|
:param market: Market ticker used by blockchain (eg. swth_eth1). |
|
451
|
|
|
:return: Prices as dict |
|
452
|
|
|
""" |
|
453
|
|
|
api_params = { |
|
454
|
|
|
"market": market |
|
455
|
|
|
} |
|
456
|
|
|
return self.tradehub_get_request(path='/get_prices', params=api_params) |
|
457
|
|
|
|
|
458
|
|
|
def get_reward_curve(self): |
|
459
|
|
|
return self.tradehub_get_request(path='/get_reward_curve') |
|
460
|
|
|
|
|
461
|
|
|
def get_rich_list(self, token: str): |
|
462
|
|
|
""" |
|
463
|
|
|
|
|
464
|
|
|
.. warning:: |
|
465
|
|
|
This endpoint is not working yet. |
|
466
|
|
|
|
|
467
|
|
|
:param token: |
|
468
|
|
|
:return: |
|
469
|
|
|
""" |
|
470
|
|
|
# TODO responses currently not available |
|
471
|
|
|
api_params = { |
|
472
|
|
|
"token": token |
|
473
|
|
|
} |
|
474
|
|
|
return self.tradehub_get_request(path='/get_rich_list', params=api_params) |
|
475
|
|
|
|
|
476
|
|
|
def get_staking_pool(self): |
|
477
|
|
|
return self.tradehub_get_request(path='/staking/pool') |
|
478
|
|
|
|
|
479
|
|
|
def get_status(self) -> dict: |
|
480
|
|
|
""" |
|
481
|
|
|
Return cosmos RPC status endpoint. |
|
482
|
|
|
|
|
483
|
|
|
Example:: |
|
484
|
|
|
|
|
485
|
|
|
public_client.get_status() |
|
486
|
|
|
|
|
487
|
|
|
The expected return result for this function is as follows:: |
|
488
|
|
|
|
|
489
|
|
|
{ |
|
490
|
|
|
"jsonrpc": "2.0", |
|
491
|
|
|
"id": -1, |
|
492
|
|
|
"result": { |
|
493
|
|
|
"node_info": { |
|
494
|
|
|
"protocol_version": { |
|
495
|
|
|
"p2p": "7", |
|
496
|
|
|
"block": "10", |
|
497
|
|
|
"app": "0" |
|
498
|
|
|
}, |
|
499
|
|
|
"id": "f4cee80e4dec5a686139cb82729118e15f7ce19c", |
|
500
|
|
|
"listen_addr": "tcp://0.0.0.0:26656", |
|
501
|
|
|
"network": "switcheo-tradehub-1", |
|
502
|
|
|
"version": "0.33.7", |
|
503
|
|
|
"channels": "4020212223303800", |
|
504
|
|
|
"moniker": "Devel Sentry Node 2", |
|
505
|
|
|
"other": { |
|
506
|
|
|
"tx_index": "on", |
|
507
|
|
|
"rpc_address": "tcp://0.0.0.0:26659" |
|
508
|
|
|
} |
|
509
|
|
|
}, |
|
510
|
|
|
"sync_info": { |
|
511
|
|
|
"latest_block_hash": "4A2C89C105D7864AA74C9DE4752AF5B59E96045EBAF984C69DD447C4524EC36F", |
|
512
|
|
|
"latest_app_hash": "773651392EEDBFF6AEE088F76E7D75F2932B4D9F74CA27D568F706ADFC12B174", |
|
513
|
|
|
"latest_block_height": "6119142", |
|
514
|
|
|
"latest_block_time": "2021-01-09T22:18:52.722611018Z", |
|
515
|
|
|
"earliest_block_hash": "B4AF1F3D3D3FD5795BDDB7A6A2E6CA4E34D06338505D6EC46DD8F99E72ADCDAB", |
|
516
|
|
|
"earliest_app_hash": "", |
|
517
|
|
|
"earliest_block_height": "1", |
|
518
|
|
|
"earliest_block_time": "2020-08-14T07:32:27.856700491Z", |
|
519
|
|
|
"catching_up": false |
|
520
|
|
|
}, |
|
521
|
|
|
"validator_info": { |
|
522
|
|
|
"address": "DCB03C204B7F94765B4ADCE1D8BEE88AA43AE811", |
|
523
|
|
|
"pub_key": { |
|
524
|
|
|
"type": "tendermint/PubKeyEd25519", |
|
525
|
|
|
"value": "1GmDSymN6jTqQlZA2KeyzqknIncGMMrwnnas/DWGNOI=" |
|
526
|
|
|
}, |
|
527
|
|
|
"voting_power": "0" |
|
528
|
|
|
} |
|
529
|
|
|
} |
|
530
|
|
|
} |
|
531
|
|
|
|
|
532
|
|
|
:return: Status as dict |
|
533
|
|
|
""" |
|
534
|
|
|
return self.tradehub_get_request(path='/get_status') |
|
535
|
|
|
|
|
536
|
|
|
def get_transaction_types(self) -> List[str]: |
|
537
|
|
|
""" |
|
538
|
|
|
Get transaction types used by tradehub. |
|
539
|
|
|
|
|
540
|
|
|
Example:: |
|
541
|
|
|
|
|
542
|
|
|
public_client.get_transaction_types() |
|
543
|
|
|
|
|
544
|
|
|
The expected return result for this function is as follows:: |
|
545
|
|
|
|
|
546
|
|
|
[ |
|
547
|
|
|
"submit_proposal", |
|
548
|
|
|
"create_pool", |
|
549
|
|
|
"set_reward_curve", |
|
550
|
|
|
"send", |
|
551
|
|
|
... |
|
552
|
|
|
] |
|
553
|
|
|
|
|
554
|
|
|
:return: List with transaction types as strings. |
|
555
|
|
|
""" |
|
556
|
|
|
return self.tradehub_get_request(path='/get_transaction_types') |
|
557
|
|
|
|
|
558
|
|
|
def get_transactions_fees(self): |
|
559
|
|
|
gas_fees = self.tradehub_get_request(path='/get_txns_fees') |
|
560
|
|
|
fees = {} |
|
561
|
|
|
for gas_fee in gas_fees["result"]: |
|
562
|
|
|
fees[gas_fee["msg_type"]] = gas_fee["fee"] |
|
563
|
|
|
return fees |
|
564
|
|
|
|
|
565
|
|
|
def get_token(self, denom) -> dict: |
|
566
|
|
|
""" |
|
567
|
|
|
Get information about a token. |
|
568
|
|
|
|
|
569
|
|
|
Example:: |
|
570
|
|
|
|
|
571
|
|
|
public_client.get_token("swth") |
|
572
|
|
|
|
|
573
|
|
|
The expected return result for this function is as follows:: |
|
574
|
|
|
|
|
575
|
|
|
{ |
|
576
|
|
|
"name":"Switcheo", |
|
577
|
|
|
"symbol":"swth", |
|
578
|
|
|
"denom":"swth", |
|
579
|
|
|
"decimals":8, |
|
580
|
|
|
"blockchain":"neo", |
|
581
|
|
|
"chain_id":4, |
|
582
|
|
|
"asset_id":"32e125258b7db0a0dffde5bd03b2b859253538ab", |
|
583
|
|
|
"is_active":true, |
|
584
|
|
|
"is_collateral":false, |
|
585
|
|
|
"lock_proxy_hash":"17d0f66eca7fcbfddc8d9706f20513bf5d7419cd", |
|
586
|
|
|
"delegated_supply":"100000000000000000", |
|
587
|
|
|
"originator":"swth1mw90en8tcqnvdjhp64qmyhuq4qasvhy25dpmvw" |
|
588
|
|
|
} |
|
589
|
|
|
|
|
590
|
|
|
.. warning:: |
|
591
|
|
|
|
|
592
|
|
|
This endpoint returns numbers as string(eg. "delegated_supply":"100000000000000000") or integer(eg. "decimals":8) |
|
593
|
|
|
|
|
594
|
|
|
|
|
595
|
|
|
:param denom: Denom used by tradehub. |
|
596
|
|
|
:return: Information about token as dict. |
|
597
|
|
|
""" |
|
598
|
|
|
api_params = { |
|
599
|
|
|
"token": denom |
|
600
|
|
|
} |
|
601
|
|
|
return self.tradehub_get_request(path='/get_token', params=api_params) |
|
602
|
|
|
|
|
603
|
|
|
def get_tokens(self) -> List[dict]: |
|
604
|
|
|
""" |
|
605
|
|
|
Get all known tokens on tradehub chain. |
|
606
|
|
|
|
|
607
|
|
|
Example:: |
|
608
|
|
|
|
|
609
|
|
|
public_client.get_tokens() |
|
610
|
|
|
|
|
611
|
|
|
The expected return result for this function is as follows:: |
|
612
|
|
|
|
|
613
|
|
|
[ |
|
614
|
|
|
{ |
|
615
|
|
|
"name":"Switcheo", |
|
616
|
|
|
"symbol":"swth", |
|
617
|
|
|
"denom":"swth", |
|
618
|
|
|
"decimals":8, |
|
619
|
|
|
"blockchain":"neo", |
|
620
|
|
|
"chain_id":4, |
|
621
|
|
|
"asset_id":"32e125258b7db0a0dffde5bd03b2b859253538ab", |
|
622
|
|
|
"is_active":true, |
|
623
|
|
|
"is_collateral":false, |
|
624
|
|
|
"lock_proxy_hash":"17d0f66eca7fcbfddc8d9706f20513bf5d7419cd", |
|
625
|
|
|
"delegated_supply":"100000000000000000", |
|
626
|
|
|
"originator":"swth1mw90en8tcqnvdjhp64qmyhuq4qasvhy25dpmvw" |
|
627
|
|
|
}, |
|
628
|
|
|
... |
|
629
|
|
|
] |
|
630
|
|
|
|
|
631
|
|
|
.. warning:: |
|
632
|
|
|
This endpoint returns numbers as string(eg. "delegated_supply":"100000000000000000") or integer(eg. "decimals":8) |
|
633
|
|
|
|
|
634
|
|
|
:return: List with tokens as dict |
|
635
|
|
|
""" |
|
636
|
|
|
return self.tradehub_get_request(path='/get_tokens') |
|
637
|
|
|
|
|
638
|
|
|
def get_token_details(self) -> dict: |
|
639
|
|
|
tokens = self.get_tokens() |
|
640
|
|
|
tokens_details = {} |
|
641
|
|
|
for token in tokens: |
|
642
|
|
|
if token["is_active"]: |
|
643
|
|
|
tokens_details[token["denom"]] = { |
|
644
|
|
|
'name': token["name"], |
|
645
|
|
|
'symbol': token["symbol"], |
|
646
|
|
|
'decimals': token["decimals"], |
|
647
|
|
|
} |
|
648
|
|
|
return tokens_details |
|
649
|
|
|
|
|
650
|
|
|
def get_top_r_profits(self, market: str, limit: int): |
|
651
|
|
|
""" |
|
652
|
|
|
|
|
653
|
|
|
.. warning:: |
|
654
|
|
|
This endpoint is not working yet. |
|
655
|
|
|
|
|
656
|
|
|
:param market: |
|
657
|
|
|
:param limit: |
|
658
|
|
|
:return: |
|
659
|
|
|
""" |
|
660
|
|
|
# TODO responses currently not available |
|
661
|
|
|
api_params = { |
|
662
|
|
|
"market": market, |
|
663
|
|
|
"limit": limit |
|
664
|
|
|
} |
|
665
|
|
|
return self.tradehub_get_request(path='/get_top_r_profits', params=api_params) |
|
666
|
|
|
|
|
667
|
|
|
def get_total_balances(self): |
|
668
|
|
|
""" |
|
669
|
|
|
|
|
670
|
|
|
.. warning:: |
|
671
|
|
|
This endpoint is not working yet. |
|
672
|
|
|
|
|
673
|
|
|
:return: |
|
674
|
|
|
""" |
|
675
|
|
|
# TODO responses currently not available |
|
676
|
|
|
return self.tradehub_get_request(path='/get_total_balances') |
|
677
|
|
|
|
|
678
|
|
|
def get_validator_delegations(self, operator_address): |
|
679
|
|
|
return self.tradehub_get_request(path='/staking/validators/{}/delegations'.format(operator_address)) |
|
680
|
|
|
|
|
681
|
|
|
def get_validator_public_nodes(self): |
|
682
|
|
|
public_nodes = {} |
|
683
|
|
|
tradehub_state = self.get_tradehub_monitor() |
|
684
|
|
|
for validator in tradehub_state: |
|
685
|
|
|
public_nodes[validator["moniker"]] = validator["ip"] |
|
686
|
|
|
return public_nodes |
|
687
|
|
|
|
|
688
|
|
|
def get_validator_public_node_ips(self): |
|
689
|
|
|
public_node_ips = [] |
|
690
|
|
|
nodes_dict = self.get_validator_public_nodes() |
|
691
|
|
|
for key in nodes_dict.keys(): |
|
692
|
|
|
public_node_ips.append(nodes_dict[key]) |
|
693
|
|
|
return public_node_ips |
|
694
|
|
|
|
|
695
|
|
|
def get_validator_missed_blocks(self): |
|
696
|
|
|
validators_missed_blocks = {} |
|
697
|
|
|
validators_signing_info = self.get_validator_signing_info()["result"] |
|
698
|
|
|
for validator_signing_info in validators_signing_info: |
|
699
|
|
|
validators_missed_blocks[validator_signing_info["address"]] = validator_signing_info["missed_blocks_counter"] |
|
700
|
|
|
return validators_missed_blocks |
|
701
|
|
|
|
|
702
|
|
|
def get_validator_signing_info(self, limit: int = 100): |
|
703
|
|
|
api_params = {} |
|
704
|
|
|
api_params["limit"] = limit |
|
705
|
|
|
return self.tradehub_get_request(path='/slashing/signing_infos', params=api_params) |
|
706
|
|
|
|
|
707
|
|
|
def get_validators(self, status: str = None): |
|
708
|
|
|
api_params = {} |
|
709
|
|
|
if status is not None and status in ["unbonding", "unbonded"]: |
|
710
|
|
|
api_params["status"] = status |
|
711
|
|
|
return self.tradehub_get_request(path='/staking/validators', params=api_params) |
|
712
|
|
|
|
|
713
|
|
|
def get_vault_types(self) -> list: |
|
714
|
|
|
""" |
|
715
|
|
|
|
|
716
|
|
|
:param token: |
|
717
|
|
|
:return : |
|
718
|
|
|
""" |
|
719
|
|
|
# TODO responses currently not an empty list |
|
720
|
|
|
return self.tradehub_get_request(path='/get_vault_types') |
|
721
|
|
|
|
|
722
|
|
|
def get_vaults(self, swth_address: str) -> dict: |
|
723
|
|
|
api_params = { |
|
724
|
|
|
"address": swth_address, |
|
725
|
|
|
} |
|
726
|
|
|
return self.tradehub_get_request(path='/get_vaults', params=api_params) |
|
727
|
|
|
|