Skip to content

Commit d68a41b

Browse files
authored
Allow Receiving Broadcast from Source Project (#8622)
* Allow Receiving Broadcast from Source Project * empty
1 parent 09ca345 commit d68a41b

File tree

4 files changed

+15
-9
lines changed

4 files changed

+15
-9
lines changed

Algorithm/QCAlgorithm.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3526,7 +3526,9 @@ private RestResponse SendBroadcast(string typeName, Dictionary<string, object> p
35263526
{
35273527
payload["$type"] = typeName;
35283528
}
3529-
return _api.BroadcastLiveCommand(ProjectId, payload);
3529+
return _api.BroadcastLiveCommand(Globals.OrganizationID,
3530+
AlgorithmMode == AlgorithmMode.Live ? ProjectId : null,
3531+
payload);
35303532
}
35313533

35323534
private static Symbol GetCanonicalOptionSymbol(Symbol symbol)

Api/Api.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,10 +1065,11 @@ public RestResponse CreateLiveCommand(int projectId, object command)
10651065
/// <summary>
10661066
/// Broadcast a live command
10671067
/// </summary>
1068-
/// <param name="sourceProjectId">Project for the live instance we want to source the command from</param>
1068+
/// <param name="organizationId">Organization ID of the projects we would like to broadcast the command to</param>
1069+
/// <param name="excludeProjectId">Project for the live instance we want to exclude from the broadcast list</param>
10691070
/// <param name="command">The command to run</param>
10701071
/// <returns><see cref="RestResponse"/></returns>
1071-
public RestResponse BroadcastLiveCommand(int sourceProjectId, object command)
1072+
public RestResponse BroadcastLiveCommand(string organizationId, int? excludeProjectId, object command)
10721073
{
10731074
var request = new RestRequest("live/commands/broadcast", Method.POST)
10741075
{
@@ -1077,7 +1078,8 @@ public RestResponse BroadcastLiveCommand(int sourceProjectId, object command)
10771078

10781079
request.AddParameter("application/json", JsonConvert.SerializeObject(new
10791080
{
1080-
sourceProjectId,
1081+
organizationId,
1082+
excludeProjectId,
10811083
command
10821084
}), ParameterType.RequestBody);
10831085

Common/Interfaces/IApi.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -544,9 +544,10 @@ public OptimizationSummary CreateOptimization(
544544
/// <summary>
545545
/// Broadcast a live command
546546
/// </summary>
547-
/// <param name="sourceProjectId">Project for the live instance we want to source the command from</param>
547+
/// <param name="organizationId">Organization ID of the projects we would like to broadcast the command to</param>
548+
/// <param name="excludeProjectId">Project for the live instance we want to exclude from the broadcast list</param>
548549
/// <param name="command">The command to run</param>
549550
/// <returns><see cref="RestResponse"/></returns>
550-
public RestResponse BroadcastLiveCommand(int sourceProjectId, object command);
551+
public RestResponse BroadcastLiveCommand(string organizationId, int? excludeProjectId, object command);
551552
}
552553
}

Tests/Api/CommandTests.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ public void LiveCommand(string commandType)
6767
[TestCase("MyCommand2")]
6868
[TestCase("MyCommand3")]
6969
[TestCase("")]
70-
public void BroadcastCommand(string commandType)
70+
[TestCase("", true)]
71+
public void BroadcastCommand(string commandType, bool excludeProject = false)
7172
{
7273
var command = new Dictionary<string, object>
7374
{
@@ -81,8 +82,8 @@ public void BroadcastCommand(string commandType)
8182
{
8283
// allow algo to be deployed and prices to be set so we can trade
8384
Thread.Sleep(TimeSpan.FromSeconds(10));
84-
// Our project will not receive the broadcast but we can still use it to send a command
85-
var result = _apiClient.BroadcastLiveCommand(projectId, command);
85+
// Our project will not receive the broadcast, unless we pass null value, but we can still use it to send a command
86+
var result = _apiClient.BroadcastLiveCommand(Globals.OrganizationID, excludeProject ? projectId : null, command);
8687
Assert.IsTrue(result.Success);
8788
}
8889
finally

0 commit comments

Comments
 (0)