Skip to content

Commit 1bffc7c

Browse files
committed
(fix) Removed quantization logic from notional formatting logic
1 parent dedef04 commit 1bffc7c

File tree

2 files changed

+9
-18
lines changed

2 files changed

+9
-18
lines changed

pyinjective/core/market.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@ 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-
quantization_factor = self.min_notional if self.min_notional > Decimal("0") else self.min_quantity_tick_size
43-
quantized_value = (chain_formatted_value // quantization_factor) * quantization_factor
44-
extended_chain_formatted_value = quantized_value * Decimal(f"1e{ADDITIONAL_CHAIN_FORMAT_DECIMALS}")
42+
extended_chain_formatted_value = chain_formatted_value * Decimal(f"1e{ADDITIONAL_CHAIN_FORMAT_DECIMALS}")
4543

4644
return extended_chain_formatted_value
4745

@@ -122,9 +120,7 @@ def calculate_margin_in_chain_format(
122120
def notional_to_chain_format(self, human_readable_value: Decimal) -> Decimal:
123121
decimals = self.quote_token.decimals
124122
chain_formatted_value = human_readable_value * Decimal(f"1e{decimals}")
125-
quantization_factor = self.min_notional if self.min_notional > Decimal("0") else self.min_quantity_tick_size
126-
quantized_value = (chain_formatted_value // quantization_factor) * quantization_factor
127-
extended_chain_formatted_value = quantized_value * Decimal(f"1e{ADDITIONAL_CHAIN_FORMAT_DECIMALS}")
123+
extended_chain_formatted_value = chain_formatted_value * Decimal(f"1e{ADDITIONAL_CHAIN_FORMAT_DECIMALS}")
128124

129125
return extended_chain_formatted_value
130126

@@ -234,9 +230,7 @@ def calculate_margin_in_chain_format(
234230
def notional_to_chain_format(self, human_readable_value: Decimal) -> Decimal:
235231
decimals = self.quote_token.decimals
236232
chain_formatted_value = human_readable_value * Decimal(f"1e{decimals}")
237-
quantization_factor = self.min_notional if self.min_notional > Decimal("0") else self.min_quantity_tick_size
238-
quantized_value = (chain_formatted_value // quantization_factor) * quantization_factor
239-
extended_chain_formatted_value = quantized_value * Decimal(f"1e{ADDITIONAL_CHAIN_FORMAT_DECIMALS}")
233+
extended_chain_formatted_value = chain_formatted_value * Decimal(f"1e{ADDITIONAL_CHAIN_FORMAT_DECIMALS}")
240234

241235
return extended_chain_formatted_value
242236

tests/core/test_market.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,9 @@ def test_convert_notional_to_chain_format(self, inj_usdt_spot_market: SpotMarket
4343
chain_value = inj_usdt_spot_market.notional_to_chain_format(human_readable_value=original_notional)
4444
notional_decimals = inj_usdt_spot_market.quote_token.decimals
4545
expected_value = original_notional * Decimal(f"1e{notional_decimals}")
46-
quantized_value = (expected_value // inj_usdt_spot_market.min_notional) * inj_usdt_spot_market.min_notional
47-
quantized_chain_format_value = quantized_value * Decimal(f"1e{ADDITIONAL_CHAIN_FORMAT_DECIMALS}")
46+
expected_chain_format_value = expected_value * Decimal(f"1e{ADDITIONAL_CHAIN_FORMAT_DECIMALS}")
4847

49-
assert quantized_chain_format_value == chain_value
48+
assert expected_chain_format_value == chain_value
5049

5150
def test_convert_quantity_from_chain_format(self, inj_usdt_spot_market: SpotMarket):
5251
expected_quantity = Decimal("123.456")
@@ -157,10 +156,9 @@ def test_convert_notional_to_chain_format(self, btc_usdt_perp_market: Derivative
157156
chain_value = btc_usdt_perp_market.notional_to_chain_format(human_readable_value=original_notional)
158157
notional_decimals = btc_usdt_perp_market.quote_token.decimals
159158
expected_value = original_notional * Decimal(f"1e{notional_decimals}")
160-
quantized_value = (expected_value // btc_usdt_perp_market.min_notional) * btc_usdt_perp_market.min_notional
161-
quantized_chain_format_value = quantized_value * Decimal(f"1e{ADDITIONAL_CHAIN_FORMAT_DECIMALS}")
159+
expected_chain_format_value = expected_value * Decimal(f"1e{ADDITIONAL_CHAIN_FORMAT_DECIMALS}")
162160

163-
assert quantized_chain_format_value == chain_value
161+
assert expected_chain_format_value == chain_value
164162

165163
def test_convert_quantity_from_chain_format(self, btc_usdt_perp_market: DerivativeMarket):
166164
expected_quantity = Decimal("123.456")
@@ -430,10 +428,9 @@ def test_convert_notional_to_chain_format(self, first_match_bet_market: BinaryOp
430428
chain_value = first_match_bet_market.notional_to_chain_format(human_readable_value=original_notional)
431429
notional_decimals = first_match_bet_market.quote_token.decimals
432430
expected_value = original_notional * Decimal(f"1e{notional_decimals}")
433-
quantized_value = (expected_value // first_match_bet_market.min_notional) * first_match_bet_market.min_notional
434-
quantized_chain_format_value = quantized_value * Decimal(f"1e{ADDITIONAL_CHAIN_FORMAT_DECIMALS}")
431+
expected_chain_format_value = expected_value * Decimal(f"1e{ADDITIONAL_CHAIN_FORMAT_DECIMALS}")
435432

436-
assert quantized_chain_format_value == chain_value
433+
assert expected_chain_format_value == chain_value
437434

438435
def test_convert_quantity_from_chain_format_with_fixed_denom(self, first_match_bet_market: BinaryOptionMarket):
439436
original_quantity = Decimal("123.456789")

0 commit comments

Comments
 (0)