From 21956a868b39744afce9b92da16de20c475fe19b Mon Sep 17 00:00:00 2001 From: Achilleas Kalantzis Date: Thu, 15 Sep 2022 22:54:49 +0300 Subject: [PATCH] chore: fix precision loss in margin --- pyinjective/utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyinjective/utils.py b/pyinjective/utils.py index e5b067f3..33b7030b 100644 --- a/pyinjective/utils.py +++ b/pyinjective/utils.py @@ -63,13 +63,13 @@ def derivative_margin_to_backend(price, quantity, leverage, denom) -> int: def binary_options_buy_margin_to_backend(price, quantity, denom) -> int: price_tick_size = Decimal(denom.min_price_tick_size) / pow(10, denom.quote) - margin = price * quantity + margin = Decimal(str(price)) * Decimal(str(quantity)) exchange_margin = floor_to(margin, float(price_tick_size)) * pow(10, 18 + denom.quote) return int(exchange_margin) def binary_options_sell_margin_to_backend(price, quantity, denom) -> int: price_tick_size = Decimal(denom.min_price_tick_size) / pow(10, denom.quote) - margin = (1 - (price / pow (10, denom.quote))) * quantity + margin = (1 - (Decimal(str(price)) / pow (10, denom.quote))) * Decimal(str(quantity)) exchange_margin = floor_to(margin, float(price_tick_size)) * pow(10, 18 + denom.quote) return int(exchange_margin)