Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Tests] add orders precision tests #2676

Merged
merged 1 commit into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading