2018-11-14 18:14:34 +00:00
|
|
|
# pragma pylint: disable=missing-docstring, C0103, C0330
|
|
|
|
# pragma pylint: disable=protected-access, too-many-lines, invalid-name, too-many-arguments
|
|
|
|
|
2019-04-24 19:24:00 +00:00
|
|
|
from unittest.mock import MagicMock
|
|
|
|
|
|
|
|
from freqtrade.edge import PairInfo
|
2019-06-16 08:13:12 +00:00
|
|
|
from freqtrade.optimize import setup_configuration, start_edge
|
2019-05-25 18:06:18 +00:00
|
|
|
from freqtrade.optimize.edge_cli import EdgeCli
|
2018-12-25 13:35:48 +00:00
|
|
|
from freqtrade.state import RunMode
|
2019-09-08 07:54:15 +00:00
|
|
|
from tests.conftest import (get_args, log_has, log_has_re, patch_exchange,
|
|
|
|
patched_configuration_load_config_file)
|
2018-11-14 18:14:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_setup_configuration_without_arguments(mocker, default_conf, caplog) -> None:
|
2019-07-14 22:44:25 +00:00
|
|
|
patched_configuration_load_config_file(mocker, default_conf)
|
2018-11-14 18:14:34 +00:00
|
|
|
|
|
|
|
args = [
|
|
|
|
'--config', 'config.json',
|
|
|
|
'--strategy', 'DefaultStrategy',
|
|
|
|
'edge'
|
|
|
|
]
|
|
|
|
|
2019-05-28 17:25:01 +00:00
|
|
|
config = setup_configuration(get_args(args), RunMode.EDGE)
|
|
|
|
assert config['runmode'] == RunMode.EDGE
|
2018-12-25 13:35:48 +00:00
|
|
|
|
2018-11-14 18:14:34 +00:00
|
|
|
assert 'max_open_trades' in config
|
|
|
|
assert 'stake_currency' in config
|
|
|
|
assert 'stake_amount' in config
|
|
|
|
assert 'exchange' in config
|
|
|
|
assert 'pair_whitelist' in config['exchange']
|
|
|
|
assert 'datadir' in config
|
2019-08-11 18:16:52 +00:00
|
|
|
assert log_has('Using data directory: {} ...'.format(config['datadir']), caplog)
|
2018-11-14 18:14:34 +00:00
|
|
|
assert 'ticker_interval' in config
|
2019-08-11 18:16:52 +00:00
|
|
|
assert not log_has_re('Parameter -i/--ticker-interval detected .*', caplog)
|
2018-11-14 18:14:34 +00:00
|
|
|
|
|
|
|
assert 'timerange' not in config
|
|
|
|
assert 'stoploss_range' not in config
|
|
|
|
|
|
|
|
|
2019-01-01 13:07:40 +00:00
|
|
|
def test_setup_edge_configuration_with_arguments(mocker, edge_conf, caplog) -> None:
|
2019-07-14 22:44:25 +00:00
|
|
|
patched_configuration_load_config_file(mocker, edge_conf)
|
2019-07-11 22:41:09 +00:00
|
|
|
mocker.patch(
|
2019-07-12 00:26:27 +00:00
|
|
|
'freqtrade.configuration.configuration.create_datadir',
|
|
|
|
lambda c, x: x
|
2019-07-11 22:41:09 +00:00
|
|
|
)
|
2018-11-14 18:14:34 +00:00
|
|
|
|
|
|
|
args = [
|
|
|
|
'--config', 'config.json',
|
|
|
|
'--strategy', 'DefaultStrategy',
|
|
|
|
'--datadir', '/foo/bar',
|
|
|
|
'edge',
|
|
|
|
'--ticker-interval', '1m',
|
|
|
|
'--timerange', ':100',
|
|
|
|
'--stoplosses=-0.01,-0.10,-0.001'
|
|
|
|
]
|
|
|
|
|
2019-05-28 17:25:01 +00:00
|
|
|
config = setup_configuration(get_args(args), RunMode.EDGE)
|
2018-11-14 18:14:34 +00:00
|
|
|
assert 'max_open_trades' in config
|
|
|
|
assert 'stake_currency' in config
|
|
|
|
assert 'stake_amount' in config
|
|
|
|
assert 'exchange' in config
|
|
|
|
assert 'pair_whitelist' in config['exchange']
|
|
|
|
assert 'datadir' in config
|
2019-05-28 17:25:01 +00:00
|
|
|
assert config['runmode'] == RunMode.EDGE
|
2019-08-11 18:16:52 +00:00
|
|
|
assert log_has('Using data directory: {} ...'.format(config['datadir']), caplog)
|
2018-11-14 18:14:34 +00:00
|
|
|
assert 'ticker_interval' in config
|
2019-04-24 19:24:00 +00:00
|
|
|
assert log_has('Parameter -i/--ticker-interval detected ... Using ticker_interval: 1m ...',
|
2019-08-11 18:16:52 +00:00
|
|
|
caplog)
|
2018-11-14 18:14:34 +00:00
|
|
|
|
|
|
|
assert 'timerange' in config
|
2019-08-11 18:16:52 +00:00
|
|
|
assert log_has('Parameter --timerange detected: {} ...'.format(config['timerange']), caplog)
|
2018-11-14 18:14:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_start(mocker, fee, edge_conf, caplog) -> None:
|
|
|
|
start_mock = MagicMock()
|
|
|
|
mocker.patch('freqtrade.exchange.Exchange.get_fee', fee)
|
|
|
|
patch_exchange(mocker)
|
2018-11-15 09:31:56 +00:00
|
|
|
mocker.patch('freqtrade.optimize.edge_cli.EdgeCli.start', start_mock)
|
2019-07-14 22:44:25 +00:00
|
|
|
patched_configuration_load_config_file(mocker, edge_conf)
|
2019-07-11 21:39:42 +00:00
|
|
|
|
2018-11-14 18:14:34 +00:00
|
|
|
args = [
|
|
|
|
'--config', 'config.json',
|
|
|
|
'--strategy', 'DefaultStrategy',
|
|
|
|
'edge'
|
|
|
|
]
|
|
|
|
args = get_args(args)
|
2019-05-28 17:25:01 +00:00
|
|
|
start_edge(args)
|
2019-08-11 18:16:52 +00:00
|
|
|
assert log_has('Starting freqtrade in Edge mode', caplog)
|
2018-11-14 18:14:34 +00:00
|
|
|
assert start_mock.call_count == 1
|
|
|
|
|
|
|
|
|
|
|
|
def test_edge_init(mocker, edge_conf) -> None:
|
|
|
|
patch_exchange(mocker)
|
2019-06-15 11:04:15 +00:00
|
|
|
edge_conf['stake_amount'] = 20
|
2018-11-14 18:14:34 +00:00
|
|
|
edge_cli = EdgeCli(edge_conf)
|
|
|
|
assert edge_cli.config == edge_conf
|
2019-06-15 11:04:15 +00:00
|
|
|
assert edge_cli.config['stake_amount'] == 'unlimited'
|
2018-11-14 18:14:34 +00:00
|
|
|
assert callable(edge_cli.edge.calculate)
|
|
|
|
|
|
|
|
|
|
|
|
def test_generate_edge_table(edge_conf, mocker):
|
|
|
|
patch_exchange(mocker)
|
|
|
|
edge_cli = EdgeCli(edge_conf)
|
|
|
|
|
|
|
|
results = {}
|
2018-11-21 23:04:20 +00:00
|
|
|
results['ETH/BTC'] = PairInfo(-0.01, 0.60, 2, 1, 3, 10, 60)
|
|
|
|
|
2018-11-14 18:14:34 +00:00
|
|
|
assert edge_cli._generate_edge_table(results).count(':|') == 7
|
|
|
|
assert edge_cli._generate_edge_table(results).count('| ETH/BTC |') == 1
|
|
|
|
assert edge_cli._generate_edge_table(results).count(
|
|
|
|
'| risk reward ratio | required risk reward | expectancy |') == 1
|