GetMarketHours: a late open after the day's last segment keeps the whole day open
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 72/100
Direzione di ricerca
Inizia in Common/Securities/SecurityExchangeHours.cs, nel ciclo delle aperture tardive in GetMarketHours, e confronta l’inizializzazione del suo indice con quella del ciclo delle chiusure anticipate sopra. Riproduci il caso con l’esempio di Thanksgiving fornito oppure con un test mirato per un’apertura tardiva dopo l’ultimo segmento. Il lavoro è concluso quando GetMarketHours non restituisce segmenti per quel giorno, mantenendo il comportamento descritto per le chiusure anticipate.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Expected Behavior
When a date's late open falls after every segment of that day, SecurityExchangeHours.GetMarketHours should return no segments for the day (nothing trades before the late open, and the day's sessions have all ended by then).
Actual Behavior
It returns the day's full regular schedule. In the late-open loop (Common/Securities/SecurityExchangeHours.cs, master):
var index = 0;
segmentsLateOpen = new List<MarketHoursSegment>();
for (var i = 0; i < marketHoursSegments.Count; i++)
{
var segment = marketHoursSegments[i];
if (segment.Start <= lateOpenTime && lateOpenTime <= segment.End) { ...; index = i + 1; break; }
else if (lateOpenTime < segment.Start) { index = i; break; }
}
segmentsLateOpen.AddRange(marketHoursSegments.TakeLast(marketHoursSegments.Count - index));
If lateOpenTime is after the last segment's end, neither branch runs, index stays 0, and TakeLast(Count - 0) keeps every segment. So the late open has the opposite of its intended effect.
In the current master market-hours-database.json this happens on 11 entry-dates:
Future-cme-LE,Future-cme-GF,Future-cme-HE: 2011-11-24 and 2012-11-22 (Thanksgiving). Each haslateOpens17:00 and a Thursday regular segment of 08:30-13:05 CT, which is therefore reported open on Thanksgiving.Future-cme-LBR: the same two dates (09:00-15:05 segment).Future-cme-ETH,Future-cme-MET,Future-cme-MBT: 2020-07-03 (lateOpen 17:00 after an 08:30-16:00 segment). These dates are before those contracts listed, so this case is harmless in practice.
None of these dates is in the entry's own holidays list, so the holiday short-circuit does not apply.
Potential Solution
Initialise the late-open index the way the early-close loop just above initialises its own:
var index = marketHoursSegments.Count; // a late open after every segment leaves nothing to trade
Then TakeLast(0) returns no segments. When an early close precedes such a late open on the same day, the existing segmentsEarlyClose.AddRange(segmentsLateOpen) step still keeps the pre-early-close segments.
(A sibling defect in the early-close loop, index = i - 1 when the early close falls in a gap between segments, was already fixed in #9869. I found it in the same check, then saw the fix on master.)
Reproducing the Problem
Untested sketch. I have not run C# here: the behaviour comes from reading GetMarketHours on master, cross-checked with a line-by-line Python port of it run against master's market-hours-database.json.
var mhdb = MarketHoursDatabase.FromDataFolder();
var hours = mhdb.GetExchangeHours(Market.CME, Symbol.Create("LE", SecurityType.Future, Market.CME), SecurityType.Future);
var thanksgiving = new DateTime(2011, 11, 24, 10, 0, 0); // exchange-local (America/Chicago), inside 08:30-13:05
Assert.IsFalse(hours.IsOpen(thanksgiving, extendedMarketHours: false)); // expected to fail today: returns true
Assert.IsEmpty(hours.GetMarketHours(thanksgiving).Segments); // expected to fail today: 1 segment
System Information
Code: master, SecurityExchangeHours.cs as of 82810ea63d55 (2026-10-05, its latest commit). Data: master Data/market-hours/market-hours-database.json, fetched 2026-10-11. OS-independent; this is a logic issue.
Checklist
- I have completely filled out this template
- I have confirmed that this issue exists on the current
masterbranch (by code reading and a port run against master data; not by running LEAN) - I have confirmed that this is not a duplicate issue by searching issues
- I have provided detailed steps to reproduce the issue (the test above is a sketch, not run)
- Lingua principale
- C#
- Stelle
- 21.9k
- Fork
- 5.3k
- Merge medio
- 19h 31m
- PR unite (30g)
- 44
Preparare l'ambiente
Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.
- Include un Dockerfile o un file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di QuantConnect/Lean
-
AlpacaBrokerageModel refuses extended-hours limit orders with the GTC time in force, which Alpaca acceptsForse già presa @AlexCatarino l’ha presa 1 giorno fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
QuantConnect/Lean#9892 ·
I maintainer di solito rispondono entro 1 giorno
-
library-request
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
QuantConnect/Lean#9879 ·
I maintainer di solito rispondono entro 1 giorno
-
[Library Upgrade] autogluonApertalibrary-request
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
QuantConnect/Lean#9743 ·
I maintainer di solito rispondono entro 1 giorno
-
library-request
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
QuantConnect/Lean#9500 ·
I maintainer di solito rispondono entro 1 giorno
-
Library Upgrade: dglApertalibrary-request
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
QuantConnect/Lean#9499 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di QuantConnect/Lean
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
I maintainer di solito rispondono entro 1 giorno
-
area:re1 bounty help wanted needs-game
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
StackExchange/StackExchange.Redis#3274 ·
I maintainer di solito rispondono entro 1 giorno
-
affected/v17 affected/v18 area/frontend type/bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
umbraco/Umbraco-CMS#24186 ·
I maintainer di solito rispondono entro 2 giorni