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
9 changes: 0 additions & 9 deletions Common/Messages/Messages.Securities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -970,15 +970,6 @@ public static string SymbolNotFoundInSymbolPropertiesDatabase(QuantConnect.Symbo
/// </summary>
public static class SecurityTransactionManager
{
/// <summary>
/// Returns a string message saying CancelOpenOrders operation is not allowed in Initialize or during warm up
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string CancelOpenOrdersNotAllowedOnInitializeOrWarmUp()
{
return $"This operation is not allowed in {FormatCode("Initialize")} or during warm up: {FormatCode("CancelOpenOrders")}. Please move this code to the {FormatCode("OnWarmupFinished")}() method.";
}

/// <summary>
/// Returns a string message saying the order was canceled by the CancelOpenOrders() at the given time
/// </summary>
Expand Down
4 changes: 2 additions & 2 deletions Common/Securities/SecurityTransactionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ public List<OrderTicket> CancelOpenOrders()
{
if (_algorithm != null && _algorithm.IsWarmingUp)
{
throw new InvalidOperationException(Messages.SecurityTransactionManager.CancelOpenOrdersNotAllowedOnInitializeOrWarmUp());
return new List<OrderTicket>();
}

var cancelledOrders = new List<OrderTicket>();
Expand All @@ -275,7 +275,7 @@ public List<OrderTicket> CancelOpenOrders(Symbol symbol, string tag = null)
{
if (_algorithm != null && _algorithm.IsWarmingUp)
{
throw new InvalidOperationException(Messages.SecurityTransactionManager.CancelOpenOrdersNotAllowedOnInitializeOrWarmUp());
return new List<OrderTicket>();
}

var cancelledOrders = new List<OrderTicket>();
Expand Down
12 changes: 12 additions & 0 deletions Tests/Common/Securities/SecurityTransactionManagerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,18 @@ public void WorksProperlyWithPyObjects()
transactionHandler.Exit();
}

[Test]
public void CancelOpenOrdersReturnsEmptyWhileWarmingUp()
{
var algorithm = new QCAlgorithm();
algorithm.SubscriptionManager.SetDataManager(new DataManagerStub(algorithm));
var spy = algorithm.AddEquity("SPY").Symbol;

Assert.IsTrue(algorithm.IsWarmingUp);
Assert.IsEmpty(algorithm.Transactions.CancelOpenOrders());
Assert.IsEmpty(algorithm.Transactions.CancelOpenOrders(spy));
}

[Test]
public void OrderEnumerablesAreMemoizedExposingCount()
{
Expand Down
Loading