1
|
|
|
from typing import Union, List, Optional |
2
|
|
|
from tradehub.decentralized_client import NetworkCrawlerClient |
3
|
|
|
|
4
|
|
|
|
5
|
|
|
class PublicClient(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 check_username(self, username: str) -> dict: |
32
|
|
|
""" |
33
|
|
|
|
34
|
|
|
:param username: |
35
|
|
|
:return: |
36
|
|
|
""" |
37
|
|
|
api_params = { |
38
|
|
|
"username": username, |
39
|
|
|
} |
40
|
|
|
return self.tradehub_get_request(path='/username_check', params=api_params) |
41
|
|
|
|
42
|
|
|
def get_account(self, swth_address: str) -> dict: |
43
|
|
|
""" |
44
|
|
|
Request account information about swth wallet. |
45
|
|
|
|
46
|
|
|
Example:: |
47
|
|
|
|
48
|
|
|
# wallet behind Devel And Co validator |
49
|
|
|
public_client.get_account("swth1vwges9p847l9csj8ehrlgzajhmt4fcq4sd7gzl") |
50
|
|
|
|
51
|
|
|
The expected return result for this function is as follows:: |
52
|
|
|
|
53
|
|
|
{ |
54
|
|
|
"height": "6102489", |
55
|
|
|
"result": { |
56
|
|
|
"type": "cosmos-sdk/Account", |
57
|
|
|
"value": { |
58
|
|
|
"address": "swth1vwges9p847l9csj8ehrlgzajhmt4fcq4sd7gzl", |
59
|
|
|
"coins": [ |
60
|
|
|
{ |
61
|
|
|
"denom": "cel1", |
62
|
|
|
"amount": "7" |
63
|
|
|
}, |
64
|
|
|
{ |
65
|
|
|
"denom": "eth1", |
66
|
|
|
"amount": "64752601707981" |
67
|
|
|
}, |
68
|
|
|
{ |
69
|
|
|
"denom": "nex1", |
70
|
|
|
"amount": "12289" |
71
|
|
|
}, |
72
|
|
|
{ |
73
|
|
|
"denom": "nneo2", |
74
|
|
|
"amount": "31555" |
75
|
|
|
}, |
76
|
|
|
{ |
77
|
|
|
"denom": "swth", |
78
|
|
|
"amount": "4113439708" |
79
|
|
|
}, |
80
|
|
|
{ |
81
|
|
|
"denom": "usdc1", |
82
|
|
|
"amount": "45376" |
83
|
|
|
}, |
84
|
|
|
{ |
85
|
|
|
"denom": "wbtc1", |
86
|
|
|
"amount": "29" |
87
|
|
|
} |
88
|
|
|
], |
89
|
|
|
"public_key": { |
90
|
|
|
"type": "tendermint/PubKeySecp256k1", |
91
|
|
|
"value": "AtCcJkRx1VhzZkOV06yrxKMZ9IvdRxqv5S4gJSQI/aCB" |
92
|
|
|
}, |
93
|
|
|
"account_number": "1756", |
94
|
|
|
"sequence": "55" |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
.. note: |
100
|
|
|
This endpoint returns numbers which are NOT human readable values. Consider 'base_precision' and |
101
|
|
|
'quote_precision' to calculate a multiplication factor = 10 ^ ('base_precision' - 'quote_precision'). |
102
|
|
|
See 'get_markets' |
103
|
|
|
|
104
|
|
|
:param swth_address: tradehub switcheo address starting with 'swth1' on mainnet and 'tswth1' on testnet. |
105
|
|
|
:return: json response |
106
|
|
|
""" |
107
|
|
|
api_params = { |
108
|
|
|
"account": swth_address, |
109
|
|
|
} |
110
|
|
|
return self.tradehub_get_request(path='/get_account', params=api_params) |
111
|
|
|
|
112
|
|
|
def get_active_wallets(self, token: str) -> int: |
113
|
|
|
""" |
114
|
|
|
|
115
|
|
|
:param token: |
116
|
|
|
:return active_wallet_cnt: |
117
|
|
|
""" |
118
|
|
|
api_params = { |
119
|
|
|
"token": token, |
120
|
|
|
} |
121
|
|
|
return self.tradehub_get_request(path='/get_active_wallets', params=api_params) |
122
|
|
|
|
123
|
|
|
def get_address(self, username: str) -> str: |
124
|
|
|
""" |
125
|
|
|
Request swth1 tradehub address which is represented by a username. |
126
|
|
|
|
127
|
|
|
Example:: |
128
|
|
|
|
129
|
|
|
public_client.get_address("devel484") |
130
|
|
|
|
131
|
|
|
The expected return result for this function is as follows:: |
132
|
|
|
|
133
|
|
|
"swth1qlue2pat9cxx2s5xqrv0ashs475n9va963h4hz" |
134
|
|
|
|
135
|
|
|
.. warning:: |
136
|
|
|
This endpoint returns only a string if address is found. If no address is found an exception with |
137
|
|
|
status code 404 will be raised. |
138
|
|
|
|
139
|
|
|
.. note:: |
140
|
|
|
Usernames are in lowercase and can only be 15 characters long. |
141
|
|
|
|
142
|
|
|
:param username: Username is lower case. |
143
|
|
|
:return: swth1 address if found |
144
|
|
|
""" |
145
|
|
|
api_params = { |
146
|
|
|
"username": username |
147
|
|
|
} |
148
|
|
|
return self.tradehub_get_request(path='/get_address', params=api_params) |
149
|
|
|
|
150
|
|
|
def get_address_rewards(self, address: str): |
151
|
|
|
return self.tradehub_get_request(path='/distribution/delegators/{}/rewards'.format(address)) |
152
|
|
|
|
153
|
|
|
def get_address_staking(self, address: str): |
154
|
|
|
return self.tradehub_get_request(path='/staking/delegators/{}/delegations'.format(address)) |
155
|
|
|
|
156
|
|
|
def get_address_trades(self, limit: int = 200, pagination: bool = None, address: str = None): |
157
|
|
|
api_params = {} |
158
|
|
|
if pagination is not None: |
159
|
|
|
api_params["pagination"] = pagination |
160
|
|
|
if address is not None: |
161
|
|
|
api_params["account"] = address |
162
|
|
|
return self.tradehub_get_request(path='/get_trades_by_account', params=api_params) |
163
|
|
|
|
164
|
|
|
def get_all_validators(self) -> List[dict]: |
165
|
|
|
""" |
166
|
|
|
Get all validators. This includes active, unbonding and unbonded validators. |
167
|
|
|
|
168
|
|
|
Example:: |
169
|
|
|
|
170
|
|
|
public_client.get_all_validators() |
171
|
|
|
|
172
|
|
|
The expected return result for this function is as follows:: |
173
|
|
|
|
174
|
|
|
[ |
175
|
|
|
{ |
176
|
|
|
"OperatorAddress":"swthvaloper1vwges9p847l9csj8ehrlgzajhmt4fcq4dmg8x0", |
177
|
|
|
"ConsPubKey":"swthvalconspub1zcjduepqcufdssqqfycjwz2srp42tytrs7gtdkkry9cpspea3zqsjzqd2tps73pr63", |
178
|
|
|
"Jailed":false, |
179
|
|
|
"Status":2, |
180
|
|
|
"Tokens":"22414566.55131922", |
181
|
|
|
"DelegatorShares":"22414566.55131922", |
182
|
|
|
"Description":{ |
183
|
|
|
"moniker":"Devel \u0026 Co", |
184
|
|
|
"identity":"c572aef1818379c38996878357c321398165fcf0", |
185
|
|
|
"website":"https://gitlab.com/switcheo-utils", |
186
|
|
|
"security_contact":"", |
187
|
|
|
"details":"'Devel' @Devel484 25Y (GER) and 'Coco' @colino87 33Y (FR) are two developers from the Switcheo community who have joined forces to develop awesome applications and tools to support the Switcheo Ecosystem. Stay tuned. Telegram: @DevelAndCo"}, |
188
|
|
|
"UnbondingHeight":0, |
189
|
|
|
"UnbondingCompletionTime":"1970-01-01T00:00:00Z", |
190
|
|
|
"Commission":{ |
191
|
|
|
"commission_rates":{ |
192
|
|
|
"rate":"0.004200000000000000", |
193
|
|
|
"max_rate":"0.200000000000000000", |
194
|
|
|
"max_change_rate":"0.010000000000000000" |
195
|
|
|
}, |
196
|
|
|
"update_time":"2020-11-27T20:25:33.45991154Z" |
197
|
|
|
}, |
198
|
|
|
"MinSelfDelegation":"1", |
199
|
|
|
"ConsAddress":"swthvalcons1pqnlj0na6k8u9y27j3elrx584mt3380dal0j9s", |
200
|
|
|
"ConsAddressByte":"0827F93E7DD58FC2915E9473F19A87AED7189DED", |
201
|
|
|
"WalletAddress":"swth1vwges9p847l9csj8ehrlgzajhmt4fcq4sd7gzl", |
202
|
|
|
"BondStatus":"bonded" |
203
|
|
|
}, |
204
|
|
|
... |
205
|
|
|
] |
206
|
|
|
|
207
|
|
|
.. warning:: |
208
|
|
|
The response from this endpoint uses different types off name conventions! |
209
|
|
|
For example 'MinSelfDelegation' and 'max_change_rate'. |
210
|
|
|
|
211
|
|
|
.. warning:: |
212
|
|
|
This endpoint returns numbers as string(eg. "volume":"2100") or integer(eg. "resolution":5) |
213
|
|
|
|
214
|
|
|
:return: list with validators. |
215
|
|
|
""" |
216
|
|
|
return self.tradehub_get_request(path='/get_all_validators') |
217
|
|
|
|
218
|
|
|
def get_balance(self, swth_address: str) -> dict: |
219
|
|
|
""" |
220
|
|
|
Get balance which includes available, in open orders and open positions. |
221
|
|
|
|
222
|
|
|
Example:: |
223
|
|
|
|
224
|
|
|
# wallet behind Devel And Co validator |
225
|
|
|
public_client.get_balance("swth1vwges9p847l9csj8ehrlgzajhmt4fcq4sd7gzl") |
226
|
|
|
|
227
|
|
|
The expected return result for this function is as follows:: |
228
|
|
|
|
229
|
|
|
{ |
230
|
|
|
"cel1":{ |
231
|
|
|
"available":"0.0007", |
232
|
|
|
"order":"0", |
233
|
|
|
"position":"0", |
234
|
|
|
"denom":"cel1" |
235
|
|
|
}, |
236
|
|
|
"eth1":{ |
237
|
|
|
"available":"0.000064752601707981", |
238
|
|
|
"order":"0", |
239
|
|
|
"position":"0", |
240
|
|
|
"denom":"eth1" |
241
|
|
|
}, |
242
|
|
|
"nex1":{ |
243
|
|
|
"available":"0.00012289", |
244
|
|
|
"order":"0", |
245
|
|
|
"position":"0", |
246
|
|
|
"denom":"nex1" |
247
|
|
|
}, |
248
|
|
|
"nneo2":{ |
249
|
|
|
"available":"0.00031555", |
250
|
|
|
"order":"0", |
251
|
|
|
"position":"0", |
252
|
|
|
"denom":"nneo2" |
253
|
|
|
}, |
254
|
|
|
"swth":{ |
255
|
|
|
"available":"41.13439708", |
256
|
|
|
"order":"0", |
257
|
|
|
"position":"0", |
258
|
|
|
"denom":"swth" |
259
|
|
|
}, |
260
|
|
|
"usdc1":{ |
261
|
|
|
"available":"0.045376", |
262
|
|
|
"order":"0", |
263
|
|
|
"position":"0", |
264
|
|
|
"denom":"usdc1" |
265
|
|
|
}, |
266
|
|
|
"wbtc1":{ |
267
|
|
|
"available":"0.00000029", |
268
|
|
|
"order":"0", |
269
|
|
|
"position":"0", |
270
|
|
|
"denom":"wbtc1" |
271
|
|
|
} |
272
|
|
|
} |
273
|
|
|
|
274
|
|
|
.. note:: |
275
|
|
|
Only non zero balances are returned. |
276
|
|
|
|
277
|
|
|
.. note:: |
278
|
|
|
Values are already in human readable format. |
279
|
|
|
|
280
|
|
|
:param swth_address: tradehub switcheo address starting with 'swth1' on mainnet and 'tswth1' on testnet. |
281
|
|
|
:return: dict with currently holding tokens. |
282
|
|
|
""" |
283
|
|
|
api_params = { |
284
|
|
|
"account": swth_address |
285
|
|
|
} |
286
|
|
|
return self.tradehub_get_request(path='/get_balance', params=api_params) |
287
|
|
|
|
288
|
|
|
def get_block(self, block_nbr: int = 1): |
289
|
|
|
return self.tradehub_get_request(path='/blocks/{}'.format(block_nbr)) |
290
|
|
|
|
291
|
|
|
def get_block_time(self) -> str: |
292
|
|
|
""" |
293
|
|
|
Get the block time in format HH:MM:SS.ZZZZZZ. |
294
|
|
|
|
295
|
|
|
Example:: |
296
|
|
|
|
297
|
|
|
public_client.get_block_time() |
298
|
|
|
|
299
|
|
|
The expected return result for this function is as follows:: |
300
|
|
|
|
301
|
|
|
"00:00:02.190211" |
302
|
|
|
|
303
|
|
|
.. warning:: |
304
|
|
|
This endpoint returns only a string. |
305
|
|
|
|
306
|
|
|
:return: block time as string. |
307
|
|
|
""" |
308
|
|
|
return self.tradehub_get_request(path='/get_block_time') |
309
|
|
|
|
310
|
|
|
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]: |
311
|
|
|
""" |
312
|
|
|
Get latest blocks or request specific blocks. |
313
|
|
|
|
314
|
|
|
Example:: |
315
|
|
|
|
316
|
|
|
public_client.get_blocks() |
317
|
|
|
|
318
|
|
|
The expected return result for this function is as follows:: |
319
|
|
|
|
320
|
|
|
[ |
321
|
|
|
{ |
322
|
|
|
"block_height":"6103923", |
323
|
|
|
"time":"2021-01-09T14:15:53.071509+01:00", |
324
|
|
|
"count":"1", |
325
|
|
|
"proposer_address":"swthvalcons17m2ueqqqt8u0jz4rv5kvk4kg0teel4sckytjlc" |
326
|
|
|
}, |
327
|
|
|
{ |
328
|
|
|
"block_height":"6103922", |
329
|
|
|
"time":"2021-01-09T14:15:50.824548+01:00", |
330
|
|
|
"count":"0", |
331
|
|
|
"proposer_address":"swthvalcons1zecfdrf22f6syz8xj4vn8jsvsalxdhwl9tlflk" |
332
|
|
|
}, |
333
|
|
|
... |
334
|
|
|
] |
335
|
|
|
|
336
|
|
|
.. warning:: This endpoint is not well documented in official documents. The parameters are NOT required. |
337
|
|
|
|
338
|
|
|
:param before_id: Before block height(exclusive). |
339
|
|
|
:param after_id: After block height(exclusive). |
340
|
|
|
:param order_by: Not specified yet. |
341
|
|
|
:param swth_valcons: Switcheo tradehub validator consensus starting with 'swthvalcons1' on mainnet and |
342
|
|
|
'tswthvalcons1' on testnet. |
343
|
|
|
:param limit: Limit the responded result. Values greater than 200 have no effect and a maximum off 200 |
344
|
|
|
results are returned. |
345
|
|
|
:return: List with found blocks matching the requested parameters. Can be empty list []. |
346
|
|
|
""" |
347
|
|
|
api_params = { |
348
|
|
|
"before_id": before_id, |
349
|
|
|
"after_id": after_id, |
350
|
|
|
"order_by": order_by, |
351
|
|
|
"proposer": swth_valcons, |
352
|
|
|
"limit": limit |
353
|
|
|
} |
354
|
|
|
|
355
|
|
|
return self.tradehub_get_request(path='/get_blocks', params=api_params) |
356
|
|
|
|
357
|
|
|
def get_candlesticks(self, market: str, granularity: int, from_epoch: int, to_epoch: int) -> List[dict]: |
358
|
|
|
""" |
359
|
|
|
Get candlesticks for a market. |
360
|
|
|
|
361
|
|
|
Example:: |
362
|
|
|
|
363
|
|
|
public_client.get_candlesticks("swth_eth1", 5, 1610203000, 1610203090) |
364
|
|
|
|
365
|
|
|
The expected return result for this function is as follows:: |
366
|
|
|
|
367
|
|
|
[ |
368
|
|
|
{ |
369
|
|
|
"id":38648, |
370
|
|
|
"market":"swth_eth1", |
371
|
|
|
"time":"2021-01-09T15:35:00+01:00", |
372
|
|
|
"resolution":5, |
373
|
|
|
"open":"0.0000212", |
374
|
|
|
"close":"0.0000212", |
375
|
|
|
"high":"0.0000212", |
376
|
|
|
"low":"0.0000212", |
377
|
|
|
"volume":"2100", |
378
|
|
|
"quote_volume":"0.04452" |
379
|
|
|
}, |
380
|
|
|
... |
381
|
|
|
] |
382
|
|
|
|
383
|
|
|
|
384
|
|
|
.. warning:: |
385
|
|
|
|
386
|
|
|
This endpoint is not well documented in official documents. |
387
|
|
|
The example market swth_eth does not exist on mainnet. The correct market ticker is 'swth_eth1'. |
388
|
|
|
See get_markets() for correct tickers. |
389
|
|
|
|
390
|
|
|
.. warning:: |
391
|
|
|
|
392
|
|
|
If any off the required parameters is not provided or incorrect the server responses with 500 status codes. |
393
|
|
|
|
394
|
|
|
.. warning:: |
395
|
|
|
|
396
|
|
|
Responses are marked as 'plain' and not as 'text/json'. |
397
|
|
|
|
398
|
|
|
.. warning:: |
399
|
|
|
|
400
|
|
|
This endpoint returns numbers as string(ex. "volume":"2100") or integer(ex. "resolution":5) |
401
|
|
|
|
402
|
|
|
:raises ValueError: If 'granularity' is not 1, 5, 30, 60, 360 or 1440. |
403
|
|
|
|
404
|
|
|
|
405
|
|
|
:param market: Market ticker used by blockchain (eg. swth_eth1). |
406
|
|
|
:param granularity: Candlestick period in minutes, possible values are: 1, 5, 30, 60, 360 or 1440. |
407
|
|
|
:param from_epoch: Start of time range for data in epoch seconds. |
408
|
|
|
:param to_epoch: End of time range for data in epoch seconds. |
409
|
|
|
:return: List with candles as dict. |
410
|
|
|
""" |
411
|
|
|
if granularity not in [1, 5, 30, 60, 360, 1440]: |
412
|
|
|
raise ValueError(f"Granularity/Resolution has to be on off the following values: 1, 5, 30, 60, 360 or 1440") |
413
|
|
|
|
414
|
|
|
api_params = { |
415
|
|
|
"market": market, |
416
|
|
|
"resolution": granularity, |
417
|
|
|
"from": from_epoch, |
418
|
|
|
"to": to_epoch |
419
|
|
|
} |
420
|
|
|
return self.tradehub_get_request(path='/candlesticks', params=api_params) |
421
|
|
|
|
422
|
|
|
def get_commitment_curve(self): |
423
|
|
|
return self.tradehub_get_request(path='/get_commitment_curve') |
424
|
|
|
|
425
|
|
|
def get_delegation_rewards(self, swth_address: str) -> dict: |
426
|
|
|
""" |
427
|
|
|
Request delegation rewards made by a tradehub wallet. |
428
|
|
|
|
429
|
|
|
Example:: |
430
|
|
|
|
431
|
|
|
# wallet behind Devel And Co validator |
432
|
|
|
public_client.get_delegation_rewards("swth1vwges9p847l9csj8ehrlgzajhmt4fcq4sd7gzl") |
433
|
|
|
|
434
|
|
|
The expected return result for this function is as follows:: |
435
|
|
|
|
436
|
|
|
{ |
437
|
|
|
"height": "6104998", |
438
|
|
|
"result": { |
439
|
|
|
"rewards": [ |
440
|
|
|
{ |
441
|
|
|
"validator_address": "swthvaloper1vwges9p847l9csj8ehrlgzajhmt4fcq4dmg8x0", |
442
|
|
|
"reward": [ |
443
|
|
|
{ |
444
|
|
|
"denom": "swth", |
445
|
|
|
"amount": "7928468882.342780820000000000" |
446
|
|
|
}, |
447
|
|
|
... |
448
|
|
|
] |
449
|
|
|
}, |
450
|
|
|
... |
451
|
|
|
], |
452
|
|
|
"total": [ |
453
|
|
|
{ |
454
|
|
|
"denom": "cel1", |
455
|
|
|
"amount": "0.032116540000000000" |
456
|
|
|
}, |
457
|
|
|
... |
458
|
|
|
] |
459
|
|
|
} |
460
|
|
|
} |
461
|
|
|
|
462
|
|
|
.. warning:: |
463
|
|
|
|
464
|
|
|
Only non zero balances are returned. |
465
|
|
|
|
466
|
|
|
.. warning:: |
467
|
|
|
|
468
|
|
|
Values are NOT in human readable format even if the values contain a decimal separator. |
469
|
|
|
|
470
|
|
|
.. warning:: |
471
|
|
|
|
472
|
|
|
This endpoint returns amounts which are NOT human readable values. Consider 'base_precision' and |
473
|
|
|
'quote_precision' to calculate a multiplication factor = 10 ^ ('base_precision' - 'quote_precision') |
474
|
|
|
|
475
|
|
|
.. note:: |
476
|
|
|
|
477
|
|
|
This endpoint does not include unclaimed commissions off a validator. If a validator wallet is requested |
478
|
|
|
only the rewards earned by delegation are returned. |
479
|
|
|
|
480
|
|
|
:param swth_address: tradehub switcheo address starting with 'swth1' on mainnet and 'tswth1' on testnet. |
481
|
|
|
:return: return dict with generated unclaimed rewards. |
482
|
|
|
""" |
483
|
|
|
api_params = { |
484
|
|
|
"account": swth_address, |
485
|
|
|
} |
486
|
|
|
return self.tradehub_get_request(path='/get_delegation_rewards', params=api_params) |
487
|
|
|
|
488
|
|
|
def get_distribution_parameters(self): |
489
|
|
|
return self.tradehub_get_request(path='/distribution/parameters') |
490
|
|
|
|
491
|
|
|
def get_external_transfers(self, swth_address: str) -> List[dict]: |
492
|
|
|
""" |
493
|
|
|
Get external transfers(withdraws or deposits) from other blockchains. |
494
|
|
|
|
495
|
|
|
Example:: |
496
|
|
|
|
497
|
|
|
# wallet Devel |
498
|
|
|
public_client.get_delegation_rewards("swth1qlue2pat9cxx2s5xqrv0ashs475n9va963h4hz") |
499
|
|
|
|
500
|
|
|
The expected return result for this function is as follows:: |
501
|
|
|
|
502
|
|
|
[ |
503
|
|
|
{ |
504
|
|
|
"address":"swth1qlue2pat9cxx2s5xqrv0ashs475n9va963h4hz", |
505
|
|
|
"amount":"0.9826", |
506
|
|
|
"block_height":5937838, |
507
|
|
|
"blockchain":"eth", |
508
|
|
|
"contract_hash":"9a016ce184a22dbf6c17daa59eb7d3140dbd1c54", |
509
|
|
|
"denom":"eth1", |
510
|
|
|
"fee_address":"swth1prv0t8j8tqcdngdmjlt59pwy6dxxmtqgycy2h7", |
511
|
|
|
"fee_amount":"0.0174", |
512
|
|
|
"id":"12853", |
513
|
|
|
"status":"success", |
514
|
|
|
"symbol":"ETH", |
515
|
|
|
"timestamp":1609839309, |
516
|
|
|
"token_name":"Ethereum", |
517
|
|
|
"transaction_hash":"", |
518
|
|
|
"transfer_type":"deposit" |
519
|
|
|
}, |
520
|
|
|
... |
521
|
|
|
] |
522
|
|
|
|
523
|
|
|
.. warning:: |
524
|
|
|
|
525
|
|
|
This endpoint returns numbers as string(eg. "id":"12853") or integer(eg. "timestamp":1609839309) |
526
|
|
|
|
527
|
|
|
.. note:: |
528
|
|
|
|
529
|
|
|
This endpoint return amounts in human readable format. |
530
|
|
|
|
531
|
|
|
:param swth_address: tradehub switcheo address starting with 'swth1' on mainnet and 'tswth1' on testnet. |
532
|
|
|
:return: List with external transfers |
533
|
|
|
""" |
534
|
|
|
api_params = { |
535
|
|
|
"account": swth_address |
536
|
|
|
} |
537
|
|
|
return self.tradehub_get_request(path='/get_external_transfers', params=api_params) |
538
|
|
|
|
539
|
|
|
def get_inflation_start_time(self): |
540
|
|
|
return self.tradehub_get_request(path='/get_inflation_start_time') |
541
|
|
|
|
542
|
|
|
def get_insurance_fund_balance(self): |
543
|
|
|
""" |
544
|
|
|
|
545
|
|
|
.. warning:: |
546
|
|
|
|
547
|
|
|
This endpoint is not working yet. |
548
|
|
|
|
549
|
|
|
:return: |
550
|
|
|
""" |
551
|
|
|
# TODO result currently [] |
552
|
|
|
return self.tradehub_get_request(path='/get_insurance_balance') |
553
|
|
|
|
554
|
|
|
def get_latest_blocks(self): |
555
|
|
|
return self.tradehub_get_request(path='/blocks/latest') |
556
|
|
|
|
557
|
|
|
def get_leverage(self, swth_address: str, market: str): |
558
|
|
|
""" |
559
|
|
|
|
560
|
|
|
.. warning:: |
561
|
|
|
|
562
|
|
|
This endpoint is not working yet. |
563
|
|
|
|
564
|
|
|
:param swth_address: |
565
|
|
|
:param market: |
566
|
|
|
:return: |
567
|
|
|
""" |
568
|
|
|
# TODO result currently not available |
569
|
|
|
api_params = { |
570
|
|
|
"account": swth_address, |
571
|
|
|
"market": market |
572
|
|
|
} |
573
|
|
|
return self.tradehub_get_request(path='/get_leverage', params=api_params) |
574
|
|
|
|
575
|
|
|
def get_liquidity_pools(self): |
576
|
|
|
return self.tradehub_get_request(path='/get_liquidity_pools') |
577
|
|
|
|
578
|
|
|
def get_liquidations(self, before_id: int, after_id: int, order_by: str, limit: int): |
579
|
|
|
""" |
580
|
|
|
|
581
|
|
|
.. warning:: |
582
|
|
|
|
583
|
|
|
This endpoint is not working yet. |
584
|
|
|
|
585
|
|
|
:param before_id: |
586
|
|
|
:param after_id: |
587
|
|
|
:param order_by: |
588
|
|
|
:param limit: |
589
|
|
|
:return: |
590
|
|
|
""" |
591
|
|
|
# TODO result currently not available |
592
|
|
|
api_params = { |
593
|
|
|
"before_id": before_id, |
594
|
|
|
"after_id": after_id, |
595
|
|
|
"order_by": order_by, |
596
|
|
|
"limit": limit |
597
|
|
|
} |
598
|
|
|
return self.tradehub_get_request(path='/get_liquidations', params=api_params) |
599
|
|
|
|
600
|
|
|
def get_market(self, market: str) -> dict: |
601
|
|
|
""" |
602
|
|
|
Get information about a market. |
603
|
|
|
|
604
|
|
|
Example:: |
605
|
|
|
|
606
|
|
|
public_client.get_market("swth_eth1") |
607
|
|
|
|
608
|
|
|
The expected return result for this function is as follows:: |
609
|
|
|
|
610
|
|
|
{ |
611
|
|
|
"type":"", |
612
|
|
|
"name":"swth_eth1", |
613
|
|
|
"display_name":"SWTH_ETH", |
614
|
|
|
"description":"SWTH/ETH Spot Market", |
615
|
|
|
"market_type":"spot", |
616
|
|
|
"base":"swth", |
617
|
|
|
"base_name":"Switcheo", |
618
|
|
|
"base_precision":8, |
619
|
|
|
"quote":"eth1", |
620
|
|
|
"quote_name":"Ethereum", |
621
|
|
|
"quote_precision":18, |
622
|
|
|
"lot_size":"1", |
623
|
|
|
"tick_size":"0.0000001", |
624
|
|
|
"min_quantity":"200", |
625
|
|
|
"maker_fee":"-0.0005", |
626
|
|
|
"taker_fee":"0.0025", |
627
|
|
|
"risk_step_size":"0", |
628
|
|
|
"initial_margin_base":"1", |
629
|
|
|
"initial_margin_step":"0", |
630
|
|
|
"maintenance_margin_ratio":"0", |
631
|
|
|
"max_liquidation_order_ticket":"0", |
632
|
|
|
"max_liquidation_order_duration":0, |
633
|
|
|
"impact_size":"0", |
634
|
|
|
"mark_price_band":0, |
635
|
|
|
"last_price_protected_band":0, |
636
|
|
|
"index_oracle_id":"", |
637
|
|
|
"expiry_time":"1970-01-01T01:00:00+01:00", |
638
|
|
|
"is_active":true, |
639
|
|
|
"is_settled":false, |
640
|
|
|
"closed_block_height":0, |
641
|
|
|
"created_block_height":0 |
642
|
|
|
} |
643
|
|
|
|
644
|
|
|
.. warning:: |
645
|
|
|
|
646
|
|
|
This endpoint is not well documented in official documents. |
647
|
|
|
The example market swth_eth does not exist on mainnet. The correct market ticker is 'swth_eth1'. |
648
|
|
|
See get_markets() for correct tickers. |
649
|
|
|
|
650
|
|
|
.. warning:: |
651
|
|
|
|
652
|
|
|
This endpoint returns numbers as string(eg. "lot_size":"1") or integer(eg. "base_precision":8). |
653
|
|
|
|
654
|
|
|
.. warning:: |
655
|
|
|
|
656
|
|
|
This endpoint returns the same dict structure even the market does not exist with default values! |
657
|
|
|
|
658
|
|
|
:param market: Market ticker used by blockchain (eg. swth_eth1). |
659
|
|
|
:return: |
660
|
|
|
""" |
661
|
|
|
api_params = { |
662
|
|
|
"market": market, |
663
|
|
|
} |
664
|
|
|
return self.tradehub_get_request(path='/get_market', params=api_params) |
665
|
|
|
|
666
|
|
|
def get_market_stats(self, market: Optional[str] = None) -> List[dict]: |
667
|
|
|
""" |
668
|
|
|
Get statistics about one or all markets. |
669
|
|
|
|
670
|
|
|
Example:: |
671
|
|
|
|
672
|
|
|
public_client.get_market_stats() |
673
|
|
|
|
674
|
|
|
The expected return result for this function is as follows:: |
675
|
|
|
|
676
|
|
|
[ |
677
|
|
|
{ |
678
|
|
|
"day_high":"0.0000215", |
679
|
|
|
"day_low":"0.000021", |
680
|
|
|
"day_open":"0.0000211", |
681
|
|
|
"day_close":"0.0000212", |
682
|
|
|
"day_volume":"436030", |
683
|
|
|
"day_quote_volume":"9.2787298", |
684
|
|
|
"index_price":"0", |
685
|
|
|
"mark_price":"0", |
686
|
|
|
"last_price":"0.00212000", |
687
|
|
|
"market":"swth_eth1", |
688
|
|
|
"market_type":"spot", |
689
|
|
|
"open_interest":"0" |
690
|
|
|
} |
691
|
|
|
... |
692
|
|
|
] |
693
|
|
|
|
694
|
|
|
|
695
|
|
|
:param market: Market ticker used by blockchain (eg. swth_eth1). |
696
|
|
|
:return: List with market stats as dict |
697
|
|
|
""" |
698
|
|
|
api_params = { |
699
|
|
|
"market": market |
700
|
|
|
} |
701
|
|
|
return self.tradehub_get_request(path='/get_market_stats', params=api_params) |
702
|
|
|
|
703
|
|
|
def get_markets(self, market_type: Optional[str] = None, is_active: Optional[bool] = None, is_settled: Optional[bool] = None) -> List[dict]: |
704
|
|
|
""" |
705
|
|
|
Get all markets or filter markets. |
706
|
|
|
|
707
|
|
|
Example:: |
708
|
|
|
|
709
|
|
|
public_client.get_markets() |
710
|
|
|
|
711
|
|
|
The expected return result for this function is as follows:: |
712
|
|
|
|
713
|
|
|
[ |
714
|
|
|
{ |
715
|
|
|
"type":"", |
716
|
|
|
"name":"swth_eth1", |
717
|
|
|
"display_name":"SWTH_ETH", |
718
|
|
|
"description":"SWTH/ETH Spot Market", |
719
|
|
|
"market_type":"spot", |
720
|
|
|
"base":"swth", |
721
|
|
|
"base_name":"Switcheo", |
722
|
|
|
"base_precision":8, |
723
|
|
|
"quote":"eth1", |
724
|
|
|
"quote_name":"Ethereum", |
725
|
|
|
"quote_precision":18, |
726
|
|
|
"lot_size":"1", |
727
|
|
|
"tick_size":"0.0000001", |
728
|
|
|
"min_quantity":"200", |
729
|
|
|
"maker_fee":"-0.0005", |
730
|
|
|
"taker_fee":"0.0025", |
731
|
|
|
"risk_step_size":"0", |
732
|
|
|
"initial_margin_base":"1", |
733
|
|
|
"initial_margin_step":"0", |
734
|
|
|
"maintenance_margin_ratio":"0", |
735
|
|
|
"max_liquidation_order_ticket":"0", |
736
|
|
|
"max_liquidation_order_duration":0, |
737
|
|
|
"impact_size":"0", |
738
|
|
|
"mark_price_band":0, |
739
|
|
|
"last_price_protected_band":0, |
740
|
|
|
"index_oracle_id":"", |
741
|
|
|
"expiry_time":"1970-01-01T01:00:00+01:00", |
742
|
|
|
"is_active":true, |
743
|
|
|
"is_settled":false, |
744
|
|
|
"closed_block_height":0, |
745
|
|
|
"created_block_height":0 |
746
|
|
|
}, |
747
|
|
|
... |
748
|
|
|
] |
749
|
|
|
|
750
|
|
|
.. warning:: |
751
|
|
|
This endpoint returns numbers as string(eg. "lot_size":"1") or integer(eg. "base_precision":8) |
752
|
|
|
|
753
|
|
|
:param market_type: type of the market can be 'futures' or 'spot' |
754
|
|
|
:param is_active: if only active markets should be returned |
755
|
|
|
:param is_settled: if only settled markets should be returned |
756
|
|
|
:return: List with returned market stats as dict |
757
|
|
|
""" |
758
|
|
|
|
759
|
|
|
if market_type and market_type not in ['futures', 'spot']: |
760
|
|
|
raise ValueError(f"Parameter 'market_type' only can be 'futures' or 'spot'. Got {market_type} instead.") |
761
|
|
|
|
762
|
|
|
api_params = { |
763
|
|
|
"market_type": market_type, |
764
|
|
|
"is_active": is_active, |
765
|
|
|
"is_settled": is_settled |
766
|
|
|
} |
767
|
|
|
|
768
|
|
|
return self.tradehub_get_request(path='/get_markets', params=api_params) |
769
|
|
|
|
770
|
|
|
def get_nodes(self) -> dict: |
771
|
|
|
""" |
772
|
|
|
""" |
773
|
|
|
# TODO no results yet available |
774
|
|
|
return self.tradehub_get_request(path='/monitor') |
775
|
|
|
|
776
|
|
|
def get_oracle_result(self, oracle_id: str): |
777
|
|
|
""" |
778
|
|
|
|
779
|
|
|
.. warning:: |
780
|
|
|
|
781
|
|
|
This endpoint is not working yet. |
782
|
|
|
|
783
|
|
|
:param oracle_id: |
784
|
|
|
:return: |
785
|
|
|
""" |
786
|
|
|
# TODO no results yet available |
787
|
|
|
api_params = { |
788
|
|
|
"id": oracle_id |
789
|
|
|
} |
790
|
|
|
return self.tradehub_get_request(path='/get_oracle_result', params=api_params) |
791
|
|
|
|
792
|
|
|
def get_oracle_results(self): |
793
|
|
|
""" |
794
|
|
|
|
795
|
|
|
.. warning:: |
796
|
|
|
|
797
|
|
|
This endpoint is not working yet. |
798
|
|
|
|
799
|
|
|
:return: |
800
|
|
|
""" |
801
|
|
|
# TODO no results yet available |
802
|
|
|
return self.tradehub_get_request(path='/get_oracle_results') |
803
|
|
|
|
804
|
|
|
def get_orderbook(self, market: str, limit: Optional[int] = None): |
805
|
|
|
""" |
806
|
|
|
Get the orderbook from a market. |
807
|
|
|
|
808
|
|
|
Example:: |
809
|
|
|
|
810
|
|
|
public_client.get_orderbook("swth_eth1") |
811
|
|
|
|
812
|
|
|
The expected return result for this function is as follows:: |
813
|
|
|
|
814
|
|
|
{ |
815
|
|
|
"asks": [ |
816
|
|
|
{ |
817
|
|
|
"price":"0.0000214", |
818
|
|
|
"quantity":"49863" |
819
|
|
|
}, |
820
|
|
|
{ |
821
|
|
|
"price":"0.0000215", |
822
|
|
|
"quantity":"49446" |
823
|
|
|
}, |
824
|
|
|
... |
825
|
|
|
], |
826
|
|
|
"bids": [ |
827
|
|
|
{ |
828
|
|
|
"price":"0.0000212", |
829
|
|
|
"quantity":"50248" |
830
|
|
|
}, |
831
|
|
|
{ |
832
|
|
|
"price":"0.0000211", |
833
|
|
|
"quantity":"50295" |
834
|
|
|
}, |
835
|
|
|
... |
836
|
|
|
] |
837
|
|
|
} |
838
|
|
|
|
839
|
|
|
.. warning:: |
840
|
|
|
|
841
|
|
|
This endpoint returns an empty 'asks' and 'bids' list if the market is not known. |
842
|
|
|
|
843
|
|
|
:param market: Market ticker used by blockchain (eg. swth_eth1). |
844
|
|
|
:param limit: Number off returned orders per side(asks, bids). |
845
|
|
|
:return: Orderbook as 'asks' and 'bids' list |
846
|
|
|
""" |
847
|
|
|
api_params = { |
848
|
|
|
"market": market, |
849
|
|
|
"limit": limit |
850
|
|
|
} |
851
|
|
|
return self.tradehub_get_request(path='/get_orderbook', params=api_params) |
852
|
|
|
|
853
|
|
|
def get_order(self, order_id: str) -> dict: |
854
|
|
|
""" |
855
|
|
|
Get a specific order by id. |
856
|
|
|
|
857
|
|
|
Example:: |
858
|
|
|
|
859
|
|
|
public_client.get_order("4F54D2AE0D793F833806109B4278335BF3D392D4096B682B9A27AF9F8A8BCA58") |
860
|
|
|
|
861
|
|
|
The expected return result for this function is as follows:: |
862
|
|
|
|
863
|
|
|
{ |
864
|
|
|
"order_id":"4F54D2AE0D793F833806109B4278335BF3D392D4096B682B9A27AF9F8A8BCA58", |
865
|
|
|
"block_height":6117321, |
866
|
|
|
"triggered_block_height":0, |
867
|
|
|
"address":"swth1wmcj8gmz4tszy5v8c0d9lxnmguqcdkw22275w5", |
868
|
|
|
"market":"eth1_usdc1", |
869
|
|
|
"side":"buy", |
870
|
|
|
"price":"1255.68", |
871
|
|
|
"quantity":"0.01", |
872
|
|
|
"available":"0.01", |
873
|
|
|
"filled":"0", |
874
|
|
|
"order_status":"open", |
875
|
|
|
"order_type":"limit", |
876
|
|
|
"initiator":"amm", |
877
|
|
|
"time_in_force":"gtc", |
878
|
|
|
"stop_price":"0", |
879
|
|
|
"trigger_type":"", |
880
|
|
|
"allocated_margin_denom":"usdc1", |
881
|
|
|
"allocated_margin_amount":"0", |
882
|
|
|
"is_liquidation":false, |
883
|
|
|
"is_post_only":false, |
884
|
|
|
"is_reduce_only":false, |
885
|
|
|
"type":"", |
886
|
|
|
"block_created_at":"2021-01-09T22:13:34.711571+01:00", |
887
|
|
|
"username":"", |
888
|
|
|
"id":"990817" |
889
|
|
|
} |
890
|
|
|
|
891
|
|
|
:param order_id: Order identified by id |
892
|
|
|
:return: Order as dict |
893
|
|
|
""" |
894
|
|
|
api_params = { |
895
|
|
|
"order_id": order_id |
896
|
|
|
} |
897
|
|
|
return self.tradehub_get_request(path='/get_order', params=api_params) |
898
|
|
|
|
899
|
|
|
def get_orders(self, swth_address: Optional[str] = None, before_id: Optional[int] = None, |
900
|
|
|
after_id: Optional[int] = None, market: Optional[str] = None, order_type: Optional[str] = None, |
901
|
|
|
initiator: Optional[str] = None, order_status: Optional[str] = None, limit: Optional[int] = None) -> List[dict]: |
902
|
|
|
""" |
903
|
|
|
Request last orders or filter them. |
904
|
|
|
|
905
|
|
|
Example:: |
906
|
|
|
|
907
|
|
|
public_client.get_orders() |
908
|
|
|
|
909
|
|
|
The expected return result for this function is as follows:: |
910
|
|
|
|
911
|
|
|
[ |
912
|
|
|
{ |
913
|
|
|
"order_id":"4F54D2AE0D793F833806109B4278335BF3D392D4096B682B9A27AF9F8A8BCA58", |
914
|
|
|
"block_height":6117321, |
915
|
|
|
"triggered_block_height":0, |
916
|
|
|
"address":"swth1wmcj8gmz4tszy5v8c0d9lxnmguqcdkw22275w5", |
917
|
|
|
"market":"eth1_usdc1", |
918
|
|
|
"side":"buy", |
919
|
|
|
"price":"1255.68", |
920
|
|
|
"quantity":"0.01", |
921
|
|
|
"available":"0.01", |
922
|
|
|
"filled":"0", |
923
|
|
|
"order_status":"open", |
924
|
|
|
"order_type":"limit", |
925
|
|
|
"initiator":"amm", |
926
|
|
|
"time_in_force":"gtc", |
927
|
|
|
"stop_price":"0", |
928
|
|
|
"trigger_type":"", |
929
|
|
|
"allocated_margin_denom":"usdc1", |
930
|
|
|
"allocated_margin_amount":"0", |
931
|
|
|
"is_liquidation":false, |
932
|
|
|
"is_post_only":false, |
933
|
|
|
"is_reduce_only":false, |
934
|
|
|
"type":"", |
935
|
|
|
"block_created_at":"2021-01-09T22:13:34.711571+01:00", |
936
|
|
|
"username":"", |
937
|
|
|
"id":"990817" |
938
|
|
|
}, |
939
|
|
|
... |
940
|
|
|
] |
941
|
|
|
|
942
|
|
|
.. warning:: |
943
|
|
|
|
944
|
|
|
This endpoint is not well documented in official documents. |
945
|
|
|
Parameter account is NOT required! It is possible to provide more parameters, |
946
|
|
|
known ones are documented here. |
947
|
|
|
|
948
|
|
|
.. warning:: |
949
|
|
|
|
950
|
|
|
This endpoint returns numbers as string(eg. "id":"990817") or integer(eg. "block_height":6117321) |
951
|
|
|
|
952
|
|
|
:param swth_address: tradehub switcheo address starting with 'swth1' on mainnet and 'tswth1' on testnet. |
953
|
|
|
:param before_id: return orders before id(exclusive). |
954
|
|
|
:param after_id: return orders after id(exclusive). |
955
|
|
|
:param market: Market ticker used by blockchain (eg. swth_eth1). |
956
|
|
|
:param order_type: Return specific orders, allowed values: 'limit', 'market', 'stop-market' or 'stop-limit'. |
957
|
|
|
:param initiator: Filter by user or automated market maker orders, allowed values: 'user' or 'amm'. |
958
|
|
|
:param order_status: Filter by order status, allowed values: 'open' or 'closed'. |
959
|
|
|
:param limit: Limit response, values above 200 have no effect. |
960
|
|
|
:return: List off orders as dict |
961
|
|
|
""" |
962
|
|
|
api_params = { |
963
|
|
|
"account": swth_address, |
964
|
|
|
"before_id": before_id, |
965
|
|
|
"after_id": after_id, |
966
|
|
|
"market": market, |
967
|
|
|
"order_type": order_type, |
968
|
|
|
"initiator": initiator, |
969
|
|
|
"order_status": order_status, |
970
|
|
|
"limit": limit |
971
|
|
|
} |
972
|
|
|
return self.tradehub_get_request(path='/get_orders', params=api_params) |
973
|
|
|
|
974
|
|
|
def get_position(self, swth_address: str, market: str): |
975
|
|
|
""" |
976
|
|
|
|
977
|
|
|
.. warning:: |
978
|
|
|
|
979
|
|
|
This endpoint is not working yet. |
980
|
|
|
|
981
|
|
|
:param swth_address: |
982
|
|
|
:param market: |
983
|
|
|
:return: |
984
|
|
|
""" |
985
|
|
|
# TODO responses currently not available |
986
|
|
|
api_params = { |
987
|
|
|
"account": swth_address, |
988
|
|
|
"market": market |
989
|
|
|
} |
990
|
|
|
return self.tradehub_get_request(path='/get_position', params=api_params) |
991
|
|
|
|
992
|
|
|
def get_positions(self, swth_address: str): |
993
|
|
|
""" |
994
|
|
|
|
995
|
|
|
.. warning:: |
996
|
|
|
|
997
|
|
|
This endpoint is not working yet. |
998
|
|
|
|
999
|
|
|
:param swth_address: |
1000
|
|
|
:return: |
1001
|
|
|
""" |
1002
|
|
|
# TODO responses currently not available |
1003
|
|
|
api_params = { |
1004
|
|
|
"account": swth_address |
1005
|
|
|
} |
1006
|
|
|
return self.tradehub_get_request(path='/get_positions', params=api_params) |
1007
|
|
|
|
1008
|
|
|
def get_positions_sorted_by_pnl(self, market): |
1009
|
|
|
""" |
1010
|
|
|
|
1011
|
|
|
.. warning:: |
1012
|
|
|
|
1013
|
|
|
This endpoint is not working yet. |
1014
|
|
|
|
1015
|
|
|
:param market: |
1016
|
|
|
:return: |
1017
|
|
|
""" |
1018
|
|
|
# TODO responses currently not available |
1019
|
|
|
api_params = { |
1020
|
|
|
"market": market |
1021
|
|
|
} |
1022
|
|
|
return self.tradehub_get_request(path='/get_positions_sorted_by_pnl', params=api_params) |
1023
|
|
|
|
1024
|
|
|
def get_positions_sorted_by_risk(self, market): |
1025
|
|
|
""" |
1026
|
|
|
|
1027
|
|
|
.. warning:: |
1028
|
|
|
|
1029
|
|
|
This endpoint is not working yet. |
1030
|
|
|
|
1031
|
|
|
:param market: |
1032
|
|
|
:return: |
1033
|
|
|
""" |
1034
|
|
|
# TODO responses currently not available |
1035
|
|
|
api_params = { |
1036
|
|
|
"market": market |
1037
|
|
|
} |
1038
|
|
|
return self.tradehub_get_request(path='/get_positions_sorted_by_risk', params=api_params) |
1039
|
|
|
|
1040
|
|
|
def get_positions_sorted_by_size(self, market): |
1041
|
|
|
""" |
1042
|
|
|
|
1043
|
|
|
.. warning:: |
1044
|
|
|
|
1045
|
|
|
This endpoint is not working yet. |
1046
|
|
|
|
1047
|
|
|
:param market: |
1048
|
|
|
:return: |
1049
|
|
|
""" |
1050
|
|
|
# TODO responses currently not available |
1051
|
|
|
api_params = { |
1052
|
|
|
"market": market |
1053
|
|
|
} |
1054
|
|
|
return self.tradehub_get_request(path='/get_positions_sorted_by_size', params=api_params) |
1055
|
|
|
|
1056
|
|
|
def get_prices(self, market: Optional[str]) -> dict: |
1057
|
|
|
""" |
1058
|
|
|
Get prices off a market. |
1059
|
|
|
|
1060
|
|
|
Example:: |
1061
|
|
|
|
1062
|
|
|
public_client.get_prices("swth_eth1") |
1063
|
|
|
|
1064
|
|
|
The expected return result for this function is as follows:: |
1065
|
|
|
|
1066
|
|
|
{ |
1067
|
|
|
"last":"207000", |
1068
|
|
|
"index":"0", |
1069
|
|
|
"fair":"0", |
1070
|
|
|
"mark":"0", |
1071
|
|
|
"mark_avg":"0", |
1072
|
|
|
"settlement":"0", |
1073
|
|
|
"fair_index_delta_avg":"0", |
1074
|
|
|
"market":"", |
1075
|
|
|
"marking_strategy":"", |
1076
|
|
|
"index_updated_at":"0001-01-01T00:00:00Z", |
1077
|
|
|
"last_updated_at":"2021-01-09T22:50:59.068526+01:00", |
1078
|
|
|
"block_height":0 |
1079
|
|
|
} |
1080
|
|
|
|
1081
|
|
|
.. warning:: |
1082
|
|
|
|
1083
|
|
|
This endpoint is not well documented in official documents. |
1084
|
|
|
Parameter 'market' is NOT required, but strongly recommended. The return result has an empty 'market' field. |
1085
|
|
|
|
1086
|
|
|
.. warning:: |
1087
|
|
|
|
1088
|
|
|
This endpoint returns amounts which are NOT human readable values. Consider 'base_precision' and |
1089
|
|
|
'quote_precision' to calculate a multiplication factor = 10 ^ ('base_precision' - 'quote_precision') |
1090
|
|
|
|
1091
|
|
|
.. warning:: |
1092
|
|
|
|
1093
|
|
|
This endpoint returns numbers as string(eg. "last":"207000") or integer(eg. "block_height":0) |
1094
|
|
|
|
1095
|
|
|
.. warning:: |
1096
|
|
|
|
1097
|
|
|
This endpoint returns a result even if the market is not known. Result contains default values. |
1098
|
|
|
|
1099
|
|
|
:param market: Market ticker used by blockchain (eg. swth_eth1). |
1100
|
|
|
:return: Prices as dict |
1101
|
|
|
""" |
1102
|
|
|
api_params = { |
1103
|
|
|
"market": market |
1104
|
|
|
} |
1105
|
|
|
return self.tradehub_get_request(path='/get_prices', params=api_params) |
1106
|
|
|
|
1107
|
|
|
def get_profile(self, swth_address: str) -> dict: |
1108
|
|
|
""" |
1109
|
|
|
Get profile from a tradehub wallet. |
1110
|
|
|
|
1111
|
|
|
Example:: |
1112
|
|
|
|
1113
|
|
|
public_client.get_profile("swth1qlue2pat9cxx2s5xqrv0ashs475n9va963h4hz") |
1114
|
|
|
|
1115
|
|
|
The expected return result for this function is as follows:: |
1116
|
|
|
|
1117
|
|
|
{ |
1118
|
|
|
"address":"swth1qlue2pat9cxx2s5xqrv0ashs475n9va963h4hz", |
1119
|
|
|
"last_seen_block":"6036318", |
1120
|
|
|
"last_seen_time":"2021-01-07T21:47:14.593249+01:00", |
1121
|
|
|
"twitter":"", |
1122
|
|
|
"username":"devel484" |
1123
|
|
|
} |
1124
|
|
|
|
1125
|
|
|
:param swth_address: tradehub switcheo address starting with 'swth1' on mainnet and 'tswth1' on testnet. |
1126
|
|
|
:return: Profile as dict |
1127
|
|
|
""" |
1128
|
|
|
api_params = { |
1129
|
|
|
"account": swth_address |
1130
|
|
|
} |
1131
|
|
|
return self.tradehub_get_request(path='/get_profile', params=api_params) |
1132
|
|
|
|
1133
|
|
|
def get_reward_curve(self): |
1134
|
|
|
return self.tradehub_get_request(path='/get_reward_curve') |
1135
|
|
|
|
1136
|
|
|
def get_rich_list(self, token: str): |
1137
|
|
|
""" |
1138
|
|
|
|
1139
|
|
|
.. warning:: |
1140
|
|
|
This endpoint is not working yet. |
1141
|
|
|
|
1142
|
|
|
:param token: |
1143
|
|
|
:return: |
1144
|
|
|
""" |
1145
|
|
|
# TODO responses currently not available |
1146
|
|
|
api_params = { |
1147
|
|
|
"token": token |
1148
|
|
|
} |
1149
|
|
|
return self.tradehub_get_request(path='/get_rich_list', params=api_params) |
1150
|
|
|
|
1151
|
|
|
def get_staking_pool(self): |
1152
|
|
|
return self.tradehub_get_request(path='/staking/pool') |
1153
|
|
|
|
1154
|
|
|
def get_status(self) -> dict: |
1155
|
|
|
""" |
1156
|
|
|
Return cosmos RPC status endpoint. |
1157
|
|
|
|
1158
|
|
|
Example:: |
1159
|
|
|
|
1160
|
|
|
public_client.get_status() |
1161
|
|
|
|
1162
|
|
|
The expected return result for this function is as follows:: |
1163
|
|
|
|
1164
|
|
|
{ |
1165
|
|
|
"jsonrpc": "2.0", |
1166
|
|
|
"id": -1, |
1167
|
|
|
"result": { |
1168
|
|
|
"node_info": { |
1169
|
|
|
"protocol_version": { |
1170
|
|
|
"p2p": "7", |
1171
|
|
|
"block": "10", |
1172
|
|
|
"app": "0" |
1173
|
|
|
}, |
1174
|
|
|
"id": "f4cee80e4dec5a686139cb82729118e15f7ce19c", |
1175
|
|
|
"listen_addr": "tcp://0.0.0.0:26656", |
1176
|
|
|
"network": "switcheo-tradehub-1", |
1177
|
|
|
"version": "0.33.7", |
1178
|
|
|
"channels": "4020212223303800", |
1179
|
|
|
"moniker": "Devel Sentry Node 2", |
1180
|
|
|
"other": { |
1181
|
|
|
"tx_index": "on", |
1182
|
|
|
"rpc_address": "tcp://0.0.0.0:26659" |
1183
|
|
|
} |
1184
|
|
|
}, |
1185
|
|
|
"sync_info": { |
1186
|
|
|
"latest_block_hash": "4A2C89C105D7864AA74C9DE4752AF5B59E96045EBAF984C69DD447C4524EC36F", |
1187
|
|
|
"latest_app_hash": "773651392EEDBFF6AEE088F76E7D75F2932B4D9F74CA27D568F706ADFC12B174", |
1188
|
|
|
"latest_block_height": "6119142", |
1189
|
|
|
"latest_block_time": "2021-01-09T22:18:52.722611018Z", |
1190
|
|
|
"earliest_block_hash": "B4AF1F3D3D3FD5795BDDB7A6A2E6CA4E34D06338505D6EC46DD8F99E72ADCDAB", |
1191
|
|
|
"earliest_app_hash": "", |
1192
|
|
|
"earliest_block_height": "1", |
1193
|
|
|
"earliest_block_time": "2020-08-14T07:32:27.856700491Z", |
1194
|
|
|
"catching_up": false |
1195
|
|
|
}, |
1196
|
|
|
"validator_info": { |
1197
|
|
|
"address": "DCB03C204B7F94765B4ADCE1D8BEE88AA43AE811", |
1198
|
|
|
"pub_key": { |
1199
|
|
|
"type": "tendermint/PubKeyEd25519", |
1200
|
|
|
"value": "1GmDSymN6jTqQlZA2KeyzqknIncGMMrwnnas/DWGNOI=" |
1201
|
|
|
}, |
1202
|
|
|
"voting_power": "0" |
1203
|
|
|
} |
1204
|
|
|
} |
1205
|
|
|
} |
1206
|
|
|
|
1207
|
|
|
:return: Status as dict |
1208
|
|
|
""" |
1209
|
|
|
return self.tradehub_get_request(path='/get_status') |
1210
|
|
|
|
1211
|
|
|
def get_trades(self, market: Optional[str] = None, before_id: Optional[int] = None, after_id: Optional[int] = None, |
1212
|
|
|
order_by: Optional[str] = None, limit: Optional[int] = None, |
1213
|
|
|
swth_address: Optional[str] = None) -> List[dict]: |
1214
|
|
|
""" |
1215
|
|
|
Get recent trades or filter trades. |
1216
|
|
|
|
1217
|
|
|
Example:: |
1218
|
|
|
|
1219
|
|
|
public_client.get_trades() |
1220
|
|
|
|
1221
|
|
|
The expected return result for this function is as follows:: |
1222
|
|
|
|
1223
|
|
|
[ |
1224
|
|
|
{ |
1225
|
|
|
"id":"103965", |
1226
|
|
|
"block_created_at":"2021-01-10T21:59:53.563633+01:00", |
1227
|
|
|
"taker_id":"11DCD0B7B0A0021476B8C801FD627B297EBDBBE7436BFEEC5ADB734DCF3C9291", |
1228
|
|
|
"taker_address":"swth1qlue2pat9cxx2s5xqrv0ashs475n9va963h4hz", |
1229
|
|
|
"taker_fee_amount":"0.000007", |
1230
|
|
|
"taker_fee_denom":"eth1", |
1231
|
|
|
"taker_side":"buy", |
1232
|
|
|
"maker_id":"A59962E7A61F361F7DE5BF00D7A6A8225668F449D73301FB9D3787E4C13DEE60", |
1233
|
|
|
"maker_address":"swth1wmcj8gmz4tszy5v8c0d9lxnmguqcdkw22275w5", |
1234
|
|
|
"maker_fee_amount":"-0.0000035", |
1235
|
|
|
"maker_fee_denom":"eth1", |
1236
|
|
|
"maker_side":"sell", |
1237
|
|
|
"market":"eth1_usdc1", |
1238
|
|
|
"price":"1251.51", |
1239
|
|
|
"quantity":"0.007", |
1240
|
|
|
"liquidation":"", |
1241
|
|
|
"taker_username":"devel484", |
1242
|
|
|
"maker_username":"", |
1243
|
|
|
"block_height":"6156871" |
1244
|
|
|
}, |
1245
|
|
|
... |
1246
|
|
|
] |
1247
|
|
|
|
1248
|
|
|
|
1249
|
|
|
:param market: Market ticker used by blockchain (eg. swth_eth1). |
1250
|
|
|
:param before_id: get orders before id(exclusive). |
1251
|
|
|
:param after_id: get orders after id(exclusive). |
1252
|
|
|
:param order_by: TODO no official documentation. |
1253
|
|
|
:param limit: limit the responded result, values above 200 have no effect. |
1254
|
|
|
:param swth_address: tradehub switcheo address starting with 'swth1' on mainnet and 'tswth1' on testnet. |
1255
|
|
|
:return: List off trades as dict |
1256
|
|
|
""" |
1257
|
|
|
api_params = { |
1258
|
|
|
"market": market, |
1259
|
|
|
"before_id": before_id, |
1260
|
|
|
"after_id": after_id, |
1261
|
|
|
"order_by": order_by, |
1262
|
|
|
"limit": limit, |
1263
|
|
|
"account": swth_address |
1264
|
|
|
} |
1265
|
|
|
return self.tradehub_get_request(path='/get_trades', params=api_params) |
1266
|
|
|
|
1267
|
|
|
def get_transaction(self, tx_hash: str): |
1268
|
|
|
""" |
1269
|
|
|
Get a transaction by providing the hash. |
1270
|
|
|
|
1271
|
|
|
Example:: |
1272
|
|
|
|
1273
|
|
|
public_client.get_transaction("A93BEAC075562D4B6031262BDDE8B9A720346A54D8570A881E3671FEB6E6EFD4") |
1274
|
|
|
|
1275
|
|
|
The expected return result for this function is as follows:: |
1276
|
|
|
|
1277
|
|
|
{ |
1278
|
|
|
"id":"311003", |
1279
|
|
|
"hash":"A93BEAC075562D4B6031262BDDE8B9A720346A54D8570A881E3671FEB6E6EFD4", |
1280
|
|
|
"address":"swth1vwges9p847l9csj8ehrlgzajhmt4fcq4sd7gzl", |
1281
|
|
|
"username":"", |
1282
|
|
|
"msgs": [ |
1283
|
|
|
{ |
1284
|
|
|
"msg_type":"vote", |
1285
|
|
|
"msg":"{\"proposal_id\":10,\"voter\":\"swth1vwges9p847l9csj8ehrlgzajhmt4fcq4sd7gzl\",\"option\":\"Yes\"}" |
1286
|
|
|
}, |
1287
|
|
|
... |
1288
|
|
|
], |
1289
|
|
|
"code":"0", |
1290
|
|
|
"gas_used":"64818", |
1291
|
|
|
"gas_limit":"200000", |
1292
|
|
|
"memo":"", |
1293
|
|
|
"height":"6034329", |
1294
|
|
|
"block_time":"2021-01-07T20:35:08.526914+01:00" |
1295
|
|
|
} |
1296
|
|
|
|
1297
|
|
|
.. warning:: |
1298
|
|
|
|
1299
|
|
|
This endpoint returns the same dict structure even if the transaction does not exist with default values! |
1300
|
|
|
|
1301
|
|
|
.. note:: |
1302
|
|
|
|
1303
|
|
|
The field 'msg' contain a escaped JSON string. |
1304
|
|
|
|
1305
|
|
|
|
1306
|
|
|
:param tx_hash: Transaction hash for a specific transaction. |
1307
|
|
|
:return: |
1308
|
|
|
""" |
1309
|
|
|
api_params = { |
1310
|
|
|
"hash": tx_hash |
1311
|
|
|
} |
1312
|
|
|
return self.tradehub_get_request(path='/get_transaction', params=api_params) |
1313
|
|
|
|
1314
|
|
|
def get_transaction_log(self, transaction_hash: str): |
1315
|
|
|
api_params = {} |
1316
|
|
|
api_params["hash"] = transaction_hash |
1317
|
|
|
return self.tradehub_get_request(path='/get_tx_log', params=api_params) |
1318
|
|
|
|
1319
|
|
|
def get_transaction_types(self) -> List[str]: |
1320
|
|
|
""" |
1321
|
|
|
Get transaction types used by tradehub. |
1322
|
|
|
|
1323
|
|
|
Example:: |
1324
|
|
|
|
1325
|
|
|
public_client.get_transaction_types() |
1326
|
|
|
|
1327
|
|
|
The expected return result for this function is as follows:: |
1328
|
|
|
|
1329
|
|
|
[ |
1330
|
|
|
"submit_proposal", |
1331
|
|
|
"create_pool", |
1332
|
|
|
"set_reward_curve", |
1333
|
|
|
"send", |
1334
|
|
|
... |
1335
|
|
|
] |
1336
|
|
|
|
1337
|
|
|
:return: List with transaction types as strings. |
1338
|
|
|
""" |
1339
|
|
|
return self.tradehub_get_request(path='/get_transaction_types') |
1340
|
|
|
|
1341
|
|
|
def get_transactions(self, swth_address: Optional[str] = None, msg_type: Optional[str] = None, |
1342
|
|
|
height: Optional[int] = None, start_block: Optional[int] = None, |
1343
|
|
|
end_block: Optional[int] = None, before_id: Optional[int] = None, |
1344
|
|
|
after_id: Optional[int] = None, order_by: Optional[str] = None, |
1345
|
|
|
limit: Optional[int] = None) -> List[dict]: |
1346
|
|
|
""" |
1347
|
|
|
Get latest transactions or filter them. |
1348
|
|
|
|
1349
|
|
|
Example:: |
1350
|
|
|
|
1351
|
|
|
public_client.get_transactions() |
1352
|
|
|
|
1353
|
|
|
The expected return result for this function is as follows:: |
1354
|
|
|
|
1355
|
|
|
[ |
1356
|
|
|
{ |
1357
|
|
|
"id":"322811", |
1358
|
|
|
"hash":"9742B27016F08484D8FADFD361C34563F3FDA92A36A8DD3B844A2F86E3552451", |
1359
|
|
|
"address":"swth1xkahzn8ymps6xdu6feulutawu42fkyqz5fgvhx", |
1360
|
|
|
"username":"", |
1361
|
|
|
"msg_type":"create_order", |
1362
|
|
|
"msg":'{\"market\":\"eth1_usdc1\",\"side\":\"buy\",\"quantity\":\"0.019\",\"type\":\"limit\",\"price\":\"1283.98\",\"is_post_only\":false,\"is_reduce_only\":false,\"originator\":\"swth1xkahzn8ymps6xdu6feulutawu42fkyqz5fgvhx\"}', |
1363
|
|
|
"code":"0", |
1364
|
|
|
"gas_used":"140666", |
1365
|
|
|
"gas_limit":"100000000000", |
1366
|
|
|
"memo":"", |
1367
|
|
|
"height":"6119373", |
1368
|
|
|
"block_time":"2021-01-09T23:27:10.247711+01:00" |
1369
|
|
|
}, |
1370
|
|
|
... |
1371
|
|
|
] |
1372
|
|
|
|
1373
|
|
|
.. note:: |
1374
|
|
|
|
1375
|
|
|
The field 'msg' contain a escaped JSON string. |
1376
|
|
|
|
1377
|
|
|
:param swth_address: tradehub switcheo address starting with 'swth1' on mainnet and 'tswth1' on testnet. |
1378
|
|
|
:param msg_type: filter by msg_type, allowed values can be fetch with 'get_transaction_types' |
1379
|
|
|
:param height: get order at a specific height |
1380
|
|
|
:param start_block: get orders after block(exclusive) |
1381
|
|
|
:param end_block: get orders before block(exclusive) |
1382
|
|
|
:param before_id: get orders before id(exclusive) |
1383
|
|
|
:param after_id: get orders after id(exclusive) |
1384
|
|
|
:param order_by: TODO no official documentation |
1385
|
|
|
:param limit: limit the responded result, values above 200 have no effect |
1386
|
|
|
:return: List with transactions as dict |
1387
|
|
|
""" |
1388
|
|
|
api_params = { |
1389
|
|
|
"address": swth_address, |
1390
|
|
|
"msg_type": msg_type, |
1391
|
|
|
"height": height, |
1392
|
|
|
"start_block": start_block, |
1393
|
|
|
"end_block": end_block, |
1394
|
|
|
"before_id": before_id, |
1395
|
|
|
"after_id": after_id, |
1396
|
|
|
"order_by": order_by, |
1397
|
|
|
"limit": limit |
1398
|
|
|
} |
1399
|
|
|
return self.tradehub_get_request(path='/get_transactions', params=api_params) |
1400
|
|
|
|
1401
|
|
|
def get_transactions_fees(self): |
1402
|
|
|
gas_fees = self.tradehub_get_request(path='/get_txns_fees') |
1403
|
|
|
fees = {} |
1404
|
|
|
for gas_fee in gas_fees["result"]: |
1405
|
|
|
fees[gas_fee["msg_type"]] = gas_fee["fee"] |
1406
|
|
|
return fees |
1407
|
|
|
|
1408
|
|
|
def get_token(self, denom) -> dict: |
1409
|
|
|
""" |
1410
|
|
|
Get information about a token. |
1411
|
|
|
|
1412
|
|
|
Example:: |
1413
|
|
|
|
1414
|
|
|
public_client.get_token("swth") |
1415
|
|
|
|
1416
|
|
|
The expected return result for this function is as follows:: |
1417
|
|
|
|
1418
|
|
|
{ |
1419
|
|
|
"name":"Switcheo", |
1420
|
|
|
"symbol":"swth", |
1421
|
|
|
"denom":"swth", |
1422
|
|
|
"decimals":8, |
1423
|
|
|
"blockchain":"neo", |
1424
|
|
|
"chain_id":4, |
1425
|
|
|
"asset_id":"32e125258b7db0a0dffde5bd03b2b859253538ab", |
1426
|
|
|
"is_active":true, |
1427
|
|
|
"is_collateral":false, |
1428
|
|
|
"lock_proxy_hash":"17d0f66eca7fcbfddc8d9706f20513bf5d7419cd", |
1429
|
|
|
"delegated_supply":"100000000000000000", |
1430
|
|
|
"originator":"swth1mw90en8tcqnvdjhp64qmyhuq4qasvhy25dpmvw" |
1431
|
|
|
} |
1432
|
|
|
|
1433
|
|
|
.. warning:: |
1434
|
|
|
|
1435
|
|
|
This endpoint returns numbers as string(eg. "delegated_supply":"100000000000000000") or integer(eg. "decimals":8) |
1436
|
|
|
|
1437
|
|
|
|
1438
|
|
|
:param denom: Denom used by tradehub. |
1439
|
|
|
:return: Information about token as dict. |
1440
|
|
|
""" |
1441
|
|
|
api_params = { |
1442
|
|
|
"token": denom |
1443
|
|
|
} |
1444
|
|
|
return self.tradehub_get_request(path='/get_token', params=api_params) |
1445
|
|
|
|
1446
|
|
|
def get_tokens(self) -> List[dict]: |
1447
|
|
|
""" |
1448
|
|
|
Get all known tokens on tradehub chain. |
1449
|
|
|
|
1450
|
|
|
Example:: |
1451
|
|
|
|
1452
|
|
|
public_client.get_tokens() |
1453
|
|
|
|
1454
|
|
|
The expected return result for this function is as follows:: |
1455
|
|
|
|
1456
|
|
|
[ |
1457
|
|
|
{ |
1458
|
|
|
"name":"Switcheo", |
1459
|
|
|
"symbol":"swth", |
1460
|
|
|
"denom":"swth", |
1461
|
|
|
"decimals":8, |
1462
|
|
|
"blockchain":"neo", |
1463
|
|
|
"chain_id":4, |
1464
|
|
|
"asset_id":"32e125258b7db0a0dffde5bd03b2b859253538ab", |
1465
|
|
|
"is_active":true, |
1466
|
|
|
"is_collateral":false, |
1467
|
|
|
"lock_proxy_hash":"17d0f66eca7fcbfddc8d9706f20513bf5d7419cd", |
1468
|
|
|
"delegated_supply":"100000000000000000", |
1469
|
|
|
"originator":"swth1mw90en8tcqnvdjhp64qmyhuq4qasvhy25dpmvw" |
1470
|
|
|
}, |
1471
|
|
|
... |
1472
|
|
|
] |
1473
|
|
|
|
1474
|
|
|
.. warning:: |
1475
|
|
|
This endpoint returns numbers as string(eg. "delegated_supply":"100000000000000000") or integer(eg. "decimals":8) |
1476
|
|
|
|
1477
|
|
|
:return: List with tokens as dict |
1478
|
|
|
""" |
1479
|
|
|
return self.tradehub_get_request(path='/get_tokens') |
1480
|
|
|
|
1481
|
|
|
def get_token_details(self) -> dict: |
1482
|
|
|
tokens = self.get_tokens() |
1483
|
|
|
tokens_details = {} |
1484
|
|
|
for token in tokens: |
1485
|
|
|
if token["is_active"]: |
1486
|
|
|
tokens_details[token["denom"]] = { |
1487
|
|
|
'name': token["name"], |
1488
|
|
|
'symbol': token["symbol"], |
1489
|
|
|
'decimals': token["decimals"], |
1490
|
|
|
} |
1491
|
|
|
return tokens_details |
1492
|
|
|
|
1493
|
|
|
def get_top_r_profits(self, market: str, limit: int): |
1494
|
|
|
""" |
1495
|
|
|
|
1496
|
|
|
.. warning:: |
1497
|
|
|
This endpoint is not working yet. |
1498
|
|
|
|
1499
|
|
|
:param market: |
1500
|
|
|
:param limit: |
1501
|
|
|
:return: |
1502
|
|
|
""" |
1503
|
|
|
# TODO responses currently not available |
1504
|
|
|
api_params = { |
1505
|
|
|
"market": market, |
1506
|
|
|
"limit": limit |
1507
|
|
|
} |
1508
|
|
|
return self.tradehub_get_request(path='/get_top_r_profits', params=api_params) |
1509
|
|
|
|
1510
|
|
|
def get_total_balances(self): |
1511
|
|
|
""" |
1512
|
|
|
|
1513
|
|
|
.. warning:: |
1514
|
|
|
This endpoint is not working yet. |
1515
|
|
|
|
1516
|
|
|
:return: |
1517
|
|
|
""" |
1518
|
|
|
# TODO responses currently not available |
1519
|
|
|
return self.tradehub_get_request(path='/get_total_balances') |
1520
|
|
|
|
1521
|
|
|
def get_username_check(self, username: str) -> bool: |
1522
|
|
|
""" |
1523
|
|
|
Check if a username is taken or not. |
1524
|
|
|
|
1525
|
|
|
Example:: |
1526
|
|
|
|
1527
|
|
|
public_client.get_username_check("devel484") |
1528
|
|
|
|
1529
|
|
|
The expected return result for this function is as follows:: |
1530
|
|
|
|
1531
|
|
|
true |
1532
|
|
|
|
1533
|
|
|
.. warning:: |
1534
|
|
|
This endpoint do not return a JSON response, only true or false |
1535
|
|
|
|
1536
|
|
|
:param username: name to check |
1537
|
|
|
:return: True if is taken and false if free |
1538
|
|
|
""" |
1539
|
|
|
api_params = { |
1540
|
|
|
"username": username |
1541
|
|
|
} |
1542
|
|
|
return self.tradehub_get_request(path='/username_check', params=api_params) |
1543
|
|
|
|
1544
|
|
|
def get_validator_delegations(self, operator_address): |
1545
|
|
|
return self.tradehub_get_request(path='/staking/validators/{}/delegations'.format(operator_address)) |
1546
|
|
|
|
1547
|
|
|
def get_validator_public_nodes(self): |
1548
|
|
|
public_nodes = {} |
1549
|
|
|
tradehub_state = self.get_tradehub_monitor() |
1550
|
|
|
for validator in tradehub_state: |
1551
|
|
|
public_nodes[validator["moniker"]] = validator["ip"] |
1552
|
|
|
return public_nodes |
1553
|
|
|
|
1554
|
|
|
def get_validator_public_node_ips(self): |
1555
|
|
|
public_node_ips = [] |
1556
|
|
|
nodes_dict = self.get_validator_public_nodes() |
1557
|
|
|
for key in nodes_dict.keys(): |
1558
|
|
|
public_node_ips.append(nodes_dict[key]) |
1559
|
|
|
return public_node_ips |
1560
|
|
|
|
1561
|
|
|
def get_validator_missed_blocks(self): |
1562
|
|
|
validators_missed_blocks = {} |
1563
|
|
|
validators_signing_info = self.get_validator_signing_info()["result"] |
1564
|
|
|
for validator_signing_info in validators_signing_info: |
1565
|
|
|
validators_missed_blocks[validator_signing_info["address"]] = validator_signing_info["missed_blocks_counter"] |
1566
|
|
|
return validators_missed_blocks |
1567
|
|
|
|
1568
|
|
|
def get_validator_signing_info(self, limit: int = 100): |
1569
|
|
|
api_params = {} |
1570
|
|
|
api_params["limit"] = limit |
1571
|
|
|
return self.tradehub_get_request(path='/slashing/signing_infos', params=api_params) |
1572
|
|
|
|
1573
|
|
|
def get_validators(self, status=None): |
1574
|
|
|
api_params = {} |
1575
|
|
|
if status is not None and status in ["unbonding", "unbonded"]: |
1576
|
|
|
api_params["status"] = status |
1577
|
|
|
return self.tradehub_get_request(path='/staking/validators', params=api_params) |
1578
|
|
|
|
1579
|
|
|
def get_vault_types(self) -> list: |
1580
|
|
|
""" |
1581
|
|
|
|
1582
|
|
|
:param token: |
1583
|
|
|
:return : |
1584
|
|
|
""" |
1585
|
|
|
# TODO responses currently not an empty list |
1586
|
|
|
return self.tradehub_get_request(path='/get_vault_types') |
1587
|
|
|
|
1588
|
|
|
def get_vaults(self, swth_address: str) -> dict: |
1589
|
|
|
api_params = { |
1590
|
|
|
"address": swth_address, |
1591
|
|
|
} |
1592
|
|
|
return self.tradehub_get_request(path='/get_vaults', params=api_params) |
1593
|
|
|
|