Preserve bank holidays when copying exchange-hours calendars

Đang mở Phù hợp với người mới
#10,189 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue nà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
85/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
csharp
Lĩnh vực
databases, testing

Hướng nghiên cứu

Đọc Common/Util/MarketHoursDatabaseJsonConverter.cs và Common/Securities/SecurityExchangeHours.cs, tập trung vào các đường dẫn sao chép mục và Update được mô tả trong issue. Tìm bài kiểm thử round-trip hiện có cho giờ thị trường và bổ sung kiểm thử hồi quy để bảo toàn các ngày nghỉ ngân hàng; thêm một kiểm thử làm mới để xác minh các ngày nghỉ đã bị xóa được loại bỏ. Hoàn tất khi cả hai lần chuyển đều dùng tập ngày nghỉ ngân hàng thay thế và các bài kiểm thử đều chạy thành công.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

priority:p2
Observed behavior

Bank holidays are not preserved when a market-hours calendar is serialized or refreshed:

  1. MarketHoursDatabaseJsonConverter.MarketHoursDatabaseEntryJson(Entry) copies holidays, early closes and late opens, but never populates BankHolidays (Common/Util/MarketHoursDatabaseJsonConverter.cs). Serializing a database entry with one explicit bank holiday and deserializing it produces zero bank holidays.
  2. SecurityExchangeHours.Update replaces _holidays, _earlyCloses and _lateOpens, but not _bankHolidays (Common/Securities/SecurityExchangeHours.cs:693-714). Updating a calendar containing one bank holiday from a calendar containing none leaves the old holiday present. MarketHoursDatabase.Entry.Update uses this path when the database refreshes.

Both omissions exist on master. Bank holidays are used by expiry-date calculations, so losing or retaining an obsolete date can change those calculations even when the regular trading schedule is correct.

Minimal serialization reproduction
var day = new DateTime(2025, 11, 11);
var hours = new SecurityExchangeHours(
    TimeZones.Utc,
    Array.Empty<DateTime>(),
    Enum.GetValues<DayOfWeek>().ToDictionary(d => d, LocalMarketHours.OpenAllDay),
    new Dictionary<DateTime, TimeSpan>(),
    new Dictionary<DateTime, TimeSpan>(),
    new[] { day });
var database = new MarketHoursDatabase(
    new Dictionary<SecurityDatabaseKey, MarketHoursDatabase.Entry>
    {
        [new SecurityDatabaseKey(Market.InteractiveBrokers, "TEST", SecurityType.Cfd)] =
            new MarketHoursDatabase.Entry(TimeZones.Utc, hours)
    });
var copy = JsonConvert.DeserializeObject<MarketHoursDatabase>(
    JsonConvert.SerializeObject(database));
Console.WriteLine(hours.BankHolidays.Count); // 1
Console.WriteLine(copy.GetEntry(Market.InteractiveBrokers, "TEST", SecurityType.Cfd)
    .ExchangeHours.BankHolidays.Count); // 0, expected 1

The refresh case was also reproduced by invoking SecurityExchangeHours.Update on the original hours, with SecurityExchangeHours.AlwaysOpen(TimeZones.Utc) as its replacement: actual bank-holiday count 1, expected 0.

Required result

Round-tripping an entry preserves its bank-holiday set, and refreshing an existing exchange-hours instance adopts the replacement set, including removals. Other calendar fields and existing inheritance rules remain unchanged. Add regression coverage for both transfers; the current round-trip test does not compare bank holidays.

Ngôn ngữ chính
C#
Star
22.5k
Fork
5.4k
Merge trung bình
13 giờ 11 phút
Pull request đã merge (30 ngày)
104

Chuẩn bị môi trường

Mở trong Codespaces

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.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của QuantConnect/Lean

Tất cả issue của QuantConnect/Lean

Issue tương tự

Thêm issue về C#

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.