GetMarketHours: a late open after the day's last segment keeps the whole day open
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 72/100
Hướng nghiên cứu
Bắt đầu tại Common/Securities/SecurityExchangeHours.cs, ở vòng lặp mở cửa muộn trong GetMarketHours, rồi so sánh cách khởi tạo chỉ mục của vòng lặp này với vòng lặp đóng cửa sớm phía trên. Tái hiện trường hợp bằng ví dụ Thanksgiving được cung cấp hoặc bằng một bài kiểm thử tập trung cho tình huống mở cửa muộn sau phân đoạn cuối cùng. Hoàn thành khi GetMarketHours không trả về phân đoạn nào cho ngày đó, đồng thời giữ nguyên hành vi đóng cửa sớm đã mô tả.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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)
- Ngôn ngữ chính
- C#
- Star
- 22.1k
- Fork
- 5.3k
- Merge trung bình
- 1 ngày 8 giờ
- Pull request đã merge (30 ngày)
- 32
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Có Dockerfile hoặc tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của QuantConnect/Lean
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 82/100
QuantConnect/Lean#9957 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
QuantConnect/Lean#9955 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
QuantConnect/Lean#9953 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
WebullFeeModel charges SPXW options the SPX exchange feeCó thể đã có người làm @Amadeus-22 đã nhận 8 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
QuantConnect/Lean#9922 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
TradeStationBrokerageModel rejects extended-hours limit orders on equity optionsCó thể đã có người làm @AlexCatarino đã nhận 8 ngày trước. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
QuantConnect/Lean#9920 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của QuantConnect/Lean
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Open-Systems-Pharmacology/OSPSuite.Core#3049 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
needs attention public-client untriaged
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 73/100
AzureAD/microsoft-authentication-library-for-dotnet#6242 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
docs: HTML config transform example sets advancedCustomization at a path the UI does not readĐang mở
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 90/100
criticalmanufacturing/cli#882 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Dome-Works/DOME#129 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug sev:L
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
Systemorph/MeshWeaver#7480 ·
Maintainer thường phản hồi trong vòng 1 ngày