Add tests for new scenario

This commit is contained in:
Matthias 2019-10-18 06:38:07 +02:00
parent c735d35265
commit 0ac46eddca
2 changed files with 44 additions and 0 deletions

View File

@ -608,6 +608,14 @@ def limit_buy_order_old_partial():
}
@pytest.fixture
def limit_buy_order_old_partial_canceled(limit_buy_order_old_partial):
res = deepcopy(limit_buy_order_old_partial)
res['status'] = 'canceled'
res['fee'] = {'cost': 0.0001, 'currency': 'ETH'}
return res
@pytest.fixture
def limit_sell_order():
return {

View File

@ -2076,6 +2076,42 @@ def test_check_handle_timedout_partial(default_conf, ticker, limit_buy_order_old
assert trades[0].stake_amount == open_trade.open_rate * trades[0].amount
def test_check_handle_timedout_partial_fee(default_conf, ticker, open_trade, caplog,
limit_buy_order_old_partial, trades_for_order,
limit_buy_order_old_partial_canceled, mocker) -> None:
rpc_mock = patch_RPCManager(mocker)
cancel_order_mock = MagicMock(return_value=limit_buy_order_old_partial_canceled)
patch_exchange(mocker)
mocker.patch.multiple(
'freqtrade.exchange.Exchange',
get_ticker=ticker,
get_order=MagicMock(return_value=limit_buy_order_old_partial),
cancel_order=cancel_order_mock,
get_trades_for_order=MagicMock(return_value=trades_for_order),
)
freqtrade = FreqtradeBot(default_conf)
assert open_trade.amount == limit_buy_order_old_partial['amount']
open_trade.fee_open = 0.0025
open_trade.fee_close = 0.0025
Trade.session.add(open_trade)
# cancelling a half-filled order should update the amount to the bought amount
# and apply fees if necessary.
freqtrade.check_handle_timedout()
assert log_has_re(r"Applying fee on amount for Trade.* Order", caplog)
assert cancel_order_mock.call_count == 1
assert rpc_mock.call_count == 1
trades = Trade.query.filter(Trade.open_order_id.is_(open_trade.open_order_id)).all()
assert len(trades) == 1
# Verify that tradehas been updated
assert trades[0].amount == limit_buy_order_old_partial['amount'] - 0.0001
assert trades[0].open_order_id is None
assert trades[0].fee_open == 0
def test_check_handle_timedout_exception(default_conf, ticker, open_trade, mocker, caplog) -> None:
patch_RPCManager(mocker)
patch_exchange(mocker)