Bots & Automation

Trading Bot Notifications: APIs, Webhooks and Telegram Alerts

How trading bots talk to the outside world: polling APIs vs webhooks, sending trade alerts to Telegram, what to send, keeping tokens safe and what works in cloud vs local instances.

By AlgoXP3 min readUpdated

Polling an API compared with a webhook that pushes events to the trading bot

A trading bot that runs silently is hard to trust. Sooner or later you want it to tell you things: a trade was opened, a daily limit was hit, the connection dropped. Sending that information out - and sometimes receiving instructions in - is done through APIs and webhooks.

Two ways to exchange information

API calls (request and response). Your bot calls a service when it decides to: “send this message”, “give me today’s economic calendar”. Simple, under your control, and the most common pattern for notifications.

Webhooks (push). The service calls a URL you provide when an event happens: “a payment arrived”, “a TradingView alert fired”. Faster than asking every minute, but you need a server that can receive requests, and you must check that requests are genuine.

Polling. A compromise: your bot asks a service every N seconds whether something changed. Easy to build, wasteful if events are rare, and subject to rate limits.

For a trading bot, the typical design is: outgoing API calls for notifications, and - if you need external signals - a separate service that receives webhooks and passes validated signals on.

What a bot should report

Too many messages are as useless as none. A practical set:

Event Why it matters Priority
Bot started / stopped You know it is running Normal
Position opened / closed with R result Trade awareness Normal
Daily loss limit reached, trading paused Requires attention High
Order rejected, repeated errors Something is broken High
No heartbeat for X minutes Bot or connection down High
Daily summary Overview without noise Low

See monitoring trading bots without alert fatigue for how to decide what deserves a notification.

Sending alerts to Telegram

Telegram is popular because sending a message is a single HTTPS request:

  1. Create a bot with Telegram’s BotFather and receive a token.
  2. Send a message to your bot, then find your chat ID (via the API’s update method).
  3. From the trading bot, send a request to the Bot API’s sendMessage method with the token, chat ID and text.

Good practice for the message itself:

  • Start with the bot name, symbol and event: [GoldTrend XAUUSD] CLOSED +1.8R.
  • Include numbers you act on: equity, day’s P/L, open risk.
  • Keep it short; details belong in the log.

Doing it from a cTrader cBot

Recent versions of cTrader give algorithms a built-in HTTP API, so a cBot can send requests without elevated access rights. In practice:

  • Put the token and chat ID in bot parameters, not in the code.
  • Send messages asynchronously or rarely enough that a slow network never delays trading logic.
  • Check the response; log failures instead of retrying endlessly.
  • Be aware of the environment: community reports and cTrader staff indicate that cBots running as cloud instances cannot make outgoing internet requests, while local instances can. If notifications matter, run the bot locally on a computer or VPS, or monitor it another way.

Receiving signals from outside

Some traders want a bot to act on external signals - for example, alerts from another charting tool. This adds risk:

  • Authenticate every incoming signal (secret token, signature).
  • Validate it: symbol, direction, size limits, time window.
  • Deduplicate: the same webhook can arrive twice.
  • Keep risk controls in the trading bot, not in the signal source. The bot decides whether a signal is allowed.

Security basics

  • Tokens and API keys are passwords. Store them only on the machine that needs them.
  • Never paste them into chats, screenshots or public code.
  • Use separate tokens per bot, so one leak does not expose everything.
  • Revoke and replace a token immediately if it may have leaked.

More in security for trading bots.

Key takeaways

  • Use outgoing API calls for notifications; webhooks when a service must push events to you.
  • Report events you act on, with clear priorities, and send summaries instead of noise.
  • Keep tokens in parameters or protected settings, never in code or chats.
  • Check whether your bot’s environment allows outgoing requests before relying on alerts.

FAQ

Can a cBot send messages to Telegram?

Yes, by sending an HTTP request to the Telegram Bot API with a bot token and chat ID. Recent cTrader versions provide a built-in Http API for this. Check that the environment where the bot runs allows outgoing internet requests; cloud instances may not.

What is the difference between an API and a webhook?

With an API, your program asks a service for information or sends it a request when it wants. With a webhook, the service calls your program's URL when an event happens. Polling is simple; webhooks are faster and lighter for events.

Where should I store the Telegram token?

As a bot parameter or in a protected settings file on the machine that runs the bot - never in shared code, screenshots, chats or public repositories. If it leaks, revoke it and create a new one.

Sources and further reading

  1. cTrader Help: Network access for algos - help.ctrader.com
  2. cTrader Help: Use network access - help.ctrader.com
  3. Telegram Bot API - core.telegram.org