diff --git a/Api/Api.cs b/Api/Api.cs index ca7e65770bd3..a0df726b2d6b 100644 --- a/Api/Api.cs +++ b/Api/Api.cs @@ -706,6 +706,31 @@ public RestResponse DeleteBacktestTags(int projectId, string backtestId, IReadOn return result; } + /// + /// Updates the tags collection for a backtest + /// + /// Project for the backtest we want to update + /// Backtest id we want to update + /// The new backtest tags + /// + public RestResponse UpdateBacktestTags(int projectId, string backtestId, IReadOnlyCollection tags) + { + var request = new RestRequest("backtests/tags/update", Method.POST) + { + RequestFormat = DataFormat.Json + }; + + request.AddParameter("application/json", JsonConvert.SerializeObject(new + { + projectId, + backtestId, + tags + }), ParameterType.RequestBody); + + ApiConnection.TryRequest(request, out RestResponse result); + return result; + } + /// /// Create a live algorithm. /// diff --git a/Engine/Results/LiveTradingResultHandler.cs b/Engine/Results/LiveTradingResultHandler.cs index 00ca69b05b26..ab320372726b 100644 --- a/Engine/Results/LiveTradingResultHandler.cs +++ b/Engine/Results/LiveTradingResultHandler.cs @@ -1292,7 +1292,7 @@ public void SetSummaryStatistic(string name, string value) /// Handles updates to the algorithm's name /// /// The new name - public void AlgorithmNameUpdated(string name) + public virtual void AlgorithmNameUpdated(string name) { Messages.Enqueue(new AlgorithmNameUpdatePacket(AlgorithmId, name)); } @@ -1301,7 +1301,7 @@ public void AlgorithmNameUpdated(string name) /// Handles updates to the algorithm's tags /// /// The new tags - public void AlgorithmTagsUpdated(HashSet tags) + public virtual void AlgorithmTagsUpdated(HashSet tags) { Messages.Enqueue(new AlgorithmTagsUpdatePacket(AlgorithmId, tags)); } diff --git a/Tests/Api/ProjectTests.cs b/Tests/Api/ProjectTests.cs index f6619486d79f..fc7babf9990b 100644 --- a/Tests/Api/ProjectTests.cs +++ b/Tests/Api/ProjectTests.cs @@ -395,6 +395,16 @@ public void AddAndDeleteBacktestTags() readTagsResult = ApiClient.GetBacktestTags(TestProject.ProjectId, TestBacktest.BacktestId); Assert.IsTrue(readTagsResult.Success, $"Error reading backtest tags:\n {string.Join("\n ", readTagsResult.Errors)}"); CollectionAssert.IsEmpty(readTagsResult.Tags); + + // Override the whole set of tags + var newTags = new List { "tag4", "tag5", "tag6" }; + var updateTagsResult = ApiClient.UpdateBacktestTags(TestProject.ProjectId, TestBacktest.BacktestId, newTags); + Assert.IsTrue(updateTagsResult.Success, $"Error updating backtest tags:\n {string.Join("\n ", updateTagsResult.Errors)}"); + + // Read the backtest tags and verify the tags were updated + readTagsResult = ApiClient.GetBacktestTags(TestProject.ProjectId, TestBacktest.BacktestId); + Assert.IsTrue(readTagsResult.Success, $"Error reading backtest tags:\n {string.Join("\n ", readTagsResult.Errors)}"); + CollectionAssert.AreEquivalent(newTags, readTagsResult.Tags); } private static string GetTimestamp()