PublicClient.get_candlesticks()   A
last analyzed

Complexity

Conditions 2

Size

Total Lines 64
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 9
nop 5
dl 0
loc 64
rs 9.95
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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