QuantConnect / Lean.Brokerages.InteractiveBrokers

InteractiveBrokers Brokerage Plugin
Apache License 2.0
27 stars 17 forks source link

Do Not Wait Update Response For Filled Orders #60

Closed AlexCatarino closed 1 year ago

AlexCatarino commented 1 year ago

Expected Behavior

If an order is filled, we don't wait for other responses.

Actual Behavior

If we are trading with tick-resolution data, we might find ourselves in this case: 1 - Place Limit Order: 2023-06-23T18:45:15.2442393Z TRACE:: LiveTradingResultHandler.OrderEvent(): Time: 06/23/2023 18:45:15 OrderID: 106 EventID: 1 Symbol: TSLA Status: Submitted Quantity: -23 LimitPrice: 256.98 Message: Interactive Brokers Order Event BrokerId: 476 2 - Update Limit Order: 2023-06-23T18:45:16.0520910Z TRACE:: InteractiveBrokersBrokerage.UpdateOrder(): Symbol: TSLA Quantity: -23 Status: Submitted Id: 106 3 - Meanwhile the Limit Order was filled: 2023-06-23T18:45:16.0653963Z TRACE:: InteractiveBrokersBrokerage.HandleOrderStatusUpdates(): OrderId: 476, Status: Filled, Filled: 23, Remaining: 0, AverageFillPrice: 256.98, PermId: 1803924168, ParentId: 0, LastFillPrice: 256.98, ClientId: 0, WhyHeld: ,MktCapPrice: 0 4 - So the Update was rejected: 2023-06-23T18:45:16.1461694Z TRACE:: InteractiveBrokersBrokerage.HandleError(): RequestId: 476 ErrorCode: 104 - Cannot modify a filled order.. Origin: [Id=476] IBPlaceOrder: TSLA (STK TSLA USD Smart NASDAQ 0 )

It led to a NoBrokerageResponse 2023-06-23T18:50:16.1445549Z ERROR:: Brokerage.OnMessage(): Error - Code: NoBrokerageResponse - Timeout waiting for brokerage response for brokerage order id 476 lean id 106

Probably from the Update.

Potential Solution

If an order is filled, stop waiting on other responses.

Reproducing the Problem

N/A

Checklist

gatienod10 commented 1 year ago

After update Limit Order and response.IsSuccess is True. How to stop waiting on other responses?