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
7 changes: 7 additions & 0 deletions Common/Brokerages/InteractiveBrokersBrokerageModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,13 @@ public override bool CanSubmitOrder(Security security, Order order, out Brokerag
return false;
}

if (order.Type == OrderType.ComboLegLimit && order.GroupOrderManager?.Count >= 4)
{
message = new BrokerageMessageEvent(BrokerageMessageType.Warning, "NotSupported",
Messages.InteractiveBrokersBrokerageModel.UnsupportedFourLegComboLegLimitOrders(this));
return false;
}

// validate security type
if (security.Type != SecurityType.Equity &&
security.Type != SecurityType.Forex &&
Expand Down
9 changes: 9 additions & 0 deletions Common/Messages/Messages.Brokerages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,15 @@ public static string UnsupportedExerciseForIndexAndCashSettledOptions(Brokerages
order.Type} exercises for index and cash-settled options.");
}

/// <summary>
/// Returns a string message saying the given brokerage model does not support four-leg combo leg limit orders
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string UnsupportedFourLegComboLegLimitOrders(Brokerages.InteractiveBrokersBrokerageModel brokerageModel)
{
return Invariant($"The {brokerageModel.GetType().Name} does not support four-leg ComboLegLimit orders. Use ComboLimit orders for four-leg combinations or more.");
}

/// <summary>
/// Returns a string message containing the minimum and maximum limits for the allowable order size as well as the currency
/// </summary>
Expand Down
31 changes: 31 additions & 0 deletions Tests/Common/Brokerages/InteractiveBrokersBrokerageModelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,37 @@ public void CanSubmitMOOOrdersForOptionAndEquity(string ticker, SecurityType sec
Assert.IsTrue(result);
}

[TestCase(OrderType.ComboLegLimit, 2, true)]
[TestCase(OrderType.ComboLimit, 4, true)]
[TestCase(OrderType.ComboLegLimit, 4, false)]
public void CanSubmitComboOrdersWithExpectedLegValidation(OrderType orderType, int legCount, bool shouldSubmit)
{
var algo = new AlgorithmStub();
var security = algo.AddSecurity(SecurityType.Option, "SPY");
var groupOrderManager = new GroupOrderManager(1, legCount, 1, 100m);

Order order = orderType switch
{
OrderType.ComboLimit => new ComboLimitOrder(security.Symbol, 1, 100m, DateTime.UtcNow, groupOrderManager),
OrderType.ComboLegLimit => new ComboLegLimitOrder(security.Symbol, 1, 100m, DateTime.UtcNow, groupOrderManager),
_ => throw new ArgumentOutOfRangeException(nameof(orderType), orderType, "Unexpected combo order type")
};

var canSubmit = _interactiveBrokersBrokerageModel.CanSubmitOrder(security, order, out var message);
Assert.AreEqual(shouldSubmit, canSubmit);

if (shouldSubmit)
{
Assert.IsNull(message);
}
else
{
Assert.AreEqual(BrokerageMessageType.Warning, message.Type);
Assert.AreEqual("NotSupported", message.Code);
StringAssert.Contains("does not support four-leg ComboLegLimit orders", message.Message);
}
}

[TestCase("ES", SecurityType.Future)]
[TestCase("SPY", SecurityType.Equity)]
[TestCase("DE10YBEUR", SecurityType.Cfd)]
Expand Down