SecurityExchangeHours.GetNextMarketClose returns midnight when the next day has an early close (GetNextOrPreviousSegment)
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
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.
由索引模型根据 Issue 内容生成。
描述
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
masterbranch - I have confirmed that this is not a duplicate issue by searching issues
- I have provided detailed steps to reproduce the issue
- 主要语言
- C#
- 星标
- 22.3k
- 派生
- 5.4k
- 平均合并
- 1 天 14 小时
- 30 天内合并 PR
- 53
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 提供 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
QuantConnect/Lean 的其他 Issue
-
难度 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
-
good first issue
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
bug P2
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 85/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
-
bug godot
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 2 天内回复