-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathasync_client.py
2541 lines (2219 loc) · 101 KB
/
async_client.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import asyncio
from copy import deepcopy
from decimal import Decimal
from typing import Any, Callable, Dict, List, Optional, Tuple
from warnings import warn
from google.protobuf import json_format
from pyinjective.client.chain.grpc.chain_grpc_auth_api import ChainGrpcAuthApi
from pyinjective.client.chain.grpc.chain_grpc_authz_api import ChainGrpcAuthZApi
from pyinjective.client.chain.grpc.chain_grpc_bank_api import ChainGrpcBankApi
from pyinjective.client.chain.grpc.chain_grpc_distribution_api import ChainGrpcDistributionApi
from pyinjective.client.chain.grpc.chain_grpc_exchange_api import ChainGrpcExchangeApi
from pyinjective.client.chain.grpc.chain_grpc_permissions_api import ChainGrpcPermissionsApi
from pyinjective.client.chain.grpc.chain_grpc_token_factory_api import ChainGrpcTokenFactoryApi
from pyinjective.client.chain.grpc.chain_grpc_wasm_api import ChainGrpcWasmApi
from pyinjective.client.chain.grpc_stream.chain_grpc_chain_stream import ChainGrpcChainStream
from pyinjective.client.indexer.grpc.indexer_grpc_account_api import IndexerGrpcAccountApi
from pyinjective.client.indexer.grpc.indexer_grpc_auction_api import IndexerGrpcAuctionApi
from pyinjective.client.indexer.grpc.indexer_grpc_derivative_api import IndexerGrpcDerivativeApi
from pyinjective.client.indexer.grpc.indexer_grpc_explorer_api import IndexerGrpcExplorerApi
from pyinjective.client.indexer.grpc.indexer_grpc_insurance_api import IndexerGrpcInsuranceApi
from pyinjective.client.indexer.grpc.indexer_grpc_meta_api import IndexerGrpcMetaApi
from pyinjective.client.indexer.grpc.indexer_grpc_oracle_api import IndexerGrpcOracleApi
from pyinjective.client.indexer.grpc.indexer_grpc_portfolio_api import IndexerGrpcPortfolioApi
from pyinjective.client.indexer.grpc.indexer_grpc_spot_api import IndexerGrpcSpotApi
from pyinjective.client.indexer.grpc_stream.indexer_grpc_account_stream import IndexerGrpcAccountStream
from pyinjective.client.indexer.grpc_stream.indexer_grpc_auction_stream import IndexerGrpcAuctionStream
from pyinjective.client.indexer.grpc_stream.indexer_grpc_derivative_stream import IndexerGrpcDerivativeStream
from pyinjective.client.indexer.grpc_stream.indexer_grpc_explorer_stream import IndexerGrpcExplorerStream
from pyinjective.client.indexer.grpc_stream.indexer_grpc_meta_stream import IndexerGrpcMetaStream
from pyinjective.client.indexer.grpc_stream.indexer_grpc_oracle_stream import IndexerGrpcOracleStream
from pyinjective.client.indexer.grpc_stream.indexer_grpc_portfolio_stream import IndexerGrpcPortfolioStream
from pyinjective.client.indexer.grpc_stream.indexer_grpc_spot_stream import IndexerGrpcSpotStream
from pyinjective.client.model.pagination import PaginationOption
from pyinjective.composer import Composer
from pyinjective.core.ibc.channel.grpc.ibc_channel_grpc_api import IBCChannelGrpcApi
from pyinjective.core.ibc.client.grpc.ibc_client_grpc_api import IBCClientGrpcApi
from pyinjective.core.ibc.connection.grpc.ibc_connection_grpc_api import IBCConnectionGrpcApi
from pyinjective.core.ibc.transfer.grpc.ibc_transfer_grpc_api import IBCTransferGrpcApi
from pyinjective.core.market import BinaryOptionMarket, DerivativeMarket, SpotMarket
from pyinjective.core.network import Network
from pyinjective.core.tendermint.grpc.tendermint_grpc_api import TendermintGrpcApi
from pyinjective.core.token import Token
from pyinjective.core.tokens_file_loader import TokensFileLoader
from pyinjective.core.tx.grpc.tx_grpc_api import TxGrpcApi
from pyinjective.exceptions import NotFoundError
from pyinjective.proto.cosmos.auth.v1beta1 import query_pb2_grpc as auth_query_grpc
from pyinjective.proto.cosmos.authz.v1beta1 import query_pb2_grpc as authz_query_grpc
from pyinjective.proto.cosmos.bank.v1beta1 import query_pb2_grpc as bank_query_grpc
from pyinjective.proto.cosmos.base.tendermint.v1beta1 import query_pb2_grpc as tendermint_query_grpc
from pyinjective.proto.cosmos.crypto.ed25519 import keys_pb2 as ed25519_keys # noqa: F401 for validator set responses
from pyinjective.proto.cosmos.tx.v1beta1 import service_pb2 as tx_service, service_pb2_grpc as tx_service_grpc
from pyinjective.proto.exchange import (
injective_accounts_rpc_pb2_grpc as exchange_accounts_rpc_grpc,
injective_auction_rpc_pb2_grpc as auction_rpc_grpc,
injective_derivative_exchange_rpc_pb2_grpc as derivative_exchange_rpc_grpc,
injective_explorer_rpc_pb2_grpc as explorer_rpc_grpc,
injective_insurance_rpc_pb2_grpc as insurance_rpc_grpc,
injective_meta_rpc_pb2_grpc as exchange_meta_rpc_grpc,
injective_oracle_rpc_pb2_grpc as oracle_rpc_grpc,
injective_portfolio_rpc_pb2_grpc as portfolio_rpc_grpc,
injective_spot_exchange_rpc_pb2_grpc as spot_exchange_rpc_grpc,
)
from pyinjective.proto.ibc.lightclients.tendermint.v1 import ( # noqa: F401 for validator set responses
tendermint_pb2 as ibc_tendermint,
)
from pyinjective.proto.injective.stream.v1beta1 import (
query_pb2 as chain_stream_query,
query_pb2_grpc as stream_rpc_grpc,
)
from pyinjective.proto.injective.types.v1beta1 import account_pb2
from pyinjective.utils.logger import LoggerProvider
DEFAULT_TIMEOUTHEIGHT_SYNC_INTERVAL = 20 # seconds
DEFAULT_TIMEOUTHEIGHT = 30 # blocks
DEFAULT_SESSION_RENEWAL_OFFSET = 120 # seconds
DEFAULT_BLOCK_TIME = 2 # seconds
class AsyncClient:
def __init__(
self,
network: Network,
):
self.addr = ""
self.number = 0
self.sequence = 0
self.network = network
# chain stubs
self.chain_channel = self.network.create_chain_grpc_channel()
self.stubCosmosTendermint = tendermint_query_grpc.ServiceStub(self.chain_channel)
self.stubAuth = auth_query_grpc.QueryStub(self.chain_channel)
self.stubAuthz = authz_query_grpc.QueryStub(self.chain_channel)
self.stubBank = bank_query_grpc.QueryStub(self.chain_channel)
self.stubTx = tx_service_grpc.ServiceStub(self.chain_channel)
self.exchange_cookie = ""
self.timeout_height = 1
# exchange stubs
self.exchange_channel = self.network.create_exchange_grpc_channel()
self.stubMeta = exchange_meta_rpc_grpc.InjectiveMetaRPCStub(self.exchange_channel)
self.stubExchangeAccount = exchange_accounts_rpc_grpc.InjectiveAccountsRPCStub(self.exchange_channel)
self.stubOracle = oracle_rpc_grpc.InjectiveOracleRPCStub(self.exchange_channel)
self.stubInsurance = insurance_rpc_grpc.InjectiveInsuranceRPCStub(self.exchange_channel)
self.stubSpotExchange = spot_exchange_rpc_grpc.InjectiveSpotExchangeRPCStub(self.exchange_channel)
self.stubDerivativeExchange = derivative_exchange_rpc_grpc.InjectiveDerivativeExchangeRPCStub(
self.exchange_channel
)
self.stubAuction = auction_rpc_grpc.InjectiveAuctionRPCStub(self.exchange_channel)
self.stubPortfolio = portfolio_rpc_grpc.InjectivePortfolioRPCStub(self.exchange_channel)
# explorer stubs
self.explorer_channel = self.network.create_explorer_grpc_channel()
self.stubExplorer = explorer_rpc_grpc.InjectiveExplorerRPCStub(self.explorer_channel)
self.chain_stream_channel = self.network.create_chain_stream_grpc_channel()
self.chain_stream_stub = stream_rpc_grpc.StreamStub(channel=self.chain_stream_channel)
self._timeout_height_sync_task = None
self._initialize_timeout_height_sync_task()
self._tokens_and_markets_initialization_lock = asyncio.Lock()
self._tokens_by_denom = dict()
self._tokens_by_symbol = dict()
self._spot_markets: Optional[Dict[str, SpotMarket]] = None
self._derivative_markets: Optional[Dict[str, DerivativeMarket]] = None
self._binary_option_markets: Optional[Dict[str, BinaryOptionMarket]] = None
self.bank_api = ChainGrpcBankApi(
channel=self.chain_channel,
cookie_assistant=network.chain_cookie_assistant,
)
self.auth_api = ChainGrpcAuthApi(
channel=self.chain_channel,
cookie_assistant=network.chain_cookie_assistant,
)
self.authz_api = ChainGrpcAuthZApi(
channel=self.chain_channel,
cookie_assistant=network.chain_cookie_assistant,
)
self.distribution_api = ChainGrpcDistributionApi(
channel=self.chain_channel,
cookie_assistant=network.chain_cookie_assistant,
)
self.chain_exchange_api = ChainGrpcExchangeApi(
channel=self.chain_channel,
cookie_assistant=network.chain_cookie_assistant,
)
self.ibc_channel_api = IBCChannelGrpcApi(
channel=self.chain_channel,
cookie_assistant=network.chain_cookie_assistant,
)
self.ibc_client_api = IBCClientGrpcApi(
channel=self.chain_channel,
cookie_assistant=network.chain_cookie_assistant,
)
self.ibc_connection_api = IBCConnectionGrpcApi(
channel=self.chain_channel,
cookie_assistant=network.chain_cookie_assistant,
)
self.ibc_transfer_api = IBCTransferGrpcApi(
channel=self.chain_channel,
cookie_assistant=network.chain_cookie_assistant,
)
self.permissions_api = ChainGrpcPermissionsApi(
channel=self.chain_channel,
cookie_assistant=network.chain_cookie_assistant,
)
self.tendermint_api = TendermintGrpcApi(
channel=self.chain_channel,
cookie_assistant=network.chain_cookie_assistant,
)
self.token_factory_api = ChainGrpcTokenFactoryApi(
channel=self.chain_channel,
cookie_assistant=network.chain_cookie_assistant,
)
self.tx_api = TxGrpcApi(
channel=self.chain_channel,
cookie_assistant=network.chain_cookie_assistant,
)
self.wasm_api = ChainGrpcWasmApi(
channel=self.chain_channel,
cookie_assistant=network.chain_cookie_assistant,
)
self.chain_stream_api = ChainGrpcChainStream(
channel=self.chain_stream_channel,
cookie_assistant=network.chain_cookie_assistant,
)
self.exchange_account_api = IndexerGrpcAccountApi(
channel=self.exchange_channel,
cookie_assistant=network.exchange_cookie_assistant,
)
self.exchange_auction_api = IndexerGrpcAuctionApi(
channel=self.exchange_channel,
cookie_assistant=network.exchange_cookie_assistant,
)
self.exchange_derivative_api = IndexerGrpcDerivativeApi(
channel=self.exchange_channel,
cookie_assistant=network.exchange_cookie_assistant,
)
self.exchange_insurance_api = IndexerGrpcInsuranceApi(
channel=self.exchange_channel,
cookie_assistant=network.exchange_cookie_assistant,
)
self.exchange_meta_api = IndexerGrpcMetaApi(
channel=self.exchange_channel,
cookie_assistant=network.exchange_cookie_assistant,
)
self.exchange_oracle_api = IndexerGrpcOracleApi(
channel=self.exchange_channel,
cookie_assistant=network.exchange_cookie_assistant,
)
self.exchange_portfolio_api = IndexerGrpcPortfolioApi(
channel=self.exchange_channel,
cookie_assistant=network.exchange_cookie_assistant,
)
self.exchange_spot_api = IndexerGrpcSpotApi(
channel=self.exchange_channel,
cookie_assistant=network.exchange_cookie_assistant,
)
self.exchange_account_stream_api = IndexerGrpcAccountStream(
channel=self.exchange_channel,
cookie_assistant=network.exchange_cookie_assistant,
)
self.exchange_auction_stream_api = IndexerGrpcAuctionStream(
channel=self.exchange_channel,
cookie_assistant=network.exchange_cookie_assistant,
)
self.exchange_derivative_stream_api = IndexerGrpcDerivativeStream(
channel=self.exchange_channel,
cookie_assistant=network.exchange_cookie_assistant,
)
self.exchange_meta_stream_api = IndexerGrpcMetaStream(
channel=self.exchange_channel,
cookie_assistant=network.exchange_cookie_assistant,
)
self.exchange_oracle_stream_api = IndexerGrpcOracleStream(
channel=self.exchange_channel,
cookie_assistant=network.exchange_cookie_assistant,
)
self.exchange_portfolio_stream_api = IndexerGrpcPortfolioStream(
channel=self.exchange_channel,
cookie_assistant=network.exchange_cookie_assistant,
)
self.exchange_spot_stream_api = IndexerGrpcSpotStream(
channel=self.exchange_channel,
cookie_assistant=network.exchange_cookie_assistant,
)
self.exchange_explorer_api = IndexerGrpcExplorerApi(
channel=self.explorer_channel,
cookie_assistant=network.explorer_cookie_assistant,
)
self.exchange_explorer_stream_api = IndexerGrpcExplorerStream(
channel=self.explorer_channel,
cookie_assistant=network.explorer_cookie_assistant,
)
async def all_tokens(self) -> Dict[str, Token]:
if self._tokens_by_symbol is None:
async with self._tokens_and_markets_initialization_lock:
if self._tokens_by_symbol is None:
await self._initialize_tokens_and_markets()
return deepcopy(self._tokens_by_symbol)
async def all_spot_markets(self) -> Dict[str, SpotMarket]:
if self._spot_markets is None:
async with self._tokens_and_markets_initialization_lock:
if self._spot_markets is None:
await self._initialize_tokens_and_markets()
return deepcopy(self._spot_markets)
async def all_derivative_markets(self) -> Dict[str, DerivativeMarket]:
if self._derivative_markets is None:
async with self._tokens_and_markets_initialization_lock:
if self._derivative_markets is None:
await self._initialize_tokens_and_markets()
return deepcopy(self._derivative_markets)
async def all_binary_option_markets(self) -> Dict[str, BinaryOptionMarket]:
if self._binary_option_markets is None:
async with self._tokens_and_markets_initialization_lock:
if self._binary_option_markets is None:
await self._initialize_tokens_and_markets()
return deepcopy(self._binary_option_markets)
def get_sequence(self):
current_seq = self.sequence
self.sequence += 1
return current_seq
def get_number(self):
return self.number
async def fetch_tx(self, hash: str) -> Dict[str, Any]:
return await self.tx_api.fetch_tx(hash=hash)
async def close_exchange_channel(self):
await self.exchange_channel.close()
self._cancel_timeout_height_sync_task()
async def close_chain_channel(self):
await self.chain_channel.close()
self._cancel_timeout_height_sync_task()
async def sync_timeout_height(self):
try:
block = await self.fetch_latest_block()
self.timeout_height = int(block["block"]["header"]["height"]) + DEFAULT_TIMEOUTHEIGHT
except Exception as e:
LoggerProvider().logger_for_class(logging_class=self.__class__).debug(
f"error while fetching latest block, setting timeout height to 0: {e}"
)
self.timeout_height = 0
# default client methods
async def fetch_account(self, address: str) -> Optional[account_pb2.EthAccount]:
result_account = None
try:
account = await self.auth_api.fetch_account(address=address)
parsed_account = account_pb2.EthAccount()
if parsed_account.DESCRIPTOR.full_name in account["account"]["@type"]:
json_format.ParseDict(js_dict=account["account"], message=parsed_account, ignore_unknown_fields=True)
self.number = parsed_account.base_account.account_number
self.sequence = parsed_account.base_account.sequence
result_account = parsed_account
except Exception as e:
LoggerProvider().logger_for_class(logging_class=self.__class__).debug(
f"error while fetching sequence and number {e}"
)
return result_account
async def get_request_id_by_tx_hash(self, tx_hash: str) -> List[int]:
tx = await self.tx_api.fetch_tx(hash=tx_hash)
request_ids = []
for log in tx["txResponse"].get("logs", []):
request_event = [
event for event in log.get("events", []) if event["type"] == "request" or event["type"] == "report"
]
if len(request_event) == 1:
attrs = request_event[0].get("attributes", [])
attr_id = [attr for attr in attrs if attr["key"] == "id"]
if len(attr_id) == 1:
request_id = attr_id[0]["value"]
request_ids.append(int(request_id))
if len(request_ids) == 0:
raise NotFoundError("Request Id is not found")
return request_ids
async def simulate(self, tx_bytes: bytes) -> Dict[str, Any]:
return await self.tx_api.simulate(tx_bytes=tx_bytes)
async def broadcast_tx_sync_mode(self, tx_bytes: bytes) -> Dict[str, Any]:
return await self.tx_api.broadcast(tx_bytes=tx_bytes, mode=tx_service.BroadcastMode.BROADCAST_MODE_SYNC)
async def broadcast_tx_async_mode(self, tx_bytes: bytes) -> Dict[str, Any]:
return await self.tx_api.broadcast(tx_bytes=tx_bytes, mode=tx_service.BroadcastMode.BROADCAST_MODE_ASYNC)
async def get_chain_id(self) -> str:
latest_block = await self.fetch_latest_block()
return latest_block["block"]["header"]["chainId"]
async def fetch_grants(
self,
granter: str,
grantee: str,
msg_type_url: Optional[str] = None,
pagination: Optional[PaginationOption] = None,
) -> Dict[str, Any]:
return await self.authz_api.fetch_grants(
granter=granter,
grantee=grantee,
msg_type_url=msg_type_url,
pagination=pagination,
)
async def fetch_bank_balances(self, address: str) -> Dict[str, Any]:
return await self.bank_api.fetch_balances(account_address=address)
async def fetch_bank_balance(self, address: str, denom: str) -> Dict[str, Any]:
return await self.bank_api.fetch_balance(account_address=address, denom=denom)
async def fetch_spendable_balances(
self,
address: str,
pagination: Optional[PaginationOption] = None,
) -> Dict[str, Any]:
return await self.bank_api.fetch_spendable_balances(account_address=address, pagination=pagination)
async def fetch_spendable_balances_by_denom(
self,
address: str,
denom: str,
) -> Dict[str, Any]:
return await self.bank_api.fetch_spendable_balances_by_denom(account_address=address, denom=denom)
async def fetch_total_supply(self, pagination: Optional[PaginationOption] = None) -> Dict[str, Any]:
return await self.bank_api.fetch_total_supply(pagination=pagination)
async def fetch_supply_of(self, denom: str) -> Dict[str, Any]:
return await self.bank_api.fetch_supply_of(denom=denom)
async def fetch_denom_metadata(self, denom: str) -> Dict[str, Any]:
return await self.bank_api.fetch_denom_metadata(denom=denom)
async def fetch_denoms_metadata(self, pagination: Optional[PaginationOption] = None) -> Dict[str, Any]:
return await self.bank_api.fetch_denoms_metadata(pagination=pagination)
async def fetch_denom_owners(self, denom: str, pagination: Optional[PaginationOption] = None) -> Dict[str, Any]:
return await self.bank_api.fetch_denom_owners(denom=denom, pagination=pagination)
async def fetch_send_enabled(
self,
denoms: Optional[List[str]] = None,
pagination: Optional[PaginationOption] = None,
) -> Dict[str, Any]:
return await self.bank_api.fetch_send_enabled(denoms=denoms, pagination=pagination)
async def fetch_validator_distribution_info(self, validator_address: str) -> Dict[str, Any]:
return await self.distribution_api.fetch_validator_distribution_info(validator_address=validator_address)
async def fetch_validator_outstanding_rewards(self, validator_address: str) -> Dict[str, Any]:
return await self.distribution_api.fetch_validator_outstanding_rewards(validator_address=validator_address)
async def fetch_validator_commission(self, validator_address: str) -> Dict[str, Any]:
return await self.distribution_api.fetch_validator_commission(validator_address=validator_address)
async def fetch_validator_slashes(
self,
validator_address: str,
starting_height: Optional[int] = None,
ending_height: Optional[int] = None,
pagination: Optional[PaginationOption] = None,
) -> Dict[str, Any]:
return await self.distribution_api.fetch_validator_slashes(
validator_address=validator_address,
starting_height=starting_height,
ending_height=ending_height,
pagination=pagination,
)
async def fetch_delegation_rewards(
self,
delegator_address: str,
validator_address: str,
) -> Dict[str, Any]:
return await self.distribution_api.fetch_delegation_rewards(
delegator_address=delegator_address,
validator_address=validator_address,
)
async def fetch_delegation_total_rewards(
self,
delegator_address: str,
) -> Dict[str, Any]:
return await self.distribution_api.fetch_delegation_total_rewards(
delegator_address=delegator_address,
)
async def fetch_delegator_validators(
self,
delegator_address: str,
) -> Dict[str, Any]:
return await self.distribution_api.fetch_delegator_validators(
delegator_address=delegator_address,
)
async def fetch_delegator_withdraw_address(
self,
delegator_address: str,
) -> Dict[str, Any]:
return await self.distribution_api.fetch_delegator_withdraw_address(
delegator_address=delegator_address,
)
async def fetch_community_pool(self) -> Dict[str, Any]:
return await self.distribution_api.fetch_community_pool()
# Exchange module
async def fetch_subaccount_deposits(
self,
subaccount_id: Optional[str] = None,
subaccount_trader: Optional[str] = None,
subaccount_nonce: Optional[int] = None,
) -> Dict[str, Any]:
return await self.chain_exchange_api.fetch_subaccount_deposits(
subaccount_id=subaccount_id,
subaccount_trader=subaccount_trader,
subaccount_nonce=subaccount_nonce,
)
async def fetch_subaccount_deposit(
self,
subaccount_id: str,
denom: str,
) -> Dict[str, Any]:
return await self.chain_exchange_api.fetch_subaccount_deposit(
subaccount_id=subaccount_id,
denom=denom,
)
async def fetch_exchange_balances(self) -> Dict[str, Any]:
return await self.chain_exchange_api.fetch_exchange_balances()
async def fetch_aggregate_volume(self, account: str) -> Dict[str, Any]:
return await self.chain_exchange_api.fetch_aggregate_volume(account=account)
async def fetch_aggregate_volumes(
self,
accounts: Optional[List[str]] = None,
market_ids: Optional[List[str]] = None,
) -> Dict[str, Any]:
return await self.chain_exchange_api.fetch_aggregate_volumes(
accounts=accounts,
market_ids=market_ids,
)
async def fetch_aggregate_market_volume(
self,
market_id: str,
) -> Dict[str, Any]:
return await self.chain_exchange_api.fetch_aggregate_market_volume(
market_id=market_id,
)
async def fetch_aggregate_market_volumes(
self,
market_ids: Optional[List[str]] = None,
) -> Dict[str, Any]:
return await self.chain_exchange_api.fetch_aggregate_market_volumes(
market_ids=market_ids,
)
async def fetch_denom_decimal(self, denom: str) -> Dict[str, Any]:
return await self.chain_exchange_api.fetch_denom_decimal(denom=denom)
async def fetch_denom_decimals(self, denoms: Optional[List[str]] = None) -> Dict[str, Any]:
return await self.chain_exchange_api.fetch_denom_decimals(denoms=denoms)
async def fetch_chain_spot_markets(
self,
status: Optional[str] = None,
market_ids: Optional[List[str]] = None,
) -> Dict[str, Any]:
return await self.chain_exchange_api.fetch_spot_markets(
status=status,
market_ids=market_ids,
)
async def fetch_chain_spot_market(
self,
market_id: str,
) -> Dict[str, Any]:
return await self.chain_exchange_api.fetch_spot_market(
market_id=market_id,
)
async def fetch_chain_full_spot_markets(
self,
status: Optional[str] = None,
market_ids: Optional[List[str]] = None,
with_mid_price_and_tob: Optional[bool] = None,
) -> Dict[str, Any]:
return await self.chain_exchange_api.fetch_full_spot_markets(
status=status,
market_ids=market_ids,
with_mid_price_and_tob=with_mid_price_and_tob,
)
async def fetch_chain_full_spot_market(
self,
market_id: str,
with_mid_price_and_tob: Optional[bool] = None,
) -> Dict[str, Any]:
return await self.chain_exchange_api.fetch_full_spot_market(
market_id=market_id,
with_mid_price_and_tob=with_mid_price_and_tob,
)
async def fetch_chain_spot_orderbook(
self,
market_id: str,
order_side: Optional[str] = None,
limit_cumulative_notional: Optional[str] = None,
limit_cumulative_quantity: Optional[str] = None,
pagination: Optional[PaginationOption] = None,
) -> Dict[str, Any]:
# Order side could be "Side_Unspecified", "Buy", "Sell"
return await self.chain_exchange_api.fetch_spot_orderbook(
market_id=market_id,
order_side=order_side,
limit_cumulative_notional=limit_cumulative_notional,
limit_cumulative_quantity=limit_cumulative_quantity,
pagination=pagination,
)
async def fetch_chain_trader_spot_orders(
self,
market_id: str,
subaccount_id: str,
) -> Dict[str, Any]:
return await self.chain_exchange_api.fetch_trader_spot_orders(
market_id=market_id,
subaccount_id=subaccount_id,
)
async def fetch_chain_account_address_spot_orders(
self,
market_id: str,
account_address: str,
) -> Dict[str, Any]:
return await self.chain_exchange_api.fetch_account_address_spot_orders(
market_id=market_id,
account_address=account_address,
)
async def fetch_chain_spot_orders_by_hashes(
self,
market_id: str,
subaccount_id: str,
order_hashes: List[str],
) -> Dict[str, Any]:
return await self.chain_exchange_api.fetch_spot_orders_by_hashes(
market_id=market_id,
subaccount_id=subaccount_id,
order_hashes=order_hashes,
)
async def fetch_chain_subaccount_orders(
self,
subaccount_id: str,
market_id: str,
) -> Dict[str, Any]:
return await self.chain_exchange_api.fetch_subaccount_orders(
subaccount_id=subaccount_id,
market_id=market_id,
)
async def fetch_chain_trader_spot_transient_orders(
self,
market_id: str,
subaccount_id: str,
) -> Dict[str, Any]:
return await self.chain_exchange_api.fetch_trader_spot_transient_orders(
market_id=market_id,
subaccount_id=subaccount_id,
)
async def fetch_spot_mid_price_and_tob(
self,
market_id: str,
) -> Dict[str, Any]:
return await self.chain_exchange_api.fetch_spot_mid_price_and_tob(
market_id=market_id,
)
async def fetch_derivative_mid_price_and_tob(
self,
market_id: str,
) -> Dict[str, Any]:
return await self.chain_exchange_api.fetch_derivative_mid_price_and_tob(
market_id=market_id,
)
async def fetch_chain_derivative_orderbook(
self,
market_id: str,
limit_cumulative_notional: Optional[str] = None,
pagination: Optional[PaginationOption] = None,
) -> Dict[str, Any]:
return await self.chain_exchange_api.fetch_derivative_orderbook(
market_id=market_id,
limit_cumulative_notional=limit_cumulative_notional,
pagination=pagination,
)
async def fetch_chain_trader_derivative_orders(
self,
market_id: str,
subaccount_id: str,
) -> Dict[str, Any]:
return await self.chain_exchange_api.fetch_trader_derivative_orders(
market_id=market_id,
subaccount_id=subaccount_id,
)
async def fetch_chain_account_address_derivative_orders(
self,
market_id: str,
account_address: str,
) -> Dict[str, Any]:
return await self.chain_exchange_api.fetch_account_address_derivative_orders(
market_id=market_id,
account_address=account_address,
)
async def fetch_chain_derivative_orders_by_hashes(
self,
market_id: str,
subaccount_id: str,
order_hashes: List[str],
) -> Dict[str, Any]:
return await self.chain_exchange_api.fetch_derivative_orders_by_hashes(
market_id=market_id,
subaccount_id=subaccount_id,
order_hashes=order_hashes,
)
async def fetch_chain_trader_derivative_transient_orders(
self,
market_id: str,
subaccount_id: str,
) -> Dict[str, Any]:
return await self.chain_exchange_api.fetch_trader_derivative_transient_orders(
market_id=market_id,
subaccount_id=subaccount_id,
)
async def fetch_chain_derivative_markets(
self,
status: Optional[str] = None,
market_ids: Optional[List[str]] = None,
with_mid_price_and_tob: Optional[bool] = None,
) -> Dict[str, Any]:
return await self.chain_exchange_api.fetch_derivative_markets(
status=status,
market_ids=market_ids,
with_mid_price_and_tob=with_mid_price_and_tob,
)
async def fetch_chain_derivative_market(
self,
market_id: str,
) -> Dict[str, Any]:
return await self.chain_exchange_api.fetch_derivative_market(
market_id=market_id,
)
async def fetch_derivative_market_address(self, market_id: str) -> Dict[str, Any]:
return await self.chain_exchange_api.fetch_derivative_market_address(market_id=market_id)
async def fetch_subaccount_trade_nonce(self, subaccount_id: str) -> Dict[str, Any]:
return await self.chain_exchange_api.fetch_subaccount_trade_nonce(subaccount_id=subaccount_id)
async def fetch_chain_positions(self) -> Dict[str, Any]:
return await self.chain_exchange_api.fetch_positions()
async def fetch_chain_subaccount_positions(self, subaccount_id: str) -> Dict[str, Any]:
return await self.chain_exchange_api.fetch_subaccount_positions(subaccount_id=subaccount_id)
async def fetch_chain_subaccount_position_in_market(self, subaccount_id: str, market_id: str) -> Dict[str, Any]:
return await self.chain_exchange_api.fetch_subaccount_position_in_market(
subaccount_id=subaccount_id,
market_id=market_id,
)
async def fetch_chain_subaccount_effective_position_in_market(
self, subaccount_id: str, market_id: str
) -> Dict[str, Any]:
return await self.chain_exchange_api.fetch_subaccount_effective_position_in_market(
subaccount_id=subaccount_id,
market_id=market_id,
)
async def fetch_chain_perpetual_market_info(self, market_id: str) -> Dict[str, Any]:
return await self.chain_exchange_api.fetch_perpetual_market_info(market_id=market_id)
async def fetch_chain_expiry_futures_market_info(self, market_id: str) -> Dict[str, Any]:
return await self.chain_exchange_api.fetch_expiry_futures_market_info(market_id=market_id)
async def fetch_chain_perpetual_market_funding(self, market_id: str) -> Dict[str, Any]:
return await self.chain_exchange_api.fetch_perpetual_market_funding(market_id=market_id)
async def fetch_subaccount_order_metadata(self, subaccount_id: str) -> Dict[str, Any]:
return await self.chain_exchange_api.fetch_subaccount_order_metadata(subaccount_id=subaccount_id)
async def fetch_trade_reward_points(
self,
accounts: Optional[List[str]] = None,
pending_pool_timestamp: Optional[int] = None,
) -> Dict[str, Any]:
return await self.chain_exchange_api.fetch_trade_reward_points(
accounts=accounts,
pending_pool_timestamp=pending_pool_timestamp,
)
async def fetch_pending_trade_reward_points(
self,
accounts: Optional[List[str]] = None,
pending_pool_timestamp: Optional[int] = None,
) -> Dict[str, Any]:
return await self.chain_exchange_api.fetch_pending_trade_reward_points(
accounts=accounts,
pending_pool_timestamp=pending_pool_timestamp,
)
async def fetch_trade_reward_campaign(self) -> Dict[str, Any]:
return await self.chain_exchange_api.fetch_trade_reward_campaign()
async def fetch_fee_discount_account_info(self, account: str) -> Dict[str, Any]:
return await self.chain_exchange_api.fetch_fee_discount_account_info(account=account)
async def fetch_fee_discount_schedule(self) -> Dict[str, Any]:
return await self.chain_exchange_api.fetch_fee_discount_schedule()
async def fetch_balance_mismatches(self, dust_factor: int) -> Dict[str, Any]:
return await self.chain_exchange_api.fetch_balance_mismatches(dust_factor=dust_factor)
async def fetch_balance_with_balance_holds(self) -> Dict[str, Any]:
return await self.chain_exchange_api.fetch_balance_with_balance_holds()
async def fetch_fee_discount_tier_statistics(self) -> Dict[str, Any]:
return await self.chain_exchange_api.fetch_fee_discount_tier_statistics()
async def fetch_mito_vault_infos(self) -> Dict[str, Any]:
return await self.chain_exchange_api.fetch_mito_vault_infos()
async def fetch_market_id_from_vault(self, vault_address: str) -> Dict[str, Any]:
return await self.chain_exchange_api.fetch_market_id_from_vault(vault_address=vault_address)
async def fetch_historical_trade_records(self, market_id: str) -> Dict[str, Any]:
return await self.chain_exchange_api.fetch_historical_trade_records(market_id=market_id)
async def fetch_is_opted_out_of_rewards(self, account: str) -> Dict[str, Any]:
return await self.chain_exchange_api.fetch_is_opted_out_of_rewards(account=account)
async def fetch_opted_out_of_rewards_accounts(self) -> Dict[str, Any]:
return await self.chain_exchange_api.fetch_opted_out_of_rewards_accounts()
async def fetch_market_volatility(
self,
market_id: str,
trade_grouping_sec: Optional[int] = None,
max_age: Optional[int] = None,
include_raw_history: Optional[bool] = None,
include_metadata: Optional[bool] = None,
) -> Dict[str, Any]:
return await self.chain_exchange_api.fetch_market_volatility(
market_id=market_id,
trade_grouping_sec=trade_grouping_sec,
max_age=max_age,
include_raw_history=include_raw_history,
include_metadata=include_metadata,
)
async def fetch_chain_binary_options_markets(self, status: Optional[str] = None) -> Dict[str, Any]:
return await self.chain_exchange_api.fetch_binary_options_markets(status=status)
async def fetch_trader_derivative_conditional_orders(
self,
subaccount_id: Optional[str] = None,
market_id: Optional[str] = None,
) -> Dict[str, Any]:
return await self.chain_exchange_api.fetch_trader_derivative_conditional_orders(
subaccount_id=subaccount_id,
market_id=market_id,
)
async def fetch_market_atomic_execution_fee_multiplier(
self,
market_id: str,
) -> Dict[str, Any]:
return await self.chain_exchange_api.fetch_market_atomic_execution_fee_multiplier(
market_id=market_id,
)
async def fetch_l3_derivative_orderbook(self, market_id: str) -> Dict[str, Any]:
return await self.chain_exchange_api.fetch_l3_derivative_orderbook(market_id=market_id)
async def fetch_l3_spot_orderbook(self, market_id: str) -> Dict[str, Any]:
return await self.chain_exchange_api.fetch_l3_spot_orderbook(market_id=market_id)
async def fetch_market_balance(self, market_id: str) -> Dict[str, Any]:
return await self.chain_exchange_api.fetch_market_balance(market_id=market_id)
async def fetch_market_balances(self) -> Dict[str, Any]:
return await self.chain_exchange_api.fetch_market_balances()
async def fetch_denom_min_notional(self, denom: str) -> Dict[str, Any]:
return await self.chain_exchange_api.fetch_denom_min_notional(denom=denom)
async def fetch_denom_min_notionals(self) -> Dict[str, Any]:
return await self.chain_exchange_api.fetch_denom_min_notionals()
# Injective Exchange client methods
# Auction RPC
async def fetch_auction(self, round: int) -> Dict[str, Any]:
return await self.exchange_auction_api.fetch_auction(round=round)
async def fetch_auctions(self) -> Dict[str, Any]:
return await self.exchange_auction_api.fetch_auctions()
async def listen_bids_updates(
self,
callback: Callable,
on_end_callback: Optional[Callable] = None,
on_status_callback: Optional[Callable] = None,
):
await self.exchange_auction_stream_api.stream_bids(
callback=callback,
on_end_callback=on_end_callback,
on_status_callback=on_status_callback,
)
async def fetch_inj_burnt(self) -> Dict[str, Any]:
return await self.exchange_auction_api.fetch_inj_burnt()
# Meta RPC
async def fetch_ping(self) -> Dict[str, Any]:
return await self.exchange_meta_api.fetch_ping()
async def fetch_version(self) -> Dict[str, Any]:
return await self.exchange_meta_api.fetch_version()
async def fetch_info(self) -> Dict[str, Any]:
return await self.exchange_meta_api.fetch_info()
async def listen_keepalive(
self,
callback: Callable,
on_end_callback: Optional[Callable] = None,
on_status_callback: Optional[Callable] = None,
):
await self.exchange_meta_stream_api.stream_keepalive(
callback=callback,
on_end_callback=on_end_callback,
on_status_callback=on_status_callback,
)
# Wasm module
async def fetch_contract_info(self, address: str) -> Dict[str, Any]:
return await self.wasm_api.fetch_contract_info(address=address)
async def fetch_contract_history(
self,
address: str,
pagination: Optional[PaginationOption] = None,
) -> Dict[str, Any]:
return await self.wasm_api.fetch_contract_history(
address=address,
pagination=pagination,
)
async def fetch_contracts_by_code(
self,
code_id: int,
pagination: Optional[PaginationOption] = None,
) -> Dict[str, Any]:
return await self.wasm_api.fetch_contracts_by_code(
code_id=code_id,
pagination=pagination,
)
async def fetch_all_contracts_state(
self,
address: str,
pagination: Optional[PaginationOption] = None,
) -> Dict[str, Any]:
return await self.wasm_api.fetch_all_contracts_state(
address=address,
pagination=pagination,
)
async def fetch_raw_contract_state(self, address: str, query_data: str) -> Dict[str, Any]:
return await self.wasm_api.fetch_raw_contract_state(address=address, query_data=query_data)
async def fetch_smart_contract_state(self, address: str, query_data: str) -> Dict[str, Any]:
return await self.wasm_api.fetch_smart_contract_state(address=address, query_data=query_data)
async def fetch_code(self, code_id: int) -> Dict[str, Any]:
return await self.wasm_api.fetch_code(code_id=code_id)
async def fetch_codes(
self,
pagination: Optional[PaginationOption] = None,
) -> Dict[str, Any]:
return await self.wasm_api.fetch_codes(
pagination=pagination,
)
async def fetch_pinned_codes(
self,
pagination: Optional[PaginationOption] = None,
) -> Dict[str, Any]:
return await self.wasm_api.fetch_pinned_codes(
pagination=pagination,