Skip to content

Commit 9c1c243

Browse files
telegram alarm when volume is over 500k
1 parent 2dbdce8 commit 9c1c243

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

Trading-Automation/.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
research/
2-
secret.py
2+
secrets.py
33
*.csv
44
bot_state.json
55
symbols.yaml

Trading-Automation/trading_automation.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
11781209
if __name__ == "__main__":
11791210
refresh_symbols()
11801211
trade_log = load_trade_history()

Trading-Automation/update_symbols.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
# API_SECRET = os.environ['BINANCE_SECRET']
1010

1111
OUTPUT_FILE = "symbols.yaml"
12-
UPDATE_INTERVAL = 180
12+
UPDATE_INTERVAL = 60
1313
cg = CoinGeckoAPI()
1414

1515
def fetch_with_retry(func, *args, retries=3, **kwargs):

0 commit comments

Comments
 (0)