Skip to content

Commit ec41ef2

Browse files
Fix option symbol fix missing fields (#21)
* Fix option symbol fix missing fields * Minor tweak
1 parent 4f1df69 commit ec41ef2

File tree

3 files changed

+22
-22
lines changed

3 files changed

+22
-22
lines changed

QuantConnect.Wolverine/Utility.cs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,6 @@ public static class Utility
2525
/// </summary>
2626
public const int LIMIT_DECIMAL_PLACE = 3;
2727

28-
public static QF.MaturityMonthYear GetMaturityMonthYear(Symbol symbol)
29-
{
30-
if (symbol.SecurityType != SecurityType.Option)
31-
{
32-
throw new NotSupportedException("GetMaturityMonthYear() can only be called for the Option security type.");
33-
}
34-
35-
var ticker = SymbolRepresentation.GenerateFutureTicker(symbol.ID.Symbol, symbol.ID.Date);
36-
var properties = SymbolRepresentation.ParseFutureTicker(ticker);
37-
38-
var maturity = $"{2000 + properties.ExpirationYearShort:D4}{properties.ExpirationMonth:D2}";
39-
40-
return new QF.MaturityMonthYear(maturity);
41-
}
42-
4328
public static QF.TimeInForce ConvertTimeInForce(TimeInForce timeInForce, OrderType orderType)
4429
{
4530
if (timeInForce == TimeInForce.GoodTilCanceled)

QuantConnect.Wolverine/WolverineOrderRoutingSessionHandler.cs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
using QuickFix.FIX42;
1818
using QuickFix.Fields;
1919
using QuantConnect.Orders;
20+
using System.Globalization;
2021
using QuantConnect.Securities;
2122
using QuantConnect.Securities.Equity;
2223
using QuantConnect.Brokerages.Fix.Connection;
@@ -26,6 +27,7 @@ namespace QuantConnect.Brokerages.Wolverine
2627
{
2728
public class WolverineOrderRoutingSessionHandler : MessageCracker, IFixOrdersController
2829
{
30+
private readonly SymbolPropertiesDatabase _symbolPropertiesDatabase = SymbolPropertiesDatabase.FromDataFolder();
2931
private readonly Dictionary<string, string> _exchangeMapping = new() {
3032
{ Exchange.AMEX.Name, "AMEX" },
3133
{ Exchange.ARCA.Name, "ARCA" },
@@ -74,7 +76,7 @@ public bool PlaceOrder(Order order)
7476
{
7577
var side = new Side(order.Direction == OrderDirection.Buy ? Side.BUY : Side.SELL);
7678

77-
var ticker = _symbolMapper.GetBrokerageSymbol(order.Symbol);
79+
var ticker = _symbolMapper.GetBrokerageSymbol(order.Symbol.HasUnderlying ? order.Symbol.Underlying : order.Symbol);
7880
var securityType = new QuickFix.Fields.SecurityType(_symbolMapper.GetBrokerageSecurityType(order.Symbol.SecurityType));
7981

8082
var wexOrder = new NewOrderSingle
@@ -92,10 +94,22 @@ public bool PlaceOrder(Order order)
9294
ExDestination = new ExDestination(GetOrderExchange(order))
9395
};
9496

95-
if (order.Symbol.SecurityType == SecurityType.Option)
97+
if (order.Symbol.SecurityType.IsOption())
9698
{
97-
wexOrder.MaturityMonthYear = Utility.GetMaturityMonthYear(order.Symbol);
9899
wexOrder.StrikePrice = new StrikePrice(decimal.Round(order.Price, Utility.LIMIT_DECIMAL_PLACE));
100+
101+
var expirationDate = order.Symbol.ID.Date;
102+
wexOrder.SetField(new MaturityMonthYear(expirationDate.ToString("yyyyMM", CultureInfo.InvariantCulture)));
103+
wexOrder.SetField(new MaturityDay(expirationDate.Day.ToString(CultureInfo.InvariantCulture)));
104+
wexOrder.SetField(new ContractMultiplier(GetSymbolProperties(order.Symbol).ContractMultiplier));
105+
wexOrder.SetField(new PutOrCall(order.Symbol.ID.OptionRight == OptionRight.Call ? PutOrCall.CALL : PutOrCall.PUT));
106+
}
107+
else if (order.Symbol.SecurityType == SecurityType.Future)
108+
{
109+
var expirationDate = order.Symbol.ID.Date;
110+
wexOrder.SetField(new MaturityMonthYear(expirationDate.ToString("yyyyMM", CultureInfo.InvariantCulture)));
111+
wexOrder.SetField(new MaturityDay(expirationDate.Day.ToString(CultureInfo.InvariantCulture)));
112+
wexOrder.SetField(new ContractMultiplier(GetSymbolProperties(order.Symbol).ContractMultiplier));
99113
}
100114

101115
switch (order.Type)
@@ -162,5 +176,10 @@ private string GetOrderExchange(Order order)
162176
}
163177
return wolverineExchange + exchangePostFix;
164178
}
179+
180+
private SymbolProperties GetSymbolProperties(Symbol symbol)
181+
{
182+
return _symbolPropertiesDatabase.GetSymbolProperties(symbol.ID.Market, symbol, symbol.SecurityType, Currencies.USD);
183+
}
165184
}
166185
}

QuantConnect.Wolverine/WolverineSymbolMapper.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,6 @@ public WolverineSymbolMapper(IMapFileProvider mapFileProvider)
4242

4343
public string GetBrokerageSymbol(Symbol symbol)
4444
{
45-
if (symbol.ID.SecurityType != SecurityType.Equity && symbol.ID.SecurityType != SecurityType.Option)
46-
{
47-
throw new ArgumentException("Invalid security type: " + symbol.ID.SecurityType);
48-
}
4945
return GetMappedTicker(symbol);
5046
}
5147

0 commit comments

Comments
 (0)