Telegram candle message should be configurable

This commit is contained in:
Matthias 2022-07-11 12:10:29 +02:00
parent ed03ef47ef
commit 8e8f026ea7
5 changed files with 26 additions and 13 deletions

View File

@ -155,7 +155,8 @@
"entry_cancel": "on", "entry_cancel": "on",
"exit_cancel": "on", "exit_cancel": "on",
"protection_trigger": "off", "protection_trigger": "off",
"protection_trigger_global": "on" "protection_trigger_global": "on",
"show_candle": "off"
}, },
"reload": true, "reload": true,
"balance_dust_level": 0.01 "balance_dust_level": 0.01

View File

@ -97,7 +97,8 @@ Example configuration showing the different settings:
"entry_fill": "off", "entry_fill": "off",
"exit_fill": "off", "exit_fill": "off",
"protection_trigger": "off", "protection_trigger": "off",
"protection_trigger_global": "on" "protection_trigger_global": "on",
"show_candle": "off"
}, },
"reload": true, "reload": true,
"balance_dust_level": 0.01 "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. `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. `*_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. `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. `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. `reload` allows you to disable reload-buttons on selected messages.

View File

@ -313,6 +313,10 @@ CONF_SCHEMA = {
'type': 'string', 'type': 'string',
'enum': TELEGRAM_SETTING_OPTIONS, 'enum': TELEGRAM_SETTING_OPTIONS,
}, },
'show_candle': {
'type': 'string',
'enum': ['off', 'ohlc'],
},
} }
}, },
'reload': {'type': 'boolean'}, 'reload': {'type': 'boolean'},

View File

@ -868,7 +868,7 @@ class FreqtradeBot(LoggingMixin):
if analyzed_candle is not None: if analyzed_candle is not None:
candle_columns = analyzed_candle[['date', 'open', 'high', 'low', 'close']] candle_columns = analyzed_candle[['date', 'open', 'high', 'low', 'close']]
msg.update({ msg.update({
'analyzed_candle': candle_columns.to_json(date_unit='s', date_format='iso') 'analyzed_candle': candle_columns.to_dict()
}) })
# Send the message # Send the message
@ -1567,7 +1567,7 @@ class FreqtradeBot(LoggingMixin):
if analyzed_candle is not None: if analyzed_candle is not None:
candle_columns = analyzed_candle[['date', 'open', 'high', 'low', 'close']] candle_columns = analyzed_candle[['date', 'open', 'high', 'low', 'close']]
msg.update({ msg.update({
'analyzed_candle': candle_columns.to_json(date_unit='s', date_format='iso') 'analyzed_candle': candle_columns.to_dict()
}) })
# Send the message # Send the message

View File

@ -243,6 +243,19 @@ class Telegram(RPCHandler):
""" """
return f"{msg['exchange']}{' (dry)' if self._config['dry_run'] else ''}" 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: def _format_entry_msg(self, msg: Dict[str, Any]) -> str:
if self._rpc._fiat_converter: if self._rpc._fiat_converter:
msg['stake_amount_fiat'] = self._rpc._fiat_converter.convert_amount( 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" {entry_side['entered'] if is_fill else entry_side['enter']} {msg['pair']}"
f" (#{msg['trade_id']})\n" f" (#{msg['trade_id']})\n"
) )
if msg.get('analyzed_candle'): message += self._add_analyzed_candle(msg)
message += f"*Analyzed Candle:* `{msg['analyzed_candle']}`\n"
message += f"*Enter Tag:* `{msg['enter_tag']}`\n" if msg.get('enter_tag') else "" message += f"*Enter Tag:* `{msg['enter_tag']}`\n" if msg.get('enter_tag') else ""
message += f"*Amount:* `{msg['amount']:.8f}`\n" message += f"*Amount:* `{msg['amount']:.8f}`\n"
if msg.get('leverage') and msg.get('leverage', 1.0) != 1.0: if msg.get('leverage') and msg.get('leverage', 1.0) != 1.0:
@ -308,12 +320,7 @@ class Telegram(RPCHandler):
message = ( message = (
f"{msg['emoji']} *{self._exchange_from_msg(msg)}:* " f"{msg['emoji']} *{self._exchange_from_msg(msg)}:* "
f"{'Exited' if is_fill else 'Exiting'} {msg['pair']} (#{msg['trade_id']})\n" f"{'Exited' if is_fill else 'Exiting'} {msg['pair']} (#{msg['trade_id']})\n"
) f"{self._add_analyzed_candle(msg)}"
if not is_fill and msg.get('analyzed_candle'):
message += (
f"*Analyzed Candle:* `{msg['analyzed_candle']}`\n"
)
message += (
f"*{'Profit' if is_fill else 'Unrealized Profit'}:* " f"*{'Profit' if is_fill else 'Unrealized Profit'}:* "
f"`{msg['profit_ratio']:.2%}{msg['profit_extra']}`\n" f"`{msg['profit_ratio']:.2%}{msg['profit_extra']}`\n"
f"*Enter Tag:* `{msg['enter_tag']}`\n" f"*Enter Tag:* `{msg['enter_tag']}`\n"