-
Notifications
You must be signed in to change notification settings - Fork 33
Release/v1.8.0 #358
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Release/v1.8.0 #358
Changes from all commits
01ee3f9
206383b
c1487d0
a87553e
f205480
aad28f0
387b1fc
932388c
c8ad358
a86166d
c54d107
9f7b8e3
2b202ee
be9cc3f
74a6433
845e813
1764dd9
50bdfbe
bff2fa9
f206f58
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -157,8 +157,8 @@ def __init__( | |
| self._initialize_timeout_height_sync_task() | ||
|
|
||
| self._tokens_and_markets_initialization_lock = asyncio.Lock() | ||
| self._tokens_by_denom: Optional[Dict[str, Token]] = None | ||
| self._tokens_by_symbol: Optional[Dict[str, Token]] = None | ||
| self._tokens_by_denom = dict() | ||
| self._tokens_by_symbol = dict() | ||
|
Comment on lines
+160
to
+161
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Variable Initialization May Prevent Tokens and Markets from Initializing Properly By initializing To fix this issue, update the conditions to check if the dictionaries are empty instead of Apply this diff: @@ -195,7 +195,7 @@ class AsyncClient:
async def all_tokens(self) -> Dict[str, Token]:
- if self._tokens_by_symbol is None:
+ if not self._tokens_by_symbol:
async with self._tokens_and_markets_initialization_lock:
- if self._tokens_by_symbol is None:
+ if not self._tokens_by_symbol:
await self._initialize_tokens_and_markets()
return deepcopy(self._tokens_by_symbol)Repeat similar changes for the other methods: @@ -202,7 +202,7 @@ class AsyncClient:
async def all_spot_markets(self) -> Dict[str, SpotMarket]:
- if self._spot_markets is None:
+ if not self._spot_markets:
async with self._tokens_and_markets_initialization_lock:
- if self._spot_markets is None:
+ if not self._spot_markets:
await self._initialize_tokens_and_markets()
return deepcopy(self._spot_markets)
|
||
| 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 | ||
|
|
@@ -3291,87 +3291,81 @@ async def _initialize_tokens_and_markets(self): | |
| derivative_markets = dict() | ||
| binary_option_markets = dict() | ||
| tokens_by_symbol, tokens_by_denom = await self._tokens_from_official_lists(network=self.network) | ||
| markets_info = (await self.fetch_spot_markets(market_statuses=["active"]))["markets"] | ||
| valid_markets = ( | ||
| market_info | ||
| for market_info in markets_info | ||
| if len(market_info.get("baseTokenMeta", {}).get("symbol", "")) > 0 | ||
| and len(market_info.get("quoteTokenMeta", {}).get("symbol", "")) > 0 | ||
| ) | ||
|
|
||
| for market_info in valid_markets: | ||
| base_token = self._token_representation( | ||
| token_meta=market_info["baseTokenMeta"], | ||
| denom=market_info["baseDenom"], | ||
| tokens_by_denom=tokens_by_denom, | ||
| tokens_by_symbol=tokens_by_symbol, | ||
| ) | ||
| quote_token = self._token_representation( | ||
| token_meta=market_info["quoteTokenMeta"], | ||
| denom=market_info["quoteDenom"], | ||
| tokens_by_denom=tokens_by_denom, | ||
| tokens_by_symbol=tokens_by_symbol, | ||
| ) | ||
| self._tokens_by_denom.update(tokens_by_denom) | ||
| self._tokens_by_symbol.update(tokens_by_symbol) | ||
|
|
||
| markets_info = (await self.fetch_chain_spot_markets(status="Active"))["markets"] | ||
| for market_info in markets_info: | ||
| base_token = self._tokens_by_denom.get(market_info["baseDenom"]) | ||
| quote_token = self._tokens_by_denom.get(market_info["quoteDenom"]) | ||
|
Comment on lines
+3299
to
+3300
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Handle Potential At lines 3299-3300, Add checks to ensure tokens are found before proceeding: base_token = self._tokens_by_denom.get(market_info["baseDenom"])
quote_token = self._tokens_by_denom.get(market_info["quoteDenom"])
if base_token is None or quote_token is None:
# Handle missing tokens, e.g., log a warning or skip this market
continue # or raise an exception
market = SpotMarket(
id=market_info["marketId"],
status=market_info["status"],
ticker=market_info["ticker"],
base_token=base_token,
quote_token=quote_token,
# ... rest of the initialization
) |
||
|
|
||
| market = SpotMarket( | ||
| id=market_info["marketId"], | ||
| status=market_info["marketStatus"], | ||
| status=market_info["status"], | ||
| ticker=market_info["ticker"], | ||
| base_token=base_token, | ||
| quote_token=quote_token, | ||
| maker_fee_rate=Decimal(market_info["makerFeeRate"]), | ||
| taker_fee_rate=Decimal(market_info["takerFeeRate"]), | ||
| service_provider_fee=Decimal(market_info["serviceProviderFee"]), | ||
| min_price_tick_size=Decimal(market_info["minPriceTickSize"]), | ||
| min_quantity_tick_size=Decimal(market_info["minQuantityTickSize"]), | ||
| min_notional=Decimal(market_info["minNotional"]), | ||
| maker_fee_rate=Token.convert_value_from_extended_decimal_format(Decimal(market_info["makerFeeRate"])), | ||
| taker_fee_rate=Token.convert_value_from_extended_decimal_format(Decimal(market_info["takerFeeRate"])), | ||
| service_provider_fee=Token.convert_value_from_extended_decimal_format( | ||
| Decimal(market_info["relayerFeeShareRate"]) | ||
| ), | ||
| min_price_tick_size=Token.convert_value_from_extended_decimal_format( | ||
| Decimal(market_info["minPriceTickSize"]) | ||
| ), | ||
| min_quantity_tick_size=Token.convert_value_from_extended_decimal_format( | ||
| Decimal(market_info["minQuantityTickSize"]) | ||
| ), | ||
| min_notional=Token.convert_value_from_extended_decimal_format(Decimal(market_info["minNotional"])), | ||
| ) | ||
|
|
||
| spot_markets[market.id] = market | ||
|
|
||
| markets_info = (await self.fetch_derivative_markets(market_statuses=["active"]))["markets"] | ||
| valid_markets = ( | ||
| market_info | ||
| for market_info in markets_info | ||
| if len(market_info.get("quoteTokenMeta", {}).get("symbol", "")) > 0 | ||
| ) | ||
|
|
||
| for market_info in valid_markets: | ||
| quote_token = self._token_representation( | ||
| token_meta=market_info["quoteTokenMeta"], | ||
| denom=market_info["quoteDenom"], | ||
| tokens_by_denom=tokens_by_denom, | ||
| tokens_by_symbol=tokens_by_symbol, | ||
| ) | ||
|
|
||
| market = DerivativeMarket( | ||
| id=market_info["marketId"], | ||
| status=market_info["marketStatus"], | ||
| ticker=market_info["ticker"], | ||
| oracle_base=market_info["oracleBase"], | ||
| oracle_quote=market_info["oracleQuote"], | ||
| oracle_type=market_info["oracleType"], | ||
| oracle_scale_factor=market_info["oracleScaleFactor"], | ||
| initial_margin_ratio=Decimal(market_info["initialMarginRatio"]), | ||
| maintenance_margin_ratio=Decimal(market_info["maintenanceMarginRatio"]), | ||
| markets_info = (await self.fetch_chain_derivative_markets(status="Active", with_mid_price_and_tob=False))[ | ||
| "markets" | ||
| ] | ||
| for market_info in markets_info: | ||
| market = market_info["market"] | ||
| quote_token = self._tokens_by_denom.get(market["quoteDenom"]) | ||
|
|
||
|
Comment on lines
+3329
to
+3330
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Ensure In lines 3329-3330, Include a check for quote_token = self._tokens_by_denom.get(market["quoteDenom"])
if quote_token is None:
# Handle missing token
continue # or raise an exception
derivative_market = DerivativeMarket(
id=market["marketId"],
status=market["status"],
ticker=market["ticker"],
# ... rest of the initialization
quote_token=quote_token,
# ... rest of the initialization
) |
||
| derivative_market = DerivativeMarket( | ||
| id=market["marketId"], | ||
| status=market["status"], | ||
| ticker=market["ticker"], | ||
| oracle_base=market["oracleBase"], | ||
| oracle_quote=market["oracleQuote"], | ||
| oracle_type=market["oracleType"], | ||
| oracle_scale_factor=market["oracleScaleFactor"], | ||
| initial_margin_ratio=Token.convert_value_from_extended_decimal_format( | ||
| Decimal(market["initialMarginRatio"]) | ||
| ), | ||
| maintenance_margin_ratio=Token.convert_value_from_extended_decimal_format( | ||
| Decimal(market["maintenanceMarginRatio"]) | ||
| ), | ||
| quote_token=quote_token, | ||
| maker_fee_rate=Decimal(market_info["makerFeeRate"]), | ||
| taker_fee_rate=Decimal(market_info["takerFeeRate"]), | ||
| service_provider_fee=Decimal(market_info["serviceProviderFee"]), | ||
| min_price_tick_size=Decimal(market_info["minPriceTickSize"]), | ||
| min_quantity_tick_size=Decimal(market_info["minQuantityTickSize"]), | ||
| min_notional=Decimal(market_info["minNotional"]), | ||
| maker_fee_rate=Token.convert_value_from_extended_decimal_format(Decimal(market["makerFeeRate"])), | ||
| taker_fee_rate=Token.convert_value_from_extended_decimal_format(Decimal(market["takerFeeRate"])), | ||
| service_provider_fee=Token.convert_value_from_extended_decimal_format( | ||
| Decimal(market["relayerFeeShareRate"]) | ||
| ), | ||
| min_price_tick_size=Token.convert_value_from_extended_decimal_format( | ||
| Decimal(market["minPriceTickSize"]) | ||
| ), | ||
| min_quantity_tick_size=Token.convert_value_from_extended_decimal_format( | ||
| Decimal(market["minQuantityTickSize"]) | ||
| ), | ||
| min_notional=Token.convert_value_from_extended_decimal_format(Decimal(market["minNotional"])), | ||
| ) | ||
|
|
||
| derivative_markets[market.id] = market | ||
| derivative_markets[derivative_market.id] = derivative_market | ||
|
|
||
| markets_info = (await self.fetch_binary_options_markets(market_status="active"))["markets"] | ||
| markets_info = (await self.fetch_chain_binary_options_markets(status="Active"))["markets"] | ||
| for market_info in markets_info: | ||
| quote_token = tokens_by_denom.get(market_info["quoteDenom"], None) | ||
| quote_token = self._tokens_by_denom.get(market_info["quoteDenom"]) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Validate At line 3364, Add a check before initializing the market: quote_token = self._tokens_by_denom.get(market_info["quoteDenom"])
if quote_token is None:
# Handle missing token
continue # or raise an exception
market = BinaryOptionMarket(
id=market_info["marketId"],
status=market_info["status"],
ticker=market_info["ticker"],
# ... rest of the initialization
quote_token=quote_token,
# ... rest of the initialization
) |
||
|
|
||
| market = BinaryOptionMarket( | ||
| id=market_info["marketId"], | ||
| status=market_info["marketStatus"], | ||
| status=market_info["status"], | ||
| ticker=market_info["ticker"], | ||
| oracle_symbol=market_info["oracleSymbol"], | ||
| oracle_provider=market_info["oracleProvider"], | ||
|
|
@@ -3380,21 +3374,25 @@ async def _initialize_tokens_and_markets(self): | |
| expiration_timestamp=market_info["expirationTimestamp"], | ||
| settlement_timestamp=market_info["settlementTimestamp"], | ||
| quote_token=quote_token, | ||
| maker_fee_rate=Decimal(market_info["makerFeeRate"]), | ||
| taker_fee_rate=Decimal(market_info["takerFeeRate"]), | ||
| service_provider_fee=Decimal(market_info["serviceProviderFee"]), | ||
| min_price_tick_size=Decimal(market_info["minPriceTickSize"]), | ||
| min_quantity_tick_size=Decimal(market_info["minQuantityTickSize"]), | ||
| min_notional=Decimal(market_info["minNotional"]), | ||
| maker_fee_rate=Token.convert_value_from_extended_decimal_format(Decimal(market_info["makerFeeRate"])), | ||
| taker_fee_rate=Token.convert_value_from_extended_decimal_format(Decimal(market_info["takerFeeRate"])), | ||
| service_provider_fee=Token.convert_value_from_extended_decimal_format( | ||
| Decimal(market_info["relayerFeeShareRate"]) | ||
| ), | ||
| min_price_tick_size=Token.convert_value_from_extended_decimal_format( | ||
| Decimal(market_info["minPriceTickSize"]) | ||
| ), | ||
| min_quantity_tick_size=Token.convert_value_from_extended_decimal_format( | ||
| Decimal(market_info["minQuantityTickSize"]) | ||
| ), | ||
| min_notional=Token.convert_value_from_extended_decimal_format(Decimal(market_info["minNotional"])), | ||
| settlement_price=None | ||
| if market_info["settlementPrice"] == "" | ||
| else Decimal(market_info["settlementPrice"]), | ||
| else Token.convert_value_from_extended_decimal_format(Decimal(market_info["settlementPrice"])), | ||
| ) | ||
|
|
||
| binary_option_markets[market.id] = market | ||
|
|
||
| self._tokens_by_denom = tokens_by_denom | ||
| self._tokens_by_symbol = tokens_by_symbol | ||
| self._spot_markets = spot_markets | ||
| self._derivative_markets = derivative_markets | ||
| self._binary_option_markets = binary_option_markets | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,25 +1,7 @@ | ||
| import os | ||
| from configparser import ConfigParser | ||
|
|
||
| GAS_PRICE = 160_000_000 | ||
| GAS_FEE_BUFFER_AMOUNT = 25_000 | ||
| MAX_MEMO_CHARACTERS = 256 | ||
| ADDITIONAL_CHAIN_FORMAT_DECIMALS = 18 | ||
| TICKER_TOKENS_SEPARATOR = "/" | ||
| INJ_DENOM = "inj" | ||
| INJ_DECIMALS = 18 | ||
|
|
||
| devnet_config = ConfigParser() | ||
| devnet_config.read(os.path.join(os.path.dirname(__file__), "denoms_devnet.ini")) | ||
|
|
||
| testnet_config = ConfigParser() | ||
| testnet_config.read(os.path.join(os.path.dirname(__file__), "denoms_testnet.ini")) | ||
|
|
||
| mainnet_config = ConfigParser() | ||
| mainnet_config.read(os.path.join(os.path.dirname(__file__), "denoms_mainnet.ini")) | ||
|
|
||
| CONFIGS = { | ||
| "devnet": devnet_config, | ||
| "testnet": testnet_config, | ||
| "mainnet": mainnet_config, | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Enhance changelog entry with migration guidance
The changelog indicates significant changes in the markets initialization process, but lacks guidance for users who need to migrate their code. Consider adding a migration section that explains:
Example addition: