Skip to content

Commit

Permalink
Minor fix for cross order id (QuantConnect#8213)
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin-Molinero authored and wtindall1 committed Nov 10, 2024
1 parent 7c78835 commit 06d205f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
17 changes: 14 additions & 3 deletions Brokerages/Brokerage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

Expand Down Expand Up @@ -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);
}
}
Expand Down
2 changes: 1 addition & 1 deletion Common/Orders/BrokerageOrderIdChangedEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace QuantConnect.Orders
public class BrokerageOrderIdChangedEvent
{
/// <summary>
/// The order ID.
/// The lean order ID.
/// </summary>
public int OrderId { get; set; }

Expand Down

0 comments on commit 06d205f

Please sign in to comment.