From 22733e44bf282ae558962e2d62339c3a4d4f5921 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sat, 5 Oct 2019 15:34:31 +0200 Subject: [PATCH] Add tests for --fee --- freqtrade/configuration/configuration.py | 2 +- tests/optimize/test_backtesting.py | 50 ++++++++++++++---------- tests/optimize/test_edge_cli.py | 10 +++++ tests/test_configuration.py | 2 +- 4 files changed, 42 insertions(+), 22 deletions(-) diff --git a/freqtrade/configuration/configuration.py b/freqtrade/configuration/configuration.py index ccbc41f34a3..df461a5cab7 100644 --- a/freqtrade/configuration/configuration.py +++ b/freqtrade/configuration/configuration.py @@ -328,7 +328,7 @@ def _args_to_config(self, config: Dict[str, Any], argname: str, configuration instead of the content) """ if (argname in self.args and self.args[argname] is not None - and self.args[argname] is not False): + and self.args[argname] is not False): config.update({argname: self.args[argname]}) if logfun: diff --git a/tests/optimize/test_backtesting.py b/tests/optimize/test_backtesting.py index fa40809d8c5..ff3d14541d5 100644 --- a/tests/optimize/test_backtesting.py +++ b/tests/optimize/test_backtesting.py @@ -26,6 +26,21 @@ patched_configuration_load_config_file) +ORDER_TYPES = [ + { + 'buy': 'limit', + 'sell': 'limit', + 'stoploss': 'limit', + 'stoploss_on_exchange': False + }, + { + 'buy': 'limit', + 'sell': 'limit', + 'stoploss': 'limit', + 'stoploss_on_exchange': True + }] + + def trim_dictlist(dict_list, num): new = {} for pair, pair_data in dict_list.items(): @@ -211,7 +226,8 @@ def test_setup_bt_configuration_with_arguments(mocker, default_conf, caplog) -> '--disable-max-market-positions', '--timerange', ':100', '--export', '/bar/foo', - '--export-filename', 'foo_bar.json' + '--export-filename', 'foo_bar.json', + '--fee', '0', ] config = setup_configuration(get_args(args), RunMode.BACKTEST) @@ -243,6 +259,9 @@ def test_setup_bt_configuration_with_arguments(mocker, default_conf, caplog) -> assert 'exportfilename' in config assert log_has('Storing backtest results to {} ...'.format(config['exportfilename']), caplog) + assert 'fee' in config + assert log_has('Parameter --fee detected, setting fee to: {} ...'.format(config['fee']), caplog) + def test_setup_configuration_unlimited_stake_amount(mocker, default_conf, caplog) -> None: default_conf['stake_amount'] = constants.UNLIMITED_STAKE_AMOUNT @@ -277,21 +296,6 @@ def test_start(mocker, fee, default_conf, caplog) -> None: assert start_mock.call_count == 1 -ORDER_TYPES = [ - { - 'buy': 'limit', - 'sell': 'limit', - 'stoploss': 'limit', - 'stoploss_on_exchange': False - }, - { - 'buy': 'limit', - 'sell': 'limit', - 'stoploss': 'limit', - 'stoploss_on_exchange': True - }] - - @pytest.mark.parametrize("order_types", ORDER_TYPES) def test_backtesting_init(mocker, default_conf, order_types) -> None: """ @@ -314,10 +318,6 @@ def test_backtesting_init(mocker, default_conf, order_types) -> None: def test_backtesting_init_no_ticker_interval(mocker, default_conf, caplog) -> None: - """ - Check that stoploss_on_exchange is set to False while backtesting - since backtesting assumes a perfect stoploss anyway. - """ patch_exchange(mocker) del default_conf['ticker_interval'] default_conf['strategy_list'] = ['DefaultStrategy', @@ -330,6 +330,16 @@ def test_backtesting_init_no_ticker_interval(mocker, default_conf, caplog) -> No "or as cli argument `--ticker-interval 5m`", caplog) +def test_tickerdata_with_fee(default_conf, mocker, testdatadir) -> None: + patch_exchange(mocker) + default_conf['fee'] = 0.1234 + + fee_mock = mocker.patch('freqtrade.exchange.Exchange.get_fee', MagicMock(return_value=0.5)) + backtesting = Backtesting(default_conf) + assert backtesting.fee == 0.1234 + assert fee_mock.call_count == 0 + + def test_tickerdata_to_dataframe_bt(default_conf, mocker, testdatadir) -> None: patch_exchange(mocker) timerange = TimeRange(None, 'line', 0, -100) diff --git a/tests/optimize/test_edge_cli.py b/tests/optimize/test_edge_cli.py index 97103da55d6..2c45a8d512b 100644 --- a/tests/optimize/test_edge_cli.py +++ b/tests/optimize/test_edge_cli.py @@ -98,6 +98,16 @@ def test_edge_init(mocker, edge_conf) -> None: assert callable(edge_cli.edge.calculate) +def test_edge_init_fee(mocker, edge_conf) -> None: + patch_exchange(mocker) + edge_conf['fee'] = 0.1234 + edge_conf['stake_amount'] = 20 + fee_mock = mocker.patch('freqtrade.exchange.Exchange.get_fee', MagicMock(return_value=0.5)) + edge_cli = EdgeCli(edge_conf) + assert edge_cli.edge.fee == 0.1234 + assert fee_mock.call_count == 0 + + def test_generate_edge_table(edge_conf, mocker): patch_exchange(mocker) edge_cli = EdgeCli(edge_conf) diff --git a/tests/test_configuration.py b/tests/test_configuration.py index 0f2d6a50adf..6d2c0ed005e 100644 --- a/tests/test_configuration.py +++ b/tests/test_configuration.py @@ -403,7 +403,7 @@ def test_setup_configuration_with_arguments(mocker, default_conf, caplog) -> Non assert log_has('Parameter -i/--ticker-interval detected ... Using ticker_interval: 1m ...', caplog) - assert 'position_stacking'in config + assert 'position_stacking' in config assert log_has('Parameter --enable-position-stacking detected ...', caplog) assert 'use_max_market_positions' in config