From 3cee04fb8c7ba348d5e6a5ed8cb5b2cfdad1f33d Mon Sep 17 00:00:00 2001 From: Janne Sinivirta Date: Thu, 7 Jun 2018 12:56:39 +0300 Subject: [PATCH 1/2] bot should not repaint: do not include last partial candle in analysis --- freqtrade/analyze.py | 1 + freqtrade/tests/optimize/test_backtesting.py | 6 +++--- freqtrade/tests/test_analyze.py | 4 ++-- freqtrade/tests/test_misc.py | 2 +- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/freqtrade/analyze.py b/freqtrade/analyze.py index 5756b845c..fac922e9f 100644 --- a/freqtrade/analyze.py +++ b/freqtrade/analyze.py @@ -62,6 +62,7 @@ class Analyze(object): 'close': 'last', 'volume': 'max', }) + frame.drop(frame.tail(1).index, inplace=True) # eliminate partial candle return frame def populate_indicators(self, dataframe: DataFrame) -> DataFrame: diff --git a/freqtrade/tests/optimize/test_backtesting.py b/freqtrade/tests/optimize/test_backtesting.py index f924d21c6..33d9703de 100644 --- a/freqtrade/tests/optimize/test_backtesting.py +++ b/freqtrade/tests/optimize/test_backtesting.py @@ -317,7 +317,7 @@ def test_tickerdata_to_dataframe(default_conf, mocker) -> None: backtesting = Backtesting(default_conf) data = backtesting.tickerdata_to_dataframe(tickerlist) - assert len(data['UNITTEST/BTC']) == 100 + assert len(data['UNITTEST/BTC']) == 99 # Load Analyze to compare the result between Backtesting function and Analyze are the same analyze = Analyze(default_conf) @@ -341,7 +341,7 @@ def test_get_timeframe(default_conf, mocker) -> None: ) min_date, max_date = backtesting.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' + assert max_date.isoformat() == '2017-11-14T22:58:00+00:00' def test_generate_text_table(default_conf, mocker): @@ -478,7 +478,7 @@ def test_processed(default_conf, mocker) -> None: def test_backtest_pricecontours(default_conf, fee, mocker) -> None: mocker.patch('freqtrade.optimize.backtesting.exchange.get_fee', fee) - tests = [['raise', 17], ['lower', 0], ['sine', 17]] + tests = [['raise', 17], ['lower', 0], ['sine', 16]] for [contour, numres] in tests: simple_backtest(default_conf, contour, numres, mocker) diff --git a/freqtrade/tests/test_analyze.py b/freqtrade/tests/test_analyze.py index 418f31851..578eea6e6 100644 --- a/freqtrade/tests/test_analyze.py +++ b/freqtrade/tests/test_analyze.py @@ -46,7 +46,7 @@ def test_analyze_object() -> None: def test_dataframe_correct_length(result): dataframe = Analyze.parse_ticker_dataframe(result) - assert len(result.index) == len(dataframe.index) + assert len(result.index) - 1 == len(dataframe.index) # last partial candle removed def test_dataframe_correct_columns(result): @@ -188,4 +188,4 @@ def test_tickerdata_to_dataframe(default_conf) -> None: 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 + assert len(data['UNITTEST/BTC']) == 99 # partial candle was removed diff --git a/freqtrade/tests/test_misc.py b/freqtrade/tests/test_misc.py index 1c6723043..b57900428 100644 --- a/freqtrade/tests/test_misc.py +++ b/freqtrade/tests/test_misc.py @@ -39,7 +39,7 @@ def test_datesarray_to_datetimearray(ticker_history): assert dates[0].minute == 50 date_len = len(dates) - assert date_len == 3 + assert date_len == 2 def test_common_datearray(default_conf) -> None: From f5b47fbd8630fc601fd716609974c5269b2f6932 Mon Sep 17 00:00:00 2001 From: Janne Sinivirta Date: Thu, 7 Jun 2018 13:12:44 +0300 Subject: [PATCH 2/2] flake8 fixes --- freqtrade/analyze.py | 2 +- freqtrade/tests/test_analyze.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/freqtrade/analyze.py b/freqtrade/analyze.py index fac922e9f..f18ae291c 100644 --- a/freqtrade/analyze.py +++ b/freqtrade/analyze.py @@ -62,7 +62,7 @@ class Analyze(object): 'close': 'last', 'volume': 'max', }) - frame.drop(frame.tail(1).index, inplace=True) # eliminate partial candle + frame.drop(frame.tail(1).index, inplace=True) # eliminate partial candle return frame def populate_indicators(self, dataframe: DataFrame) -> DataFrame: diff --git a/freqtrade/tests/test_analyze.py b/freqtrade/tests/test_analyze.py index 578eea6e6..e8d0816aa 100644 --- a/freqtrade/tests/test_analyze.py +++ b/freqtrade/tests/test_analyze.py @@ -188,4 +188,4 @@ def test_tickerdata_to_dataframe(default_conf) -> None: 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']) == 99 # partial candle was removed + assert len(data['UNITTEST/BTC']) == 99 # partial candle was removed