Live Trading

Notifications

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. Notifications are different from commands 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:

var body = "2023-07-13T12:20:00.2033226Z,EURUSD,1.11853,89187,Market,Filled,99758.33511";
Notify.Email(emailAddress: "quant@office.com", subject: "Last Trade", body: body);
body = "2023-07-13T12:20:00.2033226Z,EURUSD,1.11853,89187,Market,Filled,99758.33511"
self.notify.email(address="quant@office.com", subject="Last Trade", body=body)

You can include an attachment and set its name.

var attachment = "2023-07-13T12:20:00.2033226Z,EURUSD,1.11853,89187,Market,Filled,99758.33511";
var headers = new Dictionary<string, string> { { "filename", "trades.csv" } };
Notify.Email(address: "quant@office.com", subject: "Last Trade", message: "See attachment", data: attachment, headers: headers);
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:

var fileContent = "2023-07-13T12:20:00.2033226Z,EURUSD,1.11853,89187,Market,Filled,99758.33511";
Notify.Ftp(hostname: "myftpserver.com", username: "admin", password: "12345", filePath: "trades.csv", fileContent: fileContent, port: 21);
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:

var fileContent = "2023-07-13T12:20:00.2033226Z,EURUSD,1.11853,89187,Market,Filled,99758.33511";
Notify.Sftp(hostname: "mysftpserver.com", username: "admin", password: "12345", filePath: "trades.csv", fileContent: fileContent, port: 21);
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.

var fileContent = "2023-07-13T12:20:00.2033226Z,EURUSD,1.11853,89187,Market,Filled,99758.33511";
Notify.Sftp(hostname: "mysftpserver.com", username: "admin", privateKey: "12345", privateKeyPassphrase: "67890", filePath: "trades.csv", fileContent: fileContent, port: 21);
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 filePathfile_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:

var message = "2023-07-13T12:20:00.2033226Z,EURUSD,1.11853,89187,Market,Filled,99758.33511";
Notify.Sms(phoneNumber: "+100503016366", message: message);
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:

var message = "2023-07-13T12:20:00.2033226Z,EURUSD,1.11853,89187,Market,Filled,99758.33511";
Notify.Telegram(id: "503016366", message: message, token: "1234");
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 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:

var data = "";
var headers = new Dictionary<string, string> { { "Authorization", "Basic XXXXXX" } };
Notify.Web(url: "http://api.myserver.com", data: data, headers: headers);
data = ""
headers = { 'Authorization': 'Basic XXXXX' }
self.notify.web(url="http://api.myserver.com", data=data, headers=headers)

The data argument can be any serializable typea string, float, or int object.

Receive Notifications

To receive external notification in your algorithm, see Commands.

Terms of Use

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

You can also see our Videos. You can also get in touch with us via Discord.

Did you find this page helpful?

Contribute to the documentation: