@@ -416,10 +416,9 @@ public override bool PlaceOrder(Order order)
416416 {
417417 try
418418 {
419- Log . Trace ( $ "InteractiveBrokersBrokerage.PlaceOrder(): Symbol: { order . Symbol . Value } Quantity: { order . Quantity } . Id: { order . Id } ") ;
420-
421419 if ( ! IsConnected )
422420 {
421+ Log . Trace ( $ "InteractiveBrokersBrokerage.PlaceOrder(): Symbol: { order . Symbol . Value } Quantity: { order . Quantity } . Id: { order . Id } ") ;
423422 OnMessage (
424423 new BrokerageMessageEvent (
425424 BrokerageMessageType . Warning ,
@@ -1536,6 +1535,8 @@ private void IBPlaceOrder(Order order, bool needsNewId, string exchange = null)
15361535 throw new ArgumentException ( "Expected order with populated BrokerId for updating orders." ) ;
15371536 }
15381537
1538+ Log . Trace ( $ "InteractiveBrokersBrokerage.PlaceOrder(): Symbol: { order . Symbol . Value } Quantity: { order . Quantity } . Id: { order . Id } . BrokerId: { ibOrderId } ") ;
1539+
15391540 _requestInformation [ ibOrderId ] = new RequestInformation
15401541 {
15411542 RequestId = ibOrderId ,
@@ -1627,9 +1628,9 @@ public static string GetContractDescription(Contract contract)
16271628 /// <param name="contract">The IB <see cref="Contract"/> object containing contract details.</param>
16281629 /// <param name="symbol">The Lean <see cref="Symbol"/> object representing the security.</param>
16291630 /// <returns>
1630- /// The name of the primary exchange as a string.
1631- /// If the market is USA and Lean provides an exchange, that value is returned.
1632- /// Otherwise, falls back to the IB contract's <c>PrimaryExch</c> field.
1631+ /// The name of the primary exchange as a string.
1632+ /// If the market is USA and Lean provides an exchange, that value is returned.
1633+ /// Otherwise, falls back to the IB contract's <c>PrimaryExch</c> field.
16331634 /// Returns <c>null</c> if no exchange information is available.
16341635 /// </returns>
16351636 internal string GetPrimaryExchange ( Contract contract , Symbol symbol )
@@ -2495,7 +2496,11 @@ private void HandleCommissionReport(object sender, IB.CommissionReportEventArgs
24952496 private Order GetOrder ( IB . ExecutionDetailsEventArgs executionDetails )
24962497 {
24972498 var mappedSymbol = MapSymbol ( executionDetails . Contract ) ;
2498- var order = _orderProvider . GetOrdersByBrokerageId ( executionDetails . Execution . OrderId ) . SingleOrDefault ( o => o . Symbol == mappedSymbol ) ;
2499+ var orders = _orderProvider . GetOrdersByBrokerageId ( executionDetails . Execution . OrderId ) ;
2500+ var order = orders . Count == 1
2501+ ? orders [ 0 ]
2502+ : orders . SingleOrDefault ( o => o . Symbol == mappedSymbol ) ;
2503+
24992504 if ( order == null )
25002505 {
25012506 if ( executionDetails . Execution . Liquidation == 1 )
@@ -2510,9 +2515,14 @@ private Order GetOrder(IB.ExecutionDetailsEventArgs executionDetails)
25102515 // this event will add the order into the lean engine
25112516 OnNewBrokerageOrderNotification ( new NewBrokerageOrderNotificationEventArgs ( order ) ) ;
25122517 }
2518+ else if ( orders . Count == 0 )
2519+ {
2520+ Log . Error ( $ "InteractiveBrokersBrokerage.HandleExecutionDetails(): Unable to locate order with BrokerageID { executionDetails . Execution . OrderId } ") ;
2521+ }
25132522 else
25142523 {
2515- Log . Error ( "InteractiveBrokersBrokerage.HandleExecutionDetails(): Unable to locate order with BrokerageID " + executionDetails . Execution . OrderId ) ;
2524+ Log . Error ( $ "InteractiveBrokersBrokerage.HandleExecutionDetails(): Unable to locate order with BrokerageID { executionDetails . Execution . OrderId } " +
2525+ $ "for symbol { mappedSymbol . ID } . Actual securities traded with this order ID are { string . Join ( ", " , orders . Select ( x => x . Symbol . ID ) ) } ") ;
25162526 }
25172527 }
25182528
@@ -2708,7 +2718,7 @@ private void HandlePortfolioUpdates(object sender, IB.UpdatePortfolioEventArgs e
27082718 }
27092719
27102720 /// <summary>
2711- /// Merges a holding into the current holdings dictionary.
2721+ /// Merges a holding into the current holdings dictionary.
27122722 /// If the symbol already exists, quantities are summed and a new weighted average price is calculated.
27132723 /// If it's a new symbol, the holding is added directly.
27142724 /// </summary>
0 commit comments