QuantConnect/Lean · error · ArgumentException
Expiry event was not at the correct time, {orderEvent.UtcTim
Error message
Expiry event was not at the correct time, {orderEvent.UtcTime} What it means
Thrown in OnOrderEvent when an OTM option-expiration order event has a UtcTime that is not exactly 2016-01-16 05:00:00 UTC. The assertion verifies that option expiry processing fires at the correct time (midnight Eastern = 05:00 UTC for daily-resolution options). A time mismatch indicates the expiry scheduler or timezone conversion changed.
Source
Thrown at Algorithm.CSharp/BasicTemplateOptionsDailyAlgorithm.cs:96
}
}
/// <summary>
/// Order fill event handler. On an order fill update the resulting information is passed to this method.
/// </summary>
/// <param name="orderEvent">Order event details containing details of the events</param>
/// <remarks>This method can be called asynchronously and so should only be used by seasoned C# experts. Ensure you use proper locks on thread-unsafe objects</remarks>
public override void OnOrderEvent(OrderEvent orderEvent)
{
Log(orderEvent.ToString());
// Check for our expected OTM option expiry
if (orderEvent.Message.Contains("OTM", StringComparison.InvariantCulture))
{
// Assert it is at midnight (5AM UTC)
if (orderEvent.UtcTime != new DateTime(2016, 1, 16, 5, 0, 0))
{
throw new ArgumentException($"Expiry event was not at the correct time, {orderEvent.UtcTime}");
}
_optionExpired = true;
}
}
public override void OnEndOfAlgorithm()
{
// Assert we had our option expire and fill a liquidation order
if (_optionExpired != true)
{
throw new ArgumentException("Algorithm did not process the option expiration like expected");
}
}
/// <summary>
/// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
/// </summary>View on GitHub (pinned to d2c3659f87)
Solutions
- Verify the AAPL option contract expiry date in the data matches 2016-01-15 (expiration processed the following midnight/early morning).
- Check the algorithm's SetTimeZone — for daily options the expiry is processed at midnight exchange time.
- Inspect the OptionExerciseProcess or expiry event generation code for timing changes.
- Log orderEvent.UtcTime alongside the expected value to identify the exact offset difference.
- Confirm daylight saving time status for the date (January = EST = UTC-5, so midnight EST = 05:00 UTC).
Example fix
// before
if (orderEvent.UtcTime != new DateTime(2016, 1, 16, 5, 0, 0))
{
throw new ArgumentException($"Expiry event was not at the correct time, {orderEvent.UtcTime}");
}
// after — compute expected from exchange timezone for robustness
var expectedExpiryUtc = new DateTime(2016, 1, 16, 5, 0, 0);
Log($"Expiry event UtcTime: {orderEvent.UtcTime}, Expected: {expectedExpiryUtc}");
if (orderEvent.UtcTime != expectedExpiryUtc)
{
throw new ArgumentException($"Expiry event was not at the correct time, {orderEvent.UtcTime}");
} Defensive patterns
Strategy: validation
Validate before calling
// Validate expiry timing before asserting
var expectedUtc = new DateTime(2016, 1, 16, 5, 0, 0);
if (orderEvent.Message.Contains("OTM") && orderEvent.UtcTime != expectedUtc)
{
Log($"Expiry timing off: got {orderEvent.UtcTime} (kind={orderEvent.UtcTime.Kind}), expected {expectedUtc}");
} Prevention
- Document the expected UTC expiry time and its derivation (exchange midnight + UTC offset).
- Log all OTM-related order events with full UtcTime to build a trace.
- Verify the option contract expiry date in data matches the expected date.
- Check for daylight saving time transitions that affect the UTC offset.
When it happens
Trigger: The Lean engine's option-expiry timing logic changed, the algorithm's time zone is configured differently, daylight saving time boundaries shifted the UTC offset, or the option data's expiry date was modified.
Common situations: Engine refactoring of the OptionExerciseProcess or expiry scheduling, timezone database updates, changes to how daily-resolution options compute their expiration timestamp, or data file modifications to the AAPL option expiry date.
Related errors
- Algorithm did not process the option expiration like expecte
- Unexpected open interest time: {openInterest.Single().EndTim
- Unexpected history data start time
- Index is not tradable.
- Trade volume should be greater than zero by the end of this
AI-assisted analysis of QuantConnect/Lean@d2c3659f87 (2026-08-13).
Data as JSON: /api/errors/95aabf258a3ac39a.
Report an issue: GitHub.