Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep OnData and OnOrderEvent python reference #2809

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions AlgorithmFactory/Python/Wrappers/AlgorithmPythonWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ namespace QuantConnect.AlgorithmFactory.Python.Wrappers
public class AlgorithmPythonWrapper : IAlgorithm
{
private readonly dynamic _algorithm = null;
private readonly dynamic _onData;
private readonly dynamic _onOrderEvent;
private readonly IAlgorithm _baseAlgorithm;
private readonly bool _isOnDataDefined = false;

Expand Down Expand Up @@ -82,8 +84,11 @@ public AlgorithmPythonWrapper(string moduleName)

// determines whether OnData method was defined or inherits from QCAlgorithm
// If it is not, OnData from the base class will not be called
var pythonType = (_algorithm as PyObject).GetAttr("OnData").GetPythonType();
_onData = (_algorithm as PyObject).GetAttr("OnData");
var pythonType = _onData.GetPythonType();
_isOnDataDefined = pythonType.Repr().Equals("<class \'method\'>");

_onOrderEvent = (_algorithm as PyObject).GetAttr("OnOrderEvent");
}
}

Expand Down Expand Up @@ -543,7 +548,7 @@ public void OnData(Slice slice)
{
using (Py.GIL())
{
_algorithm.OnData(SubscriptionManager.HasCustomData ? new PythonSlice(slice) : slice);
_onData(SubscriptionManager.HasCustomData ? new PythonSlice(slice) : slice);
}
}
}
Expand Down Expand Up @@ -688,7 +693,7 @@ public void OnOrderEvent(OrderEvent newEvent)
{
using (Py.GIL())
{
_algorithm.OnOrderEvent(newEvent);
_onOrderEvent(newEvent);
}
}

Expand Down