DEV Community

Propfirmkey
Propfirmkey

Posted on

Building a Telegram Bot for Trade Notifications

Stay connected to your trading activity with a custom Telegram notification bot. Here's how to build one for prop firm trading.

Setup

import requests
from datetime import datetime

class TradingBot:
    def __init__(self, token, chat_id):
        self.token = token
        self.chat_id = chat_id
        self.base_url = f"https://api.telegram.org/bot{token}"

    def send_message(self, text, parse_mode="HTML"):
        requests.post(f"{self.base_url}/sendMessage", json={
            "chat_id": self.chat_id,
            "text": text,
            "parse_mode": parse_mode
        })

    def notify_trade(self, trade):
        emoji = "🟒" if trade['pnl'] > 0 else "πŸ”΄"
        msg = f"""{emoji} <b>Trade Alert</b>

Symbol: {trade['symbol']}
Direction: {trade['direction'].upper()}
Entry: {trade['entry']:.2f}
Exit: {trade['exit']:.2f}
PnL: ${trade['pnl']:.2f}
Time: {datetime.now().strftime('%H:%M:%S')}"""
        self.send_message(msg)

    def daily_summary(self, stats):
        msg = f"""πŸ“Š <b>Daily Summary</b>

Trades: {stats['total']}
Winners: {stats['winners']} | Losers: {stats['losers']}
Win Rate: {stats['win_rate']:.1%}
PnL: ${stats['pnl']:.2f}
Max DD: ${stats['max_dd']:.2f}
Account: ${stats['balance']:.2f}"""
        self.send_message(msg)
Enter fullscreen mode Exit fullscreen mode

Advanced Features

Drawdown Alerts

def check_drawdown(self, current_balance, peak_balance, max_allowed):
    drawdown = peak_balance - current_balance
    pct = drawdown / peak_balance * 100

    if pct > 70:  # 70% of max drawdown
        self.send_message(
            f"⚠️ <b>DRAWDOWN WARNING</b>\n"
            f"Current DD: ${drawdown:.2f} ({pct:.1f}% of max)\n"
            f"Max allowed: ${max_allowed:.2f}\n"
            f"<b>Consider reducing position size!</b>"
        )
Enter fullscreen mode Exit fullscreen mode

Performance Tracking

Track your progress toward the prop firm profit target and get motivated with milestone notifications.

Prop Firm Integration

This bot is especially useful during prop firm evaluations where monitoring drawdown levels is critical. Set alerts at 50%, 70%, and 90% of your maximum drawdown to stay safe.

Resources

Find the best prop firm for your trading style at PropFirmKey. Compare drawdown rules and other parameters at PropFirmKey comparisons.

Top comments (0)