/* * 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.Concurrent; using System.Collections.Generic; using System.ComponentModel.Composition; using QuantConnect.Brokerages; using QuantConnect.Data.UniverseSelection; using QuantConnect.Interfaces; using QuantConnect.Lean.Engine.TransactionHandlers; using QuantConnect.Orders; using QuantConnect.Packets; using QuantConnect.Statistics; namespace QuantConnect.Lean.Engine.Results { /// /// Handle the results of the backtest: where should we send the profit, portfolio updates: /// Backtester or the Live trading platform: /// [InheritedExport(typeof(IResultHandler))] public interface IResultHandler : IStatisticsService { /// /// Put messages to process into the queue so they are processed by this thread. /// ConcurrentQueue Messages { get; set; } /// /// Boolean flag indicating the result hander thread is busy. /// False means it has completely finished and ready to dispose. /// bool IsActive { get; } /// /// Event fired each time that we add/remove securities from the data feed /// void OnSecuritiesChanged(SecurityChanges changes); /// /// Initialize the result handler with this result packet. /// /// DTO parameters class to initialize a result handler void Initialize(ResultHandlerInitializeParameters parameters); /// /// Process debug messages with the preconfigured settings. /// /// String debug message void DebugMessage(string message); /// /// Process system debug messages with the preconfigured settings. /// /// String debug message void SystemDebugMessage(string message); /// /// Send a list of security types to the browser /// /// Security types list inside algorithm void SecurityType(List types); /// /// Send a logging message to the log list for storage. /// /// Message we'd in the log. void LogMessage(string message); /// /// Send an error message back to the browser highlighted in red with a stacktrace. /// /// Error message we'd like shown in console. /// Stacktrace information string void ErrorMessage(string error, string stacktrace = ""); /// /// Send a runtime error message back to the browser highlighted with in red /// /// Error message. /// Stacktrace information string void RuntimeError(string message, string stacktrace = ""); /// /// Process brokerage message events /// /// The brokerage message event void BrokerageMessage(BrokerageMessageEvent brokerageMessageEvent); /// /// Method to update the with various performance metrics. /// Called once a day by scheduled event in AlgorithmManager /// /// Current time void Sample(DateTime time); /// /// Set the algorithm of the result handler after its been initialized. /// /// Algorithm object matching IAlgorithm interface /// Algorithm starting capital for statistics calculations void SetAlgorithm(IAlgorithm algorithm, decimal startingPortfolioValue); /// /// Send a algorithm status update to the user of the algorithms running state. /// /// Status enum of the algorithm. /// Optional string message describing reason for status change. void SendStatusUpdate(AlgorithmStatus status, string message = ""); /// /// Set a dynamic runtime statistic to show in the (live) algorithm header /// /// Runtime headline statistic name /// Runtime headline statistic value void RuntimeStatistic(string key, string value); /// /// Send a new order event. /// /// Update, processing or cancellation of an order, update the IDE in live mode or ignore in backtesting. void OrderEvent(OrderEvent newEvent); /// /// Terminate the result thread and apply any required exit procedures like sending final results. /// void Exit(); /// /// Process any synchronous events in here that are primarily triggered from the algorithm loop /// void ProcessSynchronousEvents(bool forceProcess = false); /// /// Save the results /// /// The name of the results /// The results to save void SaveResults(string name, Result result); /// /// Handles updates to the algorithm's name /// /// The new name void AlgorithmNameUpdated(string name); /// /// Handles updates to the algorithm's tags /// /// The new tags void AlgorithmTagsUpdated(HashSet tags); } }