diff --git a/CHANGELOG.md b/CHANGELOG.md index bd2471b9..136f7802 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to this project will be documented in this file. +## [1.9.1] - 2025-03-03 +### Fixed +- Added quantization in the functions that convert notional values to chain format + ## [1.9.0] - 2025-02-13 ### Added - Added support for all new queries and messages from the new Permissions module diff --git a/pyinjective/core/market.py b/pyinjective/core/market.py index 3824232f..01973dc8 100644 --- a/pyinjective/core/market.py +++ b/pyinjective/core/market.py @@ -1,5 +1,5 @@ from dataclasses import dataclass -from decimal import Decimal +from decimal import ROUND_UP, Decimal from typing import Optional from pyinjective.constant import ADDITIONAL_CHAIN_FORMAT_DECIMALS @@ -39,7 +39,8 @@ 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}") - extended_chain_formatted_value = chain_formatted_value * Decimal(f"1e{ADDITIONAL_CHAIN_FORMAT_DECIMALS}") + quantized_balue = chain_formatted_value.quantize(Decimal("1"), rounding=ROUND_UP) + extended_chain_formatted_value = quantized_balue * Decimal(f"1e{ADDITIONAL_CHAIN_FORMAT_DECIMALS}") return extended_chain_formatted_value @@ -120,7 +121,8 @@ 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}") - extended_chain_formatted_value = chain_formatted_value * Decimal(f"1e{ADDITIONAL_CHAIN_FORMAT_DECIMALS}") + quantized_notional = chain_formatted_value.quantize(Decimal("1"), rounding=ROUND_UP) + extended_chain_formatted_value = quantized_notional * Decimal(f"1e{ADDITIONAL_CHAIN_FORMAT_DECIMALS}") return extended_chain_formatted_value @@ -230,7 +232,8 @@ 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}") - extended_chain_formatted_value = chain_formatted_value * Decimal(f"1e{ADDITIONAL_CHAIN_FORMAT_DECIMALS}") + quantized_value = chain_formatted_value.quantize(Decimal("1"), rounding=ROUND_UP) + extended_chain_formatted_value = quantized_value * Decimal(f"1e{ADDITIONAL_CHAIN_FORMAT_DECIMALS}") return extended_chain_formatted_value diff --git a/pyproject.toml b/pyproject.toml index 5b6cc95c..811c4747 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "injective-py" -version = "1.9.0" +version = "1.9.1" description = "Injective Python SDK, with Exchange API Client" authors = ["Injective Labs "] license = "Apache-2.0"