/* * 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 System.ComponentModel.Composition; using QuantConnect.Api; using QuantConnect.Notifications; using QuantConnect.Optimizer.Objectives; using QuantConnect.Optimizer.Parameters; using QuantConnect.Statistics; namespace QuantConnect.Interfaces { /// /// API for QuantConnect.com /// [InheritedExport(typeof(IApi))] public interface IApi : IDisposable { /// /// Initialize the control system /// void Initialize(int userId, string token, string dataFolder); /// /// Create a project with the specified name and language via QuantConnect.com API /// /// Project name /// Programming language to use /// Organization to create this project under /// that includes information about the newly created project ProjectResponse CreateProject(string name, Language language, string organizationId = null); /// /// Read in a project from the QuantConnect.com API. /// /// Project id you own /// about a specific project ProjectResponse ReadProject(int projectId); /// /// Add a file to a project /// /// The project to which the file should be added /// The name of the new file /// The content of the new file /// that includes information about the newly created file RestResponse AddProjectFile(int projectId, string name, string content); /// /// Update the name of a file /// /// Project id to which the file belongs /// The current name of the file /// The new name for the file /// indicating success RestResponse UpdateProjectFileName(int projectId, string oldFileName, string newFileName); /// /// Update the contents of a file /// /// Project id to which the file belongs /// The name of the file that should be updated /// The new contents of the file /// indicating success RestResponse UpdateProjectFileContent(int projectId, string fileName, string newFileContents); /// /// Read a file in a project /// /// Project id to which the file belongs /// The name of the file /// that includes the file information ProjectFilesResponse ReadProjectFile(int projectId, string fileName); /// /// Read all files in a project /// /// Project id to which the file belongs /// that includes the information about all files in the project ProjectFilesResponse ReadProjectFiles(int projectId); /// /// Read all nodes in a project. /// /// Project id to which the nodes refer /// that includes the information about all nodes in the project ProjectNodesResponse ReadProjectNodes(int projectId); /// /// Update the active state of some nodes to true. /// If you don't provide any nodes, all the nodes become inactive and AutoSelectNode is true. /// /// Project id to which the nodes refer /// List of node ids to update /// that includes the information about all nodes in the project ProjectNodesResponse UpdateProjectNodes(int projectId, string[] nodes); /// /// Delete a file in a project /// /// Project id to which the file belongs /// The name of the file that should be deleted /// that includes the information about all files in the project RestResponse DeleteProjectFile(int projectId, string name); /// /// Delete a specific project owned by the user from QuantConnect.com /// /// Project id we own and wish to delete /// RestResponse indicating success RestResponse DeleteProject(int projectId); /// /// Read back a list of all projects on the account for a user. /// /// Container for list of projects ProjectResponse ListProjects(); /// /// Create a new compile job request for this project id. /// /// Project id we wish to compile. /// Compile object result Compile CreateCompile(int projectId); /// /// Read a compile packet job result. /// /// Project id we sent for compile /// Compile id return from the creation request /// Compile object result Compile ReadCompile(int projectId, string compileId); /// /// Create a new backtest from a specified projectId and compileId /// /// /// /// /// Backtest CreateBacktest(int projectId, string compileId, string backtestName); /// /// Read out the full result of a specific backtest /// /// Project id for the backtest we'd like to read /// Backtest id for the backtest we'd like to read /// True will return backtest charts /// Backtest result object Backtest ReadBacktest(int projectId, string backtestId, bool getCharts = true); /// /// Update the backtest name /// /// Project id to update /// Backtest id to update /// New backtest name to set /// Note attached to the backtest /// Rest response on success RestResponse UpdateBacktest(int projectId, string backtestId, string name = "", string note = ""); /// /// Delete a backtest from the specified project and backtestId. /// /// Project for the backtest we want to delete /// Backtest id we want to delete /// RestResponse on success RestResponse DeleteBacktest(int projectId, string backtestId); /// /// Get a list of backtest summaries for a specific project id /// /// Project id to search /// True for include statistics in the response, false otherwise /// BacktestList container for list of backtests BacktestSummaryList ListBacktests(int projectId, bool includeStatistics = false); /// /// Read out the insights of a backtest /// /// Id of the project from which to read the backtest /// Backtest id from which we want to get the insights /// Starting index of the insights to be fetched /// Last index of the insights to be fetched. Note that end - start must be less than 100 /// /// public InsightResponse ReadBacktestInsights(int projectId, string backtestId, int start = 0, int end = 0); #pragma warning disable CS1574 /// /// Estimate optimization with the specified parameters via QuantConnect.com API /// /// Project ID of the project the optimization belongs to /// Name of the optimization /// Target of the optimization, see examples in /// Target extremum of the optimization, for example "max" or "min" /// Optimization target value /// Optimization strategy, /// Optimization compile ID /// Optimization parameters /// Optimization constraints /// Estimate object from the API. #pragma warning restore CS1574 public Estimate EstimateOptimization( int projectId, string name, string target, string targetTo, decimal? targetValue, string strategy, string compileId, HashSet parameters, IReadOnlyList constraints); #pragma warning disable CS1574 /// /// Create an optimization with the specified parameters via QuantConnect.com API /// /// Project ID of the project the optimization belongs to /// Name of the optimization /// Target of the optimization, see examples in /// Target extremum of the optimization, for example "max" or "min" /// Optimization target value /// Optimization strategy, /// Optimization compile ID /// Optimization parameters /// Optimization constraints /// Estimated cost for optimization /// Optimization node type /// Number of parallel nodes for optimization /// BaseOptimization object from the API. #pragma warning restore CS1574 public OptimizationSummary CreateOptimization( int projectId, string name, string target, string targetTo, decimal? targetValue, string strategy, string compileId, HashSet parameters, IReadOnlyList constraints, decimal estimatedCost, string nodeType, int parallelNodes); /// /// List all the optimizations for a project /// /// Project id we'd like to get a list of optimizations for /// A list of BaseOptimization objects, public List ListOptimizations(int projectId); /// /// Read an optimization /// /// Optimization id for the optimization we want to read /// public Optimization ReadOptimization(string optimizationId); /// /// Abort an optimization /// /// Optimization id for the optimization we want to abort /// public RestResponse AbortOptimization(string optimizationId); /// /// Update an optimization /// /// Optimization id we want to update /// Name we'd like to assign to the optimization /// public RestResponse UpdateOptimization(string optimizationId, string name = null); /// /// Delete an optimization /// /// Optimization id for the optimization we want to delete /// public RestResponse DeleteOptimization(string optimizationId); /// /// Gets the logs of a specific live algorithm /// /// Project Id of the live running algorithm /// Algorithm Id of the live running algorithm /// Start line of logs to read /// End line of logs to read /// List of strings that represent the logs of the algorithm LiveLog ReadLiveLogs(int projectId, string algorithmId, int startLine, int endLine); /// /// Returns a chart object from a live algorithm /// /// Project ID of the request /// The requested chart name /// The Utc start seconds timestamp of the request /// The Utc end seconds timestamp of the request /// The number of data points to request /// public ReadChartResponse ReadLiveChart(int projectId, string name, int start, int end, uint count); /// /// Read out the portfolio state of a live algorithm /// /// Id of the project from which to read the live algorithm /// public PortfolioResponse ReadLivePortfolio(int projectId); /// /// Read out the insights of a live algorithm /// /// Id of the project from which to read the live algorithm /// Starting index of the insights to be fetched /// Last index of the insights to be fetched. Note that end - start must be less than 100 /// /// public InsightResponse ReadLiveInsights(int projectId, int start = 0, int end = 0); /// /// Gets the link to the downloadable data. /// /// File path representing the data requested /// Organization to purchase this data with /// Link to the downloadable data. DataLink ReadDataLink(string filePath, string organizationId); /// /// Get valid data entries for a given filepath from data/list /// /// DataList ReadDataDirectory(string filePath); /// /// Gets data prices from data/prices /// public DataPricesList ReadDataPrices(string organizationId); /// /// Read out the report of a backtest in the project id specified. /// /// Project id to read /// Specific backtest id to read /// public BacktestReport ReadBacktestReport(int projectId, string backtestId); /// /// Returns a requested chart object from a backtest /// /// Project ID of the request /// The requested chart name /// The Utc start seconds timestamp of the request /// The Utc end seconds timestamp of the request /// The number of data points to request /// Associated Backtest ID for this chart request /// public ReadChartResponse ReadBacktestChart(int projectId, string name, int start, int end, uint count, string backtestId); /// /// Method to download and save the data purchased through QuantConnect /// /// File path representing the data requested /// A bool indicating whether the data was successfully downloaded or not. bool DownloadData(string filePath, string organizationId); /// /// Will read the organization account status /// /// The target organization id, if null will return default organization public Account ReadAccount(string organizationId = null); /// /// Fetch organization data from web API /// /// /// public Organization ReadOrganization(string organizationId = null); /// /// Create a new live algorithm for a logged in user. /// /// Id of the project on QuantConnect /// Id of the compilation on QuantConnect /// Id of the node that will run the algorithm /// Dictionary with Brokerage specific settings /// The version identifier /// Dictionary with data providers and their corresponding credentials /// Information regarding the new algorithm CreateLiveAlgorithmResponse CreateLiveAlgorithm(int projectId, string compileId, string nodeId, Dictionary brokerageSettings, string versionId = "-1", Dictionary dataProviders = null); /// /// Get a list of live running algorithms for a logged in user. /// /// Filter the statuses of the algorithms returned from the api /// Earliest launched time of the algorithms returned by the Api /// Latest launched time of the algorithms returned by the Api /// List of live algorithm instances LiveList ListLiveAlgorithms(AlgorithmStatus? status = null, DateTime? startTime = null, DateTime? endTime = null); /// /// Read out a live algorithm in the project id specified. /// /// Project id to read /// Specific instance id to read /// Live object with the results LiveAlgorithmResults ReadLiveAlgorithm(int projectId, string deployId); /// /// Liquidate a live algorithm from the specified project. /// /// Project for the live instance we want to stop /// RestResponse LiquidateLiveAlgorithm(int projectId); /// /// Stop a live algorithm from the specified project. /// /// Project for the live algo we want to delete /// RestResponse StopLiveAlgorithm(int projectId); /// /// Sends a notification /// /// The notification to send /// The project id /// containing success response and errors RestResponse SendNotification(Notification notification, int projectId); /// /// Get the algorithm current status, active or cancelled from the user /// /// /// AlgorithmControl GetAlgorithmStatus(string algorithmId); /// /// Set the algorithm status from the worker to update the UX e.g. if there was an error. /// /// Algorithm id we're setting. /// Status enum of the current worker /// Message for the algorithm status event void SetAlgorithmStatus(string algorithmId, AlgorithmStatus status, string message = ""); /// /// Send the statistics to storage for performance tracking. /// /// Identifier for algorithm /// Unrealized gainloss /// Total fees /// Net profi /// Algorithm holdings /// Total equity /// Algorithm return /// Volume traded /// Total trades since inception /// Sharpe ratio since inception void SendStatistics(string algorithmId, decimal unrealized, decimal fees, decimal netProfit, decimal holdings, decimal equity, decimal netReturn, decimal volume, int trades, double sharpe); /// /// Send an email to the user associated with the specified algorithm id /// /// The algorithm id /// The email subject /// The email message body void SendUserEmail(string algorithmId, string subject, string body); /// /// Local implementation for downloading data to algorithms /// /// URL to download /// KVP headers /// Username for basic authentication /// Password for basic authentication /// string Download(string address, IEnumerable> headers, string userName, string password); /// /// Local implementation for downloading data to algorithms /// /// URL to download /// KVP headers /// Username for basic authentication /// Password for basic authentication /// byte[] DownloadBytes(string address, IEnumerable> headers, string userName, string password); /// /// Download the object store associated with the given organization ID and key /// /// Organization ID we would like to get the Object Store from /// Keys for the Object Store files /// Folder in which the object will be stored /// True if the object was retrieved correctly, false otherwise public bool GetObjectStore(string organizationId, List keys, string destinationFolder = null); /// /// Get Object Store properties given the organization ID and the Object Store key /// /// Organization ID we would like to get the Object Store from /// Key for the Object Store file /// /// It does not work when the object store is a directory public PropertiesObjectStoreResponse GetObjectStoreProperties(string organizationId, string key); /// /// Upload files to the Object Store /// /// Organization ID we would like to upload the file to /// Key to the Object Store file /// File to be uploaded /// public RestResponse SetObjectStore(string organizationId, string key, byte[] objectData); /// /// Request to delete Object Store metadata of a specific organization and key /// /// Organization ID we would like to delete the Object Store file from /// Key to the Object Store file /// public RestResponse DeleteObjectStore(string organizationId, string key); /// /// Gets a list of LEAN versions with their corresponding basic descriptions /// public VersionsResponse ReadLeanVersions(); /// /// Broadcast a live command /// /// Organization ID of the projects we would like to broadcast the command to /// Project for the live instance we want to exclude from the broadcast list /// The command to run /// public RestResponse BroadcastLiveCommand(string organizationId, int? excludeProjectId, object command); } }