Fix wrong key usage in trade_history_timebased
This commit is contained in:
@@ -1759,36 +1759,37 @@ async def test__async_get_trade_history_id(default_conf, mocker, caplog, exchang
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.parametrize("exchange_name", EXCHANGES)
|
||||
async def test__async_get_trade_history_time(default_conf, mocker, caplog, exchange_name,
|
||||
trades_history):
|
||||
fetch_trades_result):
|
||||
|
||||
caplog.set_level(logging.DEBUG)
|
||||
|
||||
async def mock_get_trade_hist(pair, *args, **kwargs):
|
||||
if kwargs['since'] == trades_history[0][0]:
|
||||
return trades_history[:-1]
|
||||
if kwargs['since'] == fetch_trades_result[0]['timestamp']:
|
||||
return fetch_trades_result[:-1]
|
||||
else:
|
||||
return trades_history[-1:]
|
||||
return fetch_trades_result[-1:]
|
||||
|
||||
caplog.set_level(logging.DEBUG)
|
||||
exchange = get_patched_exchange(mocker, default_conf, id=exchange_name)
|
||||
# Monkey-patch async function
|
||||
exchange._async_fetch_trades = MagicMock(side_effect=mock_get_trade_hist)
|
||||
exchange._api_async.fetch_trades = MagicMock(side_effect=mock_get_trade_hist)
|
||||
pair = 'ETH/BTC'
|
||||
ret = await exchange._async_get_trade_history_time(pair, since=trades_history[0][0],
|
||||
until=trades_history[-1][0]-1)
|
||||
ret = await exchange._async_get_trade_history_time(pair,
|
||||
since=fetch_trades_result[0]['timestamp'],
|
||||
until=fetch_trades_result[-1]['timestamp']-1)
|
||||
assert type(ret) is tuple
|
||||
assert ret[0] == pair
|
||||
assert type(ret[1]) is list
|
||||
assert len(ret[1]) == len(trades_history)
|
||||
assert exchange._async_fetch_trades.call_count == 2
|
||||
fetch_trades_cal = exchange._async_fetch_trades.call_args_list
|
||||
assert len(ret[1]) == len(fetch_trades_result)
|
||||
assert exchange._api_async.fetch_trades.call_count == 2
|
||||
fetch_trades_cal = exchange._api_async.fetch_trades.call_args_list
|
||||
# first call (using since, not fromId)
|
||||
assert fetch_trades_cal[0][0][0] == pair
|
||||
assert fetch_trades_cal[0][1]['since'] == trades_history[0][0]
|
||||
assert fetch_trades_cal[0][1]['since'] == fetch_trades_result[0]['timestamp']
|
||||
|
||||
# 2nd call
|
||||
assert fetch_trades_cal[1][0][0] == pair
|
||||
assert fetch_trades_cal[0][1]['since'] == trades_history[0][0]
|
||||
assert fetch_trades_cal[1][1]['since'] == fetch_trades_result[-2]['timestamp']
|
||||
assert log_has_re(r"Stopping because until was reached.*", caplog)
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user