Fix bug when exchange result is empty

This commit is contained in:
Matthias 2018-09-02 19:15:23 +02:00
parent ffd4469c1d
commit e9deb928f6
2 changed files with 22 additions and 3 deletions

View File

@ -454,7 +454,8 @@ class Exchange(object):
data = sorted(data, key=lambda x: x[0])
# keeping last candle time as last refreshed time of the pair
self._pairs_last_refresh_time[pair] = data[-1][0] // 1000
if data:
self._pairs_last_refresh_time[pair] = data[-1][0] // 1000
# keeping candles in cache
self.klines[pair] = data

View File

@ -635,8 +635,6 @@ async def test__async_get_candle_history(default_conf, mocker, caplog):
]
]
async def async_fetch_ohlcv(pair, timeframe, since):
return tick
caplog.set_level(logging.DEBUG)
exchange = get_patched_exchange(mocker, default_conf)
# Monkey-patch async function
@ -669,6 +667,26 @@ async def test__async_get_candle_history(default_conf, mocker, caplog):
(arrow.utcnow().timestamp - 2000) * 1000)
@pytest.mark.asyncio
async def test__async_get_candle_history_empty(default_conf, mocker, caplog):
""" Test empty exchange result """
tick = []
caplog.set_level(logging.DEBUG)
exchange = get_patched_exchange(mocker, default_conf)
# Monkey-patch async function
exchange._api_async.fetch_ohlcv = get_mock_coro([])
exchange = Exchange(default_conf)
pair = 'ETH/BTC'
res = await exchange._async_get_candle_history(pair, "5m")
assert type(res) is tuple
assert len(res) == 2
assert res[0] == pair
assert res[1] == tick
assert exchange._api_async.fetch_ohlcv.call_count == 1
@pytest.mark.asyncio
async def test_async_get_candles_history(default_conf, mocker):
tick = [