From de33d69eed25c305196deee0deb4bf9c80db72e1 Mon Sep 17 00:00:00 2001 From: Janne Sinivirta Date: Mon, 25 Dec 2017 13:07:50 +0200 Subject: [PATCH] Lint fixes (#236) * correct docstring * add type annotation to trade_count_lock * fix indentations * allow globals in hyperopt.py * fix import order * simplify asserts * use proper variable name * simplify condition * fix path operation that fails on windows --- freqtrade/main.py | 7 +++---- freqtrade/optimize/__init__.py | 2 +- freqtrade/optimize/backtesting.py | 6 +++--- freqtrade/optimize/hyperopt.py | 4 ++-- freqtrade/tests/test_optimize_backtesting.py | 9 ++++----- 5 files changed, 13 insertions(+), 15 deletions(-) diff --git a/freqtrade/main.py b/freqtrade/main.py index 31a4c4c55..a3a5d49b5 100755 --- a/freqtrade/main.py +++ b/freqtrade/main.py @@ -78,8 +78,8 @@ def _process(dynamic_whitelist: Optional[int] = 0) -> bool: 'Checked all whitelisted currencies. ' 'Found no suitable entry positions for buying. Will keep looking ...' ) - except DependencyException as e: - logger.warning('Unable to create trade: %s', e) + except DependencyException as exception: + logger.warning('Unable to create trade: %s', exception) for trade in trades: # Get order details for actual price per unit @@ -291,8 +291,7 @@ def gen_pair_whitelist(base_currency: str, topn: int = 20, key: str = 'BaseVolum reverse=True ) - # topn must be greater than 0 - if not topn > 0: + if topn <= 0: topn = 20 return [s['MarketName'].replace('-', '_') for s in summaries[:topn]] diff --git a/freqtrade/optimize/__init__.py b/freqtrade/optimize/__init__.py index e94fd913c..a77576a27 100644 --- a/freqtrade/optimize/__init__.py +++ b/freqtrade/optimize/__init__.py @@ -58,7 +58,7 @@ def preprocess(tickerdata: Dict[str, List]) -> Dict[str, DataFrame]: def testdata_path() -> str: """Return the path where testdata files are stored""" - return os.path.abspath(os.path.dirname(__file__)) + '/../tests/testdata' + return os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'tests', 'testdata')) def download_pairs(pairs: List[str]) -> bool: diff --git a/freqtrade/optimize/backtesting.py b/freqtrade/optimize/backtesting.py index 5dc1c3a3d..2684d2576 100644 --- a/freqtrade/optimize/backtesting.py +++ b/freqtrade/optimize/backtesting.py @@ -68,14 +68,14 @@ def backtest(stake_amount: float, processed: Dict[str, DataFrame], max_open_trades: int = 0, realistic: bool = True) -> DataFrame: """ Implements backtesting functionality - :param config: config to use + :param stake_amount: btc amount to use for each trade :param processed: a processed dictionary with format {pair, data} :param max_open_trades: maximum number of concurrent trades (default: 0, disabled) :param realistic: do we try to simulate realistic trades? (default: True) :return: DataFrame """ trades = [] - trade_count_lock = {} + trade_count_lock: dict = {} exchange._API = Bittrex({'key': '', 'secret': ''}) for pair, pair_data in processed.items(): pair_data['buy'], pair_data['sell'] = 0, 0 @@ -120,7 +120,7 @@ def backtest(stake_amount: float, processed: Dict[str, DataFrame], current_profit_percent, current_profit_BTC, row2.Index - row.Index - ) + ) ) break labels = ['currency', 'profit_percent', 'profit_BTC', 'duration'] diff --git a/freqtrade/optimize/hyperopt.py b/freqtrade/optimize/hyperopt.py index 89038a609..dcdafc946 100644 --- a/freqtrade/optimize/hyperopt.py +++ b/freqtrade/optimize/hyperopt.py @@ -1,4 +1,4 @@ -# pragma pylint: disable=missing-docstring,W0212 +# pragma pylint: disable=missing-docstring,W0212,W0603 import json @@ -159,7 +159,7 @@ def format_results(results: DataFrame): results.profit_percent.mean() * 100.0, results.profit_BTC.sum(), results.duration.mean() * 5, - ) + ) def buy_strategy_generator(params): diff --git a/freqtrade/tests/test_optimize_backtesting.py b/freqtrade/tests/test_optimize_backtesting.py index 2863961d3..558cfd8d1 100644 --- a/freqtrade/tests/test_optimize_backtesting.py +++ b/freqtrade/tests/test_optimize_backtesting.py @@ -1,10 +1,10 @@ # pragma pylint: disable=missing-docstring,W0212 +import os from freqtrade import exchange, optimize from freqtrade.exchange import Bittrex from freqtrade.optimize.backtesting import backtest from freqtrade.optimize.__init__ import testdata_path, download_pairs, download_backtesting_testdata -import os def test_backtest(default_conf, mocker): @@ -13,8 +13,7 @@ def test_backtest(default_conf, mocker): data = optimize.load_data(ticker_interval=5, pairs=['BTC_ETH']) results = backtest(default_conf['stake_amount'], optimize.preprocess(data), 10, True) - num_results = len(results) - assert num_results > 0 + assert not results.empty def test_1min_ticker_interval(default_conf, mocker): @@ -24,7 +23,7 @@ def test_1min_ticker_interval(default_conf, mocker): # Run a backtesting for an exiting 5min ticker_interval data = optimize.load_data(ticker_interval=1, pairs=['BTC_UNITEST']) results = backtest(default_conf['stake_amount'], optimize.preprocess(data), 1, True) - assert len(results) > 0 + assert not results.empty def test_backtest_with_new_pair(default_conf, ticker_history, mocker): @@ -43,7 +42,7 @@ def test_backtest_with_new_pair(default_conf, ticker_history, mocker): def test_testdata_path(): - assert str('freqtrade/optimize/../tests/testdata') in testdata_path() + assert os.path.join('freqtrade', 'tests', 'testdata') in testdata_path() def test_download_pairs(default_conf, ticker_history, mocker):