You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/injective/utils.py
+57Lines changed: 57 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,35 @@
1
1
fromdecimalimportDecimal
2
+
"""
3
+
One thing you may need to pay more attention to is how to deal with decimals in injective exchange.
4
+
As we all known, different crypto currecies require diffrent decimal precisions.
5
+
Separately, ERC-20 tokens(e.g. INJ) have decimals of 18 or another number(like 6 for USDT and USDC).
6
+
So in injective system that means ** having 1 INJ is 1e18 inj ** and that ** 1 USDT is actually 100000 peggy0xdac17f958d2ee523a2206206994597c13d831ec7**.
2
7
8
+
For spot markets, a price reflects the ** relative exchange rate ** between two tokens.
9
+
If the tokens have the same decimal scale, that's great since the prices
10
+
become interpretable e.g. USDT/USDC (both have 6 decimals e.g. for USDT https://etherscan.io/address/0xdac17f958d2ee523a2206206994597c13d831ec7#readContract)
11
+
or MATIC/INJ (both have 18 decimals) since the decimals cancel out.
12
+
Prices however start to look wonky once you have exchanges between two tokens of different decimals, which unfortunately is most pairs with USDT or USDC denominations.
13
+
As such, I've created some simple utility functions by keeping a hardcoded dictionary in injective-py and you can aslo achieve such utilities by yourself
14
+
(e.g. you can use external API like Alchemy's getTokenMetadata to fetch decimal of base and quote asset).
3
15
16
+
So for INJ/USDT of 6.9, the price you end up getting is 6.9*10 ^ (6 - 18) = 6.9e-12.
17
+
Note that this market also happens to have a MinPriceTickSize of 1e-15.
18
+
This makes sense since since it's defining the minimum price increment of the relative exchange of INJ to USDT.
19
+
Note that this market also happens to have a MinQuantityTickSize of 1e15.
20
+
This also makes sense since it refers to the minimum INJ quantity tick size each order must have, which is 1e15/1e18 = 0.001 INJ.
0 commit comments