Adds BroadcastCommand Method (#8617)
Regression Tests / build (push) Has been cancelled
Report Generator Tests / build (push) Has been cancelled
Research Regression Tests / build (push) Has been cancelled
Python Virtual Environments / build (push) Has been cancelled
API Tests / build (push) Has been cancelled
Benchmarks / build (push) Has been cancelled
Build & Test Lean / build (push) Has been cancelled
Regression Tests / build (push) Has been cancelled
Report Generator Tests / build (push) Has been cancelled
Research Regression Tests / build (push) Has been cancelled
Python Virtual Environments / build (push) Has been cancelled
API Tests / build (push) Has been cancelled
Benchmarks / build (push) Has been cancelled
Build & Test Lean / build (push) Has been cancelled
* Adds BroadcastCommand Method Send a command to all live algorithms. * Addresses Peer-Review * Minor tweaks --------- Co-authored-by: Martin Molinero <martin.molinero1@gmail.com>
This commit is contained in:
committed by
GitHub
parent
07003af6d5
commit
49265bd773
@@ -33,6 +33,7 @@ using QuantConnect.Util;
|
||||
using QuantConnect.Interfaces;
|
||||
using QuantConnect.Orders;
|
||||
using QuantConnect.Commands;
|
||||
using QuantConnect.Api;
|
||||
|
||||
namespace QuantConnect.Algorithm
|
||||
{
|
||||
@@ -1735,15 +1736,37 @@ namespace QuantConnect.Algorithm
|
||||
/// <param name="command">The target command</param>
|
||||
/// <returns>The authenticated link</returns>
|
||||
public string Link(PyObject command)
|
||||
{
|
||||
var payload = ConvertCommandToPayload(command, out var typeName);
|
||||
return CommandLink(typeName, payload);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Broadcast a live command
|
||||
/// </summary>
|
||||
/// <param name="command">The target command</param>
|
||||
/// <returns><see cref="RestResponse"/></returns>
|
||||
public RestResponse BroadcastCommand(PyObject command)
|
||||
{
|
||||
var payload = ConvertCommandToPayload(command, out var typeName);
|
||||
return SendBroadcast(typeName, payload);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Convert the command to a dictionary payload
|
||||
/// </summary>
|
||||
/// <param name="command">The target command</param>
|
||||
/// <param name="typeName">The type of the command</param>
|
||||
/// <returns>The dictionary payload</returns>
|
||||
private Dictionary<string, object> ConvertCommandToPayload(PyObject command, out string typeName)
|
||||
{
|
||||
using var _ = Py.GIL();
|
||||
|
||||
var strResult = CommandPythonWrapper.Serialize(command);
|
||||
using var pyType = command.GetPythonType();
|
||||
var wrappedType = Extensions.CreateType(pyType);
|
||||
|
||||
var payload = JsonConvert.DeserializeObject<Dictionary<string, object>>(strResult);
|
||||
return CommandLink(wrappedType.Name, payload);
|
||||
typeName = Extensions.CreateType(pyType).Name;
|
||||
|
||||
return JsonConvert.DeserializeObject<Dictionary<string, object>>(strResult);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user