Delete trade if replacing the first order failed

part of #9128
This commit is contained in:
Matthias
2023-09-02 16:49:12 +02:00
parent be044fbacf
commit 25f5dbfcbd
3 changed files with 9 additions and 1 deletions

View File

@@ -688,6 +688,7 @@ CANCEL_REASON = {
"CANCELLED_ON_EXCHANGE": "cancelled on exchange",
"FORCE_EXIT": "forcesold",
"REPLACE": "cancelled to be replaced by new limit order",
"REPLACE_FAILED": "failed to replace order, deleting Trade",
"USER_CANCEL": "user requested order cancel"
}

View File

@@ -1420,6 +1420,13 @@ class FreqtradeBot(LoggingMixin):
order_adjust=True,
):
logger.warning(f"Could not replace order for {trade}.")
if trade.nr_of_successful_entries == 0:
# this is the first entry and we didn't get filled yet, delete trade
logger.warning(f"Removing {trade} from database.")
self._notify_enter_cancel(
trade, order_type=self.strategy.order_types['entry'],
reason=constants.CANCEL_REASON['REPLACE_FAILED'])
trade.delete()
def cancel_all_open_orders(self) -> None:
"""

View File

@@ -563,7 +563,7 @@ def test_dca_order_adjust_entry_replace_fails(
assert log_has_re(msg, caplog)
assert entry_mock.call_count == 2
assert len(Trade.get_trades().all()) == 2
assert len(Trade.get_trades().all()) == 1
assert len(Order.get_open_orders()) == 0