Skip to content

Alerts & Notifications

Send trading alerts via Telegram, email, and webhooks.

Setup

from financelib.alerts import AlertManager, TelegramNotifier, EmailNotifier, WebhookNotifier

manager = AlertManager([
    TelegramNotifier(bot_token="123:ABC...", chat_id="-1001234567"),
    EmailNotifier(smtp_host="smtp.gmail.com", smtp_port=587,
                  username="you@gmail.com", password="app-password",
                  to_addrs=["alerts@example.com"]),
    WebhookNotifier(url="https://hooks.slack.com/services/..."),
])

Environment Variables

export TELEGRAM_BOT_TOKEN="your-bot-token"
export TELEGRAM_CHAT_ID="your-chat-id"
export SMTP_HOST="smtp.gmail.com"
export SMTP_PORT=587
export SMTP_USERNAME="you@gmail.com"
export SMTP_PASSWORD="app-password"
export ALERT_EMAIL="alerts@example.com"
export WEBHOOK_URL="https://hooks.slack.com/..."

Sending Alerts

# Generic alert
manager.alert("Custom Alert", "Something happened", {"key": "value"})

# Price alert
manager.price_alert("THYAO.IS", 185.0, "above", 180.0)

# Trade execution alert
manager.trade_alert("THYAO.IS", "BUY", 175.0, 100, reason="RSI oversold")

Individual Channels

# Telegram only
tg = TelegramNotifier()
tg.send("Alert", "THYAO hit target!")

# Webhook only (Slack, Discord, custom)
wh = WebhookNotifier(url="https://your-webhook.com/endpoint")
wh.send("Trade", "BUY 100 THYAO @ 175", {"confidence": 0.85})