Skip to content

Commit

Permalink
[Tests] add orders precision tests
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeDSM committed Jul 16, 2024
1 parent 92c03b8 commit e782b1d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion additional_tests/exchanges_tests/test_bingx.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit e782b1d

Please sign in to comment.