/// <summary> /// Create a new backtest request and get the id. /// </summary> /// <param name="projectId">Id for the project to backtest</param> /// <param name="compileId">Compile id for the project</param> /// <param name="backtestName">Name for the new backtest</param> /// <returns><see cref="Backtest"/>t</returns> public Backtest CreateBacktest(int projectId, string compileId, string backtestName) { var request = new RestRequest("backtests/create", Method.POST) { RequestFormat = DataFormat.Json }; request.AddParameter("application/json", JsonConvert.SerializeObject(new { projectId, compileId, backtestName }), ParameterType.RequestBody); BacktestResponseWrapper result; ApiConnection.TryRequest(request, out result); // Use API Response values for Backtest Values result.Backtest.Success = result.Success; result.Backtest.Errors = result.Errors; // Return only the backtest object return(result.Backtest); }
/// <summary> /// Will get the prices for requested symbols /// </summary> /// <param name="symbols">Symbols for which the price is requested</param> /// <returns><see cref="Prices"/></returns> public PricesList ReadPrices(IEnumerable <Symbol> symbols) { var symbolByID = new Dictionary <string, Symbol>(); foreach (var symbol in symbols) { symbolByID[symbol.ID.ToString()] = symbol; } var request = new RestRequest("prices", Method.POST); var symbolsToRequest = string.Join(",", symbolByID.Keys); request.AddParameter("symbols", symbolsToRequest); PricesList pricesList; if (ApiConnection.TryRequest(request, out pricesList)) { foreach (var price in pricesList.Prices) { price.Symbol = symbolByID[price.SymbolID]; } } return(pricesList); }
/// <summary> /// Create a live algorithm. /// </summary> /// <param name="projectId">Id of the project on QuantConnect</param> /// <param name="compileId">Id of the compilation on QuantConnect</param> /// <param name="nodeId">Id of the node that will run the algorithm</param> /// <param name="baseLiveAlgorithmSettings">Brokerage specific <see cref="BaseLiveAlgorithmSettings">BaseLiveAlgorithmSettings</see>.</param> /// <param name="versionId">The version of the Lean used to run the algorithm. /// -1 is master, however, sometimes this can create problems with live deployments. /// If you experience problems using, try specifying the version of Lean you would like to use.</param> /// <returns>Information regarding the new algorithm <see cref="LiveAlgorithm"/></returns> public LiveAlgorithm CreateLiveAlgorithm(int projectId, string compileId, string nodeId, BaseLiveAlgorithmSettings baseLiveAlgorithmSettings, string versionId = "-1") { var request = new RestRequest("live/create", Method.POST) { RequestFormat = DataFormat.Json }; request.AddParameter("application/json", JsonConvert.SerializeObject( new LiveAlgorithmApiSettingsWrapper (projectId, compileId, nodeId, baseLiveAlgorithmSettings, versionId) ), ParameterType.RequestBody); LiveAlgorithm result; ApiConnection.TryRequest(request, out result); return(result); }
/// <summary> /// Get a list of live running algorithms for user /// </summary> /// <param name="status">Filter the statuses of the algorithms returned from the api</param> /// <param name="startTime">Earliest launched time of the algorithms returned by the Api</param> /// <param name="endTime">Latest launched time of the algorithms returned by the Api</param> /// <returns><see cref="LiveList"/></returns> public LiveList ListLiveAlgorithms(AlgorithmStatus?status = null, DateTime?startTime = null, DateTime?endTime = null) { // Only the following statuses are supported by the Api if (status.HasValue && status != AlgorithmStatus.Running && status != AlgorithmStatus.RuntimeError && status != AlgorithmStatus.Stopped && status != AlgorithmStatus.Liquidated) { throw new ArgumentException( "The Api only supports Algorithm Statuses of Running, Stopped, RuntimeError and Liquidated"); } var request = new RestRequest("live/read", Method.GET); if (status.HasValue) { request.AddParameter("status", status.ToString()); } var epochStartTime = startTime == null ? 0 : Time.DateTimeToUnixTimeStamp(startTime.Value); var epochEndTime = endTime == null?Time.DateTimeToUnixTimeStamp(DateTime.UtcNow) : Time.DateTimeToUnixTimeStamp(endTime.Value); request.AddParameter("start", epochStartTime); request.AddParameter("end", epochEndTime); LiveList result; ApiConnection.TryRequest(request, out result); return(result); }
/// <summary> /// List details of all projects /// </summary> /// <returns><see cref="ProjectResponse"/> that contains information regarding the project</returns> public ProjectResponse ListProjects() { var request = new RestRequest("projects/read", Method.GET); request.RequestFormat = DataFormat.Json; ProjectResponse result; ApiConnection.TryRequest(request, out result); return(result); }
/// <summary> /// List all the backtests for a project /// </summary> /// <param name="projectId">Project id we'd like to get a list of backtest for</param> /// <returns><see cref="BacktestList"/></returns> public BacktestList ListBacktests(int projectId) { var request = new RestRequest("backtests/read", Method.GET); request.AddParameter("projectId", projectId); BacktestList result; ApiConnection.TryRequest(request, out result); return(result); }
/// <summary> /// Read all files in a project /// </summary> /// <param name="projectId">Project id to which the file belongs</param> /// <returns><see cref="ProjectFilesResponse"/> that includes the information about all files in the project</returns> public ProjectFilesResponse ReadProjectFiles(int projectId) { var request = new RestRequest("files/read", Method.GET); request.AddParameter("projectId", projectId); ProjectFilesResponse result; ApiConnection.TryRequest(request, out result); return(result); }
/// <summary> /// Read out a live algorithm in the project id specified. /// </summary> /// <param name="projectId">Project id to read</param> /// <param name="deployId">Specific instance id to read</param> /// <returns><see cref="LiveAlgorithmResults"/></returns> public LiveAlgorithmResults ReadLiveAlgorithm(int projectId, string deployId) { var request = new RestRequest("live/read", Method.GET); request.AddParameter("projectId", projectId); request.AddParameter("deployId", deployId); LiveAlgorithmResults result; ApiConnection.TryRequest(request, out result); return(result); }
/// <summary> /// Stop a live algorithm from the specified project and deployId. /// </summary> /// <param name="projectId">Project for the live instance we want to stop</param> /// <returns><see cref="RestResponse"/></returns> public RestResponse StopLiveAlgorithm(int projectId) { var request = new RestRequest("live/update/stop", Method.POST); request.RequestFormat = DataFormat.Json; request.AddParameter("projectId", projectId); RestResponse result; ApiConnection.TryRequest(request, out result); return(result); }
/// <summary> /// Get details about a single project /// </summary> /// <param name="projectId">Id of the project</param> /// <returns><see cref="ProjectResponse"/> that contains information regarding the project</returns> public ProjectResponse ReadProject(int projectId) { var request = new RestRequest("projects/read", Method.GET); request.RequestFormat = DataFormat.Json; request.AddParameter("projectId", projectId); ProjectResponse result; ApiConnection.TryRequest(request, out result); return(result); }
/// <summary> /// Create a new backtest request and get the id. /// </summary> /// <param name="projectId">Id for the project to backtest</param> /// <param name="compileId">Compile id for the project</param> /// <param name="backtestName">Name for the new backtest</param> /// <returns><see cref="Backtest"/>t</returns> public Backtest CreateBacktest(int projectId, string compileId, string backtestName) { var request = new RestRequest("backtests/create", Method.POST); request.AddParameter("projectId", projectId); request.AddParameter("compileId", compileId); request.AddParameter("backtestName", backtestName); Backtest result; ApiConnection.TryRequest(request, out result); return(result); }
/// <summary> /// Read a compile packet job result. /// </summary> /// <param name="projectId">Project id we sent for compile</param> /// <param name="compileId">Compile id return from the creation request</param> /// <returns><see cref="Compile"/></returns> public Compile ReadCompile(int projectId, string compileId) { var request = new RestRequest("compile/read", Method.GET); request.RequestFormat = DataFormat.Json; request.AddParameter("projectId", projectId); request.AddParameter("compileId", compileId); Compile result; ApiConnection.TryRequest(request, out result); return(result); }
/// <summary> /// Reads the nodes associated with the organization, creating a /// <see cref="NodeList"/> for the response /// </summary> /// <param name="organizationId">ID of the organization</param> /// <returns><see cref="NodeList"/> containing Backtest, Research, and Live Nodes</returns> public NodeList ReadNodes(string organizationId) { var request = new RestRequest("nodes/read", Method.POST); request.RequestFormat = DataFormat.Json; request.AddParameter("organizationId", organizationId); NodeList result; ApiConnection.TryRequest(request, out result); return(result); }
/// <summary> /// Delete a file in a project /// </summary> /// <param name="projectId">Project id to which the file belongs</param> /// <param name="name">The name of the file that should be deleted</param> /// <returns><see cref="ProjectFilesResponse"/> that includes the information about all files in the project</returns> public RestResponse DeleteProjectFile(int projectId, string name) { var request = new RestRequest("files/delete", Method.POST); request.AddParameter("projectId", projectId); request.AddParameter("name", name); RestResponse result; ApiConnection.TryRequest(request, out result); return(result); }
/// <summary> /// Delete a backtest from the specified project and backtestId. /// </summary> /// <param name="projectId">Project for the backtest we want to delete</param> /// <param name="backtestId">Backtest id we want to delete</param> /// <returns><see cref="RestResponse"/></returns> public RestResponse DeleteBacktest(int projectId, string backtestId) { var request = new RestRequest("backtests/delete", Method.POST); request.RequestFormat = DataFormat.Json; request.AddParameter("backtestId", backtestId); request.AddParameter("projectId", projectId); RestResponse result; ApiConnection.TryRequest(request, out result); return(result); }
/// <summary> /// Will get the prices for requested symbols /// </summary> /// <param name="symbols">Symbols for which the price is requested</param> /// <returns><see cref="Prices"/></returns> public PricesList ReadPrices(IEnumerable <Symbol> symbols) { var request = new RestRequest("prices", Method.POST); var symbolsToRequest = string.Join(",", symbols.Select(x => x.ID.ToString())); request.AddParameter("symbols", symbolsToRequest); PricesList pricesList; ApiConnection.TryRequest(request, out pricesList); return(pricesList); }
/// <summary> /// Read out the report of a backtest in the project id specified. /// </summary> /// <param name="projectId">Project id to read</param> /// <param name="backtestId">Specific backtest id to read</param> /// <returns><see cref="BacktestReport"/></returns> public BacktestReport ReadBacktestReport(int projectId, string backtestId) { var request = new RestRequest("backtests/read/report", Method.POST); request.AddParameter("backtestId", backtestId); request.AddParameter("projectId", projectId); BacktestReport report; ApiConnection.TryRequest(request, out report); return(report); }
/// <summary> /// Stop a running node in a organization /// </summary> /// <param name="nodeId">The node ID of the node you want to stop</param> /// <param name="organizationId">ID of the organization</param> /// <returns><see cref="RestResponse"/> containing success response and errors</returns> public RestResponse StopNode(string nodeId, string organizationId) { var request = new RestRequest("nodes/stop", Method.POST); request.RequestFormat = DataFormat.Json; request.AddParameter("nodeId", nodeId); request.AddParameter("organizationId", organizationId); RestResponse result; ApiConnection.TryRequest(request, out result); return(result); }
/// <summary> /// Create a new compile job request for this project id. /// </summary> /// <param name="projectId">Project id we wish to compile.</param> /// <returns>Compile object result</returns> public Compile CreateCompile(int projectId) { var request = new RestRequest("compile/create", Method.POST); request.AddParameter("application/json", JsonConvert.SerializeObject(new { projectId = projectId }), ParameterType.RequestBody); Compile result; ApiConnection.TryRequest(request, out result); return(result); }
/// <summary> /// Update the contents of a file /// </summary> /// <param name="projectId">Project id to which the file belongs</param> /// <param name="fileName">The name of the file that should be updated</param> /// <param name="newFileContents">The new contents of the file</param> /// <returns><see cref="RestResponse"/> indicating success</returns> public RestResponse UpdateProjectFileContent(int projectId, string fileName, string newFileContents) { var request = new RestRequest("files/update", Method.POST); request.AddParameter("projectId", projectId); request.AddParameter("name", fileName); request.AddParameter("content", newFileContents); RestResponse result; ApiConnection.TryRequest(request, out result); return(result); }
/// <summary> /// Add a file to a project /// </summary> /// <param name="projectId">The project to which the file should be added</param> /// <param name="name">The name of the new file</param> /// <param name="content">The content of the new file</param> /// <returns><see cref="ProjectFilesResponse"/> that includes information about the newly created file</returns> public ProjectFilesResponse AddProjectFile(int projectId, string name, string content) { var request = new RestRequest("files/create", Method.POST); request.AddParameter("projectId", projectId); request.AddParameter("name", name); request.AddParameter("content", content); ProjectFilesResponse result; ApiConnection.TryRequest(request, out result); return(result); }
/// <summary> /// Delete a project /// </summary> /// <param name="projectId">Project id we own and wish to delete</param> /// <returns>RestResponse indicating success</returns> public RestResponse DeleteProject(int projectId) { var request = new RestRequest("projects/delete", Method.POST); request.RequestFormat = DataFormat.Json; request.AddParameter("application/json", JsonConvert.SerializeObject(new { projectId = projectId }), ParameterType.RequestBody); RestResponse result; ApiConnection.TryRequest(request, out result); return(result); }
/// <summary> /// Create a new node in the organization, node configuration is defined by the /// <see cref="SKU"/> /// </summary> /// <param name="name">The name of the new node</param> /// <param name="organizationId">ID of the organization</param> /// <param name="sku"><see cref="SKU"/> Object representing configuration</param> /// <returns>Returns <see cref="CreatedNode"/> which contains API response and /// <see cref="Node"/></returns> public CreatedNode CreateNode(string name, string organizationId, SKU sku) { var request = new RestRequest("nodes/create", Method.POST); request.AddParameter("name", name); request.AddParameter("organizationId", organizationId); request.AddParameter("sku", sku.ToString()); CreatedNode result; ApiConnection.TryRequest(request, out result); return(result); }
/// <summary> /// Gets the link to the downloadable data. /// </summary> /// <param name="symbol">Symbol of security of which data will be requested.</param> /// <param name="resolution">Resolution of data requested.</param> /// <param name="date">Date of the data requested.</param> /// <returns><see cref="Link"/> to the downloadable data.</returns> public Link ReadDataLink(Symbol symbol, Resolution resolution, DateTime date) { var request = new RestRequest("data/read", Method.GET); request.AddParameter("format", "link"); request.AddParameter("ticker", symbol.Value.ToLower()); request.AddParameter("type", symbol.ID.SecurityType.ToLower()); request.AddParameter("market", symbol.ID.Market); request.AddParameter("resolution", resolution); request.AddParameter("date", date.ToString("yyyyMMdd")); Link result; ApiConnection.TryRequest(request, out result); return(result); }
/// <summary> /// Create a project with the specified name and language via QuantConnect.com API /// </summary> /// <param name="name">Project name</param> /// <param name="language">Programming language to use</param> /// <returns>Project object from the API.</returns> public ProjectResponse CreateProject(string name, Language language) { var request = new RestRequest("projects/create", Method.POST); request.RequestFormat = DataFormat.Json; request.AddParameter("application/json", JsonConvert.SerializeObject(new { name = name, language = language }), ParameterType.RequestBody); ProjectResponse result; ApiConnection.TryRequest(request, out result); return(result); }
/// <summary> /// Read all files in a project /// </summary> /// <param name="projectId">Project id to which the file belongs</param> /// <returns><see cref="ProjectFilesResponse"/> that includes the information about all files in the project</returns> public ProjectFilesResponse ReadProjectFiles(int projectId) { var request = new RestRequest("files/read", Method.POST) { RequestFormat = DataFormat.Json }; request.AddParameter("application/json", JsonConvert.SerializeObject(new { projectId }), ParameterType.RequestBody); ProjectFilesResponse result; ApiConnection.TryRequest(request, out result); return(result); }
/// <summary> /// List all the backtests for a project /// </summary> /// <param name="projectId">Project id we'd like to get a list of backtest for</param> /// <returns><see cref="BacktestList"/></returns> public BacktestList ListBacktests(int projectId) { var request = new RestRequest("backtests/read", Method.POST) { RequestFormat = DataFormat.Json }; request.AddParameter("application/json", JsonConvert.SerializeObject(new { projectId, }), ParameterType.RequestBody); BacktestList result; ApiConnection.TryRequest(request, out result); return(result); }
/// <summary> /// Stop a live algorithm from the specified project and deployId. /// </summary> /// <param name="projectId">Project for the live instance we want to stop</param> /// <returns><see cref="RestResponse"/></returns> public RestResponse StopLiveAlgorithm(int projectId) { var request = new RestRequest("live/update/stop", Method.POST) { RequestFormat = DataFormat.Json }; request.AddParameter("application/json", JsonConvert.SerializeObject(new { projectId }), ParameterType.RequestBody); RestResponse result; ApiConnection.TryRequest(request, out result); return(result); }
/// <summary> /// Reads the nodes associated with the organization, creating a /// <see cref="NodeList"/> for the response /// </summary> /// <param name="organizationId">ID of the organization</param> /// <returns><see cref="NodeList"/> containing Backtest, Research, and Live Nodes</returns> public NodeList ReadNodes(string organizationId) { var request = new RestRequest("nodes/read", Method.POST) { RequestFormat = DataFormat.Json }; request.AddParameter("application/json", JsonConvert.SerializeObject(new { organizationId, }), ParameterType.RequestBody); NodeList result; ApiConnection.TryRequest(request, out result); return(result); }
/// <summary> /// Update a backtest name /// </summary> /// <param name="projectId">Project for the backtest we want to update</param> /// <param name="backtestId">Backtest id we want to update</param> /// <param name="name">Name we'd like to assign to the backtest</param> /// <param name="note">Note attached to the backtest</param> /// <returns><see cref="RestResponse"/></returns> public RestResponse UpdateBacktest(int projectId, string backtestId, string name = "", string note = "") { var request = new RestRequest("backtests/update", Method.POST); request.RequestFormat = DataFormat.Json; request.AddParameter("application/json", JsonConvert.SerializeObject(new { projectId = projectId, backtestId = backtestId, name = name, note = note }), ParameterType.RequestBody); Backtest result; ApiConnection.TryRequest(request, out result); return(result); }