/*
* 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 System.Net;
using QuantConnect.Api;
using QuantConnect.API;
using QuantConnect.Data.Market;
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
/// that includes information about the newly created project
ProjectResponse CreateProject(string name, Language language);
///
/// 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
ProjectFilesResponse 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);
///
/// 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
/// Backtest result object
Backtest ReadBacktest(int projectId, string backtestId);
///
/// 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 backtestName = "", string backtestNote = "");
///
/// 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 backtests for a specific project id
///
/// Project id to search
/// BacktestList container for list of backtests
BacktestList ListBacktests(int projectId);
///
/// Gets the logs of a specific live algorithm
///
/// Project Id of the live running algorithm
/// Algorithm Id of the live running algorithm
/// No logs will be returned before this time. Should be in UTC
/// No logs will be returned after this time. Should be in UTC
/// List of strings that represent the logs of the algorithm
LiveLog ReadLiveLogs(int projectId, string algorithmId, DateTime? startTime = null, DateTime? endTime = null);
///
/// Gets the link to the downloadable data.
///
/// Symbol of security of which data will be requested.
/// Resolution of data requested.
/// Date of the data requested.
/// Link to the downloadable data.
Link ReadDataLink(Symbol symbol, Resolution resolution, DateTime date);
///
/// Method to download and save the data purchased through QuantConnect
///
/// Symbol of security of which data will be requested.
/// Resolution of data requested.
/// Date of the data requested.
/// A bool indicating whether the data was successfully downloaded or not.
bool DownloadData(Symbol symbol, Resolution resolution, DateTime date);
///
/// Create a new live algorithm for a logged in user.
///
/// Id of the project on QuantConnect
/// Id of the compilation on QuantConnect
/// Type of server instance that will run the algorithm
/// Brokerage specific BaseLiveAlgorithmSettings.
/// The version identifier
/// Information regarding the new algorithm
LiveAlgorithm CreateLiveAlgorithm(int projectId, string compileId, string serverType, BaseLiveAlgorithmSettings baseLiveAlgorithmSettings, string versionId = "-1");
///
/// 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);
//Status StatusRead(int projectId, string algorithmId);
//RestResponse StatusUpdate(int projectId, string algorithmId, AlgorithmStatus status, string message = "");
//LogControl LogAllowanceRead();
//void LogAllowanceUpdate(string backtestId, string url, int length);
//void StatisticsUpdate(int projectId, string algorithmId, decimal unrealized, decimal fees, decimal netProfit, decimal holdings, decimal equity, decimal netReturn, decimal volume, int trades, double sharpe);
//void NotifyOwner(int projectId, string algorithmId, string subject, string body);
//IEnumerable MarketHours(int projectId, DateTime time, Symbol symbol);
///
/// 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 = "");
///
/// Will get the prices for requested symbols
///
/// Symbols for which the price is requested
///
PricesList ReadPrices(IEnumerable symbols);
///
/// 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);
///
/// Gets all split events between the specified times. From and to are inclusive.
///
/// The first date to get splits for
/// The last date to get splits for
/// A list of all splits in the specified range
List GetSplits(DateTime from, DateTime to);
///
/// Gets all dividend events between the specified times. From and to are inclusive.
///
/// The first date to get dividend for
/// The last date to get dividend for
/// A list of all dividend in the specified range
List GetDividends(DateTime from, DateTime to);
///
/// 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);
}
}