17 using System.Collections.Generic;
28 private static readonly Dictionary<string, byte> _optionExpirationErrorLog =
new();
50 var firstDayOfMonth =
new DateTime(date.Year, date.Month, 1).DayOfWeek;
53 var firstFriday = firstDayOfMonth == DayOfWeek.Saturday ? 7 : 6 - (int)firstDayOfMonth;
57 return firstFriday + 7 + 5 < date.Day && date.Day < firstFriday + 2 * 7 + 2 ;
102 var symbolDateTime = symbol.
ID.
Date;
105 symbolDateTime.DayOfWeek == DayOfWeek.Saturday &&
106 symbolDateTime <
new DateTime(2015, 2, 1))
115 while (!exchangeHours.IsDateOpen(symbolDateTime.AddDays(daysBefore)))
120 return symbolDateTime.AddDays(daysBefore).Date;
139 var currentTime = currentTimeUtc.ConvertFromUtc(exchangeHours.TimeZone);
145 : exchangeHours.GetPreviousTradingDay(symbol.
ID.
Date);
147 var expiryTime = exchangeHours.GetNextMarketClose(expiryDay,
false);
152 if (expiryTime >= symbol.
ID.
Date.AddDays(1).Date)
154 lock (_optionExpirationErrorLog)
158 && _optionExpirationErrorLog.TryAdd($
"{symbol.ID.Underlying}-{symbol.ID.Date}", 1))
160 Logging.Log.Error($
"OptionSymbol.IsOptionContractExpired(): limiting unexpected option expiration time for symbol {symbol.ID}. Symbol.ID.Date {symbol.ID.Date}. ExpiryTime: {expiryTime}");
163 expiryTime = symbol.
ID.
Date.AddDays(1).Date;
166 return currentTime >= expiryTime;