Skip to content

Commit 231f8cc

Browse files
Merge branch 'master' into f/sdk47
2 parents eb9ff82 + 1fc36c7 commit 231f8cc

File tree

6 files changed

+990
-537
lines changed

6 files changed

+990
-537
lines changed

Pipfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ verify_ssl = true
44
name = "pypi"
55

66
[packages]
7-
protobuf = "==3.19.1"
8-
grpcio-tools = "==1.42.0"
7+
protobuf = "*"
8+
grpcio-tools = "*"
99
grpcio = "*"
1010
asyncio = "*"
1111
aiohttp = "*"

Pipfile.lock

Lines changed: 951 additions & 523 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ Note that the [sync client](https://github.com/InjectiveLabs/sdk-python/blob/mas
7878

7979

8080
### Changelogs
81+
**0.6.2.7**
82+
* Fix margin calculation in utils
83+
84+
**0.6.2.1**
85+
* Remove version deps from Pipfile
86+
8187
**0.6.2.0**
8288
* Add MsgUnderwrite, MsgRequestRedemption in Composer
8389

pyinjective/denoms_mainnet.ini

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ min_display_quantity_tick_size = 0.001
119119
description = 'Mainnet Spot WETH/USDT'
120120
base = 18
121121
quote = 6
122-
min_price_tick_size = 0.00000000000001
123-
min_display_price_tick_size = 0.01
122+
min_price_tick_size = 0.0000000000001
123+
min_display_price_tick_size = 0.1
124124
min_quantity_tick_size = 1000000000000000
125125
min_display_quantity_tick_size = 0.001
126126

@@ -389,17 +389,17 @@ min_display_quantity_tick_size = 0.1
389389
description = 'Mainnet Derivative BTC/USDT PERP'
390390
base = 0
391391
quote = 6
392-
min_price_tick_size = 100000
393-
min_display_price_tick_size = 0.1
392+
min_price_tick_size = 1000000
393+
min_display_price_tick_size = 1.0
394394
min_quantity_tick_size = 0.0001
395395
min_display_quantity_tick_size = 0.0001
396396

397397
[0x54d4505adef6a5cef26bc403a33d595620ded4e15b9e2bc3dd489b714813366a]
398398
description = 'Mainnet Derivative ETH/USDT PERP'
399399
base = 0
400400
quote = 6
401-
min_price_tick_size = 10000
402-
min_display_price_tick_size = 0.01
401+
min_price_tick_size = 100000
402+
min_display_price_tick_size = 0.1
403403
min_quantity_tick_size = 0.01
404404
min_display_quantity_tick_size = 0.01
405405

@@ -502,6 +502,15 @@ min_display_price_tick_size = 1e-10
502502
min_quantity_tick_size = 0.1
503503
min_display_quantity_tick_size = 0.1
504504

505+
[0xcd0c859a99f26bb3530e21890937ed77d20754aa7825a599c71710514fc125ef]
506+
description = 'Mainnet Derivative 1MPEPE/USDT PERP'
507+
base = 0
508+
quote = 6
509+
min_price_tick_size = 100
510+
min_display_price_tick_size = 0.0001
511+
min_quantity_tick_size = 1
512+
min_display_quantity_tick_size = 1
513+
505514
[WETH]
506515
peggy_denom = peggy0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2
507516
decimals = 18
@@ -578,6 +587,10 @@ decimals = 6
578587
peggy_denom = peggy0x4d224452801ACEd8B2F0aebE155379bb5D594381
579588
decimals = 18
580589

590+
[PUG]
591+
peggy_denom = peggy0xf9a06dE3F6639E6ee4F079095D5093644Ad85E8b
592+
decimals = 18
593+
581594
[HUAHUA]
582595
peggy_denom = ibc/E7807A46C0B7B44B350DA58F51F278881B863EC4DCA94635DAB39E52C30766CB
583596
decimals = 6
@@ -645,3 +658,4 @@ decimals = 8
645658
[wMATIC]
646659
peggy_denom = factory/inj14ejqjyq8um4p3xfqj74yld5waqljf88f9eneuk/inj1dxv423h8ygzgxmxnvrf33ws3k94aedfdevxd8h
647660
decimals = 8
661+

pyinjective/denoms_testnet.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,11 @@ peggy_denom = peggy0x87aB3B4C8661e07D6372361211B96ed4Dc36B1B5
196196
decimals = 6
197197

198198
[USDC]
199-
peggy_denom = peggy0xf9152067989BDc8783fF586624124C05A529A5D1
199+
peggy_denom = peggy0x07865c6E87B9F70255377e024ace6630C1Eaa37F
200200
decimals = 6
201201

202202
[USDCfr]
203-
peggy_denom = peggy0x07865c6E87B9F70255377e024ace6630C1Eaa37F
203+
peggy_denom = peggy0xf9152067989BDc8783fF586624124C05A529A5D1
204204
decimals = 6
205205

206206
[APE]

pyinjective/utils.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from decimal import Decimal
22
from math import floor
3+
from typing import Union
34

45
"""
56
One thing you may need to pay more attention to is how to deal with decimals on the Injective Exchange.
@@ -56,9 +57,13 @@ def binary_options_quantity_to_backend(quantity, denom) -> int:
5657
return int(exchange_quantity)
5758

5859
def derivative_margin_to_backend(price, quantity, leverage, denom) -> int:
59-
price_tick_size = Decimal(denom.min_price_tick_size) / pow(10, denom.quote)
60-
margin = (price * quantity) / leverage
61-
exchange_margin = floor_to(margin, float(price_tick_size)) * pow(10, 18 + denom.quote)
60+
chain_format_price = Decimal(str(price)) * Decimal(f"1e{denom.quote}")
61+
chain_format_quantity = Decimal(str(quantity)) * Decimal(f"1e{denom.base}")
62+
decimal_leverage = Decimal(str(leverage))
63+
margin = (chain_format_price * chain_format_quantity) / decimal_leverage
64+
# We are using the min_quantity_tick_size to quantize the margin because that is the way margin is validated
65+
# in the chain (it might be changed to a min_notional in the future)
66+
exchange_margin = floor_to(margin, denom.min_quantity_tick_size) * Decimal(f"1e18")
6267
return int(exchange_margin)
6368

6469
def binary_options_buy_margin_to_backend(price, quantity, denom) -> int:
@@ -82,7 +87,7 @@ def amount_to_backend(amount, decimals) -> int:
8287
be_amount = amount * pow(10, decimals)
8388
return int(be_amount)
8489

85-
def floor_to(value: float, target: float) -> Decimal:
90+
def floor_to(value: Union[float, Decimal], target: Union[float, Decimal]) -> Decimal:
8691
value_tmp = Decimal(str(value))
8792
target_tmp = Decimal(str(target))
8893
result = int(floor(value_tmp / target_tmp)) * target_tmp

0 commit comments

Comments
 (0)