Skip to content

Commit 8322309

Browse files
committed
feat: add binary options utils
1 parent a5eef88 commit 8322309

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

pyinjective/utils.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,41 @@ def derivative_price_to_backend(price, denom) -> int:
3838
exchange_price = floor_to(price, float(price_tick_size)) * pow(10, 18 + denom.quote)
3939
return int(exchange_price)
4040

41+
def binary_options_price_to_backend(price, denom) -> int:
42+
price_tick_size = Decimal(denom.min_price_tick_size) / pow(10, denom.quote)
43+
exchange_price = floor_to(price, float(price_tick_size)) * pow(10, 18 + denom.quote)
44+
return int(exchange_price)
45+
4146
def derivative_quantity_to_backend(quantity, denom) -> int:
4247
quantity_tick_size = float(denom.min_quantity_tick_size) / pow(10, denom.base)
4348
scale_quantity = Decimal(18 + denom.base)
4449
exchange_quantity = floor_to(quantity, quantity_tick_size) * pow(Decimal(10), scale_quantity)
4550
return int(exchange_quantity)
4651

52+
def binary_options_quantity_to_backend(quantity, denom) -> int:
53+
quantity_tick_size = float(denom.min_quantity_tick_size) / pow(10, denom.base)
54+
scale_quantity = Decimal(18 + denom.base)
55+
exchange_quantity = floor_to(quantity, quantity_tick_size) * pow(Decimal(10), scale_quantity)
56+
return int(exchange_quantity)
57+
4758
def derivative_margin_to_backend(price, quantity, leverage, denom) -> int:
4859
price_tick_size = Decimal(denom.min_price_tick_size) / pow(10, denom.quote)
4960
margin = (price * quantity) / leverage
5061
exchange_margin = floor_to(margin, float(price_tick_size)) * pow(10, 18 + denom.quote)
5162
return int(exchange_margin)
5263

64+
def binary_options_buy_margin_to_backend(price, quantity, denom) -> int:
65+
price_tick_size = Decimal(denom.min_price_tick_size) / pow(10, denom.quote)
66+
margin = price * quantity
67+
exchange_margin = floor_to(margin, float(price_tick_size)) * pow(10, 18 + denom.quote)
68+
return int(exchange_margin)
69+
70+
def binary_options_sell_margin_to_backend(price, quantity, denom) -> int:
71+
price_tick_size = Decimal(denom.min_price_tick_size) / pow(10, denom.quote)
72+
margin = (1 - (price / pow (10, denom.quote))) * quantity
73+
exchange_margin = floor_to(margin, float(price_tick_size)) * pow(10, 18 + denom.quote)
74+
return int(exchange_margin)
75+
5376
def derivative_additional_margin_to_backend(amount, denom) -> int:
5477
price_tick_size = float(denom.min_price_tick_size) / pow(10, denom.quote)
5578
additional_margin = floor_to(amount, price_tick_size) * pow(10, 18 + denom.quote)

0 commit comments

Comments
 (0)