Change ticker format to ccxt in backtesting and optimize tests

This commit is contained in:
enenn 2018-04-09 20:21:54 +02:00
parent 261522446e
commit c3d00a8825
2 changed files with 44 additions and 31 deletions

View File

@ -50,39 +50,48 @@ def load_data_test(what):
datalen = len(pair) datalen = len(pair)
# Depending on the what parameter we now adjust the # Depending on the what parameter we now adjust the
# loaded data looks: # loaded data looks:
# pair :: [{'O': 0.123, 'H': 0.123, 'L': 0.123, # pair :: [[ 1509836520000, unix timestamp in ms
# 'C': 0.123, 'V': 123.123, # 0.00162008, open
# 'T': '2017-11-04T23:02:00', 'BV': 0.123}] # 0.00162008, high
# 0.00162008, low
# 0.00162008, close
# 108.14853839 base volume
# ]]
base = 0.001 base = 0.001
if what == 'raise': if what == 'raise':
return {'UNITTEST/BTC': return {'UNITTEST/BTC': [
[{'T': pair[x]['T'], # Keep old dates [
'V': pair[x]['V'], # Keep old volume pair[x][0], # Keep old dates
'BV': pair[x]['BV'], # keep too x * base, # But replace O,H,L,C
'O': x * base, # But replace O,H,L,C x * base + 0.0001,
'H': x * base + 0.0001, x * base - 0.0001,
'L': x * base - 0.0001, x * base,
'C': x * base} for x in range(0, datalen)]} pair[x][5], # Keep old volume
] for x in range(0, datalen)
]}
if what == 'lower': if what == 'lower':
return {'UNITTEST/BTC': return {'UNITTEST/BTC': [
[{'T': pair[x]['T'], # Keep old dates [
'V': pair[x]['V'], # Keep old volume pair[x][0], # Keep old dates
'BV': pair[x]['BV'], # keep too 1 - x * base, # But replace O,H,L,C
'O': 1 - x * base, # But replace O,H,L,C 1 - x * base + 0.0001,
'H': 1 - x * base + 0.0001, 1 - x * base - 0.0001,
'L': 1 - x * base - 0.0001, 1 - x * base,
'C': 1 - x * base} for x in range(0, datalen)]} pair[x][5] # Keep old volume
] for x in range(0, datalen)
]}
if what == 'sine': if what == 'sine':
hz = 0.1 # frequency hz = 0.1 # frequency
return {'UNITTEST/BTC': return {'UNITTEST/BTC': [
[{'T': pair[x]['T'], # Keep old dates [
'V': pair[x]['V'], # Keep old volume pair[x][0], # Keep old dates
'BV': pair[x]['BV'], # keep too math.sin(x * hz) / 1000 + base, # But replace O,H,L,C
# But replace O,H,L,C math.sin(x * hz) / 1000 + base + 0.0001,
'O': math.sin(x * hz) / 1000 + base, math.sin(x * hz) / 1000 + base - 0.0001,
'H': math.sin(x * hz) / 1000 + base + 0.0001, math.sin(x * hz) / 1000 + base,
'L': math.sin(x * hz) / 1000 + base - 0.0001, pair[x][5] # Keep old volume
'C': math.sin(x * hz) / 1000 + base} for x in range(0, datalen)]} ] for x in range(0, datalen)
]}
return data return data
@ -403,6 +412,7 @@ def test_backtesting_start(default_conf, mocker, caplog) -> None:
""" """
Test Backtesting.start() method Test Backtesting.start() method
""" """
def get_timeframe(input1, input2): def get_timeframe(input1, input2):
return Arrow(2017, 11, 14, 21, 17), Arrow(2017, 11, 14, 22, 59) return Arrow(2017, 11, 14, 21, 17), Arrow(2017, 11, 14, 22, 59)

View File

@ -182,7 +182,10 @@ def test_download_backtesting_testdata(ticker_history, mocker) -> None:
def test_download_backtesting_testdata2(mocker) -> None: def test_download_backtesting_testdata2(mocker) -> None:
tick = [{'T': 'bar'}, {'T': 'foo'}] tick = [
[1509836520000, 0.00162008, 0.00162008, 0.00162008, 0.00162008, 108.14853839],
[1509836580000, 0.00161, 0.00161, 0.00161, 0.00161, 82.390199]
]
mocker.patch('freqtrade.misc.file_dump_json', return_value=None) mocker.patch('freqtrade.misc.file_dump_json', return_value=None)
mocker.patch('freqtrade.optimize.__init__.get_ticker_history', return_value=tick) mocker.patch('freqtrade.optimize.__init__.get_ticker_history', return_value=tick)
assert download_backtesting_testdata(None, pair="UNITTEST/BTC", interval='1m') assert download_backtesting_testdata(None, pair="UNITTEST/BTC", interval='1m')