⬡ AUTOMATION · WITH CODE · 10 MIN READ

Telegram alert bot with Python: monitor your bot.

The most useful and legitimate use of Telegram in trading: receive every action of your bot on your phone, in real time — order executed, target hit, error. With ready-to-use code.

By the RoboTraderIA Team· updated May 2026· beginner to intermediate level

Your bot runs 24/5 on a VPS, but you don't watch the screen all day. How do you know it executed an order, hit a target, or — importantly — crashed with an error? The elegant answer: a Telegram bot that pings your phone on every event. It's simple to set up, free, and turns Telegram into a real tool (very different from signal groups). Let's get to the code.

Why this is "Telegram done right": unlike signal groups (where you depend on third parties), here Telegram is just a notification channel for your bot, with your rules. Transparent, under your control, with no one earning a commission. Pure technical use.

01Create the bot in BotFather

Telegram has an official bot for creating bots — BotFather. The process takes 1 minute:

1Talk to @BotFather

In Telegram, search for @BotFather (the official one, with a verified badge). Start the conversation.

2Create the bot

Send /newbot, choose a name and a username (which must end in "bot"). BotFather returns a token — something like 123456:ABC-DEF....

3Store the token securely

That token gives full control of the bot. Treat it like a password — it goes in a .env, never in committed code.

Token security: whoever has the token controls the bot. Never paste it in public code, GitHub, or share it. Use an environment variable. If it leaks, revoke it in BotFather (/revoke) and generate another.

02Get your chat ID

The bot needs to know where to send. You need your chat ID. The simple way: send any message to your bot, then query:

# get_chat_id.py — run once
import requests, os

TOKEN = os.getenv("TELEGRAM_TOKEN")
url = f"https://api.telegram.org/bot{TOKEN}/getUpdates"
resp = requests.get(url).json()

# send a message to the bot BEFORE running this
for r in resp.get("result", []):
    chat = r["message"]["chat"]
    print(f"Chat ID: {chat['id']} ({chat.get('first_name')})")

Note the number that appears — it's your chat ID, which also goes into the .env.

03Send a message (the base function)

The heart of it all — a function that sends a message. Two ways: with requests (simpler, no dependency) or with the python-telegram-bot library (more complete). For alerts, requests is enough:

# telegram_alert.py
import requests, os

TOKEN = os.getenv("TELEGRAM_TOKEN")
CHAT_ID = os.getenv("TELEGRAM_CHAT_ID")

def send_alert(message: str):
    url = f"https://api.telegram.org/bot{TOKEN}/sendMessage"
    data = {
        "chat_id": CHAT_ID,
        "text": message,
        "parse_mode": "HTML",   # allows bold, etc.
    }
    try:
        requests.post(url, data=data, timeout=10)
    except Exception as e:
        print(f"Failed to send Telegram: {e}")

# test
send_alert("✅ Alert bot connected!")

Ready to use: with this function, sending an alert becomes one line. Note the try/except — you never want a Telegram send failure to take down your bot. The alert is secondary; the trading is what matters.

04Integrate with your bot

Now the good part: calling send_alert() on your bot's important events. Taking the loop from our MT5 bot or Binance bot:

from telegram_alert import send_alert

while True:
    try:
        df = pull_candles(...)
        signal = compute_signal(df)

        if signal == "BUY" and not has_position():
            result = buy(...)
            send_alert(f"🟢 BUY executed\n"
                       f"Asset: ES | Price: {result.price}\n"
                       f"Stop: {stop} | Target: {target}")

        time.sleep(60)
    except Exception as e:
        # ERROR alert — the most important of all
        send_alert(f"🔴 BOT ERROR!\n{str(e)}")
        time.sleep(30)

The events most worth alerting: (1) error/crash — the most critical, you need to know right away; (2) order executed (entry and exit); (3) target or stop hit; (4) daily summary (how many trades, result). The error alert alone justifies building this — knowing the bot went down at 3am prevents losses.

Don't have a bot to alert from yet?

Start with the Binance bot or MT5-Python API tutorials, then plug in Telegram.

Build the bot →

05Going further: commands (with caution)

The bot can go beyond just notifying — it can receive your commands (e.g. /status to see positions, /stop to shut the bot down). That uses the python-telegram-bot library and the logic of reading updates. But here comes a serious caution:

If the bot controls the trading bot, protect it: a bot that only sends alerts is pure read — safe. But if you give it the power to send commands to the trading bot (stop, change a parameter), you need authentication: validate that the chat ID is yours and no one else's. An exposed control bot is a door for someone to tamper with your bot. For alerts, stay read-only; for control, lock it down rigorously.

06Frequently asked questions

How do you create a bot on Telegram?

By chatting with @BotFather (the official bot). Send /newbot, choose a name and a username ending in "bot", and it generates an API token you use in code. Takes about 1 minute.

What is a trading alert bot for?

Receiving real-time notifications from your bot: order executed, price hitting a level, error, bot stopped. It lets you monitor operations from your phone without watching the screen. The error alert is the most valuable.

Is it safe to use a Telegram bot with your trading bot?

For sending alerts (read), it's safe and useful. Cautions: never expose the token publicly; and if the bot sends commands to the trading bot, protect it with authentication so only you can control it.

Do you need a server to run the alert bot?

Sending alerts runs inside your own bot — wherever it is (VPS, PC). You don't need a separate server just to send. If you want the bot to receive commands continuously, then you need something always running (the same VPS as the bot works).

requests or python-telegram-bot?

For just sending alerts, requests is enough (simple, no extra dependency). For receiving commands and richer interactions, the python-telegram-bot library is more complete. Start with requests for alerts.