From 0082b7abddaf3716b9c2158643364db70df81a10 Mon Sep 17 00:00:00 2001 From: Janne Sinivirta Date: Sat, 18 Nov 2017 09:34:32 +0200 Subject: [PATCH 1/9] add missing module and class docstring --- freqtrade/analyze.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/freqtrade/analyze.py b/freqtrade/analyze.py index 347d127ad..538b400e7 100644 --- a/freqtrade/analyze.py +++ b/freqtrade/analyze.py @@ -1,3 +1,6 @@ +""" +Functions to analyze ticker data with indicators and produce buy and sell signals +""" from enum import Enum import logging from datetime import timedelta @@ -12,6 +15,7 @@ from freqtrade.vendor.qtpylib.indicators import awesome_oscillator, crossed_abov logger = logging.getLogger(__name__) class SignalType(Enum): + """ Enum to distinguish between buy and sell signals """ BUY = "buy" SELL = "sell" From 669ec30413b6a30a5d353ea1fab7fdb34683f661 Mon Sep 17 00:00:00 2001 From: Janne Sinivirta Date: Sat, 18 Nov 2017 09:34:57 +0200 Subject: [PATCH 2/9] remove unused import --- freqtrade/analyze.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/freqtrade/analyze.py b/freqtrade/analyze.py index 538b400e7..4ad2734f5 100644 --- a/freqtrade/analyze.py +++ b/freqtrade/analyze.py @@ -10,7 +10,7 @@ import talib.abstract as ta from pandas import DataFrame, to_datetime from freqtrade.exchange import get_ticker_history -from freqtrade.vendor.qtpylib.indicators import awesome_oscillator, crossed_above, crossed_below +from freqtrade.vendor.qtpylib.indicators import awesome_oscillator, crossed_above logger = logging.getLogger(__name__) From aced5cc3bac718fafd09484832bfb0df0f134002 Mon Sep 17 00:00:00 2001 From: Janne Sinivirta Date: Sat, 18 Nov 2017 09:43:42 +0200 Subject: [PATCH 3/9] rename variable to remove Mypy warning of type error --- freqtrade/tests/test_backtesting.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/freqtrade/tests/test_backtesting.py b/freqtrade/tests/test_backtesting.py index 78eeb1f72..13dbea4ab 100644 --- a/freqtrade/tests/test_backtesting.py +++ b/freqtrade/tests/test_backtesting.py @@ -47,11 +47,11 @@ def get_timeframe(data: Dict[str, Dict]) -> Tuple[arrow.Arrow, arrow.Arrow]: """ min_date, max_date = None, None for values in data.values(): - values = sorted(values, key=lambda d: arrow.get(d['T'])) - if not min_date or values[0]['T'] < min_date: - min_date = values[0]['T'] - if not max_date or values[-1]['T'] > max_date: - max_date = values[-1]['T'] + sorted_values = sorted(values, key=lambda d: arrow.get(d['T'])) + if not min_date or sorted_values[0]['T'] < min_date: + min_date = sorted_values[0]['T'] + if not max_date or sorted_values[-1]['T'] > max_date: + max_date = sorted_values[-1]['T'] return arrow.get(min_date), arrow.get(max_date) From 4e54b2739854a5b98bfcd16d3fb3f82cb13c63c7 Mon Sep 17 00:00:00 2001 From: Janne Sinivirta Date: Sat, 18 Nov 2017 09:44:28 +0200 Subject: [PATCH 4/9] use parentheses for multiline string instead of backslash --- freqtrade/tests/test_backtesting.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/freqtrade/tests/test_backtesting.py b/freqtrade/tests/test_backtesting.py index 13dbea4ab..e01c898c8 100644 --- a/freqtrade/tests/test_backtesting.py +++ b/freqtrade/tests/test_backtesting.py @@ -23,13 +23,13 @@ logger = logging.getLogger(__name__) def format_results(results: DataFrame): - return 'Made {} buys. Average profit {:.2f}%. ' \ - 'Total profit was {:.3f}. Average duration {:.1f} mins.'.format( - len(results.index), - results.profit.mean() * 100.0, - results.profit.sum(), - results.duration.mean() * 5, - ) + return ('Made {} buys. Average profit {:.2f}%. ' + 'Total profit was {:.3f}. Average duration {:.1f} mins.').format( + len(results.index), + results.profit.mean() * 100.0, + results.profit.sum(), + results.duration.mean() * 5, + ) def preprocess(backdata) -> Dict[str, DataFrame]: From 187fea0c280ae39e18d3fbd3d6bc5b4e91c511b1 Mon Sep 17 00:00:00 2001 From: Janne Sinivirta Date: Sat, 18 Nov 2017 09:45:01 +0200 Subject: [PATCH 5/9] disable bunch of meaningless pylint warnings --- freqtrade/tests/test_analyze.py | 2 +- freqtrade/tests/test_backtesting.py | 2 +- freqtrade/tests/test_hyperopt.py | 4 +++- freqtrade/tests/test_misc.py | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/freqtrade/tests/test_analyze.py b/freqtrade/tests/test_analyze.py index 499e7522a..45b186ecb 100644 --- a/freqtrade/tests/test_analyze.py +++ b/freqtrade/tests/test_analyze.py @@ -1,4 +1,4 @@ -# pragma pylint: disable=missing-docstring +# pragma pylint: disable=missing-docstring,W0621 from datetime import datetime import json import pytest diff --git a/freqtrade/tests/test_backtesting.py b/freqtrade/tests/test_backtesting.py index e01c898c8..5c86107e4 100644 --- a/freqtrade/tests/test_backtesting.py +++ b/freqtrade/tests/test_backtesting.py @@ -1,4 +1,4 @@ -# pragma pylint: disable=missing-docstring +# pragma pylint: disable=missing-docstring,W0212 import logging diff --git a/freqtrade/tests/test_hyperopt.py b/freqtrade/tests/test_hyperopt.py index 843057394..b96c2680f 100644 --- a/freqtrade/tests/test_hyperopt.py +++ b/freqtrade/tests/test_hyperopt.py @@ -1,4 +1,4 @@ -# pragma pylint: disable=missing-docstring +# pragma pylint: disable=missing-docstring,W0212 import logging import os from functools import reduce @@ -21,6 +21,7 @@ logging.disable(logging.DEBUG) # disable debug logs that slow backtesting a lot # set TARGET_TRADES to suit your number concurrent trades so its realistic to 20days of data TARGET_TRADES = 1300 TOTAL_TRIES = 4 +# pylint: disable=C0103 current_tries = 0 @@ -90,6 +91,7 @@ def test_hyperopt(backtest_conf, mocker): trade_loss = 1 - 0.4 * exp(-(trade_count - TARGET_TRADES) ** 2 / 10 ** 5.2) profit_loss = max(0, 1 - total_profit / 15000) # max profit 15000 + # pylint: disable=W0603 global current_tries current_tries += 1 print('{}/{}: {}'.format(current_tries, TOTAL_TRIES, result)) diff --git a/freqtrade/tests/test_misc.py b/freqtrade/tests/test_misc.py index c26ce7cc5..35ebf0979 100644 --- a/freqtrade/tests/test_misc.py +++ b/freqtrade/tests/test_misc.py @@ -1,4 +1,4 @@ -# pragma pylint: disable=missing-docstring +# pragma pylint: disable=missing-docstring,C0103 import time import os from argparse import Namespace From 4b08e3d5712365646bcb3e00e6c1b812adf4331b Mon Sep 17 00:00:00 2001 From: Janne Sinivirta Date: Sat, 18 Nov 2017 09:52:28 +0200 Subject: [PATCH 6/9] fix pylint warnings in __init__ files --- freqtrade/__init__.py | 1 + freqtrade/exchange/__init__.py | 6 ++++-- freqtrade/tests/__init__.py | 11 ++++++----- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/freqtrade/__init__.py b/freqtrade/__init__.py index 75254ebcc..522ceeeb0 100644 --- a/freqtrade/__init__.py +++ b/freqtrade/__init__.py @@ -1,3 +1,4 @@ +""" FreqTrade bot """ __version__ = '0.14.2' from . import main diff --git a/freqtrade/exchange/__init__.py b/freqtrade/exchange/__init__.py index a6e986f7b..4eed0a61d 100644 --- a/freqtrade/exchange/__init__.py +++ b/freqtrade/exchange/__init__.py @@ -1,3 +1,5 @@ +# pragma pylint: disable=W0603 +""" Cryptocurrency Exchanges support """ import enum import logging from random import randint @@ -77,7 +79,7 @@ def validate_pairs(pairs: List[str]) -> None: def buy(pair: str, rate: float, amount: float) -> str: if _CONF['dry_run']: global _DRY_RUN_OPEN_ORDERS - order_id = 'dry_run_buy_{}'.format(randint(0, 1e6)) + order_id = 'dry_run_buy_{}'.format(randint(0, 10**6)) _DRY_RUN_OPEN_ORDERS[order_id] = { 'pair': pair, 'rate': rate, @@ -95,7 +97,7 @@ def buy(pair: str, rate: float, amount: float) -> str: def sell(pair: str, rate: float, amount: float) -> str: if _CONF['dry_run']: global _DRY_RUN_OPEN_ORDERS - order_id = 'dry_run_sell_{}'.format(randint(0, 1e6)) + order_id = 'dry_run_sell_{}'.format(randint(0, 10**6)) _DRY_RUN_OPEN_ORDERS[order_id] = { 'pair': pair, 'rate': rate, diff --git a/freqtrade/tests/__init__.py b/freqtrade/tests/__init__.py index c6ac0797c..c5cc708c9 100644 --- a/freqtrade/tests/__init__.py +++ b/freqtrade/tests/__init__.py @@ -1,3 +1,4 @@ +# pragma pylint: disable=missing-docstring import json import os @@ -11,9 +12,9 @@ def load_backtesting_data(ticker_interval: int = 5): ] for pair in pairs: with open('{abspath}/testdata/{pair}-{ticker_interval}.json'.format( - abspath=path, - pair=pair, - ticker_interval=ticker_interval, - )) as fp: - result[pair] = json.load(fp) + abspath=path, + pair=pair, + ticker_interval=ticker_interval, + )) as tickerdata: + result[pair] = json.load(tickerdata) return result From 9ab81a987d046c977159b45243040884e4567859 Mon Sep 17 00:00:00 2001 From: Janne Sinivirta Date: Sat, 18 Nov 2017 09:58:55 +0200 Subject: [PATCH 7/9] fix pylint warnings in test_main.py --- freqtrade/tests/test_main.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/freqtrade/tests/test_main.py b/freqtrade/tests/test_main.py index 32a0bfb0a..4fe87ce6e 100644 --- a/freqtrade/tests/test_main.py +++ b/freqtrade/tests/test_main.py @@ -1,4 +1,4 @@ -# pragma pylint: disable=missing-docstring +# pragma pylint: disable=missing-docstring,C0103 import copy from unittest.mock import MagicMock @@ -26,7 +26,7 @@ def test_process_trade_creation(default_conf, ticker, health, mocker): init(default_conf, create_engine('sqlite://')) trades = Trade.query.filter(Trade.is_open.is_(True)).all() - assert len(trades) == 0 + assert not trades result = _process() assert result is True @@ -81,7 +81,8 @@ def test_process_runtime_error(default_conf, ticker, health, mocker): def test_process_trade_handling(default_conf, ticker, limit_buy_order, health, mocker): mocker.patch.dict('freqtrade.main._CONF', default_conf) mocker.patch.multiple('freqtrade.main.telegram', init=MagicMock(), send_msg=MagicMock()) - signal = mocker.patch('freqtrade.main.get_signal', side_effect=lambda *args: False if args[1] == SignalType.SELL else True) + mocker.patch('freqtrade.main.get_signal', + side_effect=lambda *args: False if args[1] == SignalType.SELL else True) mocker.patch.multiple('freqtrade.main.exchange', validate_pairs=MagicMock(), get_ticker=ticker, @@ -91,7 +92,7 @@ def test_process_trade_handling(default_conf, ticker, limit_buy_order, health, m init(default_conf, create_engine('sqlite://')) trades = Trade.query.filter(Trade.is_open.is_(True)).all() - assert len(trades) == 0 + assert not trades result = _process() assert result is True trades = Trade.query.filter(Trade.is_open.is_(True)).all() From 37a74b38badb2f0c8fe6c3bda777c40d5dc202b1 Mon Sep 17 00:00:00 2001 From: Janne Sinivirta Date: Sat, 18 Nov 2017 10:09:19 +0200 Subject: [PATCH 8/9] more little pylint fixes --- freqtrade/tests/test_exchange.py | 3 +-- freqtrade/tests/test_telegram.py | 5 ++--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/freqtrade/tests/test_exchange.py b/freqtrade/tests/test_exchange.py index 309ff4a5e..d0083af6a 100644 --- a/freqtrade/tests/test_exchange.py +++ b/freqtrade/tests/test_exchange.py @@ -1,4 +1,4 @@ -# pragma pylint: disable=missing-docstring +# pragma pylint: disable=missing-docstring,C0103 from unittest.mock import MagicMock import pytest @@ -33,4 +33,3 @@ def test_validate_pairs_not_compatible(default_conf, mocker): mocker.patch.dict('freqtrade.exchange._CONF', default_conf) with pytest.raises(RuntimeError, match=r'not compatible'): validate_pairs(default_conf['exchange']['pair_whitelist']) - diff --git a/freqtrade/tests/test_telegram.py b/freqtrade/tests/test_telegram.py index 63a01d429..f786a9702 100644 --- a/freqtrade/tests/test_telegram.py +++ b/freqtrade/tests/test_telegram.py @@ -1,10 +1,9 @@ -# pragma pylint: disable=missing-docstring, too-many-arguments, too-many-ancestors +# pragma pylint: disable=missing-docstring, too-many-arguments, too-many-ancestors, C0103 import re from datetime import datetime from random import randint from unittest.mock import MagicMock -import pytest from sqlalchemy import create_engine from telegram import Update, Message, Chat from telegram.error import NetworkError @@ -519,7 +518,7 @@ def test_send_msg(default_conf, mocker): init=MagicMock()) bot = MagicMock() send_msg('test', bot) - assert len(bot.method_calls) == 0 + assert not bot.method_calls bot.reset_mock() default_conf['telegram']['enabled'] = True From 57691c82b1625a801d5ef95489aa04ae76e67c35 Mon Sep 17 00:00:00 2001 From: Janne Sinivirta Date: Sat, 18 Nov 2017 10:13:14 +0200 Subject: [PATCH 9/9] whitelist TA-lib in pylint --- .pylintrc | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.pylintrc b/.pylintrc index a876357c4..65ed64830 100644 --- a/.pylintrc +++ b/.pylintrc @@ -1,3 +1,10 @@ +[MASTER] +extension-pkg-whitelist=numpy,talib + [BASIC] good-names=logger -ignore=vendor \ No newline at end of file +ignore=vendor + +[TYPECHECK] +ignored-modules=numpy,talib +