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

Ms test #2811

Merged
merged 2 commits into from
Nov 28, 2024
Merged

Ms test #2811

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 @@ -69,6 +69,7 @@ class AbstractAuthenticatedExchangeTester:
CANCEL_TIMEOUT = 15
EDIT_TIMEOUT = 15
MIN_PORTFOLIO_SIZE = 1
EXPECTED_QUOTE_MIN_ORDER_SIZE = 1 # min quote value of orders to create (used to check market status parsing)
EXPECT_BALANCE_FILTER_BY_MARKET_STATUS = False # set true when using filtered market status also filters
# fetched balance assets
DUPLICATE_TRADES_RATIO = 0
Expand Down Expand Up @@ -214,25 +215,36 @@ async def test_create_and_cancel_limit_orders(self):

async def inner_test_create_and_cancel_limit_orders(self, symbol=None, settlement_currency=None):
symbol = symbol or self.SYMBOL
# # DEBUG tools p1, uncomment to create specific orders
# symbol = "ADA/USDT"
# # end debug tools
market_status = self.exchange_manager.exchange.get_market_status(symbol)
exchange_data = self.get_exchange_data(symbol=symbol)
settlement_currency = settlement_currency or self.SETTLEMENT_CURRENCY
price = self.get_order_price(await self.get_price(symbol=symbol), False, symbol=symbol)
size = self.get_order_size(
# 1. try with "normal" order size
default_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)
self.check_order_size_and_price(default_size, price, symbol=symbol, allow_empty_size=self.CHECK_EMPTY_ACCOUNT)
# 2. try with minimal order size
min_size = personal_data.decimal_adapt_quantity(
market_status,
# add 25% to min order size to avoid rounding of amount of price ending up just bellow min cost
decimal.Decimal(str(self.EXPECTED_QUOTE_MIN_ORDER_SIZE)) * decimal.Decimal("1.25") / price
)
self.check_order_size_and_price(min_size, price, symbol=symbol, allow_empty_size=False)
size = min(min_size, default_size)
# # DEBUG tools p2, uncomment to create specific orders
# precision = market_status[trading_enums.ExchangeConstantsMarketStatusColumns.PRECISION.value]
# limits = market_status[trading_enums.ExchangeConstantsMarketStatusColumns.LIMITS.value]
# price = personal_data.decimal_adapt_price(
# market_status,
# decimal.Decimal("0.1810")
# decimal.Decimal("0.910")
# )
# size = personal_data.decimal_adapt_quantity(
# market_status,
# decimal.Decimal("7")
# decimal.Decimal("5.1")
# )
# # end debug tools
open_orders = await self.get_open_orders(exchange_data)
Expand Down Expand Up @@ -881,7 +893,7 @@ 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):
def check_order_size_and_price(self, size, price, symbol=None, allow_empty_size=False):
market_status = self.exchange_manager.exchange.get_market_status(str(symbol or self.SYMBOL))
precision_amount = market_status[
trading_enums.ExchangeConstantsMarketStatusColumns.PRECISION.value
Expand All @@ -897,6 +909,27 @@ def check_order_size_and_price(self, size, price, symbol=None):
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

# also check using decimal_check_and_adapt_order_details_if_necessary,
# which is used to create orders in trading modes
adapted_details = personal_data.decimal_check_and_adapt_order_details_if_necessary(
size,
price,
market_status
)
if size == trading_constants.ZERO:
if allow_empty_size:
# can happen on empty accounts
assert adapted_details == []
else:
raise AssertionError(f"{size=} but {allow_empty_size=}")
else:
cost = size * price
# will fail if order min size checks are invalid
assert adapted_details, f"Given size ({size}, cost={cost}) is too small according to parsed exchange rules"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

for order_quantity, order_price in adapted_details:
assert order_quantity == size # size should not change
assert order_price == price # price should not change


def get_sell_size_from_buy_order(self, buy_order):
sell_size = buy_order.origin_quantity
Expand Down
1 change: 1 addition & 0 deletions additional_tests/exchanges_tests/test_binance.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class TestBinanceAuthenticatedExchange(
ORDER_SIZE = 50 # % of portfolio to include in test orders
DUPLICATE_TRADES_RATIO = 0.1 # allow 10% duplicate in trades (due to trade id set to order id)
VALID_ORDER_ID = "26408108410"
EXPECTED_QUOTE_MIN_ORDER_SIZE = 5 # min quote value of orders to create (used to check market status parsing)
EXPECTED_INVALID_ORDERS_QUANTITY = [
# for some reason these orders from 2021 are broken
'7457313043',
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Drakkar-Software requirements
OctoBot-Commons==1.9.65
OctoBot-Trading==2.4.126
OctoBot-Trading==2.4.127
OctoBot-Evaluators==1.9.7
OctoBot-Tentacles-Manager==2.9.16
OctoBot-Services==1.6.21
Expand Down
Loading