Passed
Push — main ( 339f4c...4dcd0d )
by
unknown
01:23 queued 11s
created

PublicClient.__init__()   A

Complexity

Conditions 1

Size

Total Lines 16
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nop 5
dl 0
loc 16
rs 10
c 0
b 0
f 0
1
from typing import Union, List, Optional
2
from tradehub.public_blockchain_client import PublicBlockchainClient
3
4
5
class PublicClient(PublicBlockchainClient):
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
        PublicBlockchainClient.__init__(self, network=network, trusted_ips=trusted_ips, trusted_uris=trusted_uris, is_websocket_client=is_websocket_client)
27
28
    def check_username(self, username: str) -> dict:
29
        """
30
31
        :param username:
32
        :return:
33
        """
34
        api_params = {
35
            "username": username,
36
        }
37
        return self.tradehub_get_request(path='/username_check', params=api_params)
38
39
    def get_account(self, swth_address: str) -> dict:
40
        """
41
        Request account information about swth wallet.
42
43
        Example::
44
45
            # wallet behind Devel And Co validator
46
            public_client.get_account("swth1vwges9p847l9csj8ehrlgzajhmt4fcq4sd7gzl")
47
48
        The expected return result for this function is as follows::
49
50
            {
51
              "height": "6102489",
52
              "result": {
53
                "type": "cosmos-sdk/Account",
54
                "value": {
55
                  "address": "swth1vwges9p847l9csj8ehrlgzajhmt4fcq4sd7gzl",
56
                  "coins": [
57
                    {
58
                      "denom": "cel1",
59
                      "amount": "7"
60
                    },
61
                    {
62
                      "denom": "eth1",
63
                      "amount": "64752601707981"
64
                    },
65
                    {
66
                      "denom": "nex1",
67
                      "amount": "12289"
68
                    },
69
                    {
70
                      "denom": "nneo2",
71
                      "amount": "31555"
72
                    },
73
                    {
74
                      "denom": "swth",
75
                      "amount": "4113439708"
76
                    },
77
                    {
78
                      "denom": "usdc1",
79
                      "amount": "45376"
80
                    },
81
                    {
82
                      "denom": "wbtc1",
83
                      "amount": "29"
84
                    }
85
                  ],
86
                  "public_key": {
87
                    "type": "tendermint/PubKeySecp256k1",
88
                    "value": "AtCcJkRx1VhzZkOV06yrxKMZ9IvdRxqv5S4gJSQI/aCB"
89
                  },
90
                  "account_number": "1756",
91
                  "sequence": "55"
92
                }
93
              }
94
            }
95
96
        .. note:
97
            This endpoint returns numbers which are NOT human readable values. Consider 'base_precision' and
98
            'quote_precision' to calculate a multiplication factor = 10 ^ ('base_precision' - 'quote_precision').
99
            See 'get_markets'
100
101
        :param swth_address: tradehub switcheo address starting with 'swth1' on mainnet and 'tswth1' on testnet.
102
        :return: json response
103
        """
104
        api_params = {
105
            "account": swth_address,
106
        }
107
        return self.tradehub_get_request(path='/get_account', params=api_params)
108
109
    def get_active_wallets(self, token: str) -> int:
110
        """
111
112
        :param token:
113
        :return active_wallet_cnt:
114
        """
115
        api_params = {
116
            "token": token,
117
        }
118
        return self.tradehub_get_request(path='/get_active_wallets', params=api_params)
119
120
    def get_address(self, username: str) -> str:
121
        """
122
        Request swth1 tradehub address which is represented by a username.
123
124
        Example::
125
126
            public_client.get_address("devel484")
127
128
        The expected return result for this function is as follows::
129
130
            "swth1qlue2pat9cxx2s5xqrv0ashs475n9va963h4hz"
131
132
        .. warning::
133
            This endpoint returns only a string if address is found. If no address is found an exception with
134
            status code 404 will be raised.
135
136
        .. note::
137
            Usernames are in lowercase and can only be 15 characters long.
138
139
        :param username: Username is lower case.
140
        :return: swth1 address if found
141
        """
142
        api_params = {
143
            "username": username
144
        }
145
        return self.tradehub_get_request(path='/get_address', params=api_params)
146
147
    def get_address_rewards(self, address: str):
148
        return self.tradehub_get_request(path='/distribution/delegators/{}/rewards'.format(address))
149
150
    def get_address_staking(self, address: str):
151
        return self.tradehub_get_request(path='/staking/delegators/{}/delegations'.format(address))
152
153
    def get_address_trades(self, limit: int = 200, pagination: bool = None, address: str = None):
154
        api_params = {}
155
        if pagination is not None:
156
            api_params["pagination"] = pagination
157
        if address is not None:
158
            api_params["account"] = address
159
        return self.tradehub_get_request(path='/get_trades_by_account', params=api_params)
160
161
    def get_balance(self, swth_address: str) -> dict:
162
        """
163
        Get balance which includes available, in open orders and open positions.
164
165
        Example::
166
167
            # wallet behind Devel And Co validator
168
            public_client.get_balance("swth1vwges9p847l9csj8ehrlgzajhmt4fcq4sd7gzl")
169
170
        The expected return result for this function is as follows::
171
172
            {
173
                "cel1":{
174
                    "available":"0.0007",
175
                    "order":"0",
176
                    "position":"0",
177
                    "denom":"cel1"
178
                },
179
                "eth1":{
180
                    "available":"0.000064752601707981",
181
                    "order":"0",
182
                    "position":"0",
183
                    "denom":"eth1"
184
                },
185
                "nex1":{
186
                    "available":"0.00012289",
187
                    "order":"0",
188
                    "position":"0",
189
                    "denom":"nex1"
190
                },
191
                "nneo2":{
192
                    "available":"0.00031555",
193
                    "order":"0",
194
                    "position":"0",
195
                    "denom":"nneo2"
196
                },
197
                "swth":{
198
                    "available":"41.13439708",
199
                    "order":"0",
200
                    "position":"0",
201
                    "denom":"swth"
202
                },
203
                "usdc1":{
204
                    "available":"0.045376",
205
                    "order":"0",
206
                    "position":"0",
207
                    "denom":"usdc1"
208
                },
209
                "wbtc1":{
210
                    "available":"0.00000029",
211
                    "order":"0",
212
                    "position":"0",
213
                    "denom":"wbtc1"
214
                }
215
            }
216
217
        .. note::
218
            Only non zero balances are returned.
219
220
        .. note::
221
            Values are already in human readable format.
222
223
        :param swth_address: tradehub switcheo address starting with 'swth1' on mainnet and 'tswth1' on testnet.
224
        :return: dict with currently holding tokens.
225
        """
226
        api_params = {
227
            "account": swth_address
228
        }
229
        return self.tradehub_get_request(path='/get_balance', params=api_params)
230
231
    def get_candlesticks(self, market: str, granularity: int, from_epoch: int, to_epoch: int) -> List[dict]:
232
        """
233
        Get candlesticks for a market.
234
235
        Example::
236
237
            public_client.get_candlesticks("swth_eth1", 5, 1610203000, 1610203090)
238
239
        The expected return result for this function is as follows::
240
241
            [
242
                {
243
                    "id":38648,
244
                    "market":"swth_eth1",
245
                    "time":"2021-01-09T15:35:00+01:00",
246
                    "resolution":5,
247
                    "open":"0.0000212",
248
                    "close":"0.0000212",
249
                    "high":"0.0000212",
250
                    "low":"0.0000212",
251
                    "volume":"2100",
252
                    "quote_volume":"0.04452"
253
                },
254
                ...
255
            ]
256
257
258
        .. warning::
259
260
            This endpoint is not well documented in official documents.
261
            The example market swth_eth does not exist on mainnet. The correct market ticker is 'swth_eth1'.
262
            See get_markets() for correct tickers.
263
264
        .. warning::
265
266
            If any off the required parameters is not provided or incorrect the server responses with 500 status codes.
267
268
        .. warning::
269
270
            Responses are marked as 'plain' and not as 'text/json'.
271
272
        .. warning::
273
274
            This endpoint returns numbers as string(ex. "volume":"2100") or integer(ex. "resolution":5)
275
276
        :raises ValueError: If 'granularity' is not 1, 5, 30, 60, 360 or 1440.
277
278
279
        :param market: Market ticker used by blockchain (eg. swth_eth1).
280
        :param granularity: Candlestick period in minutes, possible values are: 1, 5, 30, 60, 360 or 1440.
281
        :param from_epoch: Start of time range for data in epoch seconds.
282
        :param to_epoch: End of time range for data in epoch seconds.
283
        :return: List with candles as dict.
284
        """
285
        if granularity not in [1, 5, 30, 60, 360, 1440]:
286
            raise ValueError("Granularity/Resolution has to be on off the following values: 1, 5, 30, 60, 360 or 1440")
287
288
        api_params = {
289
            "market": market,
290
            "resolution": granularity,
291
            "from": from_epoch,
292
            "to": to_epoch
293
        }
294
        return self.tradehub_get_request(path='/candlesticks', params=api_params)
295
296
    def get_delegation_rewards(self, swth_address: str) -> dict:
297
        """
298
        Request delegation rewards made by a tradehub wallet.
299
300
        Example::
301
302
            # wallet behind Devel And Co validator
303
            public_client.get_delegation_rewards("swth1vwges9p847l9csj8ehrlgzajhmt4fcq4sd7gzl")
304
305
        The expected return result for this function is as follows::
306
307
            {
308
              "height": "6104998",
309
              "result": {
310
                "rewards": [
311
                  {
312
                    "validator_address": "swthvaloper1vwges9p847l9csj8ehrlgzajhmt4fcq4dmg8x0",
313
                    "reward": [
314
                      {
315
                        "denom": "swth",
316
                        "amount": "7928468882.342780820000000000"
317
                      },
318
                      ...
319
                    ]
320
                  },
321
                  ...
322
                ],
323
                "total": [
324
                  {
325
                    "denom": "cel1",
326
                    "amount": "0.032116540000000000"
327
                  },
328
                  ...
329
                ]
330
              }
331
            }
332
333
        .. warning::
334
335
            Only non zero balances are returned.
336
337
        .. warning::
338
339
            Values are NOT in human readable format even if the values contain a decimal separator.
340
341
        .. warning::
342
343
            This endpoint returns amounts which are NOT human readable values. Consider 'base_precision' and
344
            'quote_precision' to calculate a multiplication factor = 10 ^ ('base_precision' - 'quote_precision')
345
346
        .. note::
347
348
            This endpoint does not include unclaimed commissions off a validator. If a validator wallet is requested
349
            only the rewards earned by delegation are returned.
350
351
        :param swth_address: tradehub switcheo address starting with 'swth1' on mainnet and 'tswth1' on testnet.
352
        :return: return dict with generated unclaimed rewards.
353
        """
354
        api_params = {
355
            "account": swth_address,
356
        }
357
        return self.tradehub_get_request(path='/get_delegation_rewards', params=api_params)
358
359
    def get_external_transfers(self, swth_address: str) -> List[dict]:
360
        """
361
        Get external transfers(withdraws or deposits) from other blockchains.
362
363
        Example::
364
365
            # wallet Devel
366
            public_client.get_delegation_rewards("swth1qlue2pat9cxx2s5xqrv0ashs475n9va963h4hz")
367
368
        The expected return result for this function is as follows::
369
370
            [
371
                {
372
                    "address":"swth1qlue2pat9cxx2s5xqrv0ashs475n9va963h4hz",
373
                    "amount":"0.9826",
374
                    "block_height":5937838,
375
                    "blockchain":"eth",
376
                    "contract_hash":"9a016ce184a22dbf6c17daa59eb7d3140dbd1c54",
377
                    "denom":"eth1",
378
                    "fee_address":"swth1prv0t8j8tqcdngdmjlt59pwy6dxxmtqgycy2h7",
379
                    "fee_amount":"0.0174",
380
                    "id":"12853",
381
                    "status":"success",
382
                    "symbol":"ETH",
383
                    "timestamp":1609839309,
384
                    "token_name":"Ethereum",
385
                    "transaction_hash":"",
386
                    "transfer_type":"deposit"
387
                },
388
                ...
389
            ]
390
391
        .. warning::
392
393
            This endpoint returns numbers as string(eg. "id":"12853") or integer(eg. "timestamp":1609839309)
394
395
        .. note::
396
397
            This endpoint return amounts in human readable format.
398
399
        :param swth_address: tradehub switcheo address starting with 'swth1' on mainnet and 'tswth1' on testnet.
400
        :return: List with external transfers
401
        """
402
        api_params = {
403
            "account": swth_address
404
        }
405
        return self.tradehub_get_request(path='/get_external_transfers', params=api_params)
406
407
    def get_leverage(self, swth_address: str, market: str):
408
        """
409
410
        .. warning::
411
412
            This endpoint is not working yet.
413
414
        :param swth_address:
415
        :param market:
416
        :return:
417
        """
418
        # TODO result currently not available
419
        api_params = {
420
            "account": swth_address,
421
            "market": market
422
        }
423
        return self.tradehub_get_request(path='/get_leverage', params=api_params)
424
425
    def get_orderbook(self, market: str, limit: Optional[int] = None):
426
        """
427
        Get the orderbook from a market.
428
429
        Example::
430
431
            public_client.get_orderbook("swth_eth1")
432
433
        The expected return result for this function is as follows::
434
435
            {
436
                "asks": [
437
                    {
438
                        "price":"0.0000214",
439
                        "quantity":"49863"
440
                    },
441
                    {
442
                        "price":"0.0000215",
443
                        "quantity":"49446"
444
                    },
445
                    ...
446
                ],
447
                "bids": [
448
                    {
449
                        "price":"0.0000212",
450
                        "quantity":"50248"
451
                    },
452
                    {
453
                        "price":"0.0000211",
454
                        "quantity":"50295"
455
                    },
456
                    ...
457
                ]
458
            }
459
460
        .. warning::
461
462
            This endpoint returns an empty 'asks' and 'bids' list if the market is not known.
463
464
        :param market: Market ticker used by blockchain (eg. swth_eth1).
465
        :param limit: Number off returned orders per side(asks, bids).
466
        :return: Orderbook as 'asks' and 'bids' list
467
        """
468
        api_params = {
469
            "market": market,
470
            "limit": limit
471
        }
472
        return self.tradehub_get_request(path='/get_orderbook', params=api_params)
473
474
    def get_order(self, order_id: str) -> dict:
475
        """
476
        Get a specific order by id.
477
478
        Example::
479
480
            public_client.get_order("4F54D2AE0D793F833806109B4278335BF3D392D4096B682B9A27AF9F8A8BCA58")
481
482
        The expected return result for this function is as follows::
483
484
            {
485
                "order_id":"4F54D2AE0D793F833806109B4278335BF3D392D4096B682B9A27AF9F8A8BCA58",
486
                "block_height":6117321,
487
                "triggered_block_height":0,
488
                "address":"swth1wmcj8gmz4tszy5v8c0d9lxnmguqcdkw22275w5",
489
                "market":"eth1_usdc1",
490
                "side":"buy",
491
                "price":"1255.68",
492
                "quantity":"0.01",
493
                "available":"0.01",
494
                "filled":"0",
495
                "order_status":"open",
496
                "order_type":"limit",
497
                "initiator":"amm",
498
                "time_in_force":"gtc",
499
                "stop_price":"0",
500
                "trigger_type":"",
501
                "allocated_margin_denom":"usdc1",
502
                "allocated_margin_amount":"0",
503
                "is_liquidation":false,
504
                "is_post_only":false,
505
                "is_reduce_only":false,
506
                "type":"",
507
                "block_created_at":"2021-01-09T22:13:34.711571+01:00",
508
                "username":"",
509
                "id":"990817"
510
            }
511
512
        :param order_id: Order identified by id
513
        :return: Order as dict
514
        """
515
        api_params = {
516
            "order_id": order_id
517
        }
518
        return self.tradehub_get_request(path='/get_order', params=api_params)
519
520
    def get_orders(self, swth_address: Optional[str] = None, before_id: Optional[int] = None,
521
                   after_id: Optional[int] = None, market: Optional[str] = None, order_type: Optional[str] = None,
522
                   initiator: Optional[str] = None, order_status: Optional[str] = None, limit: Optional[int] = None) -> List[dict]:
523
        """
524
        Request last orders or filter them.
525
526
        Example::
527
528
            public_client.get_orders()
529
530
        The expected return result for this function is as follows::
531
532
            [
533
                {
534
                    "order_id":"4F54D2AE0D793F833806109B4278335BF3D392D4096B682B9A27AF9F8A8BCA58",
535
                    "block_height":6117321,
536
                    "triggered_block_height":0,
537
                    "address":"swth1wmcj8gmz4tszy5v8c0d9lxnmguqcdkw22275w5",
538
                    "market":"eth1_usdc1",
539
                    "side":"buy",
540
                    "price":"1255.68",
541
                    "quantity":"0.01",
542
                    "available":"0.01",
543
                    "filled":"0",
544
                    "order_status":"open",
545
                    "order_type":"limit",
546
                    "initiator":"amm",
547
                    "time_in_force":"gtc",
548
                    "stop_price":"0",
549
                    "trigger_type":"",
550
                    "allocated_margin_denom":"usdc1",
551
                    "allocated_margin_amount":"0",
552
                    "is_liquidation":false,
553
                    "is_post_only":false,
554
                    "is_reduce_only":false,
555
                    "type":"",
556
                    "block_created_at":"2021-01-09T22:13:34.711571+01:00",
557
                    "username":"",
558
                    "id":"990817"
559
                },
560
                ...
561
            ]
562
563
        .. warning::
564
565
            This endpoint is not well documented in official documents.
566
            Parameter account is NOT required! It is possible to provide more parameters,
567
            known ones are documented here.
568
569
        .. warning::
570
571
            This endpoint returns numbers as string(eg. "id":"990817") or integer(eg. "block_height":6117321)
572
573
        :param swth_address: tradehub switcheo address starting with 'swth1' on mainnet and 'tswth1' on testnet.
574
        :param before_id: return orders before id(exclusive).
575
        :param after_id: return orders after id(exclusive).
576
        :param market: Market ticker used by blockchain (eg. swth_eth1).
577
        :param order_type: Return specific orders, allowed values: 'limit', 'market', 'stop-market' or 'stop-limit'.
578
        :param initiator: Filter by user or automated market maker orders, allowed values: 'user' or 'amm'.
579
        :param order_status: Filter by order status, allowed values: 'open' or 'closed'.
580
        :param limit: Limit response, values above 200 have no effect.
581
        :return: List off orders as dict
582
        """
583
        api_params = {
584
            "account": swth_address,
585
            "before_id": before_id,
586
            "after_id": after_id,
587
            "market": market,
588
            "order_type": order_type,
589
            "initiator": initiator,
590
            "order_status": order_status,
591
            "limit": limit
592
        }
593
        return self.tradehub_get_request(path='/get_orders', params=api_params)
594
595
    def get_position(self, swth_address: str, market: str):
596
        """
597
598
        .. warning::
599
600
            This endpoint is not working yet.
601
602
        :param swth_address:
603
        :param market:
604
        :return:
605
        """
606
        # TODO responses currently not available
607
        api_params = {
608
            "account": swth_address,
609
            "market": market
610
        }
611
        return self.tradehub_get_request(path='/get_position', params=api_params)
612
613
    def get_positions(self, swth_address: str):
614
        """
615
616
        .. warning::
617
618
            This endpoint is not working yet.
619
620
        :param swth_address:
621
        :return:
622
        """
623
        # TODO responses currently not available
624
        api_params = {
625
            "account": swth_address
626
        }
627
        return self.tradehub_get_request(path='/get_positions', params=api_params)
628
629
    def get_positions_sorted_by_pnl(self, market):
630
        """
631
632
        .. warning::
633
634
            This endpoint is not working yet.
635
636
        :param market:
637
        :return:
638
        """
639
        # TODO responses currently not available
640
        api_params = {
641
            "market": market
642
        }
643
        return self.tradehub_get_request(path='/get_positions_sorted_by_pnl', params=api_params)
644
645
    def get_positions_sorted_by_risk(self, market):
646
        """
647
648
        .. warning::
649
650
            This endpoint is not working yet.
651
652
        :param market:
653
        :return:
654
        """
655
        # TODO responses currently not available
656
        api_params = {
657
            "market": market
658
        }
659
        return self.tradehub_get_request(path='/get_positions_sorted_by_risk', params=api_params)
660
661
    def get_positions_sorted_by_size(self, market):
662
        """
663
664
        .. warning::
665
666
            This endpoint is not working yet.
667
668
        :param market:
669
        :return:
670
        """
671
        # TODO responses currently not available
672
        api_params = {
673
            "market": market
674
        }
675
        return self.tradehub_get_request(path='/get_positions_sorted_by_size', params=api_params)
676
677
    def get_profile(self, swth_address: str) -> dict:
678
        """
679
        Get profile from a tradehub wallet.
680
681
        Example::
682
683
            public_client.get_profile("swth1qlue2pat9cxx2s5xqrv0ashs475n9va963h4hz")
684
685
        The expected return result for this function is as follows::
686
687
            {
688
                "address":"swth1qlue2pat9cxx2s5xqrv0ashs475n9va963h4hz",
689
                "last_seen_block":"6036318",
690
                "last_seen_time":"2021-01-07T21:47:14.593249+01:00",
691
                "twitter":"",
692
                "username":"devel484"
693
            }
694
695
        :param swth_address: tradehub switcheo address starting with 'swth1' on mainnet and 'tswth1' on testnet.
696
        :return: Profile as dict
697
        """
698
        api_params = {
699
            "account": swth_address
700
        }
701
        return self.tradehub_get_request(path='/get_profile', params=api_params)
702
703
    def get_trades(self, market: Optional[str] = None, before_id: Optional[int] = None, after_id: Optional[int] = None,
704
                   order_by: Optional[str] = None, limit: Optional[int] = None,
705
                   swth_address: Optional[str] = None) -> List[dict]:
706
        """
707
        Get recent trades or filter trades.
708
709
        Example::
710
711
            public_client.get_trades()
712
713
        The expected return result for this function is as follows::
714
715
            [
716
                {
717
                    "id":"103965",
718
                    "block_created_at":"2021-01-10T21:59:53.563633+01:00",
719
                    "taker_id":"11DCD0B7B0A0021476B8C801FD627B297EBDBBE7436BFEEC5ADB734DCF3C9291",
720
                    "taker_address":"swth1qlue2pat9cxx2s5xqrv0ashs475n9va963h4hz",
721
                    "taker_fee_amount":"0.000007",
722
                    "taker_fee_denom":"eth1",
723
                    "taker_side":"buy",
724
                    "maker_id":"A59962E7A61F361F7DE5BF00D7A6A8225668F449D73301FB9D3787E4C13DEE60",
725
                    "maker_address":"swth1wmcj8gmz4tszy5v8c0d9lxnmguqcdkw22275w5",
726
                    "maker_fee_amount":"-0.0000035",
727
                    "maker_fee_denom":"eth1",
728
                    "maker_side":"sell",
729
                    "market":"eth1_usdc1",
730
                    "price":"1251.51",
731
                    "quantity":"0.007",
732
                    "liquidation":"",
733
                    "taker_username":"devel484",
734
                    "maker_username":"",
735
                    "block_height":"6156871"
736
                },
737
                ...
738
            ]
739
740
741
        :param market: Market ticker used by blockchain (eg. swth_eth1).
742
        :param before_id: get orders before id(exclusive).
743
        :param after_id: get orders after id(exclusive).
744
        :param order_by: TODO no official documentation.
745
        :param limit: limit the responded result, values above 200 have no effect.
746
        :param swth_address: tradehub switcheo address starting with 'swth1' on mainnet and 'tswth1' on testnet.
747
        :return: List off trades as dict
748
        """
749
        api_params = {
750
            "market": market,
751
            "before_id": before_id,
752
            "after_id": after_id,
753
            "order_by": order_by,
754
            "limit": limit,
755
            "account": swth_address
756
        }
757
        return self.tradehub_get_request(path='/get_trades', params=api_params)
758
759
    def get_transaction(self, tx_hash: str):
760
        """
761
        Get a transaction by providing the hash.
762
763
        Example::
764
765
            public_client.get_transaction("A93BEAC075562D4B6031262BDDE8B9A720346A54D8570A881E3671FEB6E6EFD4")
766
767
        The expected return result for this function is as follows::
768
769
            {
770
                "id":"311003",
771
                "hash":"A93BEAC075562D4B6031262BDDE8B9A720346A54D8570A881E3671FEB6E6EFD4",
772
                "address":"swth1vwges9p847l9csj8ehrlgzajhmt4fcq4sd7gzl",
773
                "username":"",
774
                "msgs": [
775
                    {
776
                        "msg_type":"vote",
777
                        "msg":"{\"proposal_id\":10,\"voter\":\"swth1vwges9p847l9csj8ehrlgzajhmt4fcq4sd7gzl\",\"option\":\"Yes\"}"
778
                    },
779
                    ...
780
                ],
781
                "code":"0",
782
                "gas_used":"64818",
783
                "gas_limit":"200000",
784
                "memo":"",
785
                "height":"6034329",
786
                "block_time":"2021-01-07T20:35:08.526914+01:00"
787
            }
788
789
        .. warning::
790
791
            This endpoint returns the same dict structure even if the transaction does not exist with default values!
792
793
        .. note::
794
795
            The field 'msg' contain a escaped JSON string.
796
797
798
        :param tx_hash: Transaction hash for a specific transaction.
799
        :return:
800
        """
801
        api_params = {
802
            "hash": tx_hash
803
        }
804
        return self.tradehub_get_request(path='/get_transaction', params=api_params)
805
806
    def get_transaction_log(self, transaction_hash: str):
807
        api_params = {}
808
        api_params["hash"] = transaction_hash
809
        return self.tradehub_get_request(path='/get_tx_log', params=api_params)
810
811
    def get_transactions(self, swth_address: Optional[str] = None, msg_type: Optional[str] = None,
812
                         height: Optional[int] = None, start_block: Optional[int] = None,
813
                         end_block: Optional[int] = None, before_id: Optional[int] = None,
814
                         after_id: Optional[int] = None, order_by: Optional[str] = None,
815
                         limit: Optional[int] = None) -> List[dict]:
816
        """
817
        Get latest transactions or filter them.
818
819
        Example::
820
821
            public_client.get_transactions()
822
823
        The expected return result for this function is as follows::
824
825
            [
826
                {
827
                    "id":"322811",
828
                    "hash":"9742B27016F08484D8FADFD361C34563F3FDA92A36A8DD3B844A2F86E3552451",
829
                    "address":"swth1xkahzn8ymps6xdu6feulutawu42fkyqz5fgvhx",
830
                    "username":"",
831
                    "msg_type":"create_order",
832
                    "msg":'{\"market\":\"eth1_usdc1\",\"side\":\"buy\",\"quantity\":\"0.019\",\"type\":\"limit\",\"price\":\"1283.98\",\"is_post_only\":false,\"is_reduce_only\":false,\"originator\":\"swth1xkahzn8ymps6xdu6feulutawu42fkyqz5fgvhx\"}',
833
                    "code":"0",
834
                    "gas_used":"140666",
835
                    "gas_limit":"100000000000",
836
                    "memo":"",
837
                    "height":"6119373",
838
                    "block_time":"2021-01-09T23:27:10.247711+01:00"
839
                },
840
                ...
841
            ]
842
843
        .. note::
844
845
            The field 'msg' contain a escaped JSON string.
846
847
        :param swth_address: tradehub switcheo address starting with 'swth1' on mainnet and 'tswth1' on testnet.
848
        :param msg_type: filter by msg_type, allowed values can be fetch with 'get_transaction_types'
849
        :param height: get order at a specific height
850
        :param start_block: get orders after block(exclusive)
851
        :param end_block: get orders before block(exclusive)
852
        :param before_id: get orders before id(exclusive)
853
        :param after_id: get orders after id(exclusive)
854
        :param order_by: TODO no official documentation
855
        :param limit: limit the responded result, values above 200 have no effect
856
        :return: List with transactions as dict
857
        """
858
        api_params = {
859
            "address": swth_address,
860
            "msg_type": msg_type,
861
            "height": height,
862
            "start_block": start_block,
863
            "end_block": end_block,
864
            "before_id": before_id,
865
            "after_id": after_id,
866
            "order_by": order_by,
867
            "limit": limit
868
        }
869
        return self.tradehub_get_request(path='/get_transactions', params=api_params)
870
871
    def get_username_check(self, username: str) -> bool:
872
        """
873
        Check if a username is taken or not.
874
875
         Example::
876
877
            public_client.get_username_check("devel484")
878
879
        The expected return result for this function is as follows::
880
881
            true
882
883
        .. warning::
884
            This endpoint do not return a JSON response, only true or false
885
886
        :param username: name to check
887
        :return: True if is taken and false if free
888
        """
889
        api_params = {
890
            "username": username
891
        }
892
        return self.tradehub_get_request(path='/username_check', params=api_params)
893