/*
* 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 Newtonsoft.Json;
using QuantConnect.Util;
namespace QuantConnect.Notifications
{
///
/// Local/desktop implementation of messaging system for Lean Engine.
///
[JsonConverter(typeof(NotificationJsonConverter))]
public abstract class Notification
{
///
/// Method for sending implementations of notification object types.
///
/// SMS, Email and Web are all handled by the QC Messaging Handler. To implement your own notification type implement it here.
public virtual void Send()
{
//
}
}
///
/// Web Notification Class
///
public class NotificationWeb : Notification
{
///
/// Optional email headers
///
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
public Dictionary Headers;
///
/// Send a notification message to this web address
///
public string Address;
///
/// Object data to send.
///
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
public object Data;
///
/// Constructor for sending a notification SMS to a specified phone number
///
/// Address to send to
/// Data to send
/// Optional headers to use
public NotificationWeb(string address, object data = null, Dictionary headers = null)
{
Address = address;
Data = data;
Headers = headers;
}
}
///
/// Sms Notification Class
///
public class NotificationSms : Notification
{
///
/// Send a notification message to this phone number
///
public string PhoneNumber;
///
/// Message to send. Limited to 160 characters
///
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
public string Message;
///
/// Constructor for sending a notification SMS to a specified phone number
///
///
///
public NotificationSms(string number, string message)
{
PhoneNumber = number;
Message = message;
}
}
///
/// Email notification data.
///
public class NotificationEmail : Notification
{
///
/// Optional email headers
///
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
public Dictionary Headers;
///
/// Send to address:
///
public string Address;
///
/// Email subject
///
public string Subject;
///
/// Message to send.
///
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
public string Message;
///
/// Email Data
///
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
public string Data;
///
/// Default constructor for sending an email notification
///
/// Address to send to. Will throw if invalid
///
/// Subject of the email. Will set to if null
/// Message body of the email. Will set to if null
/// Data to attach to the email. Will set to if null
/// Optional email headers to use
public NotificationEmail(string address, string subject = "", string message = "", string data = "", Dictionary headers = null)
{
if (!Validate.EmailAddress(address))
{
throw new ArgumentException(Messages.NotificationEmail.InvalidEmailAddress(address));
}
Address = address;
Data = data ?? string.Empty;
Message = message ?? string.Empty;
Subject = subject ?? string.Empty;
Headers = headers;
}
}
///
/// Telegram notification data
///
public class NotificationTelegram : Notification
{
///
/// Send a notification message to this user on Telegram
/// Can be either a personal ID or Group ID.
///
public string Id;
///
/// Message to send. Limited to 4096 characters
///
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
public string Message;
///
/// Token to use
///
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
public string Token;
///
/// Constructor for sending a telegram notification to a specific User ID
/// or group ID. Note: The bot must have an open chat with the user or be
/// added to the group for messages to deliver.
///
/// User Id or Group Id to send the message too
/// Message to send
/// Bot token to use, if null defaults to "telegram-token"
/// in config on send
public NotificationTelegram(string id, string message, string token = null)
{
Id = id;
Message = message;
Token = token;
}
}
}