Change get_next_limit_in_list to use list comprehension

This commit is contained in:
Matthias 2020-10-13 20:29:51 +02:00
parent 2ed20eee4e
commit 8165cc11df
3 changed files with 15 additions and 8 deletions

View File

@ -1072,12 +1072,12 @@ class Exchange:
@staticmethod @staticmethod
def get_next_limit_in_list(limit: int, limit_range: Optional[List[int]]): 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: if not limit_range:
return limit return limit
return min([x for x in limit_range if limit <= x])
return min(list(filter(lambda x: limit <= x, limit_range)))
@retrier @retrier
def fetch_l2_order_book(self, pair: str, limit: int = 100) -> dict: def fetch_l2_order_book(self, pair: str, limit: int = 100) -> dict:

View File

@ -132,7 +132,7 @@ def test_orderbook(mocker, default_conf, order_book_l2):
res = dp.orderbook('ETH/BTC', 5) res = dp.orderbook('ETH/BTC', 5)
assert order_book_l2.call_count == 1 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][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 type(res) is dict
assert 'bids' in res assert 'bids' in res

View File

@ -11,7 +11,7 @@ from pandas import DataFrame
from freqtrade.exceptions import (DDosProtection, DependencyException, InvalidOrderException, from freqtrade.exceptions import (DDosProtection, DependencyException, InvalidOrderException,
OperationalException, TemporaryError) 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, from freqtrade.exchange.common import (API_FETCH_ORDER_RETRY_COUNT, API_RETRY_COUNT,
calculate_backoff) calculate_backoff)
from freqtrade.exchange.exchange import (market_is_active, timeframe_to_minutes, timeframe_to_msecs, 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_pairs')
mocker.patch('freqtrade.exchange.Exchange.validate_timeframes') mocker.patch('freqtrade.exchange.Exchange.validate_timeframes')
mocker.patch('freqtrade.exchange.Exchange.validate_stakecurrency') 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 isinstance(exchange, Exchange)
assert log_has_re(r"No .* specific subclass found. Using the generic class instead.", caplog) assert log_has_re(r"No .* specific subclass found. Using the generic class instead.", caplog)
caplog.clear() 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) exchange = ExchangeResolver.load_exchange('kraken', default_conf)
assert isinstance(exchange, Exchange) assert isinstance(exchange, Exchange)
assert isinstance(exchange, Kraken) 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['bids']) == 10
assert len(order_book['asks']) == 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][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() api_mock.fetch_l2_order_book.reset_mock()
order_book = exchange.fetch_l2_order_book(pair='ETH/BTC', limit=val) order_book = exchange.fetch_l2_order_book(pair='ETH/BTC', limit=val)