⬡ AUTOMATION · WITH CODE · 10 MIN READ

Telegram alert bot with Python: monitor your trading bot.

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

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

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

Why this is the "good" side of Telegram: 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 nobody earning a commission. Purely technical use.

01Creating the bot in BotFather

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

1Talk to @BotFather

In Telegram, search for @BotFather (the official one, with the 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 .envfile, never in versioned code.

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

02Getting 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:

# pegar_chat_id.py — rode uma vez
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')})")

Write down the number that appears — that is your chat ID, and it also goes into your .env.

03Sending 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_alerta.py
import requests, os

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

def enviar_alerta(mensagem: str):
    url = f"https://api.telegram.org/bot{TOKEN}/sendMessage"
    dados = {
        "chat_id": CHAT_ID,
        "text": mensagem,
        "parse_mode": "HTML",   # allows bold, etc.
    }
    try:
        requests.post(url, data=dados, timeout=10)
    except Exception as e:
        print(f"Falha ao enviar Telegram: {e}")

# test
enviar_alerta("✅ Bot de alerta conectado!")

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

04Integrating it into your bot

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

from telegram_alerta import enviar_alerta

while True:
    try:
        df = puxar_candles(...)
        sinal = calcular_sinal(df)

        if sinal == "COMPRA" and not tem_posicao():
            resultado = comprar(...)
            enviar_alerta(f"🟢 COMPRA executada\n"
                          f"Ativo: WIN | Preço: {resultado.price}\n"
                          f"Stop: {stop} | Alvo: {alvo}")

        time.sleep(60)
    except Exception as e:
        # ERROR alert — the most important one of all
        enviar_alerta(f"🔴 ERRO no robô!\n{str(e)}")
        time.sleep(30)

The events most worth alerting on: (1) error/crash — the most critical one, you need to know right away; (2) order filled (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 3 a.m. prevents losses.

Don't have a bot to alert on yet?

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

Build the bot →

05Going further: commands (with care)

The bot can do more than just notify — it can receive commands from you (e.g. /status to see positions, /parar to shut the bot down). That uses the python-telegram-bot library and the logic for reading updates. But this is where a serious caution comes in:

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

06Frequently asked questions

How do I create a bot on Telegram?

By talking to @BotFather (the official bot). Send /newbot, choose a name and a username ending in "bot", and it generates an API token that you use in your code. It takes about 1 minute.

What is an alert bot for in trading?

Getting real-time notifications from your bot: order filled, price reaching a level, error, bot stopped. It lets you monitor the operation from your phone without sitting at the screen. The error alert is the most valuable one.

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

For sending alerts (read-only), it is safe and useful. Watch out for two things: never expose the token publicly; and if the bot sends commands to your trading bot, protect it with authentication so only you can control it.

Do I need a server to run the alert bot?

Sending alerts runs inside your own trading bot — wherever it lives (VPS, PC). You do not 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 fine).

requests or python-telegram-bot?

For sending alerts only, 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.

Related reading

🎁 Get the free trading bot (with the Quotex, Deriv and IQ Option APIs)

Open source bot + ready-made API code. You edit it by chatting with ChatGPT/Claude — no programming. Free, no spam.

👉 Want the ready-made bot instead? Go to botbinaryoptions.com →