Skip to content

Commit

Permalink
[ExchangeTests] add market filter portfolio test
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeDSM committed Dec 8, 2023
1 parent 3ea24d7 commit 02d409f
Show file tree
Hide file tree
Showing 18 changed files with 87 additions and 3 deletions.
3 changes: 2 additions & 1 deletion additional_tests/exchanges_tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def get_name(self):

@contextlib.asynccontextmanager
async def get_authenticated_exchange_manager(exchange_name, exchange_tentacle_name, config=None,
credentials_exchange_name=None):
credentials_exchange_name=None, market_filter=None):
credentials_exchange_name = credentials_exchange_name or exchange_name
_load_exchange_creds_env_variables_if_necessary()
config = {**test_config.load_test_config(), **config} if config else test_config.load_test_config()
Expand All @@ -82,6 +82,7 @@ async def get_authenticated_exchange_manager(exchange_name, exchange_tentacle_na
.is_checking_credentials(False) \
.is_sandboxed(_get_exchange_is_sandboxed(credentials_exchange_name)) \
.is_using_exchange_type(exchange_type) \
.use_market_filter(market_filter) \
.enable_storage(False) \
.disable_trading_mode() \
.is_exchange_only()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,18 @@ async def test_get_portfolio(self):
async with self.local_exchange_manager():
await self.inner_test_get_portfolio()

async def test_get_portfolio_with_market_filter(self):
# ensure market status are already loaded by another exchange manage and filters are applied
async with self.local_exchange_manager():
# get portfolio with all markets
all_markets_portfolio = await self.get_portfolio()

# now that market status are cached, test with filters
async with self.local_exchange_manager(market_filter=self._get_market_filter()):
# check portfolio fetched with filtered markets (should be equal to the one with all markets)
filtered_markets_portfolio = await self.get_portfolio()
assert filtered_markets_portfolio == all_markets_portfolio

async def inner_test_get_portfolio(self):
self.check_portfolio_content(await self.get_portfolio())

Expand Down Expand Up @@ -554,14 +566,15 @@ async def get_price(self, symbol=None):
))

@contextlib.asynccontextmanager
async def local_exchange_manager(self):
async def local_exchange_manager(self, market_filter=None):
try:
exchange_tentacle_name = self.EXCHANGE_TENTACLE_NAME or self.EXCHANGE_NAME.capitalize()
async with get_authenticated_exchange_manager(
self.EXCHANGE_NAME,
exchange_tentacle_name,
self.get_config(),
credentials_exchange_name=self.CREDENTIALS_EXCHANGE_NAME or self.EXCHANGE_NAME
credentials_exchange_name=self.CREDENTIALS_EXCHANGE_NAME or self.EXCHANGE_NAME,
market_filter=market_filter
) as exchange_manager:
self.exchange_manager = exchange_manager
yield
Expand Down Expand Up @@ -903,3 +916,12 @@ def get_exchange_data(self, symbol=None, all_symbols=None) -> exchange_data_impo
for s in _symbols
]
)

def _get_market_filter(self):
def market_filter(market):
return (
market[trading_enums.ExchangeConstantsMarketStatusColumns.SYMBOL.value]
in (self.SYMBOL, )
)

return market_filter
4 changes: 4 additions & 0 deletions additional_tests/exchanges_tests/test_ascendex.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ class TestAscendexAuthenticatedExchange(
async def test_get_portfolio(self):
await super().test_get_portfolio()

async def test_get_portfolio_with_market_filter(self):
# pass if not implemented
pass

async def test_create_and_cancel_limit_orders(self):
await super().test_create_and_cancel_limit_orders()

Expand Down
3 changes: 3 additions & 0 deletions additional_tests/exchanges_tests/test_binance.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ class TestBinanceAuthenticatedExchange(
async def test_get_portfolio(self):
await super().test_get_portfolio()

async def test_get_portfolio_with_market_filter(self):
await super().test_get_portfolio_with_market_filter()

async def test_create_and_cancel_limit_orders(self):
await super().test_create_and_cancel_limit_orders()

Expand Down
4 changes: 4 additions & 0 deletions additional_tests/exchanges_tests/test_binance_futures.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ async def _set_account_types(self, account_types):
async def test_get_portfolio(self):
await super().test_get_portfolio()

async def test_get_portfolio_with_market_filter(self):
# pass if not implemented
pass

async def test_get_empty_linear_and_inverse_positions(self):
await super().test_get_empty_linear_and_inverse_positions()

Expand Down
4 changes: 4 additions & 0 deletions additional_tests/exchanges_tests/test_bitget.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ class TestBitgetAuthenticatedExchange(
async def test_get_portfolio(self):
await super().test_get_portfolio()

async def test_get_portfolio_with_market_filter(self):
# pass if not implemented
pass

async def test_create_and_cancel_limit_orders(self):
await super().test_create_and_cancel_limit_orders()

Expand Down
4 changes: 4 additions & 0 deletions additional_tests/exchanges_tests/test_bybit.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ class TestBybitAuthenticatedExchange(
async def test_get_portfolio(self):
await super().test_get_portfolio()

async def test_get_portfolio_with_market_filter(self):
# pass if not implemented
pass

async def test_create_and_cancel_limit_orders(self):
await super().test_create_and_cancel_limit_orders()

Expand Down
4 changes: 4 additions & 0 deletions additional_tests/exchanges_tests/test_bybit_futures.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ class TestBybitFuturesAuthenticatedExchange(
async def test_get_portfolio(self):
await super().test_get_portfolio()

async def test_get_portfolio_with_market_filter(self):
# pass if not implemented
pass

async def test_get_empty_linear_and_inverse_positions(self):
await super().test_get_empty_linear_and_inverse_positions()

Expand Down
4 changes: 4 additions & 0 deletions additional_tests/exchanges_tests/test_coinbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ class TestCoinbaseAuthenticatedExchange(
async def test_get_portfolio(self):
await super().test_get_portfolio()

async def test_get_portfolio_with_market_filter(self):
# pass if not implemented
pass

async def test_create_and_cancel_limit_orders(self):
await super().test_create_and_cancel_limit_orders()

Expand Down
4 changes: 4 additions & 0 deletions additional_tests/exchanges_tests/test_cryptocom.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ class TestCryptoComAuthenticatedExchange(
async def test_get_portfolio(self):
await super().test_get_portfolio()

async def test_get_portfolio_with_market_filter(self):
# pass if not implemented
pass

async def test_create_and_cancel_limit_orders(self):
await super().test_create_and_cancel_limit_orders()

Expand Down
4 changes: 4 additions & 0 deletions additional_tests/exchanges_tests/test_hollaex.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ class TestHollaexAuthenticatedExchange(
async def test_get_portfolio(self):
await super().test_get_portfolio()

async def test_get_portfolio_with_market_filter(self):
# pass if not implemented
pass

async def test_create_and_cancel_limit_orders(self):
await super().test_create_and_cancel_limit_orders()

Expand Down
4 changes: 4 additions & 0 deletions additional_tests/exchanges_tests/test_huobi.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ class _TestHuobiAuthenticatedExchange(
async def test_get_portfolio(self):
await super().test_get_portfolio()

async def test_get_portfolio_with_market_filter(self):
# pass if not implemented
pass

async def test_create_and_cancel_limit_orders(self):
await super().test_create_and_cancel_limit_orders()

Expand Down
3 changes: 3 additions & 0 deletions additional_tests/exchanges_tests/test_kucoin.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ class TestKucoinAuthenticatedExchange(
async def test_get_portfolio(self):
await super().test_get_portfolio()

async def test_get_portfolio_with_market_filter(self):
await super().test_get_portfolio_with_market_filter()

async def test_create_and_cancel_limit_orders(self):
await super().test_create_and_cancel_limit_orders()

Expand Down
4 changes: 4 additions & 0 deletions additional_tests/exchanges_tests/test_kucoin_futures.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ class TestKucoinFuturesAuthenticatedExchange(
async def test_get_portfolio(self):
await super().test_get_portfolio()

async def test_get_portfolio_with_market_filter(self):
# pass if not implemented
pass

async def test_get_empty_linear_and_inverse_positions(self):
await super().test_get_empty_linear_and_inverse_positions()

Expand Down
4 changes: 4 additions & 0 deletions additional_tests/exchanges_tests/test_mexc.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ class TestMEXCAuthenticatedExchange(
async def test_get_portfolio(self):
await super().test_get_portfolio()

async def test_get_portfolio_with_market_filter(self):
# pass if not implemented
pass

async def test_create_and_cancel_limit_orders(self):
await super().test_create_and_cancel_limit_orders()

Expand Down
3 changes: 3 additions & 0 deletions additional_tests/exchanges_tests/test_okx.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ class TestOKXAuthenticatedExchange(
async def test_get_portfolio(self):
await super().test_get_portfolio()

async def test_get_portfolio_with_market_filter(self):
await super().test_get_portfolio_with_market_filter()

async def test_create_and_cancel_limit_orders(self):
await super().test_create_and_cancel_limit_orders()

Expand Down
4 changes: 4 additions & 0 deletions additional_tests/exchanges_tests/test_okx_futures.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ class TestOKXFuturesAuthenticatedExchange(
async def test_get_portfolio(self):
await super().test_get_portfolio()

async def test_get_portfolio_with_market_filter(self):
# pass if not implemented
pass

async def test_get_empty_linear_and_inverse_positions(self):
await super().test_get_empty_linear_and_inverse_positions()

Expand Down
4 changes: 4 additions & 0 deletions additional_tests/exchanges_tests/test_phemex.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ class TestPemexAuthenticatedExchange(
async def test_get_portfolio(self):
await super().test_get_portfolio()

async def test_get_portfolio_with_market_filter(self):
# pass if not implemented
pass

async def test_create_and_cancel_limit_orders(self):
await super().test_create_and_cancel_limit_orders()

Expand Down

0 comments on commit 02d409f

Please sign in to comment.