From 1bffc7cdb23ad7ad403a429b4675f04443d3bc4e Mon Sep 17 00:00:00 2001 From: Abel Armoa <30988000+aarmoa@users.noreply.github.com> Date: Tue, 6 Aug 2024 12:54:24 -0300 Subject: [PATCH] (fix) Removed quantization logic from notional formatting logic --- pyinjective/core/market.py | 12 +++--------- tests/core/test_market.py | 15 ++++++--------- 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/pyinjective/core/market.py b/pyinjective/core/market.py index ea28c9fe..3824232f 100644 --- a/pyinjective/core/market.py +++ b/pyinjective/core/market.py @@ -39,9 +39,7 @@ def price_to_chain_format(self, human_readable_value: Decimal) -> Decimal: def notional_to_chain_format(self, human_readable_value: Decimal) -> Decimal: decimals = self.quote_token.decimals chain_formatted_value = human_readable_value * Decimal(f"1e{decimals}") - quantization_factor = self.min_notional if self.min_notional > Decimal("0") else self.min_quantity_tick_size - quantized_value = (chain_formatted_value // quantization_factor) * quantization_factor - extended_chain_formatted_value = quantized_value * Decimal(f"1e{ADDITIONAL_CHAIN_FORMAT_DECIMALS}") + extended_chain_formatted_value = chain_formatted_value * Decimal(f"1e{ADDITIONAL_CHAIN_FORMAT_DECIMALS}") return extended_chain_formatted_value @@ -122,9 +120,7 @@ def calculate_margin_in_chain_format( def notional_to_chain_format(self, human_readable_value: Decimal) -> Decimal: decimals = self.quote_token.decimals chain_formatted_value = human_readable_value * Decimal(f"1e{decimals}") - quantization_factor = self.min_notional if self.min_notional > Decimal("0") else self.min_quantity_tick_size - quantized_value = (chain_formatted_value // quantization_factor) * quantization_factor - extended_chain_formatted_value = quantized_value * Decimal(f"1e{ADDITIONAL_CHAIN_FORMAT_DECIMALS}") + extended_chain_formatted_value = chain_formatted_value * Decimal(f"1e{ADDITIONAL_CHAIN_FORMAT_DECIMALS}") return extended_chain_formatted_value @@ -234,9 +230,7 @@ def calculate_margin_in_chain_format( def notional_to_chain_format(self, human_readable_value: Decimal) -> Decimal: decimals = self.quote_token.decimals chain_formatted_value = human_readable_value * Decimal(f"1e{decimals}") - quantization_factor = self.min_notional if self.min_notional > Decimal("0") else self.min_quantity_tick_size - quantized_value = (chain_formatted_value // quantization_factor) * quantization_factor - extended_chain_formatted_value = quantized_value * Decimal(f"1e{ADDITIONAL_CHAIN_FORMAT_DECIMALS}") + extended_chain_formatted_value = chain_formatted_value * Decimal(f"1e{ADDITIONAL_CHAIN_FORMAT_DECIMALS}") return extended_chain_formatted_value diff --git a/tests/core/test_market.py b/tests/core/test_market.py index 2a6d26e5..514e6256 100644 --- a/tests/core/test_market.py +++ b/tests/core/test_market.py @@ -43,10 +43,9 @@ def test_convert_notional_to_chain_format(self, inj_usdt_spot_market: SpotMarket chain_value = inj_usdt_spot_market.notional_to_chain_format(human_readable_value=original_notional) notional_decimals = inj_usdt_spot_market.quote_token.decimals expected_value = original_notional * Decimal(f"1e{notional_decimals}") - quantized_value = (expected_value // inj_usdt_spot_market.min_notional) * inj_usdt_spot_market.min_notional - quantized_chain_format_value = quantized_value * Decimal(f"1e{ADDITIONAL_CHAIN_FORMAT_DECIMALS}") + expected_chain_format_value = expected_value * Decimal(f"1e{ADDITIONAL_CHAIN_FORMAT_DECIMALS}") - assert quantized_chain_format_value == chain_value + assert expected_chain_format_value == chain_value def test_convert_quantity_from_chain_format(self, inj_usdt_spot_market: SpotMarket): expected_quantity = Decimal("123.456") @@ -157,10 +156,9 @@ def test_convert_notional_to_chain_format(self, btc_usdt_perp_market: Derivative chain_value = btc_usdt_perp_market.notional_to_chain_format(human_readable_value=original_notional) notional_decimals = btc_usdt_perp_market.quote_token.decimals expected_value = original_notional * Decimal(f"1e{notional_decimals}") - quantized_value = (expected_value // btc_usdt_perp_market.min_notional) * btc_usdt_perp_market.min_notional - quantized_chain_format_value = quantized_value * Decimal(f"1e{ADDITIONAL_CHAIN_FORMAT_DECIMALS}") + expected_chain_format_value = expected_value * Decimal(f"1e{ADDITIONAL_CHAIN_FORMAT_DECIMALS}") - assert quantized_chain_format_value == chain_value + assert expected_chain_format_value == chain_value def test_convert_quantity_from_chain_format(self, btc_usdt_perp_market: DerivativeMarket): expected_quantity = Decimal("123.456") @@ -430,10 +428,9 @@ def test_convert_notional_to_chain_format(self, first_match_bet_market: BinaryOp chain_value = first_match_bet_market.notional_to_chain_format(human_readable_value=original_notional) notional_decimals = first_match_bet_market.quote_token.decimals expected_value = original_notional * Decimal(f"1e{notional_decimals}") - quantized_value = (expected_value // first_match_bet_market.min_notional) * first_match_bet_market.min_notional - quantized_chain_format_value = quantized_value * Decimal(f"1e{ADDITIONAL_CHAIN_FORMAT_DECIMALS}") + expected_chain_format_value = expected_value * Decimal(f"1e{ADDITIONAL_CHAIN_FORMAT_DECIMALS}") - assert quantized_chain_format_value == chain_value + assert expected_chain_format_value == chain_value def test_convert_quantity_from_chain_format_with_fixed_denom(self, first_match_bet_market: BinaryOptionMarket): original_quantity = Decimal("123.456789")