Files
quantconnect--lean/Common/Notifications/Notification.cs
Martin-Molinero 56db26d16d Allow specifying email Headers (#4735)
* Allow specifying email Headers

* Address review

- Fix for Python Notification.Email use case
2020-09-18 21:16:43 -03:00

146 lines
4.6 KiB
C#

/*
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
using System.Collections.Generic;
using QuantConnect.Util;
namespace QuantConnect.Notifications
{
/// <summary>
/// Local/desktop implementation of messaging system for Lean Engine.
/// </summary>
public abstract class Notification
{
/// <summary>
/// Method for sending implementations of notification object types.
/// </summary>
/// <remarks>SMS, Email and Web are all handled by the QC Messaging Handler. To implement your own notification type implement it here.</remarks>
public virtual void Send()
{
//
}
}
/// <summary>
/// Web Notification Class
/// </summary>
public class NotificationWeb : Notification
{
/// <summary>
/// Send a notification message to this web address
/// </summary>
public string Address;
/// <summary>
/// Object data to send.
/// </summary>
public object Data;
/// <summary>
/// Constructor for sending a notification SMS to a specified phone number
/// </summary>
/// <param name="address"></param>
/// <param name="data"></param>
public NotificationWeb(string address, object data = null)
{
Address = address;
Data = data;
}
}
/// <summary>
/// Sms Notification Class
/// </summary>
public class NotificationSms : Notification
{
/// <summary>
/// Send a notification message to this phone number
/// </summary>
public string PhoneNumber;
/// <summary>
/// Message to send. Limited to 160 characters
/// </summary>
public string Message;
/// <summary>
/// Constructor for sending a notification SMS to a specified phone number
/// </summary>
/// <param name="number"></param>
/// <param name="message"></param>
public NotificationSms(string number, string message)
{
PhoneNumber = number;
Message = message;
}
}
/// <summary>
/// Email notification data.
/// </summary>
public class NotificationEmail : Notification
{
/// <summary>
/// Optional email headers
/// </summary>
public Dictionary<string, string> Headers;
/// <summary>
/// Send to address:
/// </summary>
public string Address;
/// <summary>
/// Email subject
/// </summary>
public string Subject;
/// <summary>
/// Message to send.
/// </summary>
public string Message;
/// <summary>
/// Email Data
/// </summary>
public string Data;
/// <summary>
/// Default constructor for sending an email notification
/// </summary>
/// <param name="address">Address to send to. Will throw <see cref="ArgumentException"/> if invalid
/// <see cref="Validate.EmailAddress"/></param>
/// <param name="subject">Subject of the email. Will set to <see cref="string.Empty"/> if null</param>
/// <param name="message">Message body of the email. Will set to <see cref="string.Empty"/> if null</param>
/// <param name="data">Data to attach to the email. Will set to <see cref="string.Empty"/> if null</param>
/// <param name="headers">Optional email headers to use</param>
public NotificationEmail(string address, string subject = "", string message = "", string data = "", Dictionary<string, string> headers = null)
{
if (!Validate.EmailAddress(address))
{
throw new ArgumentException($"Invalid email address: {address}");
}
Address = address;
Data = data ?? string.Empty;
Message = message ?? string.Empty;
Subject = subject ?? string.Empty;
Headers = headers;
}
}
}