This commit is contained in:
Matthias 2020-03-24 17:20:16 +01:00
parent 700cedc573
commit f3103be15c
2 changed files with 9 additions and 6 deletions

View File

@ -935,7 +935,7 @@ class FreqtradeBot:
:return: Reason for cancel :return: Reason for cancel
""" """
# if trade is not partially completed, just cancel the trade # if trade is not partially completed, just cancel the trade
if order['remaining'] == order['amount'] or order['filled'] == 0.0: if order['remaining'] == order['amount'] or order.get('filled') == 0.0:
if not self.exchange.check_order_canceled_empty(order): if not self.exchange.check_order_canceled_empty(order):
reason = "cancelled due to timeout" reason = "cancelled due to timeout"
# if trade is not partially completed, just delete the trade # if trade is not partially completed, just delete the trade

View File

@ -1592,13 +1592,13 @@ def test_exit_positions_exception(mocker, default_conf, limit_buy_order, caplog)
mocker.patch('freqtrade.exchange.Exchange.get_order', return_value=limit_buy_order) mocker.patch('freqtrade.exchange.Exchange.get_order', return_value=limit_buy_order)
trade = MagicMock() trade = MagicMock()
trade.open_order_id = '123' trade.open_order_id = None
trade.open_fee = 0.001 trade.open_fee = 0.001
trades = [trade] trades = [trade]
# Test raise of DependencyException exception # Test raise of DependencyException exception
mocker.patch( mocker.patch(
'freqtrade.freqtradebot.FreqtradeBot.update_trade_state', 'freqtrade.freqtradebot.FreqtradeBot.handle_trade',
side_effect=DependencyException() side_effect=DependencyException()
) )
n = freqtrade.exit_positions(trades) n = freqtrade.exit_positions(trades)
@ -1970,7 +1970,7 @@ def test_check_handle_cancelled_buy(default_conf, ticker, limit_buy_order_old, o
rpc_mock = patch_RPCManager(mocker) rpc_mock = patch_RPCManager(mocker)
cancel_order_mock = MagicMock() cancel_order_mock = MagicMock()
patch_exchange(mocker) patch_exchange(mocker)
limit_buy_order_old.update({"status": "canceled"}) limit_buy_order_old.update({"status": "canceled", 'filled': 0.0})
mocker.patch.multiple( mocker.patch.multiple(
'freqtrade.exchange.Exchange', 'freqtrade.exchange.Exchange',
fetch_ticker=ticker, fetch_ticker=ticker,
@ -2049,7 +2049,7 @@ def test_check_handle_cancelled_sell(default_conf, ticker, limit_sell_order_old,
""" Handle sell order cancelled on exchange""" """ Handle sell order cancelled on exchange"""
rpc_mock = patch_RPCManager(mocker) rpc_mock = patch_RPCManager(mocker)
cancel_order_mock = MagicMock() cancel_order_mock = MagicMock()
limit_sell_order_old.update({"status": "canceled"}) limit_sell_order_old.update({"status": "canceled", 'filled': 0.0})
patch_exchange(mocker) patch_exchange(mocker)
mocker.patch.multiple( mocker.patch.multiple(
'freqtrade.exchange.Exchange', 'freqtrade.exchange.Exchange',
@ -2276,7 +2276,7 @@ def test_handle_timedout_limit_sell(mocker, default_conf) -> None:
assert freqtrade.handle_timedout_limit_sell(trade, order) assert freqtrade.handle_timedout_limit_sell(trade, order)
assert cancel_order_mock.call_count == 1 assert cancel_order_mock.call_count == 1
order['amount'] = 2 order['amount'] = 2
assert not freqtrade.handle_timedout_limit_sell(trade, order) assert freqtrade.handle_timedout_limit_sell(trade, order) == 'partially filled - keeping order open'
# Assert cancel_order was not called (callcount remains unchanged) # Assert cancel_order was not called (callcount remains unchanged)
assert cancel_order_mock.call_count == 1 assert cancel_order_mock.call_count == 1
@ -2544,8 +2544,11 @@ def test_may_execute_sell_after_stoploss_on_exchange_hit(default_conf, ticker, f
# Create some test data # Create some test data
freqtrade.enter_positions() freqtrade.enter_positions()
freqtrade.check_handle_timedout()
trade = Trade.query.first() trade = Trade.query.first()
trades = [trade] trades = [trade]
assert trade.stoploss_order_id is None
freqtrade.exit_positions(trades) freqtrade.exit_positions(trades)
assert trade assert trade
assert trade.stoploss_order_id == '123' assert trade.stoploss_order_id == '123'