Skip to content

Commit 0416c2a

Browse files
authored
Merge pull request #374 from InjectiveLabs/fix/add_notional_quantization
fix/add_notional_quantization
2 parents a9b3c79 + 7074685 commit 0416c2a

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

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

5+
## [1.9.1] - 2025-03-03
6+
### Fixed
7+
- Added quantization in the functions that convert notional values to chain format
8+
59
## [1.9.0] - 2025-02-13
610
### Added
711
- Added support for all new queries and messages from the new Permissions module

pyinjective/core/market.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from dataclasses import dataclass
2-
from decimal import Decimal
2+
from decimal import ROUND_UP, Decimal
33
from typing import Optional
44

55
from pyinjective.constant import ADDITIONAL_CHAIN_FORMAT_DECIMALS
@@ -39,7 +39,8 @@ def price_to_chain_format(self, human_readable_value: Decimal) -> Decimal:
3939
def notional_to_chain_format(self, human_readable_value: Decimal) -> Decimal:
4040
decimals = self.quote_token.decimals
4141
chain_formatted_value = human_readable_value * Decimal(f"1e{decimals}")
42-
extended_chain_formatted_value = chain_formatted_value * Decimal(f"1e{ADDITIONAL_CHAIN_FORMAT_DECIMALS}")
42+
quantized_balue = chain_formatted_value.quantize(Decimal("1"), rounding=ROUND_UP)
43+
extended_chain_formatted_value = quantized_balue * Decimal(f"1e{ADDITIONAL_CHAIN_FORMAT_DECIMALS}")
4344

4445
return extended_chain_formatted_value
4546

@@ -120,7 +121,8 @@ def calculate_margin_in_chain_format(
120121
def notional_to_chain_format(self, human_readable_value: Decimal) -> Decimal:
121122
decimals = self.quote_token.decimals
122123
chain_formatted_value = human_readable_value * Decimal(f"1e{decimals}")
123-
extended_chain_formatted_value = chain_formatted_value * Decimal(f"1e{ADDITIONAL_CHAIN_FORMAT_DECIMALS}")
124+
quantized_notional = chain_formatted_value.quantize(Decimal("1"), rounding=ROUND_UP)
125+
extended_chain_formatted_value = quantized_notional * Decimal(f"1e{ADDITIONAL_CHAIN_FORMAT_DECIMALS}")
124126

125127
return extended_chain_formatted_value
126128

@@ -230,7 +232,8 @@ def calculate_margin_in_chain_format(
230232
def notional_to_chain_format(self, human_readable_value: Decimal) -> Decimal:
231233
decimals = self.quote_token.decimals
232234
chain_formatted_value = human_readable_value * Decimal(f"1e{decimals}")
233-
extended_chain_formatted_value = chain_formatted_value * Decimal(f"1e{ADDITIONAL_CHAIN_FORMAT_DECIMALS}")
235+
quantized_value = chain_formatted_value.quantize(Decimal("1"), rounding=ROUND_UP)
236+
extended_chain_formatted_value = quantized_value * Decimal(f"1e{ADDITIONAL_CHAIN_FORMAT_DECIMALS}")
234237

235238
return extended_chain_formatted_value
236239

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "injective-py"
3-
version = "1.9.0"
3+
version = "1.9.1"
44
description = "Injective Python SDK, with Exchange API Client"
55
authors = ["Injective Labs <[email protected]>"]
66
license = "Apache-2.0"

0 commit comments

Comments
 (0)