diff --git a/Brokerages/Brokerage.cs b/Brokerages/Brokerage.cs index ab58dd19a9d4..641e9606c631 100644 --- a/Brokerages/Brokerage.cs +++ b/Brokerages/Brokerage.cs @@ -660,7 +660,11 @@ protected virtual CrossZeroOrderResponse PlaceCrossZeroOrder(CrossZeroFirstOrder response = PlaceCrossZeroOrder(firstOrderPartRequest); if (response.IsOrderPlacedSuccessfully) { - order.BrokerId.Add(response.BrokerageOrderId.ToStringInvariant()); + var orderId = response.BrokerageOrderId; + if (!order.BrokerId.Contains(orderId)) + { + order.BrokerId.Add(orderId); + } } } @@ -796,8 +800,15 @@ protected bool TryHandleRemainingCrossZeroOrder(Order leanOrder, OrderEvent orde if (response.IsOrderPlacedSuccessfully) { // add the new brokerage id for retrieval later - leanOrder.BrokerId.Add(response.BrokerageOrderId); - LeanOrderByZeroCrossBrokerageOrderId.AddOrUpdate(response.BrokerageOrderId, leanOrder); + var orderId = response.BrokerageOrderId; + if (!leanOrder.BrokerId.Contains(orderId)) + { + leanOrder.BrokerId.Add(orderId); + } + + // leanOrder is a clone, here we can add the new brokerage order Id for the second part of the cross zero + OnOrderIdChangedEvent(new BrokerageOrderIdChangedEvent { OrderId = leanOrder.Id, BrokerId = leanOrder.BrokerId }); + LeanOrderByZeroCrossBrokerageOrderId.AddOrUpdate(orderId, leanOrder); } } diff --git a/Common/Orders/BrokerageOrderIdChangedEvent.cs b/Common/Orders/BrokerageOrderIdChangedEvent.cs index e16d0c0f668e..b85345e2921d 100644 --- a/Common/Orders/BrokerageOrderIdChangedEvent.cs +++ b/Common/Orders/BrokerageOrderIdChangedEvent.cs @@ -23,7 +23,7 @@ namespace QuantConnect.Orders public class BrokerageOrderIdChangedEvent { /// - /// The order ID. + /// The lean order ID. /// public int OrderId { get; set; }