Merge branch 'develop' into feat/short
This commit is contained in:
@@ -360,13 +360,16 @@ async def test__async_get_historic_ohlcv_binance(default_conf, mocker, caplog):
|
||||
exchange._api_async.fetch_ohlcv = get_mock_coro(ohlcv)
|
||||
|
||||
pair = 'ETH/BTC'
|
||||
res = await exchange._async_get_historic_ohlcv(pair, "5m",
|
||||
1500000000000, is_new_pair=False)
|
||||
respair, restf, res = await exchange._async_get_historic_ohlcv(
|
||||
pair, "5m", 1500000000000, is_new_pair=False)
|
||||
assert respair == pair
|
||||
assert restf == '5m'
|
||||
# Call with very old timestamp - causes tons of requests
|
||||
assert exchange._api_async.fetch_ohlcv.call_count > 400
|
||||
# assert res == ohlcv
|
||||
exchange._api_async.fetch_ohlcv.reset_mock()
|
||||
res = await exchange._async_get_historic_ohlcv(pair, "5m", 1500000000000, is_new_pair=True)
|
||||
_, _, res = await exchange._async_get_historic_ohlcv(
|
||||
pair, "5m", 1500000000000, is_new_pair=True)
|
||||
|
||||
# Called twice - one "init" call - and one to get the actual data.
|
||||
assert exchange._api_async.fetch_ohlcv.call_count == 2
|
||||
@@ -375,7 +378,7 @@ async def test__async_get_historic_ohlcv_binance(default_conf, mocker, caplog):
|
||||
|
||||
|
||||
@pytest.mark.parametrize("trading_mode,collateral,config", [
|
||||
("", "", {}),
|
||||
("spot", "", {}),
|
||||
("margin", "cross", {"options": {"defaultType": "margin"}}),
|
||||
("futures", "isolated", {"options": {"defaultType": "future"}}),
|
||||
])
|
||||
|
@@ -240,9 +240,9 @@ def test_validate_order_time_in_force(default_conf, mocker, caplog):
|
||||
(2.9999, 4, 0.005, 2.995),
|
||||
])
|
||||
def test_amount_to_precision(default_conf, mocker, amount, precision_mode, precision, expected):
|
||||
'''
|
||||
"""
|
||||
Test rounds down
|
||||
'''
|
||||
"""
|
||||
|
||||
markets = PropertyMock(return_value={'ETH/BTC': {'precision': {'amount': precision}}})
|
||||
|
||||
@@ -281,9 +281,7 @@ def test_amount_to_precision(default_conf, mocker, amount, precision_mode, preci
|
||||
|
||||
])
|
||||
def test_price_to_precision(default_conf, mocker, price, precision_mode, precision, expected):
|
||||
'''
|
||||
Test price to precision
|
||||
'''
|
||||
"""Test price to precision"""
|
||||
markets = PropertyMock(return_value={'ETH/BTC': {'precision': {'price': precision}}})
|
||||
|
||||
exchange = get_patched_exchange(mocker, default_conf, id="binance")
|
||||
@@ -967,9 +965,22 @@ def test_validate_required_startup_candles(default_conf, mocker, caplog):
|
||||
default_conf['startup_candle_count'] = 20
|
||||
ex = Exchange(default_conf)
|
||||
assert ex
|
||||
default_conf['startup_candle_count'] = 600
|
||||
# assumption is that the exchange provides 500 candles per call.s
|
||||
assert ex.validate_required_startup_candles(200, '5m') == 1
|
||||
assert ex.validate_required_startup_candles(499, '5m') == 1
|
||||
assert ex.validate_required_startup_candles(600, '5m') == 2
|
||||
assert ex.validate_required_startup_candles(501, '5m') == 2
|
||||
assert ex.validate_required_startup_candles(499, '5m') == 1
|
||||
assert ex.validate_required_startup_candles(1000, '5m') == 3
|
||||
assert ex.validate_required_startup_candles(2499, '5m') == 5
|
||||
assert log_has_re(r'Using 5 calls to get OHLCV. This.*', caplog)
|
||||
|
||||
with pytest.raises(OperationalException, match=r'This strategy requires 600.*'):
|
||||
with pytest.raises(OperationalException, match=r'This strategy requires 2500.*'):
|
||||
ex.validate_required_startup_candles(2500, '5m')
|
||||
|
||||
# Ensure the same also happens on init
|
||||
default_conf['startup_candle_count'] = 6000
|
||||
with pytest.raises(OperationalException, match=r'This strategy requires 6000.*'):
|
||||
Exchange(default_conf)
|
||||
|
||||
|
||||
@@ -1570,6 +1581,7 @@ def test_get_historic_ohlcv(default_conf, mocker, caplog, exchange_name):
|
||||
assert exchange._async_get_candle_history.call_count == 2
|
||||
# Returns twice the above OHLCV data
|
||||
assert len(ret) == 2
|
||||
assert log_has_re(r'Downloaded data for .* with length .*\.', caplog)
|
||||
|
||||
caplog.clear()
|
||||
|
||||
@@ -1651,12 +1663,13 @@ async def test__async_get_historic_ohlcv(default_conf, mocker, caplog, exchange_
|
||||
exchange._api_async.fetch_ohlcv = get_mock_coro(ohlcv)
|
||||
|
||||
pair = 'ETH/USDT'
|
||||
res = await exchange._async_get_historic_ohlcv(pair, "5m",
|
||||
1500000000000, is_new_pair=False)
|
||||
respair, restf, res = await exchange._async_get_historic_ohlcv(
|
||||
pair, "5m", 1500000000000, is_new_pair=False)
|
||||
assert respair == pair
|
||||
assert restf == '5m'
|
||||
# Call with very old timestamp - causes tons of requests
|
||||
assert exchange._api_async.fetch_ohlcv.call_count > 200
|
||||
assert res[0] == ohlcv[0]
|
||||
assert log_has_re(r'Downloaded data for .* with length .*\.', caplog)
|
||||
|
||||
|
||||
def test_refresh_latest_ohlcv(mocker, default_conf, caplog) -> None:
|
||||
@@ -1694,12 +1707,14 @@ def test_refresh_latest_ohlcv(mocker, default_conf, caplog) -> None:
|
||||
assert exchange._api_async.fetch_ohlcv.call_count == 2
|
||||
exchange._api_async.fetch_ohlcv.reset_mock()
|
||||
|
||||
exchange.required_candle_call_count = 2
|
||||
res = exchange.refresh_latest_ohlcv(pairs)
|
||||
assert len(res) == len(pairs)
|
||||
|
||||
assert log_has(f'Refreshing candle (OHLCV) data for {len(pairs)} pairs', caplog)
|
||||
assert exchange._klines
|
||||
assert exchange._api_async.fetch_ohlcv.call_count == 2
|
||||
assert exchange._api_async.fetch_ohlcv.call_count == 4
|
||||
exchange._api_async.fetch_ohlcv.reset_mock()
|
||||
for pair in pairs:
|
||||
assert isinstance(exchange.klines(pair), DataFrame)
|
||||
assert len(exchange.klines(pair)) > 0
|
||||
@@ -1715,7 +1730,7 @@ def test_refresh_latest_ohlcv(mocker, default_conf, caplog) -> None:
|
||||
res = exchange.refresh_latest_ohlcv([('IOTA/ETH', '5m'), ('XRP/ETH', '5m')])
|
||||
assert len(res) == len(pairs)
|
||||
|
||||
assert exchange._api_async.fetch_ohlcv.call_count == 2
|
||||
assert exchange._api_async.fetch_ohlcv.call_count == 0
|
||||
assert log_has(f"Using cached candle (OHLCV) data for pair {pairs[0][0]}, "
|
||||
f"timeframe {pairs[0][1]} ...",
|
||||
caplog)
|
||||
@@ -2066,15 +2081,6 @@ def test_get_sell_rate_exception(default_conf, mocker, caplog):
|
||||
assert exchange.get_rate(pair, refresh=True, side="sell") == 0.13
|
||||
|
||||
|
||||
def make_fetch_ohlcv_mock(data):
|
||||
def fetch_ohlcv_mock(pair, timeframe, since):
|
||||
if since:
|
||||
assert since > data[-1][0]
|
||||
return []
|
||||
return data
|
||||
return fetch_ohlcv_mock
|
||||
|
||||
|
||||
@pytest.mark.parametrize("exchange_name", EXCHANGES)
|
||||
@pytest.mark.asyncio
|
||||
async def test___async_get_candle_history_sort(default_conf, mocker, exchange_name):
|
||||
|
Reference in New Issue
Block a user