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
This commit is contained in:
parent
9959d53f5e
commit
de33d69eed
@ -78,8 +78,8 @@ def _process(dynamic_whitelist: Optional[int] = 0) -> bool:
|
|||||||
'Checked all whitelisted currencies. '
|
'Checked all whitelisted currencies. '
|
||||||
'Found no suitable entry positions for buying. Will keep looking ...'
|
'Found no suitable entry positions for buying. Will keep looking ...'
|
||||||
)
|
)
|
||||||
except DependencyException as e:
|
except DependencyException as exception:
|
||||||
logger.warning('Unable to create trade: %s', e)
|
logger.warning('Unable to create trade: %s', exception)
|
||||||
|
|
||||||
for trade in trades:
|
for trade in trades:
|
||||||
# Get order details for actual price per unit
|
# 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
|
reverse=True
|
||||||
)
|
)
|
||||||
|
|
||||||
# topn must be greater than 0
|
if topn <= 0:
|
||||||
if not topn > 0:
|
|
||||||
topn = 20
|
topn = 20
|
||||||
|
|
||||||
return [s['MarketName'].replace('-', '_') for s in summaries[:topn]]
|
return [s['MarketName'].replace('-', '_') for s in summaries[:topn]]
|
||||||
|
@ -58,7 +58,7 @@ def preprocess(tickerdata: Dict[str, List]) -> Dict[str, DataFrame]:
|
|||||||
|
|
||||||
def testdata_path() -> str:
|
def testdata_path() -> str:
|
||||||
"""Return the path where testdata files are stored"""
|
"""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:
|
def download_pairs(pairs: List[str]) -> bool:
|
||||||
|
@ -68,14 +68,14 @@ def backtest(stake_amount: float, processed: Dict[str, DataFrame],
|
|||||||
max_open_trades: int = 0, realistic: bool = True) -> DataFrame:
|
max_open_trades: int = 0, realistic: bool = True) -> DataFrame:
|
||||||
"""
|
"""
|
||||||
Implements backtesting functionality
|
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 processed: a processed dictionary with format {pair, data}
|
||||||
:param max_open_trades: maximum number of concurrent trades (default: 0, disabled)
|
:param max_open_trades: maximum number of concurrent trades (default: 0, disabled)
|
||||||
:param realistic: do we try to simulate realistic trades? (default: True)
|
:param realistic: do we try to simulate realistic trades? (default: True)
|
||||||
:return: DataFrame
|
:return: DataFrame
|
||||||
"""
|
"""
|
||||||
trades = []
|
trades = []
|
||||||
trade_count_lock = {}
|
trade_count_lock: dict = {}
|
||||||
exchange._API = Bittrex({'key': '', 'secret': ''})
|
exchange._API = Bittrex({'key': '', 'secret': ''})
|
||||||
for pair, pair_data in processed.items():
|
for pair, pair_data in processed.items():
|
||||||
pair_data['buy'], pair_data['sell'] = 0, 0
|
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_percent,
|
||||||
current_profit_BTC,
|
current_profit_BTC,
|
||||||
row2.Index - row.Index
|
row2.Index - row.Index
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
break
|
break
|
||||||
labels = ['currency', 'profit_percent', 'profit_BTC', 'duration']
|
labels = ['currency', 'profit_percent', 'profit_BTC', 'duration']
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# pragma pylint: disable=missing-docstring,W0212
|
# pragma pylint: disable=missing-docstring,W0212,W0603
|
||||||
|
|
||||||
|
|
||||||
import json
|
import json
|
||||||
@ -159,7 +159,7 @@ def format_results(results: DataFrame):
|
|||||||
results.profit_percent.mean() * 100.0,
|
results.profit_percent.mean() * 100.0,
|
||||||
results.profit_BTC.sum(),
|
results.profit_BTC.sum(),
|
||||||
results.duration.mean() * 5,
|
results.duration.mean() * 5,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def buy_strategy_generator(params):
|
def buy_strategy_generator(params):
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
# pragma pylint: disable=missing-docstring,W0212
|
# pragma pylint: disable=missing-docstring,W0212
|
||||||
|
|
||||||
|
import os
|
||||||
from freqtrade import exchange, optimize
|
from freqtrade import exchange, optimize
|
||||||
from freqtrade.exchange import Bittrex
|
from freqtrade.exchange import Bittrex
|
||||||
from freqtrade.optimize.backtesting import backtest
|
from freqtrade.optimize.backtesting import backtest
|
||||||
from freqtrade.optimize.__init__ import testdata_path, download_pairs, download_backtesting_testdata
|
from freqtrade.optimize.__init__ import testdata_path, download_pairs, download_backtesting_testdata
|
||||||
import os
|
|
||||||
|
|
||||||
|
|
||||||
def test_backtest(default_conf, mocker):
|
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'])
|
data = optimize.load_data(ticker_interval=5, pairs=['BTC_ETH'])
|
||||||
results = backtest(default_conf['stake_amount'], optimize.preprocess(data), 10, True)
|
results = backtest(default_conf['stake_amount'], optimize.preprocess(data), 10, True)
|
||||||
num_results = len(results)
|
assert not results.empty
|
||||||
assert num_results > 0
|
|
||||||
|
|
||||||
|
|
||||||
def test_1min_ticker_interval(default_conf, mocker):
|
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
|
# Run a backtesting for an exiting 5min ticker_interval
|
||||||
data = optimize.load_data(ticker_interval=1, pairs=['BTC_UNITEST'])
|
data = optimize.load_data(ticker_interval=1, pairs=['BTC_UNITEST'])
|
||||||
results = backtest(default_conf['stake_amount'], optimize.preprocess(data), 1, True)
|
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):
|
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():
|
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):
|
def test_download_pairs(default_conf, ticker_history, mocker):
|
||||||
|
Loading…
Reference in New Issue
Block a user