Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 7 additions & 4 deletions pyinjective/core/market.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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}")
Comment on lines +42 to +43
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix the typo in variable name "quantized_balue".

There's a typo in the variable name "quantized_balue" which should be "quantized_value" to maintain consistency with the naming convention used in the other market classes.

-        quantized_balue = chain_formatted_value.quantize(Decimal("1"), rounding=ROUND_UP)
-        extended_chain_formatted_value = quantized_balue * 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}")
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
quantized_balue = chain_formatted_value.quantize(Decimal("1"), rounding=ROUND_UP)
extended_chain_formatted_value = quantized_balue * 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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>"]
license = "Apache-2.0"
Expand Down
Loading