Change ticker interval from minutes as integer to string (1m, 5m, 1h,...)

This commit is contained in:
enenn
2018-03-24 10:21:59 +01:00
parent 616006caf8
commit db46ad6502
21 changed files with 89 additions and 70 deletions

View File

@@ -128,31 +128,32 @@ def ticker_sell_down():
@pytest.fixture
def health():
return MagicMock(return_value={
"ETH/BTC": {
'base': 'ETH',
'active': True,
'LastChecked': '2017-11-13T20:15:00.00',
'Notice': None
},
"TRST/BTC": {
'base': 'TRST',
'active': True,
'LastChecked': '2017-11-13T20:15:00.00',
'Notice': None
},
"SWT/BTC": {
'base': 'SWT',
'active': True,
'LastChecked': '2017-11-13T20:15:00.00',
'Notice': None
},
"BCC/BTC": {
'base': 'BCC',
'active': False,
'LastChecked': '2017-11-13T20:15:00.00',
'Notice': None
}})
return MagicMock(return_value=[{
'Currency': 'BTC',
'IsActive': True,
'LastChecked': '2017-11-13T20:15:00.00',
'Notice': None
}, {
'Currency': 'ETH',
'IsActive': True,
'LastChecked': '2017-11-13T20:15:00.00',
'Notice': None
}, {
'Currency': 'TRST',
'IsActive': True,
'LastChecked': '2017-11-13T20:15:00.00',
'Notice': None
}, {
'Currency': 'SWT',
'IsActive': True,
'LastChecked': '2017-11-13T20:15:00.00',
'Notice': None
}, {
'Currency': 'BCC',
'IsActive': False,
'LastChecked': '2017-11-13T20:15:00.00',
'Notice': None
}])
@pytest.fixture

View File

@@ -416,7 +416,7 @@ def test_populate_indicators() -> None:
"""
Test Hyperopt.populate_indicators()
"""
tick = load_tickerdata_file(None, 'UNITTEST/BTC', 1)
tick = load_tickerdata_file(None, 'UNITTEST/BTC', '1m')
tickerlist = {'UNITTEST/BTC': tick}
dataframes = _HYPEROPT.tickerdata_to_dataframe(tickerlist)
dataframe = _HYPEROPT.populate_indicators(dataframes['UNITTEST/BTC'])
@@ -431,7 +431,7 @@ def test_buy_strategy_generator() -> None:
"""
Test Hyperopt.buy_strategy_generator()
"""
tick = load_tickerdata_file(None, 'UNITTEST/BTC', 1)
tick = load_tickerdata_file(None, 'UNITTEST/BTC', '1m')
tickerlist = {'UNITTEST/BTC': tick}
dataframes = _HYPEROPT.tickerdata_to_dataframe(tickerlist)
dataframe = _HYPEROPT.populate_indicators(dataframes['UNITTEST/BTC'])

View File

@@ -167,7 +167,7 @@ def test_download_backtesting_testdata(ticker_history, mocker) -> None:
# Download a 1 min ticker file
file1 = 'freqtrade/tests/testdata/XEL_BTC-1m.json'
_backup_file(file1)
download_backtesting_testdata(None, pair="XEL/BTC", interval=1)
download_backtesting_testdata(None, pair="XEL/BTC", interval='1m')
assert os.path.isfile(file1) is True
_clean_test_file(file1)
@@ -175,7 +175,7 @@ def test_download_backtesting_testdata(ticker_history, mocker) -> None:
file2 = 'freqtrade/tests/testdata/STORJ_BTC-5m.json'
_backup_file(file2)
download_backtesting_testdata(None, pair="STORJ/BTC", interval=5)
download_backtesting_testdata(None, pair="STORJ/BTC", interval='5m')
assert os.path.isfile(file2) is True
_clean_test_file(file2)
@@ -184,8 +184,8 @@ def test_download_backtesting_testdata2(mocker) -> None:
tick = [{'T': 'bar'}, {'T': 'foo'}]
mocker.patch('freqtrade.misc.file_dump_json', return_value=None)
mocker.patch('freqtrade.optimize.__init__.get_ticker_history', return_value=tick)
assert download_backtesting_testdata(None, pair="UNITTEST/BTC", interval=1)
assert download_backtesting_testdata(None, pair="UNITTEST/BTC", interval=3)
assert download_backtesting_testdata(None, pair="UNITTEST/BTC", interval='1m')
assert download_backtesting_testdata(None, pair="UNITTEST/BTC", interval='3m')
def test_load_tickerdata_file() -> None:

View File

@@ -9,7 +9,7 @@ from freqtrade.strategy.default_strategy import DefaultStrategy, class_name
@pytest.fixture
def result():
with open('freqtrade/tests/testdata/ETH_BTC-1.json') as data_file:
with open('freqtrade/tests/testdata/ETH_BTC-1m.json') as data_file:
return Analyze.parse_ticker_dataframe(json.load(data_file))

View File

@@ -74,7 +74,7 @@ def test_returns_latest_buy_signal(mocker):
return_value=DataFrame([{'buy': 1, 'sell': 0, 'date': arrow.utcnow()}])
)
)
assert _ANALYZE.get_signal('ETH/BTC', 5) == (True, False)
assert _ANALYZE.get_signal('ETH/BTC', '5m') == (True, False)
mocker.patch.multiple(
'freqtrade.analyze.Analyze',
@@ -82,7 +82,7 @@ def test_returns_latest_buy_signal(mocker):
return_value=DataFrame([{'buy': 0, 'sell': 1, 'date': arrow.utcnow()}])
)
)
assert _ANALYZE.get_signal('ETH/BTC', 5) == (False, True)
assert _ANALYZE.get_signal('ETH/BTC', '5m') == (False, True)
def test_returns_latest_sell_signal(mocker):
@@ -94,7 +94,7 @@ def test_returns_latest_sell_signal(mocker):
)
)
assert _ANALYZE.get_signal('ETH/BTC', 5) == (False, True)
assert _ANALYZE.get_signal('ETH/BTC', '5m') == (False, True)
mocker.patch.multiple(
'freqtrade.analyze.Analyze',
@@ -102,13 +102,13 @@ def test_returns_latest_sell_signal(mocker):
return_value=DataFrame([{'sell': 0, 'buy': 1, 'date': arrow.utcnow()}])
)
)
assert _ANALYZE.get_signal('ETH/BTC', 5) == (True, False)
assert _ANALYZE.get_signal('ETH/BTC', '5m') == (True, False)
def test_get_signal_empty(default_conf, mocker, caplog):
caplog.set_level(logging.INFO)
mocker.patch('freqtrade.analyze.get_ticker_history', return_value=None)
assert (False, False) == _ANALYZE.get_signal('foo', int(default_conf['ticker_interval']))
assert (False, False) == _ANALYZE.get_signal('foo', default_conf['ticker_interval'])
assert log_has('Empty ticker history for pair foo', caplog.record_tuples)
@@ -121,7 +121,7 @@ def test_get_signal_exception_valueerror(default_conf, mocker, caplog):
side_effect=ValueError('xyz')
)
)
assert (False, False) == _ANALYZE.get_signal('foo', int(default_conf['ticker_interval']))
assert (False, False) == _ANALYZE.get_signal('foo', default_conf['ticker_interval'])
assert log_has('Unable to analyze ticker for pair foo: xyz', caplog.record_tuples)
@@ -134,7 +134,7 @@ def test_get_signal_empty_dataframe(default_conf, mocker, caplog):
return_value=DataFrame([])
)
)
assert (False, False) == _ANALYZE.get_signal('xyz', int(default_conf['ticker_interval']))
assert (False, False) == _ANALYZE.get_signal('xyz', default_conf['ticker_interval'])
assert log_has('Empty dataframe for pair xyz', caplog.record_tuples)
@@ -150,7 +150,7 @@ def test_get_signal_old_dataframe(default_conf, mocker, caplog):
return_value=DataFrame(ticks)
)
)
assert (False, False) == _ANALYZE.get_signal('xyz', int(default_conf['ticker_interval']))
assert (False, False) == _ANALYZE.get_signal('xyz', default_conf['ticker_interval'])
assert log_has(
'Outdated history for pair xyz. Last tick is 11 minutes old',
caplog.record_tuples
@@ -166,7 +166,7 @@ def test_get_signal_handles_exceptions(mocker):
)
)
assert _ANALYZE.get_signal('ETH/BTC', 5) == (False, False)
assert _ANALYZE.get_signal('ETH/BTC', '5m') == (False, False)
def test_parse_ticker_dataframe(ticker_history, ticker_history_without_bv):
@@ -188,7 +188,7 @@ def test_tickerdata_to_dataframe(default_conf) -> None:
analyze = Analyze(default_conf)
timerange = ((None, 'line'), None, -100)
tick = load_tickerdata_file(None, 'UNITTEST/BTC', 1, timerange=timerange)
tick = load_tickerdata_file(None, 'UNITTEST/BTC', '1m', timerange=timerange)
tickerlist = {'UNITTEST/BTC': tick}
data = analyze.tickerdata_to_dataframe(tickerlist)
assert len(data['UNITTEST/BTC']) == 100

View File

@@ -106,7 +106,7 @@ def test_parse_args_backtesting_custom() -> None:
'-c', 'test_conf.json',
'backtesting',
'--live',
'--ticker-interval', '1',
'--ticker-interval', '1m',
'--refresh-pairs-cached']
call_args = Arguments(args, '').get_parsed_arg()
assert call_args.config == 'test_conf.json'
@@ -114,7 +114,7 @@ def test_parse_args_backtesting_custom() -> None:
assert call_args.loglevel == logging.INFO
assert call_args.subparser == 'backtesting'
assert call_args.func is not None
assert call_args.ticker_interval == 1
assert call_args.ticker_interval == '1m'
assert call_args.refresh_pairs is True

View File

@@ -257,7 +257,7 @@ def test_setup_configuration_with_arguments(mocker, default_conf, caplog) -> Non
assert 'ticker_interval' in config
assert log_has('Parameter -i/--ticker-interval detected ...', caplog.record_tuples)
assert log_has(
'Using ticker_interval: 1 ...',
'Using ticker_interval: 1m ...',
caplog.record_tuples
)

View File

@@ -10,7 +10,7 @@ _pairs = ['ETH/BTC']
def load_dataframe_pair(pairs):
ld = load_data(None, ticker_interval=5, pairs=pairs)
ld = load_data(None, ticker_interval='5m', pairs=pairs)
assert isinstance(ld, dict)
assert isinstance(pairs[0], str)
dataframe = ld[pairs[0]]

View File

@@ -50,7 +50,7 @@ def test_common_datearray(default_conf, mocker) -> None:
mocker.patch('freqtrade.strategy.strategy.Strategy', MagicMock())
analyze = Analyze(default_conf)
tick = load_tickerdata_file(None, 'UNITTEST/BTC', 1)
tick = load_tickerdata_file(None, 'UNITTEST/BTC', '1m')
tickerlist = {'UNITTEST/BTC': tick}
dataframes = analyze.tickerdata_to_dataframe(tickerlist)

View File

@@ -17,7 +17,7 @@ parser.add_argument(
)
args = parser.parse_args(sys.argv[1:])
TICKER_INTERVALS = [1, 5] # ticker interval in minutes (currently implemented: 1 and 5)
TICKER_INTERVALS = ['1m', '5m'] # ticker interval in minutes (currently implemented: 1 and 5)
PAIRS = []
if args.pair: