SecurityExchangeHours.GetNextMarketClose returns midnight when the next day has an early close (GetNextOrPreviousSegment)

未关闭
#9,989 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
66/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
csharp
领域
backend, databases

调研方向

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 master branch
  • 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

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

QuantConnect/Lean 的其他 Issue

查看 QuantConnect/Lean 的全部 Issue

相似的 Issue

更多 C# Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。