Skip to content

Commit

Permalink
Add endpoint to update a backtest set of tags
Browse files Browse the repository at this point in the history
  • Loading branch information
jhonabreul committed Jan 17, 2024
1 parent 64b9f1f commit c14232e
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
25 changes: 25 additions & 0 deletions Api/Api.cs
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,31 @@ public RestResponse DeleteBacktestTags(int projectId, string backtestId, IReadOn
return result;
}

/// <summary>
/// Updates the tags collection for a backtest
/// </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="tags">The new backtest tags</param>
/// <returns><see cref="RestResponse"/></returns>
public RestResponse UpdateBacktestTags(int projectId, string backtestId, IReadOnlyCollection<string> 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;
}

/// <summary>
/// Create a live algorithm.
/// </summary>
Expand Down
4 changes: 2 additions & 2 deletions Engine/Results/LiveTradingResultHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1292,7 +1292,7 @@ public void SetSummaryStatistic(string name, string value)
/// Handles updates to the algorithm's name
/// </summary>
/// <param name="name">The new name</param>
public void AlgorithmNameUpdated(string name)
public virtual void AlgorithmNameUpdated(string name)
{
Messages.Enqueue(new AlgorithmNameUpdatePacket(AlgorithmId, name));
}
Expand All @@ -1301,7 +1301,7 @@ public void AlgorithmNameUpdated(string name)
/// Handles updates to the algorithm's tags
/// </summary>
/// <param name="tags">The new tags</param>
public void AlgorithmTagsUpdated(HashSet<string> tags)
public virtual void AlgorithmTagsUpdated(HashSet<string> tags)
{
Messages.Enqueue(new AlgorithmTagsUpdatePacket(AlgorithmId, tags));
}
Expand Down
10 changes: 10 additions & 0 deletions Tests/Api/ProjectTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> { "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()
Expand Down

0 comments on commit c14232e

Please sign in to comment.