From 6045f07a9c4fafe7d730c0d3e3d57b3e761933e5 Mon Sep 17 00:00:00 2001 From: Misagh Date: Wed, 27 Mar 2019 21:12:57 +0100 Subject: [PATCH 1/7] telegram message concatenation refactored --- freqtrade/rpc/telegram.py | 30 ++++++++++++++---------- freqtrade/tests/rpc/test_rpc_telegram.py | 6 +++++ 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/freqtrade/rpc/telegram.py b/freqtrade/rpc/telegram.py index 2c419e417..1e1436631 100644 --- a/freqtrade/rpc/telegram.py +++ b/freqtrade/rpc/telegram.py @@ -193,21 +193,25 @@ class Telegram(RPC): for result in results: result['date'] = result['date'].humanize() - messages = [ - "*Trade ID:* `{trade_id}`\n" - "*Current Pair:* {pair}\n" - "*Open Since:* `{date}`\n" - "*Amount:* `{amount}`\n" - "*Open Rate:* `{open_rate:.8f}`\n" - "*Close Rate:* `{close_rate}`\n" - "*Current Rate:* `{current_rate:.8f}`\n" - "*Close Profit:* `{close_profit}`\n" - "*Current Profit:* `{current_profit:.2f}%`\n" - "*Open Order:* `{open_order}`".format(**result) - for result in results - ] + messages = [] + for r in results: + lines = [ + "*Trade ID:* `{trade_id}`", + "*Current Pair:* {pair}", + "*Open Since:* `{date}`", + "*Amount:* `{amount}`", + "*Open Rate:* `{open_rate:.8f}`", + "*Close Rate:* `{close_rate}`" if r['close_rate'] else "", + "*Current Rate:* `{current_rate:.8f}`", + "*Close Profit:* `{close_profit}`", + "*Current Profit:* `{current_profit:.2f}%`", + "*Open Order:* `{open_order}`" + ] + messages.append("\n".join(filter(None,lines)).format(**r)) + for msg in messages: self._send_msg(msg, bot=bot) + except RPCException as e: self._send_msg(str(e), bot=bot) diff --git a/freqtrade/tests/rpc/test_rpc_telegram.py b/freqtrade/tests/rpc/test_rpc_telegram.py index dd49b0000..39973d5db 100644 --- a/freqtrade/tests/rpc/test_rpc_telegram.py +++ b/freqtrade/tests/rpc/test_rpc_telegram.py @@ -267,6 +267,12 @@ def test_status_handle(default_conf, update, ticker, fee, markets, mocker) -> No # Trigger status while we have a fulfilled order for the open trade telegram._status(bot=MagicMock(), update=update) + # close_rate should not be included in the message as the trade is not closed + # and no line should be empty + lines = msg_mock.call_args_list[0][0][0].split('\n') + assert '' not in lines + assert 'Close Rate' not in ''.join(lines) + assert msg_mock.call_count == 1 assert 'ETH/BTC' in msg_mock.call_args_list[0][0][0] From 1678a039aee6cd06981152205b833bd0202ab512 Mon Sep 17 00:00:00 2001 From: Misagh Date: Wed, 27 Mar 2019 21:32:56 +0100 Subject: [PATCH 2/7] removing close profit is trade is open --- freqtrade/rpc/telegram.py | 2 +- freqtrade/tests/rpc/test_rpc_telegram.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/freqtrade/rpc/telegram.py b/freqtrade/rpc/telegram.py index 1e1436631..0870e660b 100644 --- a/freqtrade/rpc/telegram.py +++ b/freqtrade/rpc/telegram.py @@ -203,7 +203,7 @@ class Telegram(RPC): "*Open Rate:* `{open_rate:.8f}`", "*Close Rate:* `{close_rate}`" if r['close_rate'] else "", "*Current Rate:* `{current_rate:.8f}`", - "*Close Profit:* `{close_profit}`", + "*Close Profit:* `{close_profit}`" if r['close_profit'] else "", "*Current Profit:* `{current_profit:.2f}%`", "*Open Order:* `{open_order}`" ] diff --git a/freqtrade/tests/rpc/test_rpc_telegram.py b/freqtrade/tests/rpc/test_rpc_telegram.py index 39973d5db..d1a068100 100644 --- a/freqtrade/tests/rpc/test_rpc_telegram.py +++ b/freqtrade/tests/rpc/test_rpc_telegram.py @@ -272,6 +272,7 @@ def test_status_handle(default_conf, update, ticker, fee, markets, mocker) -> No lines = msg_mock.call_args_list[0][0][0].split('\n') assert '' not in lines assert 'Close Rate' not in ''.join(lines) + assert 'Close Profit' not in ''.join(lines) assert msg_mock.call_count == 1 assert 'ETH/BTC' in msg_mock.call_args_list[0][0][0] From 0ca3a38ba6b6de63574c23ea8355863c858d0da9 Mon Sep 17 00:00:00 2001 From: Misagh Date: Wed, 27 Mar 2019 21:39:17 +0100 Subject: [PATCH 3/7] moved date to top and show open order only if it is not none --- freqtrade/rpc/telegram.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/freqtrade/rpc/telegram.py b/freqtrade/rpc/telegram.py index 0870e660b..2ba431b07 100644 --- a/freqtrade/rpc/telegram.py +++ b/freqtrade/rpc/telegram.py @@ -196,18 +196,17 @@ class Telegram(RPC): messages = [] for r in results: lines = [ - "*Trade ID:* `{trade_id}`", + "*Trade ID:* `{trade_id}` (since `{date}`)", "*Current Pair:* {pair}", - "*Open Since:* `{date}`", "*Amount:* `{amount}`", "*Open Rate:* `{open_rate:.8f}`", "*Close Rate:* `{close_rate}`" if r['close_rate'] else "", "*Current Rate:* `{current_rate:.8f}`", "*Close Profit:* `{close_profit}`" if r['close_profit'] else "", "*Current Profit:* `{current_profit:.2f}%`", - "*Open Order:* `{open_order}`" + "*Open Order:* `{open_order}`" if r['open_order'] else "", ] - messages.append("\n".join(filter(None,lines)).format(**r)) + messages.append("\n".join(filter(None ,lines)).format(**r)) for msg in messages: self._send_msg(msg, bot=bot) From 941921dd0f9f741d81da890941d9a3f6294ba81c Mon Sep 17 00:00:00 2001 From: Misagh Date: Wed, 27 Mar 2019 22:00:46 +0100 Subject: [PATCH 4/7] initial SL and SL added to RPC --- freqtrade/rpc/rpc.py | 2 ++ freqtrade/tests/rpc/test_rpc.py | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/freqtrade/rpc/rpc.py b/freqtrade/rpc/rpc.py index a5601a502..3272059a9 100644 --- a/freqtrade/rpc/rpc.py +++ b/freqtrade/rpc/rpc.py @@ -110,6 +110,8 @@ class RPC(object): amount=round(trade.amount, 8), close_profit=fmt_close_profit, current_profit=round(current_profit * 100, 2), + initial_stoploss=trade.initial_stop_loss, + stoploss=trade.stop_loss, open_order='({} {} rem={:.8f})'.format( order['type'], order['side'], order['remaining'] ) if order else None, diff --git a/freqtrade/tests/rpc/test_rpc.py b/freqtrade/tests/rpc/test_rpc.py index e6f7ea41e..f9862c9ca 100644 --- a/freqtrade/tests/rpc/test_rpc.py +++ b/freqtrade/tests/rpc/test_rpc.py @@ -58,6 +58,8 @@ def test_rpc_trade_status(default_conf, ticker, fee, markets, mocker) -> None: 'amount': 90.99181074, 'close_profit': None, 'current_profit': -0.59, + 'initial_stoploss': 0.0, + 'stoploss': 0.0, 'open_order': '(limit buy rem=0.00000000)' } == results[0] @@ -78,6 +80,8 @@ def test_rpc_trade_status(default_conf, ticker, fee, markets, mocker) -> None: 'amount': 90.99181074, 'close_profit': None, 'current_profit': ANY, + 'initial_stoploss': 0.0, + 'stoploss': 0.0, 'open_order': '(limit buy rem=0.00000000)' } == results[0] From 0e5b0ebda6fa26aab71a877a6c62616110a46d7d Mon Sep 17 00:00:00 2001 From: Misagh Date: Thu, 28 Mar 2019 12:09:07 +0100 Subject: [PATCH 5/7] adding SL and SL percentage to telegram msg --- freqtrade/rpc/rpc.py | 8 ++++++-- freqtrade/rpc/telegram.py | 3 ++- freqtrade/tests/rpc/test_rpc_telegram.py | 2 ++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/freqtrade/rpc/rpc.py b/freqtrade/rpc/rpc.py index 3272059a9..553e66d85 100644 --- a/freqtrade/rpc/rpc.py +++ b/freqtrade/rpc/rpc.py @@ -97,9 +97,13 @@ class RPC(object): current_rate = self._freqtrade.get_sell_rate(trade.pair, False) except DependencyException: current_rate = NAN + current_profit = trade.calc_profit_percent(current_rate) fmt_close_profit = (f'{round(trade.close_profit * 100, 2):.2f}%' if trade.close_profit else None) + sl_percentage = round(((trade.stop_loss - current_rate) / current_rate) * 100, 2) + txt_sl_percentage = f'{sl_percentage}%' + results.append(dict( trade_id=trade.id, pair=trade.pair, @@ -110,8 +114,8 @@ class RPC(object): amount=round(trade.amount, 8), close_profit=fmt_close_profit, current_profit=round(current_profit * 100, 2), - initial_stoploss=trade.initial_stop_loss, - stoploss=trade.stop_loss, + stop_loss=trade.stop_loss, + stop_loss_percentage=txt_sl_percentage, open_order='({} {} rem={:.8f})'.format( order['type'], order['side'], order['remaining'] ) if order else None, diff --git a/freqtrade/rpc/telegram.py b/freqtrade/rpc/telegram.py index 2ba431b07..8bec8e6cd 100644 --- a/freqtrade/rpc/telegram.py +++ b/freqtrade/rpc/telegram.py @@ -204,9 +204,10 @@ class Telegram(RPC): "*Current Rate:* `{current_rate:.8f}`", "*Close Profit:* `{close_profit}`" if r['close_profit'] else "", "*Current Profit:* `{current_profit:.2f}%`", + "*Stoploss:* `{stop_loss:.8f}` ({stop_loss_percentage})", "*Open Order:* `{open_order}`" if r['open_order'] else "", ] - messages.append("\n".join(filter(None ,lines)).format(**r)) + messages.append("\n".join(filter(None, lines)).format(**r)) for msg in messages: self._send_msg(msg, bot=bot) diff --git a/freqtrade/tests/rpc/test_rpc_telegram.py b/freqtrade/tests/rpc/test_rpc_telegram.py index d1a068100..edd099dc4 100644 --- a/freqtrade/tests/rpc/test_rpc_telegram.py +++ b/freqtrade/tests/rpc/test_rpc_telegram.py @@ -201,6 +201,8 @@ def test_status(default_conf, update, mocker, fee, ticker, markets) -> None: 'amount': 90.99181074, 'close_profit': None, 'current_profit': -0.59, + 'stop_loss': 1.099e-05, + 'stop_loss_percentage': '-2%', 'open_order': '(limit buy rem=0.00000000)' }]), _status_table=status_table, From e11eb4775e875533c21f21a7c2a8d63eaf506b55 Mon Sep 17 00:00:00 2001 From: Misagh Date: Thu, 28 Mar 2019 16:21:49 +0100 Subject: [PATCH 6/7] stoploss precentage in telegram msg removed --- freqtrade/rpc/rpc.py | 3 --- freqtrade/rpc/telegram.py | 2 +- freqtrade/tests/rpc/test_rpc.py | 6 ++---- 3 files changed, 3 insertions(+), 8 deletions(-) diff --git a/freqtrade/rpc/rpc.py b/freqtrade/rpc/rpc.py index 553e66d85..20bfe41ba 100644 --- a/freqtrade/rpc/rpc.py +++ b/freqtrade/rpc/rpc.py @@ -101,8 +101,6 @@ class RPC(object): current_profit = trade.calc_profit_percent(current_rate) fmt_close_profit = (f'{round(trade.close_profit * 100, 2):.2f}%' if trade.close_profit else None) - sl_percentage = round(((trade.stop_loss - current_rate) / current_rate) * 100, 2) - txt_sl_percentage = f'{sl_percentage}%' results.append(dict( trade_id=trade.id, @@ -115,7 +113,6 @@ class RPC(object): close_profit=fmt_close_profit, current_profit=round(current_profit * 100, 2), stop_loss=trade.stop_loss, - stop_loss_percentage=txt_sl_percentage, open_order='({} {} rem={:.8f})'.format( order['type'], order['side'], order['remaining'] ) if order else None, diff --git a/freqtrade/rpc/telegram.py b/freqtrade/rpc/telegram.py index 8bec8e6cd..d3f3521aa 100644 --- a/freqtrade/rpc/telegram.py +++ b/freqtrade/rpc/telegram.py @@ -204,7 +204,7 @@ class Telegram(RPC): "*Current Rate:* `{current_rate:.8f}`", "*Close Profit:* `{close_profit}`" if r['close_profit'] else "", "*Current Profit:* `{current_profit:.2f}%`", - "*Stoploss:* `{stop_loss:.8f}` ({stop_loss_percentage})", + "*Stoploss:* `{stop_loss:.8f}`", "*Open Order:* `{open_order}`" if r['open_order'] else "", ] messages.append("\n".join(filter(None, lines)).format(**r)) diff --git a/freqtrade/tests/rpc/test_rpc.py b/freqtrade/tests/rpc/test_rpc.py index f9862c9ca..529bf31f3 100644 --- a/freqtrade/tests/rpc/test_rpc.py +++ b/freqtrade/tests/rpc/test_rpc.py @@ -58,8 +58,7 @@ def test_rpc_trade_status(default_conf, ticker, fee, markets, mocker) -> None: 'amount': 90.99181074, 'close_profit': None, 'current_profit': -0.59, - 'initial_stoploss': 0.0, - 'stoploss': 0.0, + 'stop_loss': 0.0, 'open_order': '(limit buy rem=0.00000000)' } == results[0] @@ -80,8 +79,7 @@ def test_rpc_trade_status(default_conf, ticker, fee, markets, mocker) -> None: 'amount': 90.99181074, 'close_profit': None, 'current_profit': ANY, - 'initial_stoploss': 0.0, - 'stoploss': 0.0, + 'stop_loss': 0.0, 'open_order': '(limit buy rem=0.00000000)' } == results[0] From 2f3f5f19cdc82971525990918c08fb5d17a173f8 Mon Sep 17 00:00:00 2001 From: Misagh Date: Thu, 28 Mar 2019 16:26:59 +0100 Subject: [PATCH 7/7] sl percentage removed form rpc test --- freqtrade/rpc/rpc.py | 2 -- freqtrade/tests/rpc/test_rpc_telegram.py | 1 - 2 files changed, 3 deletions(-) diff --git a/freqtrade/rpc/rpc.py b/freqtrade/rpc/rpc.py index 20bfe41ba..55f9a302c 100644 --- a/freqtrade/rpc/rpc.py +++ b/freqtrade/rpc/rpc.py @@ -97,11 +97,9 @@ class RPC(object): current_rate = self._freqtrade.get_sell_rate(trade.pair, False) except DependencyException: current_rate = NAN - current_profit = trade.calc_profit_percent(current_rate) fmt_close_profit = (f'{round(trade.close_profit * 100, 2):.2f}%' if trade.close_profit else None) - results.append(dict( trade_id=trade.id, pair=trade.pair, diff --git a/freqtrade/tests/rpc/test_rpc_telegram.py b/freqtrade/tests/rpc/test_rpc_telegram.py index edd099dc4..b66e29143 100644 --- a/freqtrade/tests/rpc/test_rpc_telegram.py +++ b/freqtrade/tests/rpc/test_rpc_telegram.py @@ -202,7 +202,6 @@ def test_status(default_conf, update, mocker, fee, ticker, markets) -> None: 'close_profit': None, 'current_profit': -0.59, 'stop_loss': 1.099e-05, - 'stop_loss_percentage': '-2%', 'open_order': '(limit buy rem=0.00000000)' }]), _status_table=status_table,