@@ -418,6 +418,9 @@ def telegram_main():
418418 application .add_handler (CommandHandler ('start' , start_handler ))
419419 application .add_handler (MessageHandler (filters .TEXT & ~ filters .COMMAND , telegram_handle_message ))
420420
421+ # Add periodic alarm job (every 5 minutes)
422+ application .job_queue .run_repeating (alarm_job , interval = 300 , first = 10 )
423+
421424 application .run_polling ()
422425
423426
@@ -1175,6 +1178,34 @@ def resume_positions_from_binance():
11751178 except Exception :
11761179 return {}
11771180
1181+ async def send_alarm_message (text ):
1182+ """Send an alarm message to the Telegram chat."""
1183+ from telegram import Bot
1184+ bot = Bot (token = TELEGRAM_TOKEN )
1185+ await bot .send_message (chat_id = TELEGRAM_CHAT_ID , text = text )
1186+
1187+ def check_and_alarm_high_volume (context = None ):
1188+ """Check all symbols for volume > MIN_VOLUME and send Telegram alarm if found."""
1189+ stats = load_symbol_stats ()
1190+ if not stats :
1191+ return
1192+ alarmed = []
1193+ for symbol , s in stats .items ():
1194+ vol = s .get ("volume_1d" , 0 ) or 0
1195+ if vol > MIN_VOLUME :
1196+ alarmed .append ((symbol , vol ))
1197+ if alarmed :
1198+ msg = "🚨 High Volume Alert:\n "
1199+ for symbol , vol in alarmed :
1200+ msg += f"- { symbol } : Volume = { vol :,.0f} \n "
1201+ # Use asyncio to send alarm
1202+ import asyncio
1203+ asyncio .run (send_alarm_message (msg ))
1204+
1205+ # --- Telegram alarm job setup ---
1206+ async def alarm_job (context : CallbackContext ):
1207+ check_and_alarm_high_volume ()
1208+
11781209if __name__ == "__main__" :
11791210 refresh_symbols ()
11801211 trade_log = load_trade_history ()
0 commit comments