Skip to content

Commit 8e2a66e

Browse files
author
abel
committed
Merge branch 'dev' of https://github.com/InjectiveLabs/sdk-python into feat/create_api_components
2 parents f32ec5e + c1c8089 commit 8e2a66e

File tree

7 files changed

+182
-69
lines changed

7 files changed

+182
-69
lines changed

CHANGELOG.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,15 @@
22

33
All notable changes to this project will be documented in this file.
44

5-
## [1.0.1] - 2023-11-07
5+
## [1.0.1] - 2023-12-11
6+
### Added
7+
- Added low level API components for all modules (chain, exchain and explorer) to make the Python SDK compatible with the TypeScript SDK.
8+
69
### Changed
710
- Updated proto definitions to injective-core v1.12.2-testnet and injective-indexer v1.12.45-rc3
11+
- Added new functions in AsyncClient to interact with chain, exchange and explorer using the low level API components
12+
- Marked old function sin AsyncClient as deprecated (the functions will be removed in a future version)
13+
- Updated all API examples to use the new AsyncClient functions
814

915
## [1.0] - 2023-11-01
1016
### Added
@@ -17,6 +23,23 @@ All notable changes to this project will be documented in this file.
1723
- Moved changelog from the README.md file to its own CHANGELOG.md file
1824
- Remove `aiocron` dependency. Use plain asyncio tasks to solve the timeout height synchronization
1925
- Updated the gas fee buffer used to calculate fee consumption in all examples
26+
- Refactored logic in AsyncClient to load markets and tokens, to ensure there are no duplicated tokens with the same denom
27+
28+
## [0.9.10]
29+
* Synchronized markets and tokens config files to add SOL/USDT spot market
30+
31+
## [0.9.9]
32+
* Synchronized markets and tokens config files to add USDY/USDT and WHALE/USDT spot markets
33+
34+
35+
## [0.9.8]
36+
* Synchronized markets and tokens config files to add PYTH/USDT spot market
37+
38+
## [0.9.7]
39+
* Added PYTH/USDT PERP market info in mainnet metadata ini file
40+
41+
## [0.9.6]
42+
* Synchronized denom ini files with Indexer information for mainnet, testnet and devnet to include TALIS/INJ and KUJI/USDT markets
2043

2144
## [0.9.5]
2245
* Updated fetch_metadata script (to synchronize denom ini files) to reuse logic in AsyncClient

pyinjective/async_client.py

Lines changed: 41 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,8 @@ def __init__(
152152
self._initialize_timeout_height_sync_task()
153153

154154
self._tokens_and_markets_initialization_lock = asyncio.Lock()
155-
self._tokens: Optional[Dict[str, Token]] = None
155+
self._tokens_by_denom: Optional[Dict[str, Token]] = None
156+
self._tokens_by_symbol: Optional[Dict[str, Token]] = None
156157
self._spot_markets: Optional[Dict[str, SpotMarket]] = None
157158
self._derivative_markets: Optional[Dict[str, DerivativeMarket]] = None
158159
self._binary_option_markets: Optional[Dict[str, BinaryOptionMarket]] = None
@@ -295,11 +296,11 @@ def __init__(
295296
)
296297

297298
async def all_tokens(self) -> Dict[str, Token]:
298-
if self._tokens is None:
299+
if self._tokens_by_symbol is None:
299300
async with self._tokens_and_markets_initialization_lock:
300-
if self._tokens is None:
301+
if self._tokens_by_symbol is None:
301302
await self._initialize_tokens_and_markets()
302-
return deepcopy(self._tokens)
303+
return deepcopy(self._tokens_by_symbol)
303304

304305
async def all_spot_markets(self) -> Dict[str, SpotMarket]:
305306
if self._spot_markets is None:
@@ -2463,7 +2464,7 @@ async def _initialize_tokens_and_markets(self):
24632464
spot_markets = dict()
24642465
derivative_markets = dict()
24652466
binary_option_markets = dict()
2466-
tokens = dict()
2467+
tokens_by_symbol = dict()
24672468
tokens_by_denom = dict()
24682469
markets_info = (await self.fetch_spot_markets(market_statuses=["active"]))["markets"]
24692470
valid_markets = (
@@ -2485,19 +2486,16 @@ async def _initialize_tokens_and_markets(self):
24852486
symbol=base_token_symbol,
24862487
token_meta=market_info["baseTokenMeta"],
24872488
denom=market_info["baseDenom"],
2488-
all_tokens=tokens,
2489+
tokens_by_denom=tokens_by_denom,
2490+
tokens_by_symbol=tokens_by_symbol,
24892491
)
2490-
if base_token.denom not in tokens_by_denom:
2491-
tokens_by_denom[base_token.denom] = base_token
2492-
24932492
quote_token = self._token_representation(
24942493
symbol=quote_token_symbol,
24952494
token_meta=market_info["quoteTokenMeta"],
24962495
denom=market_info["quoteDenom"],
2497-
all_tokens=tokens,
2496+
tokens_by_denom=tokens_by_denom,
2497+
tokens_by_symbol=tokens_by_symbol,
24982498
)
2499-
if quote_token.denom not in tokens_by_denom:
2500-
tokens_by_denom[quote_token.denom] = quote_token
25012499

25022500
market = SpotMarket(
25032501
id=market_info["marketId"],
@@ -2528,10 +2526,9 @@ async def _initialize_tokens_and_markets(self):
25282526
symbol=quote_token_symbol,
25292527
token_meta=market_info["quoteTokenMeta"],
25302528
denom=market_info["quoteDenom"],
2531-
all_tokens=tokens,
2529+
tokens_by_denom=tokens_by_denom,
2530+
tokens_by_symbol=tokens_by_symbol,
25322531
)
2533-
if quote_token.denom not in tokens_by_denom:
2534-
tokens_by_denom[quote_token.denom] = quote_token
25352532

25362533
market = DerivativeMarket(
25372534
id=market_info["marketId"],
@@ -2580,35 +2577,41 @@ async def _initialize_tokens_and_markets(self):
25802577

25812578
binary_option_markets[market.id] = market
25822579

2583-
self._tokens = tokens
2580+
self._tokens_by_denom = tokens_by_denom
2581+
self._tokens_by_symbol = tokens_by_symbol
25842582
self._spot_markets = spot_markets
25852583
self._derivative_markets = derivative_markets
25862584
self._binary_option_markets = binary_option_markets
25872585

25882586
def _token_representation(
2589-
self, symbol: str, token_meta: Dict[str, Any], denom: str, all_tokens: Dict[str, Token]
2587+
self,
2588+
symbol: str,
2589+
token_meta: Dict[str, Any],
2590+
denom: str,
2591+
tokens_by_denom: Dict[str, Token],
2592+
tokens_by_symbol: Dict[str, Token],
25902593
) -> Token:
2591-
token = Token(
2592-
name=token_meta["name"],
2593-
symbol=symbol,
2594-
denom=denom,
2595-
address=token_meta["address"],
2596-
decimals=token_meta["decimals"],
2597-
logo=token_meta["logo"],
2598-
updated=int(token_meta["updatedAt"]),
2599-
)
2600-
2601-
existing_token = all_tokens.get(token.symbol, None)
2602-
if existing_token is None:
2603-
all_tokens[token.symbol] = token
2604-
existing_token = token
2605-
elif existing_token.denom != denom:
2606-
existing_token = all_tokens.get(token.name, None)
2607-
if existing_token is None:
2608-
all_tokens[token.name] = token
2609-
existing_token = token
2610-
2611-
return existing_token
2594+
if denom not in tokens_by_denom:
2595+
unique_symbol = denom
2596+
for symbol_candidate in [symbol, token_meta["symbol"], token_meta["name"]]:
2597+
if symbol_candidate not in tokens_by_symbol:
2598+
unique_symbol = symbol_candidate
2599+
break
2600+
2601+
token = Token(
2602+
name=token_meta["name"],
2603+
symbol=symbol,
2604+
denom=denom,
2605+
address=token_meta["address"],
2606+
decimals=token_meta["decimals"],
2607+
logo=token_meta["logo"],
2608+
updated=int(token_meta["updatedAt"]),
2609+
)
2610+
2611+
tokens_by_denom[denom] = token
2612+
tokens_by_symbol[unique_symbol] = token
2613+
2614+
return tokens_by_denom[denom]
26122615

26132616
def _chain_cookie_metadata_requestor(self) -> Coroutine:
26142617
request = tendermint_query.GetLatestBlockRequest()

pyinjective/denoms_mainnet.ini

Lines changed: 79 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,60 @@ min_display_price_tick_size = 0.00001
529529
min_quantity_tick_size = 10000000
530530
min_display_quantity_tick_size = 10
531531

532+
[0xf09dd242aea343afd7b6644151bb00d1b8770d842881009bea867658602b6bf0]
533+
description = 'Mainnet Spot TALIS/INJ'
534+
base = 6
535+
quote = 18
536+
min_price_tick_size = 1000000
537+
min_display_price_tick_size = 0.000001
538+
min_quantity_tick_size = 10000000
539+
min_display_quantity_tick_size = 10
540+
541+
[0x6922cf4383294c673971dd06aa4ae5ef47f65cb4f1ec1c2af4271c5e5ca67486]
542+
description = 'Mainnet Spot KUJI/USDT'
543+
base = 6
544+
quote = 6
545+
min_price_tick_size = 0.001
546+
min_display_price_tick_size = 0.001
547+
min_quantity_tick_size = 100000
548+
min_display_quantity_tick_size = 0.1
549+
550+
[0xa6ec1de114a5ffa85b6b235144383ce51028a1c0c2dee7db5ff8bf14d5ca0d49]
551+
description = 'Mainnet Spot PYTH/USDT'
552+
base = 6
553+
quote = 6
554+
min_price_tick_size = 0.0001
555+
min_display_price_tick_size = 0.0001
556+
min_quantity_tick_size = 1000000
557+
min_display_quantity_tick_size = 1
558+
559+
[0x75f6a79b552dac417df219ab384be19cb13b53dec7cf512d73a965aee8bc83af]
560+
description = 'Mainnet Spot USDY/USDT'
561+
base = 18
562+
quote = 6
563+
min_price_tick_size = 0.0000000000000001
564+
min_display_price_tick_size = 0.0001
565+
min_quantity_tick_size = 100000000000000000
566+
min_display_quantity_tick_size = 0.1
567+
568+
[0x689ea50a30b0aeaf162e57100fefe5348a00099774f1c1ebcd90c4b480fda46a]
569+
description = 'Mainnet Spot WHALE/USDT'
570+
base = 6
571+
quote = 6
572+
min_price_tick_size = 0.00001
573+
min_display_price_tick_size = 0.00001
574+
min_quantity_tick_size = 10000000
575+
min_display_quantity_tick_size = 10
576+
577+
[0xac938722067b1dfdfbf346d2434573fb26cb090d309b19af17df2c6827ceb32c]
578+
description = 'Mainnet Spot SOL/USDT'
579+
base = 8
580+
quote = 6
581+
min_price_tick_size = 0.0001
582+
min_display_price_tick_size = 0.01
583+
min_quantity_tick_size = 1000000
584+
min_display_quantity_tick_size = 0.01
585+
532586
[0x4ca0f92fc28be0c9761326016b5a1a2177dd6375558365116b5bdda9abc229ce]
533587
description = 'Mainnet Derivative BTC/USDT PERP'
534588
base = 0
@@ -601,15 +655,6 @@ min_display_price_tick_size = 0.01
601655
min_quantity_tick_size = 0.1
602656
min_display_quantity_tick_size = 0.1
603657

604-
[0x3b7fb1d9351f7fa2e6e0e5a11b3639ee5e0486c33a6a74f629c3fc3c3043efd5]
605-
description = 'Mainnet Derivative BONK/USDT PERP'
606-
base = 0
607-
quote = 6
608-
min_price_tick_size = 0.0001
609-
min_display_price_tick_size = 0.0000000001
610-
min_quantity_tick_size = 0.1
611-
min_display_quantity_tick_size = 0.1
612-
613658
[0xcd0c859a99f26bb3530e21890937ed77d20754aa7825a599c71710514fc125ef]
614659
description = 'Mainnet Derivative 1MPEPE/USDT PERP'
615660
base = 0
@@ -628,15 +673,6 @@ min_display_price_tick_size = 0.0001
628673
min_quantity_tick_size = 0.1
629674
min_display_quantity_tick_size = 0.1
630675

631-
[0x1afa358349b140e49441b6e68529578c7d2f27f06e18ef874f428457c0aaeb8b]
632-
description = 'Mainnet Derivative SEI/USDT PERP'
633-
base = 0
634-
quote = 6
635-
min_price_tick_size = 100
636-
min_display_price_tick_size = 0.0001
637-
min_quantity_tick_size = 0.1
638-
min_display_quantity_tick_size = 0.1
639-
640676
[0x332230109e7afb839b4750d4cf961666b608071ecb64dac55662dac37529639e]
641677
description = 'Mainnet Derivative BTC/USDTkv PERP'
642678
base = 0
@@ -673,6 +709,15 @@ min_display_price_tick_size = 0.001
673709
min_quantity_tick_size = 0.1
674710
min_display_quantity_tick_size = 0.1
675711

712+
[0x887beca72224f88fb678a13a1ae91d39c53a05459fd37ef55005eb68f745d46d]
713+
description = 'Mainnet Derivative PYTH/USDT PERP'
714+
base = 0
715+
quote = 6
716+
min_price_tick_size = 100
717+
min_display_price_tick_size = 0.0001
718+
min_quantity_tick_size = 1
719+
min_display_quantity_tick_size = 1
720+
676721
[AAVE]
677722
peggy_denom = peggy0x7Fc66500c84A76Ad7e9c93437bFc5Ac33E2DDaE9
678723
decimals = 18
@@ -737,6 +782,10 @@ decimals = 18
737782
peggy_denom = ibc/57AA1A70A4BC9769C525EBF6386F7A21536E04A79D62E1981EFCEF9428EBB205
738783
decimals = 6
739784

785+
[KUJI]
786+
peggy_denom = ibc/9A115B56E769B92621FFF90567E2D60EFD146E86E867491DB69EEDA9ADC36204
787+
decimals = 6
788+
740789
[LDO]
741790
peggy_denom = factory/inj14ejqjyq8um4p3xfqj74yld5waqljf88f9eneuk/inj1q6zlut7gtkzknkk773jecujwsdkgq882akqksk
742791
decimals = 6
@@ -769,6 +818,10 @@ decimals = 6
769818
peggy_denom = peggy0xf9a06dE3F6639E6ee4F079095D5093644Ad85E8b
770819
decimals = 18
771820

821+
[PYTH]
822+
peggy_denom = factory/inj14ejqjyq8um4p3xfqj74yld5waqljf88f9eneuk/inj1tjcf9497fwmrnk22jfu5hsdq82qshga54ajvzy
823+
decimals = 6
824+
772825
[QNT]
773826
peggy_denom = peggy0x4a220E6096B25EADb88358cb44068A3248254675
774827
decimals = 18
@@ -837,6 +890,10 @@ decimals = 6
837890
peggy_denom = ibc/4ABBEF4C8926DDDB320AE5188CFD63267ABBCEFC0583E4AE05D6E5AA2401DDAB
838891
decimals = 6
839892

893+
[USDY]
894+
peggy_denom = peggy0x96F6eF951840721AdBF46Ac996b59E0235CB985C
895+
decimals = 18
896+
840897
[UST]
841898
peggy_denom = ibc/B448C0CA358B958301D328CCDC5D5AD642FC30A6D3AE106FF721DB315F3DDE5C
842899
decimals = 6
@@ -849,6 +906,10 @@ decimals = 8
849906
peggy_denom = peggy0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2
850907
decimals = 18
851908

909+
[WHALE]
910+
peggy_denom = ibc/D6E6A20ABDD600742D22464340A7701558027759CE14D12590F8EA869CCCF445
911+
decimals = 6
912+
852913
[WMATIC]
853914
peggy_denom = factory/inj14ejqjyq8um4p3xfqj74yld5waqljf88f9eneuk/inj1dxv423h8ygzgxmxnvrf33ws3k94aedfdevxd8h
854915
decimals = 8

0 commit comments

Comments
 (0)