Hi,
I am testing orders on the paper money IB account. 
I am running into two issues regarding IB account.
1. The algo restarts every morning around 9:02am. I don't know why? I have the following logs showing consecutive 2 days:
2022-03-08 14:02:00 Launching analysis for L-ee6fa214f4ee2ab74db78867eb63453d with LEAN Engine v2.5.0.0.13694
2022-03-08 14:08:16 Interactive Brokers Brokerage account base currency: USD
2022-03-08 14:08:16 Trading Live!

2022-03-09 14:02:37 BrokerageSetupHandler.Setup(): Open order detected.  Creating order tickets for open order MMP with quantity 255. Beware that this order ticket may not accurately reflect the quantity of the order if the open order is partially filled.

2022-03-09 14:02:37 Launching analysis for L-ed8f66cb4a7ee35cf412a306537671c1 with LEAN Engine v2.5.0.0.13699
2022-03-09 14:08:23 Interactive Brokers Brokerage account base currency: USD
2022-03-09 14:08:23 Trading Live!

2. the second issue is related to an open order that I created on 03/08. This order comes back on 03/09 but the tag I have on the order is something else. Because of that, my order logic does not work. Is there a way to recover the tag for any order when we receive the order from IB after the restart?


More details about this open stopLimit order:
2022-03-08 19:12:01 New Order Event: Time: 03/08/2022 19:12:01 OrderID: 2 EventID: 1 Symbol: MMP Status: Submitted Quantity: 255 LimitPrice: 49.86 StopPrice: 49.61 Message: Interactive Brokers Order Event
2022-03-08 19:12:01 Submitted order: Time: 03/08/2022 19:12:01 OrderID: 2 EventID: 1 Symbol: MMP Status: Submitted Quantity: 255 LimitPrice: 49.86 StopPrice: 49.61 Message: Interactive Brokers Order Event
2022-03-08 19:12:01 UpdateSubmittedOrders Entry.StopLimit 

 

def OnOrderEvent(self, orderEvent):
        ticket = self.Transactions.GetOrderTicket(orderEvent.OrderId)
        order = self.Transactions.GetOrderById(orderEvent.OrderId)
                    
        if orderEvent.Status == OrderStatus.Submitted or orderEvent.Status == OrderStatus.UpdateSubmitted:
        	self.Log(f'Submitted order: {str(orderEvent)}')
            self.Log(f'UpdateSubmittedOrders {order.Tag}')

        if orderEvent.FillQuantity == 0:
            return

        if orderEvent.Status == OrderStatus.Filled:
            self.Debug(f'{self.Time}: Trade: {ticket.Symbol}, Qty:{ticket.Quantity}, Price:{ticket.AverageFillPrice}, Tag:{ticket.Tag}')
            self.Log(f'UpdateFilledOrders: {order}')
            

 

On the following day, the open order events comes with Tag of “Stop Price: ¤49.61 Limit Price: ¤49.86” which was not right.


2022-03-09 15:01:56 New Order Event: Time: 03/09/2022 15:01:56 OrderID: 2 EventID: 1 Symbol: MMP Status: Submitted Quantity: 255 LimitPrice: 49.86 StopPrice: 49.61 Message: Interactive Brokers Order Event
2022-03-09 15:01:57 New Order Event: Time: 03/09/2022 15:01:57 OrderID: 2 EventID: 2 Symbol: MMP Status: PartiallyFilled Quantity: 255 FillQuantity: 100 FillPrice: 49.63 USD LimitPrice: 49.86 StopPrice: 49.61 OrderFee: 1 USD Message: Interactive Brokers Order Fill Event - 155 remaining
2022-03-09 15:01:57 New Order Event: Time: 03/09/2022 15:01:57 OrderID: 2 EventID: 3 Symbol: MMP Status: PartiallyFilled Quantity: 255 FillQuantity: 100 FillPrice: 49.63 USD LimitPrice: 49.86 StopPrice: 49.61 Message: Interactive Brokers Order Fill Event - 55 remaining
2022-03-09 15:01:57 New Order Event: Time: 03/09/2022 15:01:57 OrderID: 2 EventID: 4 Symbol: MMP Status: Filled Quantity: 255 FillQuantity: 55 FillPrice: 49.63 USD LimitPrice: 49.86 StopPrice: 49.61 OrderFee: 0.275 USD Message: Interactive Brokers Order Fill Event
2022-03-09 15:01:57 2022-03-09 10:01:56.800064: Trade: MMP, Qty:255.0, Price:49.63, Tag:Stop Price: ¤49.61 Limit Price: ¤49.86 - Interactive Brokers Order Fill Event
2022-03-09 15:01:57 Submitted order: Time: 03/09/2022 15:01:56 OrderID: 2 EventID: 1 Symbol: MMP Status: Submitted Quantity: 255 LimitPrice: 49.86 StopPrice: 49.61 Message: Interactive Brokers Order Event
2022-03-09 15:01:57 UpdateSubmittedOrders Stop Price: ¤49.61 Limit Price: ¤49.86
2022-03-09 15:01:57 UpdateFilledOrders: OrderId: 2 (BrokerId: 5) Filled StopLimit order for 255 units of MMP: Stop Price: ¤49.61 Limit Price: ¤49.86 - Interactive Brokers Order Fill Event at stop 49.61 limit 49.86

Author