GetMarketHours: a late open after the day's last segment keeps the whole day open
维护者通常 1 天内回复
评估
调研方向
从 Common/Securities/SecurityExchangeHours.cs 中 GetMarketHours 的延迟开盘循环开始,并将其索引初始化与上方的提前收盘循环进行比较。使用提供的 Thanksgiving 示例,或针对最后一个片段之后延迟开盘的情况编写一个聚焦测试,重现该问题。完成标准是 GetMarketHours 对该日期不返回任何片段,同时保留所描述的提前收盘行为。
由索引模型根据 Issue 内容生成。
描述
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)
- 主要语言
- C#
- 星标
- 22.3k
- 派生
- 5.4k
- 平均合并
- 1 天 23 小时
- 30 天内合并 PR
- 53
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 提供 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
QuantConnect/Lean 的其他 Issue
-
`LeanData.TryParsePath` fails on an absolute universe file path可能已有人在做 @FeiyangP 于 1 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
QuantConnect/Lean#10005 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
QuantConnect/Lean#9965 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 82/100
QuantConnect/Lean#9955 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 85/100
QuantConnect/Lean#9953 ·
维护者通常 1 天内回复
-
WebullFeeModel charges SPXW options the SPX exchange fee可能重新可做 关联的 PR 已关闭且未合并。 未关闭
难度 2/5 1-3 小时 新手友好度 75/100
QuantConnect/Lean#9922 · 2 条评论 ·
维护者通常 1 天内回复
查看 QuantConnect/Lean 的全部 Issue
相似的 Issue
-
area/resource-registry status/triage
难度 1/5 1-3 小时 新手友好度 76/100
Altinn/altinn-auth#4821 ·
维护者通常 1 天内回复
-
a11y community:contribution
难度 2/5 1-3 小时 新手友好度 74/100
microsoft/fluentui-blazor#5590 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 79/100
JetBrains/resharper-unity#2510 ·
-
难度 1/5 1-3 小时 新手友好度 78/100
QuantConnect/Documentation#2838 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 70/100
AvaloniaUI/Avalonia#22697 · 1 条评论 ·
维护者通常 1 天内回复