Skip to content

Commit

Permalink
Add tests for --fee
Browse files Browse the repository at this point in the history
  • Loading branch information
xmatthias committed Oct 5, 2019
1 parent 82d4051 commit 22733e4
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 22 deletions.
2 changes: 1 addition & 1 deletion freqtrade/configuration/configuration.py
Expand Up @@ -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:
Expand Down
50 changes: 30 additions & 20 deletions tests/optimize/test_backtesting.py
Expand Up @@ -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():
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
"""
Expand All @@ -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',
Expand All @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions tests/optimize/test_edge_cli.py
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_configuration.py
Expand Up @@ -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
Expand Down

0 comments on commit 22733e4

Please sign in to comment.