From 8165cc11df8f3b68806ae2668b377ae4c17d4084 Mon Sep 17 00:00:00 2001 From: Matthias Date: Tue, 13 Oct 2020 20:29:51 +0200 Subject: [PATCH] Change get_next_limit_in_list to use list comprehension --- freqtrade/exchange/exchange.py | 6 +++--- tests/data/test_dataprovider.py | 2 +- tests/exchange/test_exchange.py | 15 +++++++++++---- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/freqtrade/exchange/exchange.py b/freqtrade/exchange/exchange.py index 66126785f..ffe81ab39 100644 --- a/freqtrade/exchange/exchange.py +++ b/freqtrade/exchange/exchange.py @@ -1072,12 +1072,12 @@ class Exchange: @staticmethod def get_next_limit_in_list(limit: int, limit_range: Optional[List[int]]): """ - Get next greater limit + Get next greater value in the list. + Used by fetch_l2_order_book if the api only supports a limited range """ if not limit_range: return limit - - return min(list(filter(lambda x: limit <= x, limit_range))) + return min([x for x in limit_range if limit <= x]) @retrier def fetch_l2_order_book(self, pair: str, limit: int = 100) -> dict: diff --git a/tests/data/test_dataprovider.py b/tests/data/test_dataprovider.py index c2ecf4b80..a64dce908 100644 --- a/tests/data/test_dataprovider.py +++ b/tests/data/test_dataprovider.py @@ -132,7 +132,7 @@ def test_orderbook(mocker, default_conf, order_book_l2): res = dp.orderbook('ETH/BTC', 5) assert order_book_l2.call_count == 1 assert order_book_l2.call_args_list[0][0][0] == 'ETH/BTC' - assert order_book_l2.call_args_list[0][0][1] == 5 + assert order_book_l2.call_args_list[0][0][1] >= 5 assert type(res) is dict assert 'bids' in res diff --git a/tests/exchange/test_exchange.py b/tests/exchange/test_exchange.py index 4adc8b2ea..7b86d3866 100644 --- a/tests/exchange/test_exchange.py +++ b/tests/exchange/test_exchange.py @@ -11,7 +11,7 @@ from pandas import DataFrame from freqtrade.exceptions import (DDosProtection, DependencyException, InvalidOrderException, OperationalException, TemporaryError) -from freqtrade.exchange import Binance, Exchange, Kraken +from freqtrade.exchange import Binance, Bittrex, Exchange, Kraken from freqtrade.exchange.common import (API_FETCH_ORDER_RETRY_COUNT, API_RETRY_COUNT, calculate_backoff) from freqtrade.exchange.exchange import (market_is_active, timeframe_to_minutes, timeframe_to_msecs, @@ -148,11 +148,19 @@ def test_exchange_resolver(default_conf, mocker, caplog): mocker.patch('freqtrade.exchange.Exchange.validate_pairs') mocker.patch('freqtrade.exchange.Exchange.validate_timeframes') mocker.patch('freqtrade.exchange.Exchange.validate_stakecurrency') - exchange = ExchangeResolver.load_exchange('Bittrex', default_conf) + + exchange = ExchangeResolver.load_exchange('huobi', default_conf) assert isinstance(exchange, Exchange) assert log_has_re(r"No .* specific subclass found. Using the generic class instead.", caplog) caplog.clear() + exchange = ExchangeResolver.load_exchange('Bittrex', default_conf) + assert isinstance(exchange, Exchange) + assert isinstance(exchange, Bittrex) + assert not log_has_re(r"No .* specific subclass found. Using the generic class instead.", + caplog) + caplog.clear() + exchange = ExchangeResolver.load_exchange('kraken', default_conf) assert isinstance(exchange, Exchange) assert isinstance(exchange, Kraken) @@ -1470,9 +1478,8 @@ def test_fetch_l2_order_book(default_conf, mocker, order_book_l2, exchange_name) assert len(order_book['bids']) == 10 assert len(order_book['asks']) == 10 assert api_mock.fetch_l2_order_book.call_args_list[0][0][0] == 'ETH/BTC' - assert api_mock.fetch_l2_order_book.call_args_list[0][0][1] == 10 - for val in [1, 5, 12, 20, 50, 100]: + for val in [1, 5, 10, 12, 20, 50, 100]: api_mock.fetch_l2_order_book.reset_mock() order_book = exchange.fetch_l2_order_book(pair='ETH/BTC', limit=val)