From e782b1dca0379746c2c365112d20c47759beedd4 Mon Sep 17 00:00:00 2001 From: Guillaume De Saint Martin Date: Tue, 16 Jul 2024 09:56:41 +0200 Subject: [PATCH] [Tests] add orders precision tests --- .../abstract_authenticated_exchange_tester.py | 18 ++++++++++++++++++ additional_tests/exchanges_tests/test_bingx.py | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/additional_tests/exchanges_tests/abstract_authenticated_exchange_tester.py b/additional_tests/exchanges_tests/abstract_authenticated_exchange_tester.py index 88aa01dc1..440a44c7e 100644 --- a/additional_tests/exchanges_tests/abstract_authenticated_exchange_tester.py +++ b/additional_tests/exchanges_tests/abstract_authenticated_exchange_tester.py @@ -195,6 +195,7 @@ async def inner_test_create_and_cancel_limit_orders(self, symbol=None, settlemen size = self.get_order_size( await self.get_portfolio(), price, symbol=symbol, settlement_currency=settlement_currency ) + self.check_order_size_and_price(size, price) # # DEBUG tools, uncomment to create specific orders # symbol = "BTC/USD:BTC" # market_status = self.exchange_manager.exchange.get_market_status(symbol) @@ -832,6 +833,23 @@ def get_order_size(self, portfolio, price, symbol=None, order_size=None, settlem order_quantity ) + def check_order_size_and_price(self, size, price, symbol=None): + market_status = self.exchange_manager.exchange.get_market_status(str(symbol or self.SYMBOL)) + precision_amount = market_status[ + trading_enums.ExchangeConstantsMarketStatusColumns.PRECISION.value + ].get(trading_enums.ExchangeConstantsMarketStatusColumns.PRECISION_AMOUNT.value, 0) + assert 0 <= precision_amount < 10 # is really the number of digits + assert int(precision_amount) == precision_amount # is an int + precision_price = market_status[ + trading_enums.ExchangeConstantsMarketStatusColumns.PRECISION.value + ].get(trading_enums.ExchangeConstantsMarketStatusColumns.PRECISION_PRICE.value, 0) + assert 0 < precision_price < 10 # is really the number of digits + assert int(precision_price) == precision_price # is an int + + assert personal_data_orders.decimal_trunc_with_n_decimal_digits(size, precision_amount) == size + assert personal_data_orders.decimal_trunc_with_n_decimal_digits(price, precision_price) == price + + def get_sell_size_from_buy_order(self, buy_order): sell_size = buy_order.origin_quantity if buy_order.fee and buy_order.fee[trading_enums.FeePropertyColumns.CURRENCY.value] == self.ORDER_CURRENCY: diff --git a/additional_tests/exchanges_tests/test_bingx.py b/additional_tests/exchanges_tests/test_bingx.py index 52b23eab6..6d87a2054 100644 --- a/additional_tests/exchanges_tests/test_bingx.py +++ b/additional_tests/exchanges_tests/test_bingx.py @@ -35,7 +35,7 @@ class TestBingxAuthenticatedExchange( USE_ORDER_OPERATION_TO_CHECK_API_KEY_RIGHTS = True EXPECT_MISSING_FEE_IN_CANCELLED_ORDERS = False - VALID_ORDER_ID = "1777764898965454838" + VALID_ORDER_ID = "1812980957928929280" async def test_get_portfolio(self): await super().test_get_portfolio()