SecurityExchangeHours.GetNextMarketClose returns midnight when the next day has an early close (GetNextOrPreviousSegment)

Abierto
#9,989 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
66/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
csharp

Línea de trabajo

Start in Common/Securities/SecurityExchangeHours.cs at GetNextOrPreviousSegment, then trace how GetNextMarketClose uses its result for a session crossing midnight. The issue provides a synthetic exchange-hours reproduction with an early close at 12:00; use it to check the behavior. Done means the reproduced call returns the next day's 12:00 close while existing market-hours behavior remains correct.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Expected Behavior

For a market that trades continuously across midnight, GetNextMarketClose(t, extendedMarketHours: true) should return the end of the continuous session. If the next day has an early close at 12:00, the session that starts at 17:00 the day before should close at 12:00 of the next day.

Actual Behavior

It returns 00:00 (midnight) of the next day, as if the market closed at midnight.

Potential Solution

In Common/Securities/SecurityExchangeHours.cs, GetNextOrPreviousSegment returns null whenever _earlyCloses contains the adjacent date, without checking whether that day's first segment starts at 00:00. GetNextMarketClose then loses the continuity information and returns the end of the current day's segment (midnight). GetMarketHours itself returns the correct segments for that day (00:00–12:00 and, with a late open, 17:00–24:00), so returning the effective first segment from GetMarketHours(nextDay) instead of null seems to fix it.

Reproducing the Problem

Synthetic exchange hours only (no data, no subscription):

var day = new DateTime(2023, 11, 23);
MarketHoursSegment Seg(int s, int e) => new(MarketHoursState.Market, TimeSpan.FromHours(s), TimeSpan.FromHours(e));
var weekly = new Dictionary<DayOfWeek, LocalMarketHours>();
foreach (var d in Enum.GetValues<DayOfWeek>())
    weekly[d] = new LocalMarketHours(d, d switch
    {
        DayOfWeek.Saturday => Array.Empty<MarketHoursSegment>(),
        DayOfWeek.Sunday => new[] { Seg(17, 24) },
        DayOfWeek.Friday => new[] { Seg(0, 16) },
        _ => new[] { Seg(0, 16), Seg(17, 24) }
    });
var hours = new SecurityExchangeHours(TimeZones.Chicago, Array.Empty<DateTime>(), weekly,
    new Dictionary<DateTime, TimeSpan> { [day] = TimeSpan.FromHours(12) },   // early close
    new Dictionary<DateTime, TimeSpan>());
var close = hours.GetNextMarketClose(day.AddDays(-1).AddHours(17), true);
Console.WriteLine(close); // expected 2023-11-23 12:00, actual 2023-11-23 00:00

Without the early close the same call returns 2023-11-23 16:00, as expected. Adding a late open at 17:00 on the same day does not change the result. IsOpen(2023-11-23 00:00) is true, so the market is open on both sides of midnight.

This affects any logic built on GetNextMarketClose around early-close days (Thanksgiving, Christmas Eve, etc.) for futures trading across midnight. For example, a scheduled "before market close" event or a daily consolidator would see an artificial close at midnight.

System Information

LEAN master at commit 22404ea28 (26-10-2026), QuantConnect.Common 2.5.0.0, .NET 10.0.14, Linux.

Checklist
  • I have completely filled out this template
  • I have confirmed that this issue exists on the current master branch
  • I have confirmed that this is not a duplicate issue by searching issues
  • I have provided detailed steps to reproduce the issue
Lenguaje dominante
C#
Estrellas
22.3k
Forks
5.4k
Merge medio
1 d 14 h
PR fusionados (30 d)
53

Preparar el entorno

Abrir en Codespaces

Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de QuantConnect/Lean

Todos los issues de QuantConnect/Lean

Issues similares

Más issues de C#

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.