Skip to content

Commit c0c0cc8

Browse files
committed
[ExchangeTests] add cross position tests
1 parent b99a655 commit c0c0cc8

File tree

4 files changed

+56
-11
lines changed

4 files changed

+56
-11
lines changed

additional_tests/exchanges_tests/abstract_authenticated_exchange_tester.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ async def test_create_and_cancel_limit_orders(self):
229229
async with self.local_exchange_manager():
230230
await self.inner_test_create_and_cancel_limit_orders()
231231

232-
async def inner_test_create_and_cancel_limit_orders(self, symbol=None, settlement_currency=None):
232+
async def inner_test_create_and_cancel_limit_orders(self, symbol=None, settlement_currency=None, margin_type=None):
233233
symbol = symbol or self.SYMBOL
234234
# # DEBUG tools p1, uncomment to create specific orders
235235
# symbol = "ADA/USDT"
@@ -247,7 +247,11 @@ async def inner_test_create_and_cancel_limit_orders(self, symbol=None, settlemen
247247
min_size = personal_data.decimal_adapt_quantity(
248248
market_status,
249249
# add 25% to min order size to avoid rounding of amount of price ending up just bellow min cost
250-
decimal.Decimal(str(self.EXPECTED_QUOTE_MIN_ORDER_SIZE)) * decimal.Decimal("1.25") / price
250+
decimal.Decimal(str(self.EXPECTED_QUOTE_MIN_ORDER_SIZE)) * (
251+
decimal.Decimal("1.25") if symbols.parse_symbol(symbol).is_spot() else decimal.Decimal("1")
252+
) / (
253+
decimal.Decimal("1") if symbols.parse_symbol(symbol).is_inverse() else price
254+
)
251255
)
252256
self.check_order_size_and_price(min_size, price, symbol=symbol, allow_empty_size=False)
253257
size = min(min_size, default_size)

additional_tests/exchanges_tests/abstract_authenticated_future_exchange_tester.py

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,25 @@ async def test_get_empty_linear_and_inverse_positions(self):
4242
await self.inner_test_get_empty_linear_and_inverse_positions()
4343

4444
async def inner_test_get_empty_linear_and_inverse_positions(self):
45+
if self.exchange_manager.exchange.SUPPORTS_SET_MARGIN_TYPE:
46+
await self.set_margin_type(trading_enums.MarginType.ISOLATED)
47+
await self._inner_test_get_empty_linear_and_inverse_positions_for_margin_type(
48+
trading_enums.MarginType.ISOLATED
49+
)
50+
await self.set_margin_type(trading_enums.MarginType.CROSS)
51+
await self._inner_test_get_empty_linear_and_inverse_positions_for_margin_type(
52+
trading_enums.MarginType.CROSS
53+
)
54+
else:
55+
await self._inner_test_get_empty_linear_and_inverse_positions_for_margin_type(None)
56+
57+
async def _inner_test_get_empty_linear_and_inverse_positions_for_margin_type(
58+
self, margin_type: trading_enums.MarginType
59+
):
4560
positions = await self.get_positions()
4661
self._check_positions_content(positions)
4762
position = await self.get_position(self.SYMBOL)
48-
self._check_position_content(position, self.SYMBOL)
63+
self._check_position_content(position, self.SYMBOL, margin_type=margin_type)
4964
for contract_type in (trading_enums.FutureContractType.LINEAR_PERPETUAL,
5065
trading_enums.FutureContractType.INVERSE_PERPETUAL):
5166
if not self.has_empty_position(self.get_filtered_positions(positions, contract_type)):
@@ -134,11 +149,13 @@ def _check_positions_content(self, positions):
134149
for position in positions:
135150
self._check_position_content(position, None)
136151

137-
def _check_position_content(self, position, symbol, position_mode=None):
152+
def _check_position_content(self, position, symbol, position_mode=None, margin_type=None):
138153
if symbol:
139154
assert position[trading_enums.ExchangeConstantsPositionColumns.SYMBOL.value] == symbol
140155
else:
141156
assert position[trading_enums.ExchangeConstantsPositionColumns.SYMBOL.value]
157+
if margin_type:
158+
assert position[trading_enums.ExchangeConstantsPositionColumns.MARGIN_TYPE.value] == margin_type
142159
leverage = position[trading_enums.ExchangeConstantsPositionColumns.LEVERAGE.value]
143160
assert isinstance(leverage, decimal.Decimal)
144161
# should not be 0 in octobot
@@ -149,11 +166,28 @@ def _check_position_content(self, position, symbol, position_mode=None):
149166
assert position[trading_enums.ExchangeConstantsPositionColumns.POSITION_MODE.value] is position_mode
150167

151168
async def inner_test_create_and_cancel_limit_orders(self, symbol=None, settlement_currency=None):
169+
if self.exchange_manager.exchange.SUPPORTS_SET_MARGIN_TYPE:
170+
await self.set_margin_type(trading_enums.MarginType.ISOLATED)
171+
await self._inner_test_create_and_cancel_limit_orders_for_margin_type(
172+
symbol=symbol, settlement_currency=settlement_currency, margin_type=trading_enums.MarginType.ISOLATED
173+
)
174+
await self.set_margin_type(trading_enums.MarginType.CROSS)
175+
await self._inner_test_create_and_cancel_limit_orders_for_margin_type(
176+
symbol=symbol, settlement_currency=settlement_currency, margin_type=trading_enums.MarginType.CROSS
177+
)
178+
else:
179+
await self._inner_test_create_and_cancel_limit_orders_for_margin_type(
180+
symbol=symbol, settlement_currency=settlement_currency, margin_type=None
181+
)
182+
183+
async def _inner_test_create_and_cancel_limit_orders_for_margin_type(
184+
self, symbol=None, settlement_currency=None, margin_type=None
185+
):
152186
# test with linear symbol
153-
await super().inner_test_create_and_cancel_limit_orders()
187+
await super().inner_test_create_and_cancel_limit_orders(margin_type=margin_type)
154188
# test with inverse symbol
155189
await super().inner_test_create_and_cancel_limit_orders(
156-
symbol=self.INVERSE_SYMBOL, settlement_currency=self.ORDER_CURRENCY
190+
symbol=self.INVERSE_SYMBOL, settlement_currency=self.ORDER_CURRENCY, margin_type=margin_type
157191
)
158192

159193
async def inner_test_create_and_fill_market_orders(self):

additional_tests/exchanges_tests/test_binance_futures.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,13 @@ class TestBinanceFuturesAuthenticatedExchange(
2929
EXCHANGE_NAME = "binance"
3030
CREDENTIALS_EXCHANGE_NAME = "BINANCE_FUTURES"
3131
ORDER_CURRENCY = "BTC"
32-
SETTLEMENT_CURRENCY = "USDT"
32+
SETTLEMENT_CURRENCY = "USDC"
3333
SYMBOL = f"{ORDER_CURRENCY}/{SETTLEMENT_CURRENCY}:{SETTLEMENT_CURRENCY}"
3434
INVERSE_SYMBOL = f"{ORDER_CURRENCY}/USD:{ORDER_CURRENCY}"
35-
ORDER_SIZE = 10 # % of portfolio to include in test orders
35+
ORDER_SIZE = 30 # % of portfolio to include in test orders
3636
DUPLICATE_TRADES_RATIO = 0.1 # allow 10% duplicate in trades (due to trade id set to order id)
3737
VALID_ORDER_ID = "26408108410"
38+
EXPECTED_QUOTE_MIN_ORDER_SIZE = 200 # min quote value of orders to create (used to check market status parsing)
3839

3940
async def _set_account_types(self, account_types):
4041
# todo remove this and use both types when exchange-side multi portfolio is enabled
@@ -86,18 +87,23 @@ async def test_is_valid_account(self):
8687
async def test_create_and_cancel_limit_orders(self):
8788
await super().test_create_and_cancel_limit_orders()
8889

89-
async def inner_test_create_and_cancel_limit_orders(self, symbol=None, settlement_currency=None):
90+
async def _inner_test_create_and_cancel_limit_orders_for_margin_type(
91+
self, symbol=None, settlement_currency=None, margin_type=None
92+
):
9093
# todo remove this and use both types when exchange-side multi portfolio is enabled
9194
# test with linear symbol
95+
await self._set_account_types(
96+
[self.exchange_manager.exchange.LINEAR_TYPE]
97+
)
9298
await abstract_authenticated_exchange_tester.AbstractAuthenticatedExchangeTester\
93-
.inner_test_create_and_cancel_limit_orders(self)
99+
.inner_test_create_and_cancel_limit_orders(self, margin_type=margin_type)
94100
# test with inverse symbol
95101
await self._set_account_types(
96102
[self.exchange_manager.exchange.INVERSE_TYPE]
97103
)
98104
await abstract_authenticated_exchange_tester.AbstractAuthenticatedExchangeTester\
99105
.inner_test_create_and_cancel_limit_orders(
100-
self, symbol=self.INVERSE_SYMBOL, settlement_currency=self.ORDER_CURRENCY
106+
self, symbol=self.INVERSE_SYMBOL, settlement_currency=self.ORDER_CURRENCY, margin_type=margin_type
101107
)
102108

103109
async def test_create_and_fill_market_orders(self):

additional_tests/exchanges_tests/test_kucoin_futures.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ async def test_is_valid_account(self):
7373
await super().test_is_valid_account()
7474

7575
async def test_create_and_cancel_limit_orders(self):
76+
# todo test cross position order creation (kucoin param) at next ccxt update (will support set margin type)
7677
await super().test_create_and_cancel_limit_orders()
7778

7879
async def test_create_and_fill_market_orders(self):

0 commit comments

Comments
 (0)