Skip to content

Commit

Permalink
Improve implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Marinovsky committed Jan 25, 2024
1 parent 7a6167a commit 87c635d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Common/Brokerages/InteractiveBrokersBrokerageModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public override bool CanSubmitOrder(Security security, Order order, out Brokerag

return false;
}
else if (order.Type == OrderType.MarketOnClose && (security.Type == SecurityType.Option || security.Type == SecurityType.IndexOption))
else if (order.Type == OrderType.MarketOnClose && security.Type.IsOption())
{
message = new BrokerageMessageEvent(BrokerageMessageType.Warning,
"InteractiveBrokers does not support Market-on-Close orders for Options",
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 @@ -117,6 +117,37 @@ public void CannotSubmitMOCOrdersForIndexOptions()
Assert.AreEqual(expectedMessage, message.Message);
}

[Test]
public void CannotSubmitMOCOrdersForFutureOptions()
{
var underlyingFuture = Symbol.CreateFuture(
QuantConnect.Securities.Futures.Indices.SP500EMini,
Market.CME,
new DateTime(2021, 3, 19));

var futureOption = Symbol.CreateOption(underlyingFuture,
Market.CME,
OptionStyle.American,
OptionRight.Call,
2550m,
new DateTime(2021, 3, 19));

var futureOptionSecurity = new QuantConnect.Securities.FutureOption.FutureOption(
futureOption,
MarketHoursDatabase.FromDataFolder().GetExchangeHours(Market.CME, futureOption, futureOption.SecurityType),
new Cash("USD", 100000m, 1m),
new OptionSymbolProperties(string.Empty, "USD", 1m, 0.01m, 1m),
new CashBook(),
new RegisteredSecurityDataTypesProvider(),
new SecurityCache(),
null);

var futureOptionOrder = new MarketOnCloseOrder(futureOption, 1, DateTime.UtcNow);
var result = _interactiveBrokersBrokerageModel.CanSubmitOrder(futureOptionSecurity, futureOptionOrder, out var message);
Assert.IsFalse(result);
var expectedMessage = "The InteractiveBrokersBrokerageModel does not support MarketOnClose order type. Only supports [Market,MarketOnOpen,Limit,StopMarket,StopLimit,TrailingStop,LimitIfTouched,ComboMarket,ComboLimit,ComboLegLimit,OptionExercise]";
Assert.AreEqual(expectedMessage, message.Message);
}

private static List<Security> GetUnsupportedOptions()
{
Expand Down

0 comments on commit 87c635d

Please sign in to comment.