Change ticker_interval from integer to string (1m, 5m, 1d, ...)
This commit is contained in:
@@ -29,8 +29,8 @@ def test_generate_text_table():
|
||||
'loss': [0, 0]
|
||||
}
|
||||
)
|
||||
print(generate_text_table({'ETH/BTC': {}}, results, 'BTC', 5))
|
||||
assert generate_text_table({'ETH/BTC': {}}, results, 'BTC', 5) == (
|
||||
print(generate_text_table({'ETH/BTC': {}}, results, 'BTC', '5m'))
|
||||
assert generate_text_table({'ETH/BTC': {}}, results, 'BTC', '5m') == (
|
||||
'pair buy count avg profit % total profit BTC avg duration profit loss\n' # noqa
|
||||
'------- ----------- -------------- ------------------ -------------- -------- ------\n' # noqa
|
||||
'ETH/BTC 2 15.00 0.60000000 100.0 2 0\n' # noqa
|
||||
@@ -39,7 +39,7 @@ def test_generate_text_table():
|
||||
|
||||
def test_get_timeframe(default_strategy):
|
||||
data = preprocess(optimize.load_data(
|
||||
None, ticker_interval=1, pairs=['UNITTEST/BTC']))
|
||||
None, ticker_interval='1m', pairs=['UNITTEST/BTC']))
|
||||
min_date, max_date = get_timeframe(data)
|
||||
assert min_date.isoformat() == '2017-11-04T23:02:00+00:00'
|
||||
assert max_date.isoformat() == '2017-11-14T22:59:00+00:00'
|
||||
@@ -51,7 +51,7 @@ def test_backtest(default_strategy, default_conf, mocker):
|
||||
get_fee=MagicMock(return_value=0.0025))
|
||||
exchange._API = ccxt.binance()
|
||||
|
||||
data = optimize.load_data(None, ticker_interval=5, pairs=['ETH/BTC'])
|
||||
data = optimize.load_data(None, ticker_interval='5m', pairs=['UNITTEST/BTC'])
|
||||
data = trim_dictlist(data, -200)
|
||||
results = backtest({'stake_amount': default_conf['stake_amount'],
|
||||
'processed': optimize.preprocess(data),
|
||||
@@ -67,7 +67,7 @@ def test_backtest_1min_ticker_interval(default_strategy, default_conf, mocker):
|
||||
exchange._API = ccxt.binance()
|
||||
|
||||
# Run a backtesting for an exiting 5min ticker_interval
|
||||
data = optimize.load_data(None, ticker_interval=1, pairs=['UNITTEST/BTC'])
|
||||
data = optimize.load_data(None, ticker_interval='1m', pairs=['UNITTEST/BTC'])
|
||||
data = trim_dictlist(data, -200)
|
||||
results = backtest({'stake_amount': default_conf['stake_amount'],
|
||||
'processed': optimize.preprocess(data),
|
||||
@@ -78,20 +78,20 @@ def test_backtest_1min_ticker_interval(default_strategy, default_conf, mocker):
|
||||
|
||||
def load_data_test(what):
|
||||
timerange = ((None, 'line'), None, -100)
|
||||
data = optimize.load_data(None, ticker_interval=1, pairs=['UNITTEST/BTC'], timerange=timerange)
|
||||
data = optimize.load_data(None, ticker_interval='1m',
|
||||
pairs=['UNITTEST/BTC'], timerange=timerange)
|
||||
pair = data['UNITTEST/BTC']
|
||||
datalen = len(pair)
|
||||
# Depending on the what parameter we now adjust the
|
||||
# loaded data looks:
|
||||
# pair :: [{'O': 0.123, 'H': 0.123, 'L': 0.123,
|
||||
# 'C': 0.123, 'V': 123.123,
|
||||
# 'T': '2017-11-04T23:02:00', 'BV': 0.123}]
|
||||
# 'T': '2017-11-04T23:02:00.000000'}]
|
||||
base = 0.001
|
||||
if what == 'raise':
|
||||
return {'UNITTEST/BTC':
|
||||
[{'T': pair[x]['T'], # Keep old dates
|
||||
'V': pair[x]['V'], # Keep old volume
|
||||
'BV': pair[x]['BV'], # keep too
|
||||
'O': x * base, # But replace O,H,L,C
|
||||
'H': x * base + 0.0001,
|
||||
'L': x * base - 0.0001,
|
||||
@@ -100,7 +100,6 @@ def load_data_test(what):
|
||||
return {'UNITTEST/BTC':
|
||||
[{'T': pair[x]['T'], # Keep old dates
|
||||
'V': pair[x]['V'], # Keep old volume
|
||||
'BV': pair[x]['BV'], # keep too
|
||||
'O': 1 - x * base, # But replace O,H,L,C
|
||||
'H': 1 - x * base + 0.0001,
|
||||
'L': 1 - x * base - 0.0001,
|
||||
@@ -110,7 +109,6 @@ def load_data_test(what):
|
||||
return {'UNITTEST/BTC':
|
||||
[{'T': pair[x]['T'], # Keep old dates
|
||||
'V': pair[x]['V'], # Keep old volume
|
||||
'BV': pair[x]['BV'], # keep too
|
||||
# But replace O,H,L,C
|
||||
'O': math.sin(x * hz) / 1000 + base,
|
||||
'H': math.sin(x * hz) / 1000 + base + 0.0001,
|
||||
@@ -131,23 +129,6 @@ def simple_backtest(config, contour, num_results):
|
||||
assert len(results) == num_results
|
||||
|
||||
|
||||
# Test backtest on offline data
|
||||
# loaded by freqdata/optimize/__init__.py::load_data()
|
||||
|
||||
|
||||
def test_backtest2(default_conf, mocker, default_strategy):
|
||||
mocker.patch.dict('freqtrade.main._CONF', default_conf)
|
||||
mocker.patch.multiple('freqtrade.optimize.backtesting.exchange',
|
||||
get_fee=MagicMock(return_value=0.0025))
|
||||
data = optimize.load_data(None, ticker_interval=5, pairs=['ETH/BTC'])
|
||||
data = trim_dictlist(data, -200)
|
||||
results = backtest({'stake_amount': default_conf['stake_amount'],
|
||||
'processed': optimize.preprocess(data),
|
||||
'max_open_trades': 10,
|
||||
'realistic': True})
|
||||
assert not results.empty
|
||||
|
||||
|
||||
def test_processed(default_conf, mocker, default_strategy):
|
||||
mocker.patch.dict('freqtrade.main._CONF', default_conf)
|
||||
dict_of_tickerrows = load_data_test('raise')
|
||||
@@ -170,7 +151,7 @@ def test_backtest_pricecontours(default_conf, mocker, default_strategy):
|
||||
|
||||
|
||||
def mocked_load_data(datadir, pairs=[], ticker_interval=0, refresh_pairs=False, timerange=None):
|
||||
tickerdata = optimize.load_tickerdata_file(datadir, 'UNITTEST/BTC', 1, timerange=timerange)
|
||||
tickerdata = optimize.load_tickerdata_file(datadir, 'UNITTEST/BTC', '1m', timerange=timerange)
|
||||
pairdata = {'UNITTEST/BTC': tickerdata}
|
||||
return pairdata
|
||||
|
||||
@@ -182,7 +163,7 @@ def test_backtest_start(default_conf, mocker, caplog):
|
||||
mocker.patch.multiple('freqtrade.optimize',
|
||||
load_data=mocked_load_data)
|
||||
args = MagicMock()
|
||||
args.ticker_interval = 1
|
||||
args.ticker_interval = '1m'
|
||||
args.level = 10
|
||||
args.live = False
|
||||
args.datadir = None
|
||||
|
@@ -6,8 +6,9 @@ import logging
|
||||
import ccxt
|
||||
import uuid
|
||||
from shutil import copyfile
|
||||
from freqtrade.strategy.strategy import Strategy
|
||||
from freqtrade import exchange, optimize
|
||||
from freqtrade.optimize.__init__ import make_testdata_path, download_pairs,\
|
||||
from freqtrade.optimize.__init__ import make_testdata_path, download_pairs, \
|
||||
download_backtesting_testdata, load_tickerdata_file, trim_tickerlist, file_dump_json
|
||||
|
||||
# Change this if modifying UNITTEST/BTC testdatafile
|
||||
@@ -53,11 +54,11 @@ def test_load_data_30min_ticker(default_conf, ticker_history, mocker, caplog):
|
||||
|
||||
file = 'freqtrade/tests/testdata/UNITTEST_BTC-30m.json'
|
||||
_backup_file(file, copy_file=True)
|
||||
optimize.load_data(None, pairs=['UNITTEST/BTC'], ticker_interval=30)
|
||||
optimize.load_data(None, pairs=['UNITTEST/BTC'], ticker_interval='30m')
|
||||
assert os.path.isfile(file) is True
|
||||
assert ('freqtrade.optimize',
|
||||
logging.INFO,
|
||||
'Download the pair: "ETH/BTC", Interval: 30 min') not in caplog.record_tuples
|
||||
'Downloading the pair: "ETH/BTC", Interval: 30 min') not in caplog.record_tuples
|
||||
_clean_test_file(file)
|
||||
|
||||
|
||||
@@ -67,13 +68,13 @@ def test_load_data_5min_ticker(default_conf, ticker_history, mocker, caplog):
|
||||
|
||||
exchange._API = ccxt.binance({'key': '', 'secret': ''})
|
||||
|
||||
file = 'freqtrade/tests/testdata/ETH_BTC-5.json'
|
||||
file = 'freqtrade/tests/testdata/ETH_BTC-5m.json'
|
||||
_backup_file(file, copy_file=True)
|
||||
optimize.load_data(None, pairs=['ETH/BTC'], ticker_interval=5)
|
||||
optimize.load_data(None, pairs=['ETH/BTC'], ticker_interval='5m')
|
||||
assert os.path.isfile(file) is True
|
||||
assert ('freqtrade.optimize',
|
||||
logging.INFO,
|
||||
'Download the pair: "ETH/BTC", Interval: 5 min') not in caplog.record_tuples
|
||||
'Downloading the pair: "ETH/BTC", Interval: 5 min') not in caplog.record_tuples
|
||||
_clean_test_file(file)
|
||||
|
||||
|
||||
@@ -83,9 +84,9 @@ def test_load_data_1min_ticker(default_conf, ticker_history, mocker, caplog):
|
||||
|
||||
exchange._API = ccxt.binance({'key': '', 'secret': ''})
|
||||
|
||||
file = 'freqtrade/tests/testdata/ETH_BTC-1.json'
|
||||
file = 'freqtrade/tests/testdata/ETH_BTC-1m.json'
|
||||
_backup_file(file, copy_file=True)
|
||||
optimize.load_data(None, ticker_interval=1, pairs=['ETH/BTC'])
|
||||
optimize.load_data(None, ticker_interval='1m', pairs=['ETH/BTC'])
|
||||
assert os.path.isfile(file) is True
|
||||
assert ('freqtrade.optimize',
|
||||
logging.INFO,
|
||||
@@ -99,13 +100,13 @@ def test_load_data_with_new_pair_1min(default_conf, ticker_history, mocker, capl
|
||||
|
||||
exchange._API = ccxt.binance({'key': '', 'secret': ''})
|
||||
|
||||
file = 'freqtrade/tests/testdata/MEME_BTC-1.json'
|
||||
file = 'freqtrade/tests/testdata/MEME_BTC-1m.json'
|
||||
_backup_file(file)
|
||||
optimize.load_data(None, ticker_interval=1, pairs=['MEME/BTC'])
|
||||
optimize.load_data(None, ticker_interval='1m', pairs=['MEME/BTC'])
|
||||
assert os.path.isfile(file) is True
|
||||
assert ('freqtrade.optimize',
|
||||
logging.INFO,
|
||||
'Download the pair: "MEME/BTC", Interval: 1 min') in caplog.record_tuples
|
||||
'Downloading the pair: "MEME/BTC", Interval: 1m') in caplog.record_tuples
|
||||
_clean_test_file(file)
|
||||
|
||||
|
||||
@@ -118,10 +119,10 @@ def test_download_pairs(default_conf, ticker_history, mocker):
|
||||
mocker.patch.dict('freqtrade.main._CONF', default_conf)
|
||||
exchange._API = ccxt.binance({'key': '', 'secret': ''})
|
||||
|
||||
file1_1 = 'freqtrade/tests/testdata/MEME_BTC-1.json'
|
||||
file1_5 = 'freqtrade/tests/testdata/MEME_BTC-5.json'
|
||||
file2_1 = 'freqtrade/tests/testdata/CFI_BTC-1.json'
|
||||
file2_5 = 'freqtrade/tests/testdata/CFI_BTC-5.json'
|
||||
file1_1 = 'freqtrade/tests/testdata/MEME_BTC-1m.json'
|
||||
file1_5 = 'freqtrade/tests/testdata/MEME_BTC-5m.json'
|
||||
file2_1 = 'freqtrade/tests/testdata/CFI_BTC-1m.json'
|
||||
file2_5 = 'freqtrade/tests/testdata/CFI_BTC-5m.json'
|
||||
|
||||
_backup_file(file1_1)
|
||||
_backup_file(file1_5)
|
||||
@@ -131,7 +132,7 @@ def test_download_pairs(default_conf, ticker_history, mocker):
|
||||
assert os.path.isfile(file1_1) is False
|
||||
assert os.path.isfile(file2_1) is False
|
||||
|
||||
assert download_pairs(None, pairs=['MEME/BTC', 'CFI/BTC'], ticker_interval=1) is True
|
||||
assert download_pairs(None, pairs=['MEME/BTC', 'CFI/BTC'], ticker_interval='1m') is True
|
||||
|
||||
assert os.path.isfile(file1_1) is True
|
||||
assert os.path.isfile(file2_1) is True
|
||||
@@ -143,7 +144,7 @@ def test_download_pairs(default_conf, ticker_history, mocker):
|
||||
assert os.path.isfile(file1_5) is False
|
||||
assert os.path.isfile(file2_5) is False
|
||||
|
||||
assert download_pairs(None, pairs=['MEME/BTC', 'CFI/BTC'], ticker_interval=5) is True
|
||||
assert download_pairs(None, pairs=['MEME/BTC', 'CFI/BTC'], ticker_interval='5m') is True
|
||||
|
||||
assert os.path.isfile(file1_5) is True
|
||||
assert os.path.isfile(file2_5) is True
|
||||
@@ -160,18 +161,18 @@ def test_download_pairs_exception(default_conf, ticker_history, mocker, caplog):
|
||||
mocker.patch.dict('freqtrade.main._CONF', default_conf)
|
||||
exchange._API = ccxt.binance({'key': '', 'secret': ''})
|
||||
|
||||
file1_1 = 'freqtrade/tests/testdata/MEME_BTC-1.json'
|
||||
file1_5 = 'freqtrade/tests/testdata/MEME_BTC-5.json'
|
||||
file1_1 = 'freqtrade/tests/testdata/MEME_BTC-1m.json'
|
||||
file1_5 = 'freqtrade/tests/testdata/MEME_BTC-5m.json'
|
||||
_backup_file(file1_1)
|
||||
_backup_file(file1_5)
|
||||
|
||||
download_pairs(None, pairs=['MEME/BTC'], ticker_interval=1)
|
||||
download_pairs(None, pairs=['MEME/BTC'], ticker_interval='1m')
|
||||
# clean files freshly downloaded
|
||||
_clean_test_file(file1_1)
|
||||
_clean_test_file(file1_5)
|
||||
assert ('freqtrade.optimize.__init__',
|
||||
logging.INFO,
|
||||
'Failed to download the pair: "MEME/BTC", Interval: 1 min') in caplog.record_tuples
|
||||
'Failed to download the pair: "MEME/BTC", Interval: 1m') in caplog.record_tuples
|
||||
|
||||
|
||||
def test_download_backtesting_testdata(default_conf, ticker_history, mocker):
|
||||
@@ -180,37 +181,37 @@ def test_download_backtesting_testdata(default_conf, ticker_history, mocker):
|
||||
exchange._API = ccxt.binance({'key': '', 'secret': ''})
|
||||
|
||||
# Download a 1 min ticker file
|
||||
file1 = 'freqtrade/tests/testdata/XEL_BTC-1.json'
|
||||
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)
|
||||
|
||||
# Download a 5 min ticker file
|
||||
file2 = 'freqtrade/tests/testdata/STORJ_BTC-5.json'
|
||||
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)
|
||||
|
||||
|
||||
def test_download_backtesting_testdata2(mocker):
|
||||
tick = [{'T': 'bar'}, {'T': 'foo'}]
|
||||
tick = [{'T': 'foo'}, {'T': 'bar'}] # invalid response
|
||||
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="UNITEST/BTC", interval=1)
|
||||
assert download_backtesting_testdata(None, pair="UNITEST/BTC", interval=3)
|
||||
assert download_backtesting_testdata(None, pair="UNITEST/BTC", interval='1m')
|
||||
assert download_backtesting_testdata(None, pair="UNITEST/BTC", interval='3m')
|
||||
|
||||
|
||||
def test_load_tickerdata_file():
|
||||
# 7 does not exist in either format.
|
||||
assert not load_tickerdata_file(None, 'UNITTEST/BTC', 7)
|
||||
# 1 exists only as a .json
|
||||
tickerdata = load_tickerdata_file(None, 'UNITTEST/BTC', 1)
|
||||
# 7m does not exist in either format.
|
||||
assert not load_tickerdata_file(None, 'UNITTEST/BTC', '7m')
|
||||
# 1m exists only as a .json
|
||||
tickerdata = load_tickerdata_file(None, 'UNITTEST/BTC', '1m')
|
||||
assert _BTC_UNITTEST_LENGTH == len(tickerdata)
|
||||
# 8 .json is empty and will fail if it's loaded. .json.gz is a copy of 1.json
|
||||
tickerdata = load_tickerdata_file(None, 'UNITTEST/BTC', 8)
|
||||
# 8m.json is empty and will fail if it's loaded. 8m.json.gz is a copy of 1m.json
|
||||
tickerdata = load_tickerdata_file(None, 'UNITTEST/BTC', '8m')
|
||||
assert _BTC_UNITTEST_LENGTH == len(tickerdata)
|
||||
|
||||
|
||||
@@ -218,19 +219,22 @@ def test_init(default_conf, mocker):
|
||||
conf = {'exchange': {'pair_whitelist': []}}
|
||||
mocker.patch('freqtrade.optimize.hyperopt_optimize_conf', return_value=conf)
|
||||
assert {} == optimize.load_data('', pairs=[], refresh_pairs=True,
|
||||
ticker_interval=int(default_conf['ticker_interval']))
|
||||
ticker_interval=default_conf['ticker_interval'])
|
||||
|
||||
|
||||
def test_tickerdata_to_dataframe():
|
||||
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}
|
||||
|
||||
strategy = Strategy()
|
||||
strategy.init({})
|
||||
data = optimize.tickerdata_to_dataframe(tickerlist)
|
||||
assert len(data['UNITTEST/BTC']) == 100
|
||||
|
||||
|
||||
def test_trim_tickerlist():
|
||||
with open('freqtrade/tests/testdata/ETH_BTC-1.json') as data_file:
|
||||
with open('freqtrade/tests/testdata/ETH_BTC-1m.json') as data_file:
|
||||
ticker_list = json.load(data_file)
|
||||
ticker_list_len = len(ticker_list)
|
||||
|
||||
@@ -275,7 +279,6 @@ def test_trim_tickerlist():
|
||||
|
||||
|
||||
def test_file_dump_json():
|
||||
|
||||
file = 'freqtrade/tests/testdata/test_{id}.json'.format(id=str(uuid.uuid4()))
|
||||
data = {'bar': 'foo'}
|
||||
|
||||
|
Reference in New Issue
Block a user