Mock fee during testing as 0.0025

Ensures profit calculations does not vary if exchange fees change, which can cause tests to fail
This commit is contained in:
enenn 2018-03-25 22:59:58 +02:00
parent 0ae5b75f33
commit 12a84cc30b
4 changed files with 53 additions and 23 deletions

View File

@ -481,7 +481,11 @@ def test_processed() -> None:
assert col in cols
def test_backtest_pricecontours(default_conf) -> None:
def test_backtest_pricecontours(init_backtesting, default_conf, mocker) -> None:
mocker.patch(
'freqtrade.optimize.backtesting.exchange.get_fee',
MagicMock(return_value=0.0025)
)
tests = [['raise', 17], ['lower', 0], ['sine', 17]]
for [contour, numres] in tests:
simple_backtest(default_conf, contour, numres)
@ -521,7 +525,11 @@ def test_backtest_only_sell(default_conf):
assert results.empty
def test_backtest_alternate_buy_sell(default_conf):
def test_backtest_alternate_buy_sell(init_backtesting, default_conf, mocker):
mocker.patch(
'freqtrade.optimize.backtesting.exchange.get_fee',
MagicMock(return_value=0.0025)
)
backtest_conf = _make_backtest_conf(conf=default_conf, pair='UNITTEST/BTC')
results = _run_backtest_1(_trend_alternate, backtest_conf)
assert len(results) == 3
@ -530,6 +538,10 @@ def test_backtest_alternate_buy_sell(default_conf):
def test_backtest_record(default_conf, mocker):
names = []
records = []
mocker.patch(
'freqtrade.optimize.backtesting.exchange.get_fee',
MagicMock(return_value=0.0025)
)
mocker.patch(
'freqtrade.optimize.backtesting.file_dump_json',
new=lambda n, r: (names.append(n), records.append(r))

View File

@ -35,7 +35,8 @@ def test_rpc_trade_status(default_conf, ticker, mocker) -> None:
mocker.patch.multiple(
'freqtrade.freqtradebot.exchange',
validate_pairs=MagicMock(),
get_ticker=ticker
get_ticker=ticker,
get_fee=MagicMock(return_value=0.0025)
)
freqtradebot = FreqtradeBot(default_conf, create_engine('sqlite://'))
@ -83,7 +84,8 @@ def test_rpc_status_table(default_conf, ticker, mocker) -> None:
mocker.patch.multiple(
'freqtrade.freqtradebot.exchange',
validate_pairs=MagicMock(),
get_ticker=ticker
get_ticker=ticker,
get_fee=MagicMock(return_value=0.0025)
)
freqtradebot = FreqtradeBot(default_conf, create_engine('sqlite://'))
@ -117,7 +119,8 @@ def test_rpc_daily_profit(default_conf, update, ticker, limit_buy_order, limit_s
mocker.patch.multiple(
'freqtrade.freqtradebot.exchange',
validate_pairs=MagicMock(),
get_ticker=ticker
get_ticker=ticker,
get_fee=MagicMock(return_value=0.0025)
)
freqtradebot = FreqtradeBot(default_conf, create_engine('sqlite://'))
@ -173,7 +176,8 @@ def test_rpc_trade_statistics(
mocker.patch.multiple(
'freqtrade.freqtradebot.exchange',
validate_pairs=MagicMock(),
get_ticker=ticker
get_ticker=ticker,
get_fee=MagicMock(return_value=0.0025)
)
freqtradebot = FreqtradeBot(default_conf, create_engine('sqlite://'))
@ -235,7 +239,8 @@ def test_rpc_trade_statistics_closed(mocker, default_conf, ticker, ticker_sell_u
mocker.patch.multiple(
'freqtrade.freqtradebot.exchange',
validate_pairs=MagicMock(),
get_ticker=ticker
get_ticker=ticker,
get_fee=MagicMock(return_value=0.0025)
)
freqtradebot = FreqtradeBot(default_conf, create_engine('sqlite://'))
@ -253,7 +258,8 @@ def test_rpc_trade_statistics_closed(mocker, default_conf, ticker, ticker_sell_u
mocker.patch.multiple(
'freqtrade.freqtradebot.exchange',
validate_pairs=MagicMock(),
get_ticker=ticker_sell_up
get_ticker=ticker_sell_up,
get_fee=MagicMock(return_value=0.0025)
)
trade.update(limit_sell_order)
trade.close_date = datetime.utcnow()
@ -490,7 +496,8 @@ def test_performance_handle(default_conf, ticker, limit_buy_order,
'freqtrade.freqtradebot.exchange',
validate_pairs=MagicMock(),
get_balances=MagicMock(return_value=ticker),
get_ticker=ticker
get_ticker=ticker,
get_fee=MagicMock(return_value=0.0025)
)
freqtradebot = FreqtradeBot(default_conf, create_engine('sqlite://'))

View File

@ -333,7 +333,7 @@ def test_status_table_handle(default_conf, update, ticker, mocker) -> None:
'freqtrade.freqtradebot.exchange',
validate_pairs=MagicMock(),
get_ticker=ticker,
buy=MagicMock(return_value='mocked_order_id')
buy=MagicMock(return_value={'id': 'mocked_order_id'})
)
msg_mock = MagicMock()
mocker.patch.multiple(
@ -389,7 +389,7 @@ def test_daily_handle(default_conf, update, ticker, limit_buy_order,
'freqtrade.freqtradebot.exchange',
validate_pairs=MagicMock(),
get_ticker=ticker,
get_pair_detail_url=MagicMock()
get_fee=MagicMock(return_value=0.0025)
)
msg_mock = MagicMock()
mocker.patch.multiple(
@ -497,7 +497,8 @@ def test_profit_handle(default_conf, update, ticker, ticker_sell_up,
mocker.patch.multiple(
'freqtrade.freqtradebot.exchange',
validate_pairs=MagicMock(),
get_ticker=ticker
get_ticker=ticker,
get_fee=MagicMock(return_value=0.0025)
)
msg_mock = MagicMock()
mocker.patch.multiple(
@ -761,7 +762,8 @@ def test_forcesell_handle(default_conf, update, ticker, ticker_sell_up, mocker)
mocker.patch.multiple(
'freqtrade.freqtradebot.exchange',
validate_pairs=MagicMock(),
get_ticker=ticker
get_ticker=ticker,
get_fee=MagicMock(return_value=0.0025)
)
freqtradebot = FreqtradeBot(default_conf, create_engine('sqlite://'))
@ -800,7 +802,8 @@ def test_forcesell_down_handle(default_conf, update, ticker, ticker_sell_down, m
mocker.patch.multiple(
'freqtrade.freqtradebot.exchange',
validate_pairs=MagicMock(),
get_ticker=ticker
get_ticker=ticker,
get_fee=MagicMock(return_value=0.0025)
)
freqtradebot = FreqtradeBot(default_conf, create_engine('sqlite://'))
@ -844,7 +847,8 @@ def test_forcesell_all_handle(default_conf, update, ticker, mocker) -> None:
mocker.patch.multiple(
'freqtrade.freqtradebot.exchange',
validate_pairs=MagicMock(),
get_ticker=ticker
get_ticker=ticker,
get_fee=MagicMock(return_value=0.0025)
)
freqtradebot = FreqtradeBot(default_conf, create_engine('sqlite://'))
@ -923,7 +927,8 @@ def test_performance_handle(default_conf, update, ticker, limit_buy_order,
mocker.patch.multiple(
'freqtrade.freqtradebot.exchange',
validate_pairs=MagicMock(),
get_ticker=ticker
get_ticker=ticker,
get_fee=MagicMock(return_value=0.0025)
)
mocker.patch('freqtrade.freqtradebot.RPCManager', MagicMock())
freqtradebot = FreqtradeBot(default_conf, create_engine('sqlite://'))
@ -987,7 +992,7 @@ def test_count_handle(default_conf, update, ticker, mocker) -> None:
'freqtrade.freqtradebot.exchange',
validate_pairs=MagicMock(),
get_ticker=ticker,
buy=MagicMock(return_value='mocked_order_id')
buy=MagicMock(return_value={'id': 'mocked_order_id'})
)
freqtradebot = FreqtradeBot(default_conf, create_engine('sqlite://'))
telegram = Telegram(freqtradebot)

View File

@ -589,7 +589,8 @@ def test_handle_trade(default_conf, limit_buy_order, limit_sell_order, mocker) -
'last': 0.00001172
}),
buy=MagicMock(return_value={'id': 'mocked_limit_buy'}),
sell=MagicMock(return_value={'id': 'mocked_limit_sell'})
sell=MagicMock(return_value={'id': 'mocked_limit_sell'}),
get_fee=MagicMock(return_value=0.0025)
)
patch_coinmarketcap(mocker, value={'price_usd': 15000.0})
@ -782,7 +783,8 @@ def test_check_handle_timedout_buy(default_conf, ticker, limit_buy_order_old, mo
validate_pairs=MagicMock(),
get_ticker=ticker,
get_order=MagicMock(return_value=limit_buy_order_old),
cancel_order=cancel_order_mock
cancel_order=cancel_order_mock,
get_fee=MagicMock(return_value=0.0025)
)
freqtrade = FreqtradeBot(default_conf, create_engine('sqlite://'))
@ -996,7 +998,8 @@ def test_execute_sell_up(default_conf, ticker, ticker_sell_up, mocker) -> None:
mocker.patch.multiple(
'freqtrade.freqtradebot.exchange',
validate_pairs=MagicMock(),
get_ticker=ticker
get_ticker=ticker,
get_fee=MagicMock(return_value=0.0025)
)
mocker.patch('freqtrade.fiat_convert.CryptoToFiatConverter._find_price', return_value=15000.0)
freqtrade = FreqtradeBot(default_conf, create_engine('sqlite://'))
@ -1037,7 +1040,8 @@ def test_execute_sell_down(default_conf, ticker, ticker_sell_down, mocker) -> No
mocker.patch.multiple(
'freqtrade.freqtradebot.exchange',
validate_pairs=MagicMock(),
get_ticker=ticker
get_ticker=ticker,
get_fee=MagicMock(return_value=0.0025)
)
freqtrade = FreqtradeBot(default_conf, create_engine('sqlite://'))
@ -1075,7 +1079,8 @@ def test_execute_sell_without_conf_sell_up(default_conf, ticker, ticker_sell_up,
mocker.patch.multiple(
'freqtrade.freqtradebot.exchange',
validate_pairs=MagicMock(),
get_ticker=ticker
get_ticker=ticker,
get_fee=MagicMock(return_value=0.0025)
)
freqtrade = FreqtradeBot(default_conf, create_engine('sqlite://'))
@ -1115,7 +1120,8 @@ def test_execute_sell_without_conf_sell_down(default_conf, ticker,
mocker.patch.multiple(
'freqtrade.freqtradebot.exchange',
validate_pairs=MagicMock(),
get_ticker=ticker
get_ticker=ticker,
get_fee=MagicMock(return_value=0.0025)
)
freqtrade = FreqtradeBot(default_conf, create_engine('sqlite://'))