Lean icon indicating copy to clipboard operation
Lean copied to clipboard

Do Not Process Option Events During Shutdown

Open AlexCatarino opened this issue 8 months ago • 0 comments

Expected Behavior

Do not process option events during shutdown

Actual Behavior

After the live deployment is stopped, we should not process options events.

The algorithm was stopped at 15:06:44 UTC

2025-05-08T15:06:44.8169540Z TRACE:: BaseCommandHandler.ProcessCommands(): Executing QuantConnect.Cloud.Commands.AlgorithmStatusCommand 2025-05-08T15:06:44.8180325Z ERROR:: AlgorithmManager.Run(): Algorithm state changed to Stopped at 05/08/2025 15:06:44 2025-05-08T15:06:44.8183469Z TRACE:: AlgorithmManager.Run(): Firing On End Of Algorithm... 2025-05-08T15:06:44.8193036Z TRACE:: AlgorithmManager.Run(): Stopping algorithm... 2025-05-08T15:06:44.8195214Z TRACE:: LiveTradingResultHandler.SendStatusUpdate(): status: 'Stopped'. 2025-05-08T15:06:44.8195394Z TRACE:: LiveTradingResultHandler.SendStatusUpdate(): status: 'Completed'.

The user closed positions manually during the shutdown, which triggered an option event:

SPY 250508C00565000 is 779981787 (ConId). We can see that position size changed from -8 to 0 between 15:07:15 and 15:07:26 UTC:

2025-05-08T15:07:15.1954269Z TRACE:: InteractiveBrokersBrokerage.HandlePortfolioUpdates(): Contract: OPT SPY USD , ConId: 779981787, Position: -8, MarketPrice: 1.19000005, MarketValue: -952, AverageCost: 202.2836166, UnrealisedPnl: 0, RealisedPnl: 666.27, AccountName: U1234567 2025-05-08T15:07:26.0081587Z TRACE:: InteractiveBrokersBrokerage.HandlePortfolioUpdates(): Contract: OPT SPY USD , ConId: 779981787, Position: 0, MarketPrice: 1.23, MarketValue: 0, AverageCost: 0, UnrealisedPnl: 616.69, RealisedPnl: 0, AccountName: U1234567

It triggered an order event:

2025-05-08T15:07:26.0197899Z TRACE:: LiveTradingResultHandler.OrderEvent(): Time: 05/08/2025 15:06:44 OrderID: 24 EventID: 1 Symbol: SPY 250508P00565000 Status: Filled Quantity: 8 FillQuantity: 8 FillPrice: 0 Message: Automatic Assignment. Underlying: 563.27 IsAssignment: True BrokerId:

Potential Solution

N/A

Reproducing the Problem

Stop the algorithm and quickly close positions manually on TWS...

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 May 13 '25 13:05 AlexCatarino