Lean icon indicating copy to clipboard operation
Lean copied to clipboard

Adds Algorithm Exception Handler

Open AlexCatarino opened this issue 1 year ago • 4 comments

Expected Behavior

Be able to take action when a runtime exception is raised.

Actual Behavior

If a runtime error occurs, we cannot take actions such as close positions and open orders.

Potential Solution

Add IAlgorithm.OnError method.

Reproducing the Problem

from AlgorithmImports import *
class FormalFluorescentYellowPenguin(QCAlgorithm):
    def initialize(self):
        self.set_start_date(2024, 6, 30)
        self.add_crypto("BTCUSD")
    def on_data(self, data):
        x=1/0
    def on_end_of_algorithm(self):
        self.liquidate()

In this case, on_end_of_algorithm is not called, so we cannot close positions and open orders if we want to.

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

AlexCatarino avatar Aug 01 '24 15:08 AlexCatarino

Hi @AlexCatarino, @Martin-Molinero I have raised the pull request for this issue.

keshavdalmia10 avatar Aug 20 '24 16:08 keshavdalmia10

Hi @keshavdalmia10, Before you work on an issue, I suggest adding comments to show that you understand what needs to be done and what you will do, then wait for feedback. When someone (e.g. me) opens a GitHub issue for a feature request, they may not know what needs to be done or the best way to do it.

By the way, your https://github.com/QuantConnect/Lean/pull/8266 doesn't have a unit and/or a regression test to show it solves the issue.

AlexCatarino avatar Aug 23 '24 14:08 AlexCatarino

Hi @keshavdalmia10, Before you work on an issue, I suggest adding comments to show that you understand what needs to be done and what you will do, then wait for feedback. When someone (e.g. me) opens a GitHub issue for a feature request, they may not know what needs to be done or the best way to do it.

By the way, your #8266 doesn't have a unit and/or a regression test to show it solves the issue.

I had pinged you on Discord for it.

keshavdalmia10 avatar Aug 23 '24 15:08 keshavdalmia10

Hi @Martin-Molinero , can you guide a little over here on how to make the test case for it?

keshavdalmia10 avatar Aug 23 '24 15:08 keshavdalmia10