Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
* limitations under the License.
*
*/
using System;
using System.Collections.Generic;
using QuantConnect.Orders;
using QuantConnect.Algorithm;
using QuantConnect.Lean.Engine.TransactionHandlers;

namespace QuantConnect.Lean.Engine.Results.Analysis.Analyses
{
Expand Down Expand Up @@ -53,7 +55,8 @@ public class OrderFillsDuringExtendedMarketHoursAnalysis : BaseResultsAnalysis

foreach (var orderEvent in orderEvents)
{
if (orderEvent.Status != OrderStatus.Filled || !algorithm.Securities.TryGetValue(orderEvent.Symbol, out var security))
if (orderEvent.Status != OrderStatus.Filled || !algorithm.Securities.TryGetValue(orderEvent.Symbol, out var security)
|| orderEvent.Message?.Contains(BrokerageTransactionHandler.LiquidateFromDelistingTag, StringComparison.InvariantCultureIgnoreCase) == true)
{
continue;
}
Expand All @@ -74,7 +77,7 @@ public class OrderFillsDuringExtendedMarketHoursAnalysis : BaseResultsAnalysis
}

var potentialSolutions = result.Count > 0 ? Solutions(language) : [];
return SingleResponse(orderEvents.Count > 0 ? orderEvents[0] : null, orderEvents.Count > 1 ? orderEvents.Count : null, potentialSolutions);
return SingleResponse(result.Count > 0 ? result[0] : null, result.Count > 1 ? result.Count : null, potentialSolutions);
}

/// <summary>
Expand Down
10 changes: 8 additions & 2 deletions Engine/TransactionHandlers/BrokerageTransactionHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ namespace QuantConnect.Lean.Engine.TransactionHandlers
/// </summary>
public class BrokerageTransactionHandler : ITransactionHandler
{
/// <summary>
/// The tag used for order events of liquidations triggered by a delisting
/// </summary>
public static readonly string LiquidateFromDelistingTag = "Liquidate from delisting";

private IAlgorithm _algorithm;
private QCAlgorithm _qcAlgorithmInstance;
private SignalExportManager _signalExport;
Expand Down Expand Up @@ -1545,7 +1550,7 @@ private void HandleDelistingNotification(DelistingNotificationEventArgs e)
var quantity = -security.Holdings.Quantity;
if (quantity != 0)
{
var tag = "Liquidate from delisting";
var tag = LiquidateFromDelistingTag;

// Create our order and add it
var order = new MarketOrder(security.Symbol, quantity, _algorithm.UtcTime, tag);
Expand All @@ -1556,7 +1561,8 @@ private void HandleDelistingNotification(DelistingNotificationEventArgs e)
{
FillPrice = security.Price,
Status = OrderStatus.Filled,
FillQuantity = order.Quantity
FillQuantity = order.Quantity,
Message = tag
};

// Process this order event
Expand Down
Loading