Lean icon indicating copy to clipboard operation
Lean copied to clipboard

BrokerageMessageHandler Python implementations

Open jhonabreul opened this issue 1 year ago • 0 comments

Expected Behavior

We can use custom implementations of the DefaultBrokerageMessageHandler in Python.

Actual Behavior

If the custom brokerage message handler inherits DefaultBrokerageMessageHandler, the base methods are used instead of the derived ones.

A workaround is implementing directly IBrokerageMessageHandler but this requires setting the __namespace__ attribute in order for Pythonnet to be able to pick it up.

Potential Solution

Add and overload for the SetBrokerageMessageHandler method in AlgorithmPythonWrapper that takes a PyObject and wraps it in BrokerageMessageHandlerPythonWrapper

Reproducing the Problem

See the algorithm in https://github.com/QuantConnect/Lean/blob/8bcd491fc3cb42882db2bd5000f1aefe331f713a/Algorithm.Python/CustomBrokerageSideOrderHandlingRegressionAlgorithm.py which can be ran with the RunRegressionAlgorithm unit test in https://github.com/QuantConnect/Lean/blob/8bcd491fc3cb42882db2bd5000f1aefe331f713a/Tests/Engine/CustomBrokerageMessageHandlerTests.cs

System Information

Windows 11 QC Cloud

Checklist

  • [x] I have completely filled out this template
  • [x] I have confirmed that this issue exists on the current master branch
  • [x] I have confirmed that this is not a duplicate issue by searching issues
  • [x] I have provided detailed steps to reproduce the issue

jhonabreul avatar Mar 28 '24 22:03 jhonabreul