@@ -39,6 +39,24 @@ def test_convert_price_to_chain_format(self, inj_usdt_spot_market: SpotMarket):
3939
4040 assert (quantized_chain_format_value == chain_value )
4141
42+ def test_convert_quantity_from_chain_format (self , inj_usdt_spot_market : SpotMarket ):
43+ expected_quantity = Decimal ("123.456" )
44+
45+ chain_format_quantity = expected_quantity * Decimal (f"1e{ inj_usdt_spot_market .base_token .decimals } " )
46+ human_readable_quantity = inj_usdt_spot_market .quantity_from_chain_format (chain_value = chain_format_quantity )
47+
48+ assert (expected_quantity == human_readable_quantity )
49+
50+ def test_convert_price_from_chain_format (self , inj_usdt_spot_market : SpotMarket ):
51+ expected_price = Decimal ("123.456" )
52+
53+ price_decimals = inj_usdt_spot_market .quote_token .decimals - inj_usdt_spot_market .base_token .decimals
54+ chain_format_price = expected_price * Decimal (f"1e{ price_decimals } " )
55+ human_readable_price = inj_usdt_spot_market .price_from_chain_format (chain_value = chain_format_price )
56+
57+ assert (expected_price == human_readable_price )
58+
59+
4260
4361class TestDerivativeMarket :
4462
@@ -76,6 +94,32 @@ def test_convert_margin_to_chain_format(self, btc_usdt_perp_market: DerivativeMa
7694
7795 assert (quantized_chain_format_value == chain_value )
7896
97+ def test_convert_quantity_from_chain_format (self , btc_usdt_perp_market : DerivativeMarket ):
98+ expected_quantity = Decimal ("123.456" )
99+
100+ chain_format_quantity = expected_quantity
101+ human_readable_quantity = btc_usdt_perp_market .quantity_from_chain_format (chain_value = chain_format_quantity )
102+
103+ assert (expected_quantity == human_readable_quantity )
104+
105+ def test_convert_price_from_chain_format (self , btc_usdt_perp_market : DerivativeMarket ):
106+ expected_price = Decimal ("123.456" )
107+
108+ price_decimals = btc_usdt_perp_market .quote_token .decimals
109+ chain_format_price = expected_price * Decimal (f"1e{ price_decimals } " )
110+ human_readable_price = btc_usdt_perp_market .price_from_chain_format (chain_value = chain_format_price )
111+
112+ assert (expected_price == human_readable_price )
113+
114+ def test_convert_margin_from_chain_format (self , btc_usdt_perp_market : DerivativeMarket ):
115+ expected_margin = Decimal ("123.456" )
116+
117+ price_decimals = btc_usdt_perp_market .quote_token .decimals
118+ chain_format_margin = expected_margin * Decimal (f"1e{ price_decimals } " )
119+ human_readable_margin = btc_usdt_perp_market .margin_from_chain_format (chain_value = chain_format_margin )
120+
121+ assert (expected_margin == human_readable_margin )
122+
79123class TestBinaryOptionMarket :
80124
81125 def test_convert_quantity_to_chain_format_with_fixed_denom (self , first_match_bet_market : BinaryOptionMarket ):
@@ -211,3 +255,56 @@ def test_calculate_margin_for_sell_without_fixed_denom(self, first_match_bet_mar
211255 quantized_chain_format_margin = quantized_margin * Decimal (f"1e18" )
212256
213257 assert (quantized_chain_format_margin == chain_value )
258+
259+ def test_convert_quantity_from_chain_format_with_fixed_denom (self , first_match_bet_market : BinaryOptionMarket ):
260+ original_quantity = Decimal ("123.456789" )
261+ fixed_denom = Denom (
262+ description = "Fixed denom" ,
263+ base = 2 ,
264+ quote = 4 ,
265+ min_quantity_tick_size = 100 ,
266+ min_price_tick_size = 10000 ,
267+ )
268+
269+ chain_formatted_quantity = original_quantity * Decimal (f"1e{ fixed_denom .base } " )
270+
271+ human_readable_quantity = first_match_bet_market .quantity_from_chain_format (
272+ chain_value = chain_formatted_quantity , special_denom = fixed_denom
273+ )
274+
275+ assert (original_quantity == human_readable_quantity )
276+
277+ def test_convert_quantity_from_chain_format_without_fixed_denom (self , first_match_bet_market : BinaryOptionMarket ):
278+ original_quantity = Decimal ("123.456789" )
279+
280+ chain_formatted_quantity = original_quantity
281+
282+ human_readable_quantity = first_match_bet_market .quantity_from_chain_format (chain_value = chain_formatted_quantity )
283+
284+ assert (original_quantity == human_readable_quantity )
285+
286+ def test_convert_price_from_chain_format_with_fixed_denom (self , first_match_bet_market : BinaryOptionMarket ):
287+ original_price = Decimal ("123.456789" )
288+ fixed_denom = Denom (
289+ description = "Fixed denom" ,
290+ base = 2 ,
291+ quote = 4 ,
292+ min_quantity_tick_size = 100 ,
293+ min_price_tick_size = 10000 ,
294+ )
295+
296+ chain_formatted_price = original_price * Decimal (f"1e{ fixed_denom .quote } " )
297+
298+ human_readable_price = first_match_bet_market .price_from_chain_format (
299+ chain_value = chain_formatted_price , special_denom = fixed_denom
300+ )
301+
302+ assert (original_price == human_readable_price )
303+
304+ def test_convert_price_from_chain_format_without_fixed_denom (self , first_match_bet_market : BinaryOptionMarket ):
305+ original_price = Decimal ("123.456789" )
306+ chain_formatted_price = original_price * Decimal (f"1e{ first_match_bet_market .quote_token .decimals } " )
307+
308+ human_readable_price = first_match_bet_market .price_from_chain_format (chain_value = chain_formatted_price )
309+
310+ assert (original_price == human_readable_price )
0 commit comments