GetNextMarketClose lets an excluded extended-hours session hide a regular close at midnight

Aperta
#10,110 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Questa issue non è ancora stata valutata.

Descrizione

priority:p2
Expected behavior

When extendedMarketHours is false, an extended-hours session at the start of the next day must not hide a regular session's close at midnight.

Actual behavior

For a Sunday regular session from 18:00 to 24:00, followed by a Monday post-market session from 00:00 to 02:00 and a regular session from 14:00 to 16:00, querying Sunday evening for the next regular close returns Monday 16:00 instead of Monday 00:00.

Reproduction
var schedule = Enum.GetValues<DayOfWeek>()
    .Select(day => LocalMarketHours.ClosedAllDay(day))
    .ToDictionary(x => x.DayOfWeek);
schedule[DayOfWeek.Sunday] = new LocalMarketHours(DayOfWeek.Sunday,
    new MarketHoursSegment(MarketHoursState.Market, TimeSpan.FromHours(18), TimeSpan.FromHours(24)));
schedule[DayOfWeek.Monday] = new LocalMarketHours(DayOfWeek.Monday,
    new MarketHoursSegment(MarketHoursState.PostMarket, TimeSpan.Zero, TimeSpan.FromHours(2)),
    new MarketHoursSegment(MarketHoursState.Market, TimeSpan.FromHours(14), TimeSpan.FromHours(16)));
var hours = new SecurityExchangeHours(TimeZones.NewYork, Enumerable.Empty<DateTime>(), schedule,
    new Dictionary<DateTime, TimeSpan>(), new Dictionary<DateTime, TimeSpan>());
var close = hours.GetNextMarketClose(new DateTime(2024, 1, 7, 19, 0, 0), false);
// Expected: 2024-01-08 00:00:00
// Actual:   2024-01-08 16:00:00
Cause

SecurityExchangeHours.GetNextMarketClose passes the next day's first segment start (GetNextOrPreviousSegment(time, isNextDay: true)) to LocalMarketHours.GetMarketClose without checking whether that segment is eligible for the requested hours. Within a day, GetMarketClose already ignores an extended-hours next segment when extended hours are excluded; across midnight it doesn't, so the 24:00 → 00:00 boundary is treated as a continuation.

The fix must take only an eligible next-day segment into account when extended hours are excluded, and keep cross-midnight continuity when extended hours are included. It's the mirror of #10090 for market opens. No market in the bundled market hours database has this layout, so only custom exchange hours are affected.

Lingua principale
C#
Stelle
22.5k
Fork
5.4k
Merge medio
22h 6m
PR unite (30g)
81

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di QuantConnect/Lean

Tutte le issue di QuantConnect/Lean

Issue simili

Altre issue su C#

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.