|
1 | 1 | from dataclasses import dataclass |
2 | | -from decimal import Decimal |
| 2 | +from decimal import ROUND_UP, Decimal |
3 | 3 | from typing import Optional |
4 | 4 |
|
5 | 5 | from pyinjective.constant import ADDITIONAL_CHAIN_FORMAT_DECIMALS |
@@ -39,7 +39,8 @@ def price_to_chain_format(self, human_readable_value: Decimal) -> Decimal: |
39 | 39 | def notional_to_chain_format(self, human_readable_value: Decimal) -> Decimal: |
40 | 40 | decimals = self.quote_token.decimals |
41 | 41 | 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}") |
43 | 44 |
|
44 | 45 | return extended_chain_formatted_value |
45 | 46 |
|
@@ -120,7 +121,8 @@ def calculate_margin_in_chain_format( |
120 | 121 | def notional_to_chain_format(self, human_readable_value: Decimal) -> Decimal: |
121 | 122 | decimals = self.quote_token.decimals |
122 | 123 | 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}") |
124 | 126 |
|
125 | 127 | return extended_chain_formatted_value |
126 | 128 |
|
@@ -230,7 +232,8 @@ def calculate_margin_in_chain_format( |
230 | 232 | def notional_to_chain_format(self, human_readable_value: Decimal) -> Decimal: |
231 | 233 | decimals = self.quote_token.decimals |
232 | 234 | 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}") |
234 | 237 |
|
235 | 238 | return extended_chain_formatted_value |
236 | 239 |
|
|
0 commit comments