From df726a54f89af8f99cb5dd3969ba280187d22d58 Mon Sep 17 00:00:00 2001 From: Stefano Ariestasia Date: Fri, 25 Feb 2022 00:20:53 +0000 Subject: [PATCH 1/3] cater for case where sell limit order expired --- freqtrade/rpc/telegram.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/freqtrade/rpc/telegram.py b/freqtrade/rpc/telegram.py index da613fab8..e71b5a9b9 100644 --- a/freqtrade/rpc/telegram.py +++ b/freqtrade/rpc/telegram.py @@ -448,7 +448,8 @@ class Telegram(RPCHandler): "*Current Pair:* {pair}", "*Amount:* `{amount} ({stake_amount} {base_currency})`", "*Entry Tag:* `{buy_tag}`" if r['buy_tag'] else "", - "*Exit Reason:* `{sell_reason}`" if r['sell_reason'] else "", + "*Exit Reason:* `{sell_reason}`" + if (r['sell_reason'] and not r['is_open']) else "", ] if position_adjust: From a2c9879375e744b1bd7fba216f61c302ca45294e Mon Sep 17 00:00:00 2001 From: Matthias Date: Tue, 1 Mar 2022 19:30:16 +0100 Subject: [PATCH 2/3] Reset sell-reason if order is cancelled --- freqtrade/freqtradebot.py | 1 + tests/test_freqtradebot.py | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/freqtrade/freqtradebot.py b/freqtrade/freqtradebot.py index 99872ff0b..8e26c4c3a 100644 --- a/freqtrade/freqtradebot.py +++ b/freqtrade/freqtradebot.py @@ -1108,6 +1108,7 @@ class FreqtradeBot(LoggingMixin): trade.close_date = None trade.is_open = True trade.open_order_id = None + trade.sell_reason = None else: # TODO: figure out how to handle partially complete sell orders reason = constants.CANCEL_REASON['PARTIALLY_FILLED_KEEP_OPEN'] diff --git a/tests/test_freqtradebot.py b/tests/test_freqtradebot.py index d7b47174b..997ec5159 100644 --- a/tests/test_freqtradebot.py +++ b/tests/test_freqtradebot.py @@ -2549,9 +2549,12 @@ def test_handle_cancel_exit_limit(mocker, default_conf_usdt, fee) -> None: exchange='binance', open_rate=0.245441, open_order_id="123456", - open_date=arrow.utcnow().datetime, + open_date=arrow.utcnow().shift(days=-2).datetime, fee_open=fee.return_value, fee_close=fee.return_value, + close_rate=0.555, + close_date=arrow.utcnow().datetime, + sell_reason="sell_reason_whatever", ) order = {'remaining': 1, 'amount': 1, @@ -2560,6 +2563,8 @@ def test_handle_cancel_exit_limit(mocker, default_conf_usdt, fee) -> None: assert freqtrade.handle_cancel_exit(trade, order, reason) assert cancel_order_mock.call_count == 1 assert send_msg_mock.call_count == 1 + assert trade.close_rate == None + assert trade.sell_reason is None send_msg_mock.reset_mock() From 69cfb0b278d1d78b528216ecd1f4ab4bc995014e Mon Sep 17 00:00:00 2001 From: Matthias Date: Tue, 1 Mar 2022 19:32:25 +0100 Subject: [PATCH 3/3] Revert change to telegram - this should be handled at the source --- freqtrade/rpc/telegram.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/freqtrade/rpc/telegram.py b/freqtrade/rpc/telegram.py index a4310e3a0..69f7f2858 100644 --- a/freqtrade/rpc/telegram.py +++ b/freqtrade/rpc/telegram.py @@ -452,8 +452,7 @@ class Telegram(RPCHandler): "*Current Pair:* {pair}", "*Amount:* `{amount} ({stake_amount} {base_currency})`", "*Entry Tag:* `{buy_tag}`" if r['buy_tag'] else "", - "*Exit Reason:* `{sell_reason}`" - if (r['sell_reason'] and not r['is_open']) else "", + "*Exit Reason:* `{sell_reason}`" if r['sell_reason'] else "", ] if position_adjust: