---
title: "Notifications"
description: "QuantConnect Cloud supports email, SMS, webhooks, and Telegram notifications for live trading algorithms."
canonical: https://www.quantconnect.com/docs/v2/writing-algorithms/live-trading/notifications
markdown: https://www.quantconnect.com/docs/v2/writing-algorithms/live-trading/notifications.md
language: python
source: https://github.com/QuantConnect/Documentation/tree/master/03%20Writing%20Algorithms/40%20Live%20Trading/40%20Notifications
modified: 2026-11-01
index: https://www.quantconnect.com/llms.txt
---

# Notifications

[Documentation](https://www.quantconnect.com/docs/v2.md) > [Writing Algorithms](https://www.quantconnect.com/docs/v2/writing-algorithms.md) > [Live Trading](https://www.quantconnect.com/docs/v2/writing-algorithms/live-trading.md) > Notifications

> Code examples are shown in Python. Append `?lang=csharp` to this URL for the C# version of this page.

## Introduction

Set up some live trading notifications so that you are notified of market events and your algorithm's performance. QuantConnect Cloud supports email, SMS, webhooks, and Telegram notifications for live trading algorithms. If you run local algorithm with LEAN or the LEAN CLI, the notification services aren't available. To view the number of notification you can send for free in QuantConnect Cloud, see the [Live Trading Notification Quotas](https://www.quantconnect.com/docs/v2/cloud-platform/organizations/resources.md#13-Live-Trading-Notification-Quotas). Notifications are different from [commands](https://www.quantconnect.com/docs/v2/writing-algorithms/live-trading/commands.md) because notifications enable you to send information out of your algorithm while commands enable you to manually call methods in your algorithm as it runs.

## Email

Email notifications can include up to 10KB of text content in the message body. These notifications can be slow since they go through your email provider. If you don't receive an email notification that you're expecting, check your junk folders.

To send email notifications in your code files, run:

```python
message = "2023-07-13T12:20:00.2033226Z,EURUSD,1.11853,89187,Market,Filled,99758.33511"
self.notify.email(address="quant@office.com", subject="Last Trade", message=message)
```

You can include an attachment and set its name.

```python
attachment = "2023-07-13T12:20:00.2033226Z,EURUSD,1.11853,89187,Market,Filled,99758.33511"
headers = { "filename": "trades.csv" }
self.notify.email(address="quant@office.com", subject="Last Trade", message="See attachment", data=attachment, headers=headers)
```

If you don't provide headers, the attachment name is `attachment.txt`.

## FTP

FTP notifications send files to your FTP server. You can use password and SSH authentication.

To send a file to your FTP server in your code files, run:

```python
file_content = "2023-07-13T12:20:00.2033226Z,EURUSD,1.11853,89187,Market,Filled,99758.33511"
self.notify.ftp(hostname="myftpserver.com", username="admin", password="12345", file_path="trades.csv", file_content=file_content, port=21)
```

To send a file to your SFTP server in your code files, run:

```python
file_content = "2023-07-13T12:20:00.2033226Z,EURUSD,1.11853,89187,Market,Filled,99758.33511"
self.notify.sftp(hostname="mysftpserver.com", username="admin", password="12345", file_path="trades.csv", file_content=file_content, port=21)
```

You can use password authentication over SFTP using SSH keys.

```python
file_content = "2023-07-13T12:20:00.2033226Z,EURUSD,1.11853,89187,Market,Filled,99758.33511"
self.notify.sftp(hostname="mysftpserver.com", username="admin", private_key="12345", private_key_passphrase="67890", file_path="trades.csv", file_content=file_content, port=21)
```

The `file_path` parameter is path to file on the FTP server. The `port` parameter is optional.

## SMS

SMS notifications are the only type of notification that you don't need an internet connection to receive. They can include up to 1,600 characters of text content in the message body.

To send SMS notifications in your code files, run:

```python
message = "2023-07-13T12:20:00.2033226Z,EURUSD,1.11853,89187,Market,Filled,99758.33511"
self.notify.sms(phone_number="+100503016366", message=message)
```

## Telegram

Telegram notifications are automated messages to a Telegram group.

To send Telegram notifications in your code files, run:

```python
message = "2023-07-13T12:20:00.2033226Z,EURUSD,1.11853,89187,Market,Filled,99758.33511"
self.notify.telegram(id="-503016366", message=message, token="1234")
```

The `id` argument is your Telegram group Id. Your group Id is in the URL when you open your group chat in the Telegram web interface. For example, the group Id of web.telegram.org/z/#-503016366 is -503016366.

The `token` optional argument is a token of a bot you must add to your Telegram group. To create a bot, chat with @BotFather and follow its instructions. If you want to use our bot, the username is @quantconnect_notifications_bot.

To add emoticons to your `message`, convert the emoticon character to UTF-32 with the [Unicode Converter](https://www.branah.com/unicode-converter) on the Branah website. For example, the rocket emoji is `0001f680` in UTF-32 format, so use `\U001f680` in your message.

## Webhooks

Webhook notifications are an HTTP-POST request to a URL you provide. The request is sent with a timeout of 300s. You can process these notifications on your web server however you want. For instance, you can inject the content of the notifications into your server's database or use it to create other notifications on your own server.

To send webhook notifications in your code files, run:

```python
data = ""
headers = { 'Authorization': 'Basic XXXXX' }
self.notify.web(address="http://api.myserver.com", data=data, headers=headers)
```

The `data` argument can be a `string`, `float`, or `int` object.

To send a webhook to a Discord server, generate a webhook URL (for instructions, see [Intro to Webhooks](https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks) in the Discord Help Center) and serialize the data in a dictionary with a `content` key.

```python
discord_url = "https://discord.com/api/webhooks/.../..."
self.notify.web(discord_url, json.dumps({'content': 'Hello world!'}))
```

## Receive Notifications

To receive external notification in your algorithm, see [Commands](https://www.quantconnect.com/docs/v2/writing-algorithms/live-trading/commands.md).

## Terms of Use

The notification system can't be used for data distribution.

## Examples

The following examples demonstrate common practices for sending notifications in live algorithms.

### Example 1: Pre-Open Order Error

The following algorithm simulate extended market hour trading on [Tradier Brokerage](https://www.quantconnect.com/docs/v2/writing-algorithms/reality-modeling/brokerages/supported-models/tradier.md). We place a market-on-open order at 7:30am and expect the order cannot submit to the broker since it is not supported, resulting into an error.

```python
class OrderErrorsAlgorithm(QCAlgorithm):
    def initialize(self) -> None:
        self.set_start_date(2024, 9, 1)
        self.set_end_date(2024, 12, 31)
        # Simulate Tradier brokerage, which does not support the market-on-open orders.
        self.set_brokerage_model(BrokerageName.TRADIER_BROKERAGE, AccountType.CASH)

        # Request extended market hour SPY data for trading.
        self.spy = self.add_equity("SPY", extended_market_hours=True).symbol

        # Set a scheduled event to trade 2 hours pre-open to place the market-on-open-order.
        self.schedule.on(
            self.date_rules.every_day(self.spy),
            self.time_rules.before_market_open(self.spy, 120),
            self.open_position
        )

    def open_position(self) -> None:
        # Buy on market open will result in an error since Tradier does not support it.
        self.market_on_open_order(self.spy, 10)

    # It will be triggered on live trading.
    def on_brokerage_message(self, message: BrokerageMessageEvent) -> None:
        if message.type == BrokerageMessageType.ERROR:
            self.log(f"{self.time}: {message.type}: Message: {message.message}")
```

### Other Examples

For more examples, see the following algorithms:

**Demonstration Algorithm**

- [LiveFeaturesAlgorithm.py](https://github.com/QuantConnect/Lean/blob/master/Algorithm.Python/LiveFeaturesAlgorithm.py) (Python)
