From 8e8f026ea77a11259e93e1691a737b0c079f7f83 Mon Sep 17 00:00:00 2001 From: Matthias Date: Mon, 11 Jul 2022 12:10:29 +0200 Subject: [PATCH] Telegram candle message should be configurable --- config_examples/config_full.example.json | 3 ++- docs/telegram-usage.md | 5 +++-- freqtrade/constants.py | 4 ++++ freqtrade/freqtradebot.py | 4 ++-- freqtrade/rpc/telegram.py | 23 +++++++++++++++-------- 5 files changed, 26 insertions(+), 13 deletions(-) diff --git a/config_examples/config_full.example.json b/config_examples/config_full.example.json index 6382e1baf..e2e9a16fd 100644 --- a/config_examples/config_full.example.json +++ b/config_examples/config_full.example.json @@ -155,7 +155,8 @@ "entry_cancel": "on", "exit_cancel": "on", "protection_trigger": "off", - "protection_trigger_global": "on" + "protection_trigger_global": "on", + "show_candle": "off" }, "reload": true, "balance_dust_level": 0.01 diff --git a/docs/telegram-usage.md b/docs/telegram-usage.md index 2145797b4..9853e15c6 100644 --- a/docs/telegram-usage.md +++ b/docs/telegram-usage.md @@ -97,7 +97,8 @@ Example configuration showing the different settings: "entry_fill": "off", "exit_fill": "off", "protection_trigger": "off", - "protection_trigger_global": "on" + "protection_trigger_global": "on", + "show_candle": "off" }, "reload": true, "balance_dust_level": 0.01 @@ -108,7 +109,7 @@ Example configuration showing the different settings: `exit` notifications are sent when the order is placed, while `exit_fill` notifications are sent when the order is filled on the exchange. `*_fill` notifications are off by default and must be explicitly enabled. `protection_trigger` notifications are sent when a protection triggers and `protection_trigger_global` notifications trigger when global protections are triggered. - +`show_candle` - show candle values as part of entry/exit messages. Only possible value is "ohlc". `balance_dust_level` will define what the `/balance` command takes as "dust" - Currencies with a balance below this will be shown. `reload` allows you to disable reload-buttons on selected messages. diff --git a/freqtrade/constants.py b/freqtrade/constants.py index 18dbea259..ce7c0ff83 100644 --- a/freqtrade/constants.py +++ b/freqtrade/constants.py @@ -313,6 +313,10 @@ CONF_SCHEMA = { 'type': 'string', 'enum': TELEGRAM_SETTING_OPTIONS, }, + 'show_candle': { + 'type': 'string', + 'enum': ['off', 'ohlc'], + }, } }, 'reload': {'type': 'boolean'}, diff --git a/freqtrade/freqtradebot.py b/freqtrade/freqtradebot.py index 2d16dc9ff..fe8bcc89b 100644 --- a/freqtrade/freqtradebot.py +++ b/freqtrade/freqtradebot.py @@ -868,7 +868,7 @@ class FreqtradeBot(LoggingMixin): if analyzed_candle is not None: candle_columns = analyzed_candle[['date', 'open', 'high', 'low', 'close']] msg.update({ - 'analyzed_candle': candle_columns.to_json(date_unit='s', date_format='iso') + 'analyzed_candle': candle_columns.to_dict() }) # Send the message @@ -1567,7 +1567,7 @@ class FreqtradeBot(LoggingMixin): if analyzed_candle is not None: candle_columns = analyzed_candle[['date', 'open', 'high', 'low', 'close']] msg.update({ - 'analyzed_candle': candle_columns.to_json(date_unit='s', date_format='iso') + 'analyzed_candle': candle_columns.to_dict() }) # Send the message diff --git a/freqtrade/rpc/telegram.py b/freqtrade/rpc/telegram.py index 16a851ce1..9ade8cb5f 100644 --- a/freqtrade/rpc/telegram.py +++ b/freqtrade/rpc/telegram.py @@ -243,6 +243,19 @@ class Telegram(RPCHandler): """ return f"{msg['exchange']}{' (dry)' if self._config['dry_run'] else ''}" + def _add_analyzed_candle(self, msg) -> str: + candle_val = self._config['telegram'].get( + 'notification_settings', {}).get('show_candle', 'off') + if candle_val != 'off' and msg.get('analyzed_candle'): + if candle_val == 'ohlc': + candle_json = msg['analyzed_candle'] + return ( + f"*Candle OHLC*: `{candle_json['open']}, {candle_json['high']}, " + f"{candle_json['low']}, {candle_json['close']}`\n" + ) + + return '' + def _format_entry_msg(self, msg: Dict[str, Any]) -> str: if self._rpc._fiat_converter: msg['stake_amount_fiat'] = self._rpc._fiat_converter.convert_amount( @@ -259,8 +272,7 @@ class Telegram(RPCHandler): f" {entry_side['entered'] if is_fill else entry_side['enter']} {msg['pair']}" f" (#{msg['trade_id']})\n" ) - if msg.get('analyzed_candle'): - message += f"*Analyzed Candle:* `{msg['analyzed_candle']}`\n" + message += self._add_analyzed_candle(msg) message += f"*Enter Tag:* `{msg['enter_tag']}`\n" if msg.get('enter_tag') else "" message += f"*Amount:* `{msg['amount']:.8f}`\n" if msg.get('leverage') and msg.get('leverage', 1.0) != 1.0: @@ -308,12 +320,7 @@ class Telegram(RPCHandler): message = ( f"{msg['emoji']} *{self._exchange_from_msg(msg)}:* " f"{'Exited' if is_fill else 'Exiting'} {msg['pair']} (#{msg['trade_id']})\n" - ) - if not is_fill and msg.get('analyzed_candle'): - message += ( - f"*Analyzed Candle:* `{msg['analyzed_candle']}`\n" - ) - message += ( + f"{self._add_analyzed_candle(msg)}" f"*{'Profit' if is_fill else 'Unrealized Profit'}:* " f"`{msg['profit_ratio']:.2%}{msg['profit_extra']}`\n" f"*Enter Tag:* `{msg['enter_tag']}`\n"