From 2ada439faa142643ee5501545548a36ac56b09ee Mon Sep 17 00:00:00 2001 From: wahyu biman Date: Sun, 3 Jul 2022 06:25:58 +0700 Subject: [PATCH] - fix message header on telegram notif - fix date format when showing in telegram notif - edit some retun value from _signal --- app/notification/tele.py | 13 ++++++++++--- app/strategy/indicator_alert.py | 13 +++++++------ 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/app/notification/tele.py b/app/notification/tele.py index 501b4ab..d171a3f 100755 --- a/app/notification/tele.py +++ b/app/notification/tele.py @@ -16,7 +16,7 @@ async def send_notif(signals): Return: None """ LOG.info('Send notification via Telegram Bot') - msg_header = """----- Signal RSI cross above 42.5 or below 57.5 ----- + msg_header = """----- Market Structure Break Alert 1H ----- """ msg = """""" @@ -25,8 +25,15 @@ async def send_notif(signals): await bot.start(bot_token=os.getenv('TELE_BOT_TOKEN')) entity = await bot.get_entity(TG_CHANNEL_NAME) msg += msg_header - for signal in signals: - msg += "-> {} \n".format(signal) + for i in signals: + if i == 0: + msg += f"""MSB High Break : +""" + elif i == 1: + msg += f"""MSB Low Break : +""" + for signal in signals[i]: + msg += "-> {} \n".format(signal) msg += f""" >>> {str(pd.to_datetime(time.time(), unit='s').tz_localize('UTC').tz_convert('Asia/Jakarta').strftime('%m/%d/%Y %H:%M:%S'))}""" await bot.send_message(entity, msg) diff --git a/app/strategy/indicator_alert.py b/app/strategy/indicator_alert.py index 09d2b6f..797f968 100755 --- a/app/strategy/indicator_alert.py +++ b/app/strategy/indicator_alert.py @@ -63,17 +63,18 @@ async def _signal(self, ohlcvs): LOG.info('Calculating signal . . .') try: - result = [] + result_up = [] + result_down = [] for ohlcv in ohlcvs: last = ohlcv[-3:-2] # check LONG or SHORT signal if (last.break_h.values[0] == 1) & (last.ema_fast.values[0] < last.close.values[0]): - result.append( - f'{ohlcv.name} - MSB High Break on ${last.close.values[0]} @{last.timestamp.values[0]}') + result_up.append( + f'{ohlcv.name} - ${last.close.values[0]} on {last.timestamp[-1:].dt.strftime("%d/%m/%Y %H:%M:%S").astype(str)}') elif (last.break_l.values[0] == 1) & (last.ema_fast.values[0] > last.close.values[0]): - result.append( - f'{ohlcv.name} - MSB Low Break on ${last.close.values[0]} @{last.timestamp.values[0]}') - return result + result_down.append( + f'{ohlcv.name} - ${last.close.values[0]} on {last.timestamp[-1:].dt.strftime("%d/%m/%Y %H:%M:%S").astype(str)}') + return [result_up, result_down] except Exception as e: LOG.exception(e)