Fix some obtruse (test)bugs

This commit is contained in:
Matthias 2021-12-07 07:25:00 +01:00
parent ba1091b9e4
commit a870e0962a
4 changed files with 64 additions and 55 deletions

View File

@ -265,7 +265,7 @@ def list_available_pairs(timeframe: Optional[str] = None, stake_currency: Option
if candletype: if candletype:
pair_interval = [pair for pair in pair_interval if pair[2] == candletype] pair_interval = [pair for pair in pair_interval if pair[2] == candletype]
else: else:
pair_interval = [pair for pair in pair_interval if pair[2] == ''] pair_interval = [pair for pair in pair_interval if pair[2] == CandleType.SPOT_]
pair_interval = sorted(pair_interval, key=lambda x: x[0]) pair_interval = sorted(pair_interval, key=lambda x: x[0])

View File

@ -720,17 +720,17 @@ def test_datahandler_ohlcv_get_available_data(testdatadir):
paircombs = JsonDataHandler.ohlcv_get_available_data(testdatadir, 'spot') paircombs = JsonDataHandler.ohlcv_get_available_data(testdatadir, 'spot')
# Convert to set to avoid failures due to sorting # Convert to set to avoid failures due to sorting
assert set(paircombs) == { assert set(paircombs) == {
('UNITTEST/BTC', '5m', ''), ('UNITTEST/BTC', '5m', CandleType.SPOT_),
('ETH/BTC', '5m', ''), ('ETH/BTC', '5m', CandleType.SPOT_),
('XLM/BTC', '5m', ''), ('XLM/BTC', '5m', CandleType.SPOT_),
('TRX/BTC', '5m', ''), ('TRX/BTC', '5m', CandleType.SPOT_),
('LTC/BTC', '5m', ''), ('LTC/BTC', '5m', CandleType.SPOT_),
('XMR/BTC', '5m', ''), ('XMR/BTC', '5m', CandleType.SPOT_),
('ZEC/BTC', '5m', ''), ('ZEC/BTC', '5m', CandleType.SPOT_),
('UNITTEST/BTC', '1m', ''), ('UNITTEST/BTC', '1m', CandleType.SPOT_),
('ADA/BTC', '5m', ''), ('ADA/BTC', '5m', CandleType.SPOT_),
('ETC/BTC', '5m', ''), ('ETC/BTC', '5m', CandleType.SPOT_),
('NXT/BTC', '5m', ''), ('NXT/BTC', '5m', CandleType.SPOT_),
('DASH/BTC', '5m', ''), ('DASH/BTC', '5m', ''),
('XRP/ETH', '1m', ''), ('XRP/ETH', '1m', ''),
('XRP/ETH', '5m', ''), ('XRP/ETH', '5m', ''),

View File

@ -7,6 +7,7 @@ import pytest
import time_machine import time_machine
from freqtrade.constants import AVAILABLE_PAIRLISTS from freqtrade.constants import AVAILABLE_PAIRLISTS
from freqtrade.enums.candletype import CandleType
from freqtrade.enums.runmode import RunMode from freqtrade.enums.runmode import RunMode
from freqtrade.exceptions import OperationalException from freqtrade.exceptions import OperationalException
from freqtrade.persistence import Trade from freqtrade.persistence import Trade
@ -461,11 +462,11 @@ def test_VolumePairList_whitelist_gen(mocker, whitelist_conf, shitcoinmarkets, t
ohlcv_history_high_vola.loc[ohlcv_history_high_vola.index == 1, 'close'] = 0.00090 ohlcv_history_high_vola.loc[ohlcv_history_high_vola.index == 1, 'close'] = 0.00090
ohlcv_data = { ohlcv_data = {
('ETH/BTC', '1d', ''): ohlcv_history, ('ETH/BTC', '1d', CandleType.SPOT_): ohlcv_history,
('TKN/BTC', '1d', ''): ohlcv_history, ('TKN/BTC', '1d', CandleType.SPOT_): ohlcv_history,
('LTC/BTC', '1d', ''): ohlcv_history.append(ohlcv_history), ('LTC/BTC', '1d', CandleType.SPOT_): ohlcv_history.append(ohlcv_history),
('XRP/BTC', '1d', ''): ohlcv_history, ('XRP/BTC', '1d', CandleType.SPOT_): ohlcv_history,
('HOT/BTC', '1d', ''): ohlcv_history_high_vola, ('HOT/BTC', '1d', CandleType.SPOT_): ohlcv_history_high_vola,
} }
mocker.patch('freqtrade.exchange.Exchange.exchange_has', MagicMock(return_value=True)) mocker.patch('freqtrade.exchange.Exchange.exchange_has', MagicMock(return_value=True))
@ -579,11 +580,11 @@ def test_VolumePairList_range(mocker, whitelist_conf, shitcoinmarkets, tickers,
ohlcv_history_high_volume.loc[:, 'volume'] = 10 ohlcv_history_high_volume.loc[:, 'volume'] = 10
ohlcv_data = { ohlcv_data = {
('ETH/BTC', '1d', ''): ohlcv_history, ('ETH/BTC', '1d', CandleType.SPOT_): ohlcv_history,
('TKN/BTC', '1d', ''): ohlcv_history, ('TKN/BTC', '1d', CandleType.SPOT_): ohlcv_history,
('LTC/BTC', '1d', ''): ohlcv_history_medium_volume, ('LTC/BTC', '1d', CandleType.SPOT_): ohlcv_history_medium_volume,
('XRP/BTC', '1d', ''): ohlcv_history_high_vola, ('XRP/BTC', '1d', CandleType.SPOT_): ohlcv_history_high_vola,
('HOT/BTC', '1d', ''): ohlcv_history_high_volume, ('HOT/BTC', '1d', CandleType.SPOT_): ohlcv_history_high_volume,
} }
mocker.patch('freqtrade.exchange.Exchange.exchange_has', MagicMock(return_value=True)) mocker.patch('freqtrade.exchange.Exchange.exchange_has', MagicMock(return_value=True))
@ -855,9 +856,9 @@ def test_agefilter_min_days_listed_too_large(mocker, default_conf, markets, tick
def test_agefilter_caching(mocker, markets, whitelist_conf_agefilter, tickers, ohlcv_history): def test_agefilter_caching(mocker, markets, whitelist_conf_agefilter, tickers, ohlcv_history):
with time_machine.travel("2021-09-01 05:00:00 +00:00") as t: with time_machine.travel("2021-09-01 05:00:00 +00:00") as t:
ohlcv_data = { ohlcv_data = {
('ETH/BTC', '1d', ''): ohlcv_history, ('ETH/BTC', '1d', CandleType.SPOT_): ohlcv_history,
('TKN/BTC', '1d', ''): ohlcv_history, ('TKN/BTC', '1d', CandleType.SPOT_): ohlcv_history,
('LTC/BTC', '1d', ''): ohlcv_history, ('LTC/BTC', '1d', CandleType.SPOT_): ohlcv_history,
} }
mocker.patch.multiple( mocker.patch.multiple(
'freqtrade.exchange.Exchange', 'freqtrade.exchange.Exchange',
@ -879,10 +880,10 @@ def test_agefilter_caching(mocker, markets, whitelist_conf_agefilter, tickers, o
assert freqtrade.exchange.refresh_latest_ohlcv.call_count == 2 assert freqtrade.exchange.refresh_latest_ohlcv.call_count == 2
ohlcv_data = { ohlcv_data = {
('ETH/BTC', '1d', ''): ohlcv_history, ('ETH/BTC', '1d', CandleType.SPOT_): ohlcv_history,
('TKN/BTC', '1d', ''): ohlcv_history, ('TKN/BTC', '1d', CandleType.SPOT_): ohlcv_history,
('LTC/BTC', '1d', ''): ohlcv_history, ('LTC/BTC', '1d', CandleType.SPOT_): ohlcv_history,
('XRP/BTC', '1d', ''): ohlcv_history.iloc[[0]], ('XRP/BTC', '1d', CandleType.SPOT_): ohlcv_history.iloc[[0]],
} }
mocker.patch('freqtrade.exchange.Exchange.refresh_latest_ohlcv', return_value=ohlcv_data) mocker.patch('freqtrade.exchange.Exchange.refresh_latest_ohlcv', return_value=ohlcv_data)
freqtrade.pairlists.refresh_pairlist() freqtrade.pairlists.refresh_pairlist()
@ -900,10 +901,10 @@ def test_agefilter_caching(mocker, markets, whitelist_conf_agefilter, tickers, o
t.move_to("2021-09-03 01:00:00 +00:00") t.move_to("2021-09-03 01:00:00 +00:00")
# Called once for XRP/BTC # Called once for XRP/BTC
ohlcv_data = { ohlcv_data = {
('ETH/BTC', '1d', ''): ohlcv_history, ('ETH/BTC', '1d', CandleType.SPOT_): ohlcv_history,
('TKN/BTC', '1d', ''): ohlcv_history, ('TKN/BTC', '1d', CandleType.SPOT_): ohlcv_history,
('LTC/BTC', '1d', ''): ohlcv_history, ('LTC/BTC', '1d', CandleType.SPOT_): ohlcv_history,
('XRP/BTC', '1d', ''): ohlcv_history, ('XRP/BTC', '1d', CandleType.SPOT_): ohlcv_history,
} }
mocker.patch('freqtrade.exchange.Exchange.refresh_latest_ohlcv', return_value=ohlcv_data) mocker.patch('freqtrade.exchange.Exchange.refresh_latest_ohlcv', return_value=ohlcv_data)
freqtrade.pairlists.refresh_pairlist() freqtrade.pairlists.refresh_pairlist()
@ -964,12 +965,12 @@ def test_rangestabilityfilter_caching(mocker, markets, default_conf, tickers, oh
get_tickers=tickers get_tickers=tickers
) )
ohlcv_data = { ohlcv_data = {
('ETH/BTC', '1d', ''): ohlcv_history, ('ETH/BTC', '1d', CandleType.SPOT_): ohlcv_history,
('TKN/BTC', '1d', ''): ohlcv_history, ('TKN/BTC', '1d', CandleType.SPOT_): ohlcv_history,
('LTC/BTC', '1d', ''): ohlcv_history, ('LTC/BTC', '1d', CandleType.SPOT_): ohlcv_history,
('XRP/BTC', '1d', ''): ohlcv_history, ('XRP/BTC', '1d', CandleType.SPOT_): ohlcv_history,
('HOT/BTC', '1d', ''): ohlcv_history, ('HOT/BTC', '1d', CandleType.SPOT_): ohlcv_history,
('BLK/BTC', '1d', ''): ohlcv_history, ('BLK/BTC', '1d', CandleType.SPOT_): ohlcv_history,
} }
mocker.patch.multiple( mocker.patch.multiple(
'freqtrade.exchange.Exchange', 'freqtrade.exchange.Exchange',

View File

@ -5,6 +5,7 @@ import pandas as pd
import pytest import pytest
from freqtrade.data.dataprovider import DataProvider from freqtrade.data.dataprovider import DataProvider
from freqtrade.enums.candletype import CandleType
from freqtrade.strategy import (merge_informative_pair, stoploss_from_absolute, stoploss_from_open, from freqtrade.strategy import (merge_informative_pair, stoploss_from_absolute, stoploss_from_open,
timeframe_to_minutes) timeframe_to_minutes)
from tests.conftest import get_patched_exchange from tests.conftest import get_patched_exchange
@ -151,18 +152,18 @@ def test_informative_decorator(mocker, default_conf):
test_data_30m = generate_test_data('30m', 40) test_data_30m = generate_test_data('30m', 40)
test_data_1h = generate_test_data('1h', 40) test_data_1h = generate_test_data('1h', 40)
data = { data = {
('XRP/USDT', '5m', ''): test_data_5m, ('XRP/USDT', '5m', CandleType.SPOT_): test_data_5m,
('XRP/USDT', '30m', ''): test_data_30m, ('XRP/USDT', '30m', CandleType.SPOT_): test_data_30m,
('XRP/USDT', '1h', ''): test_data_1h, ('XRP/USDT', '1h', CandleType.SPOT_): test_data_1h,
('LTC/USDT', '5m', ''): test_data_5m, ('LTC/USDT', '5m', CandleType.SPOT_): test_data_5m,
('LTC/USDT', '30m', ''): test_data_30m, ('LTC/USDT', '30m', CandleType.SPOT_): test_data_30m,
('LTC/USDT', '1h', ''): test_data_1h, ('LTC/USDT', '1h', CandleType.SPOT_): test_data_1h,
('NEO/USDT', '30m', ''): test_data_30m, ('NEO/USDT', '30m', CandleType.SPOT_): test_data_30m,
('NEO/USDT', '5m', ''): test_data_5m, ('NEO/USDT', '5m', CandleType.SPOT_): test_data_5m,
('NEO/USDT', '1h', ''): test_data_1h, ('NEO/USDT', '1h', CandleType.SPOT_): test_data_1h,
('ETH/USDT', '1h', ''): test_data_1h, ('ETH/USDT', '1h', CandleType.SPOT_): test_data_1h,
('ETH/USDT', '30m', ''): test_data_30m, ('ETH/USDT', '30m', CandleType.SPOT_): test_data_30m,
('ETH/BTC', '1h', ''): test_data_1h, ('ETH/BTC', '1h', CandleType.SPOT_): test_data_1h,
} }
from .strats.informative_decorator_strategy import InformativeDecoratorTest from .strats.informative_decorator_strategy import InformativeDecoratorTest
default_conf['stake_currency'] = 'USDT' default_conf['stake_currency'] = 'USDT'
@ -174,9 +175,16 @@ def test_informative_decorator(mocker, default_conf):
]) ])
assert len(strategy._ft_informative) == 6 # Equal to number of decorators used assert len(strategy._ft_informative) == 6 # Equal to number of decorators used
informative_pairs = [('XRP/USDT', '1h', ''), ('LTC/USDT', '1h', ''), ('XRP/USDT', '30m', ''), informative_pairs = [
('LTC/USDT', '30m', ''), ('NEO/USDT', '1h', ''), ('NEO/USDT', '30m', ''), ('XRP/USDT', '1h', CandleType.SPOT_),
('NEO/USDT', '5m', ''), ('ETH/BTC', '1h', ''), ('ETH/USDT', '30m', '')] ('LTC/USDT', '1h', CandleType.SPOT_),
('XRP/USDT', '30m', CandleType.SPOT_),
('LTC/USDT', '30m', CandleType.SPOT_),
('NEO/USDT', '1h', CandleType.SPOT_),
('NEO/USDT', '30m', CandleType.SPOT_),
('NEO/USDT', '5m', CandleType.SPOT_),
('ETH/BTC', '1h', CandleType.SPOT_),
('ETH/USDT', '30m', CandleType.SPOT_)]
for inf_pair in informative_pairs: for inf_pair in informative_pairs:
assert inf_pair in strategy.gather_informative_pairs() assert inf_pair in strategy.gather_informative_pairs()
@ -186,7 +194,7 @@ def test_informative_decorator(mocker, default_conf):
side_effect=test_historic_ohlcv) side_effect=test_historic_ohlcv)
analyzed = strategy.advise_all_indicators( analyzed = strategy.advise_all_indicators(
{p: data[(p, strategy.timeframe, '')] for p in ('XRP/USDT', 'LTC/USDT')}) {p: data[(p, strategy.timeframe, CandleType.SPOT_)] for p in ('XRP/USDT', 'LTC/USDT')})
expected_columns = [ expected_columns = [
'rsi_1h', 'rsi_30m', # Stacked informative decorators 'rsi_1h', 'rsi_30m', # Stacked informative decorators
'neo_usdt_rsi_1h', # NEO 1h informative 'neo_usdt_rsi_1h', # NEO 1h informative