1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
// SPDX-License-Identifier: MIT-0
//! Named futures profiles, addressed by [`MarketHoursKey`] instead of by venue.
//!
//! Futures hours track the *product family*, not just the exchange: CME
//! equity-index and CME FX contracts list on the same venue but have separately
//! sourced profiles. Keying on the family is therefore the correct granularity,
//! and the caller's sourced instrument catalog must select the exact family.
//! This crate does not map symbols, roots, product codes, or MICs to keys.
//!
//! [`MarketHoursKey`] is `#[non_exhaustive]`. [`session_profile`] exposes the
//! fixed-current static table, [`hours_for_market_hours_key`] selects sourced
//! revisions at the caller's instant, and
//! [`ExchangeCalendar`](super::ExchangeCalendar) scans date-aware profiles.
mod key_serde;
mod profiles;
pub use key_serde::ParseMarketHoursKeyError;
use key_serde::market_hours_keys;
pub use profiles::session_profile;
use std::borrow::Cow;
use chrono::{DateTime, Utc};
use chrono_tz::Tz;
use super::exchange_calendar::CalendarSource;
use super::schedules::ALWAYS_OPEN_PROFILE;
use super::schedules::from_profile;
use super::schedules::futures::international::{
asx_spi_200_profile_at, bme_ibex_profile_at, eurex_fixed_income_profile_at, eurex_profile_at,
eurex_smi_profile_at, euronext_index_futures_profile_at, hkex_index_futures_profile_at,
ice_europe_gilts_profile_at, oanda_brent_profile_at, oanda_china50_profile_at,
oanda_fx_profile_at, oanda_metals_profile_at, oanda_singapore30_profile_at,
oanda_try_fx_profile_at, oanda_us_commodity_profile_at, oanda_us_index_profile_at,
sgx_equity_index_china_profile_at, sgx_equity_index_japan_profile_at,
sgx_equity_index_ntr_usd_profile_at, sgx_equity_index_singapore_profile_at,
sgx_equity_index_taiwan_profile_at, sgx_profile_at,
};
use super::schedules::futures::us::{
bitcoin_event_contracts_profile_at, cbot_profile_at, cfe_profile_at, cme_profile_at,
cocoa_profile_at, coffee_profile_at, copper_tas_profile_at, cotton_profile_at,
cryptocurrency_profile_at, energy_metals_profile_at, event_contracts_profile_at,
fcoj_profile_at, fx_profile_at, gold_tas_profile_at, ice_us_fang_profile_at,
ice_usdx_profile_at, interest_rates_profile_at, livestock_profile_at, mini_grains_profile_at,
nkd_profile_at, palladium_tas_profile_at, platinum_tas_profile_at, rough_rice_profile_at,
silver_100oz_profile_at, silver_tas_profile_at, spot_quoted_profile_at, sugar_profile_at,
weather_profile_at,
};
use super::{Exchange, MarketHours, SessionRule};
/// A timezone-aware set of normal-week futures session rules.
///
/// `regular` carries primary trading sessions; `extended` carries electronic,
/// overnight, and other non-regular sessions. Holiday and special-session
/// overlays are deliberately modeled outside this normal-week profile.
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct FuturesSessionProfile {
/// Exchange local timezone used to interpret `SessionRule` SSM values.
pub tz: Tz,
/// Primary trading sessions.
pub regular: &'static [SessionRule],
/// Electronic, overnight, and other tradeable non-regular sessions.
pub extended: &'static [SessionRule],
/// Order-entry-only phases in which no trade can match.
pub order_entry: &'static [SessionRule],
/// True when the venue has a distinct daily close.
pub has_daily_close: bool,
/// True when the venue has a true weekend close.
pub has_weekend_close: bool,
}
impl FuturesSessionProfile {
/// Returns `true` when any regular or extended normal-week session is active.
#[must_use]
pub fn is_open(&self, t: DateTime<Utc>) -> bool {
self.to_market_hours(CalendarSource::Exchange(Exchange::Unknown))
.is_open(t)
}
/// True when `t` falls in an order-entry-only phase where nothing matches.
///
/// Mirrors [`MarketHours::is_order_entry_only`] so a profile and the hours
/// it produces answer identically.
#[must_use]
pub fn is_order_entry_only(&self, t: DateTime<Utc>) -> bool {
self.to_market_hours(CalendarSource::Exchange(Exchange::Unknown))
.is_order_entry_only(t)
}
/// True during a tradeable session or a published order-entry phase at `t`.
/// Broker-side pending-order storage outside those phases is not modelled.
#[must_use]
pub fn is_accepting_orders(&self, t: DateTime<Utc>) -> bool {
self.to_market_hours(CalendarSource::Exchange(Exchange::Unknown))
.is_accepting_orders(t)
}
/// Converts this profile into the [`MarketHours`] value the calendar query
/// surface ([`candle_end`](super::candle_end),
/// [`session_bounds`](super::session_bounds), …) consumes, tagged with
/// `source`.
///
/// The rule slices are borrowed (`Cow::Borrowed`), so this allocates
/// nothing. The tag is passed by the caller because one shared profile can
/// back several identities — [`hours_for_market_hours_key`] tags with
/// [`CalendarSource::MarketHoursKey`] since the key, not a venue,
/// identifies the profile.
#[must_use]
pub fn to_market_hours(self, source: CalendarSource) -> MarketHours {
MarketHours {
source,
tz: self.tz,
regular: Cow::Borrowed(self.regular),
extended: Cow::Borrowed(self.extended),
order_entry: Cow::Borrowed(self.order_entry),
has_daily_close: self.has_daily_close,
has_weekend_close: self.has_weekend_close,
}
}
}
market_hours_keys! {
/// Names a normal-week product-family market-hours profile.
///
/// The enum is `#[non_exhaustive]`; match it with a wildcard and enumerate
/// the keys in the compiled crate version with [`MarketHoursKey::ALL`]. Each
/// variant has one stable canonical `snake_case` name, shared by serde,
/// [`MarketHoursKey::as_str`], [`core::fmt::Display`], and
/// [`core::str::FromStr`]. Serde uses that string in every format, including
/// compact non-self-describing formats. Renaming a key is therefore a
/// breaking persisted-wire change.
///
/// The venue-keyed compatibility defaults are CME →
/// [`GlobexEquityIndex`](Self::GlobexEquityIndex), CBOT →
/// [`GlobexGrains`](Self::GlobexGrains) — which excludes the mini-sized
/// grains and Rough Rice, whose grids diverged from it (2012 and
/// 2018-01-21 respectively) and need
/// [`GlobexMiniGrains`](Self::GlobexMiniGrains) and
/// [`GlobexRoughRice`](Self::GlobexRoughRice) — COMEX/NYMEX →
/// [`GlobexEnergy`](Self::GlobexEnergy), CFE → [`CfeVix`](Self::CfeVix),
/// Eurex → [`Eurex`](Self::Eurex), ICEUS → [`IceUs`](Self::IceUs), and SGX
/// → [`Sgx`](Self::Sgx). Those defaults are wrong for products outside the
/// named families; select a product-family key instead of treating a venue
/// as one universal clock.
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub enum MarketHoursKey {
/// CME/CBOT equity-index futures on the sourced U.S. grid, including
/// YM/MYM. Excludes full-size S&P 500 (`SP`), Nikkei 225 Dollar (`NKD`),
/// and BTIC/TACO products, whose historical or current grids differ.
GlobexEquityIndex => "globex_equity_index",
/// NYMEX `CL/MCL/QM`, `NG/MNG/QG`, `HO/RB/BZ`, and `PL/PA`, plus
/// COMEX `GC/MGC`, `SI/SIL`, and `HG/MHG`, including their shared
/// energy/metals history. Excludes TAS/TAM/BTIC, options, and products
/// whose own specification publishes a different grid.
GlobexEnergy => "globex_energy",
/// COMEX 100-Ounce Silver futures (`SIL`, Globex security group 4S) —
/// the one energy/metals root CME moved to 24/7 trading, effective
/// Friday 2026-09-11 with the first weekend leg opening 16:30 CT. It
/// rode the [`GlobexEnergy`](Self::GlobexEnergy) grid from the
/// January-2010 floor and that key's scope excludes products whose own
/// specification publishes a different grid, so this key carries the
/// product's whole life: the shared energy/metals grid by reference to
/// every dated revision through 2026-09-10, the bridge day, and the
/// 24/7 grid from 2026-09-12. Excludes miNY Silver and every TAS,
/// options and spread product on the metal. The weekend block carries
/// the following open business date, as the operator's notice states;
/// no built-in holiday table routes here, because the 24/7 era's
/// holiday arrangement is not yet sourced (see the evidence file).
GlobexSilver100Oz => "globex_silver_100oz",
/// Standard-size CBOT grain/oilseed Globex hours; excludes the
/// mini-sized grain futures, which have their own
/// [`GlobexMiniGrains`](Self::GlobexMiniGrains) key, and Rough Rice,
/// whose extended session diverged on 2018-01-21 and which has its
/// own [`GlobexRoughRice`](Self::GlobexRoughRice) key.
GlobexGrains => "globex_grains",
/// CBOT mini-sized grain futures — Mini-Sized Corn (`XC`), Mini-Sized
/// Soybean (`XK`), Mini-Sized Wheat (`XW`), and Mini-Sized KC HRW
/// Wheat (`MKC`, listed 2014-03-23; launch dates remain caller
/// catalog data) — on the Globex mini grid. Its day session closed 30
/// minutes after the standard grains' from before the January-2010
/// floor, it skipped the standard grid's 2015-07-05 close change
/// entirely, and it converged with that grid only on 2022-10-02, so
/// the envelopes match today while the histories do not. Excludes the
/// standard-size corn/soybean/wheat/KC-wheat contracts, Rough Rice,
/// and the Micro Ag futures, which follow the standard grid.
GlobexMiniGrains => "globex_mini_grains",
/// CME FX futures on the standard 17:00-16:00 CT Globex grid; excludes
/// eFix, TAS, options, and products with a different specification.
/// Excludes plain BTIC (`6EB`), which CME's FX BTIC FAQ trades "up to
/// 3:40 p.m. London time (typically 9:40 a.m. CT)" — a different
/// window. The same FAQ puts BTIC+ (`6EP`) on this clock: "BTIC+
/// contracts can be traded through the standard CME Globex trading
/// hours of Sunday-Friday 5:00 p.m.-4:00 p.m. CT", so the exclusion is
/// of the trade type's plain flavour, not of the ticker family.
GlobexFx => "globex_fx",
/// CBOT U.S. Treasury (`ZT/ZF/ZN/TN/ZB/UB` and micros), 30-Day Fed
/// Funds (`ZQ`), and CME SOFR (`SR1/SR3`) Globex hours. Excludes
/// options and separately specified interest-rate product families.
GlobexInterestRates => "globex_interest_rates",
/// CME Live Cattle, Feeder Cattle, and Lean Hog futures Globex hours;
/// excludes options and separately specified TAS sessions.
GlobexLivestock => "globex_livestock",
/// CME non-spot-quoted cryptocurrency futures Globex hours.
///
/// The fixed profile uses adjacent rules for exact open/closed state.
/// [`calendar_for_market_hours_key`](super::calendar_for_market_hours_key)
/// joins the storage pieces into exact weekend blocks and applies CME's
/// following-open-business-day convention. That date is normally
/// Monday; a caller policy that closes Monday rolls the trading to
/// Tuesday. Friday 16:00 remains the weekly close. Detached fixed
/// snapshots retain table-piece bounds and do not expose that weekly
/// boundary or trade dates because they carry no key identity.
GlobexCryptocurrency => "globex_cryptocurrency",
/// CFE VIX futures hours.
CfeVix => "cfe_vix",
/// Eurex FESX/FDAX/FDXM benchmark-index futures current-season snapshot.
Eurex => "eurex",
/// ICE Futures U.S. NYSE FANG+ Index futures hours.
IceUs => "ice_us",
/// ICE Futures U.S. Sugar No. 11 (`SB`) futures and options. One
/// same-day New York session with separate order-entry phases.
IceUsSugar => "ice_us_sugar",
/// ICE Futures U.S. Coffee \"C\" (`KC`) futures and options.
IceUsCoffee => "ice_us_coffee",
/// ICE Futures U.S. Cocoa (`CC`) futures and options.
IceUsCocoa => "ice_us_cocoa",
/// ICE Futures U.S. Cotton No. 2 (`CT`) futures and options.
IceUsCotton => "ice_us_cotton",
/// ICE Futures U.S. FCOJ-A frozen concentrated orange juice (`OJ`) futures.
IceUsOrangeJuice => "ice_us_orange_juice",
/// ICE Futures U.S. U.S. Dollar Index (`DX`) futures and options.
IceUsDollarIndex => "ice_us_dollar_index",
/// CME Nikkei 225 Dollar (`NKD`) futures on CME Globex.
GlobexNikkei225Dollar => "globex_nikkei_225_dollar",
/// Eurex fixed-income futures (`FGBL`/`FGBM`/`FGBS`/`FGBX`).
EurexFixedIncome => "eurex_fixed_income",
/// Eurex SMI® index futures (`FSMI`) on the Zurich clock: continuous
/// trading 07:50-17:27 CET from the January-2010 floor until the
/// operator's Contract Specifications amendment of 2010-07-05 extended
/// it to 07:50-22:00, with the Pre-Trading and Post-Trading order-entry
/// phases beside it. The Trading Calendar editions 2011-2026 reprint
/// the extended row every year. Excludes SMI options and SMIM/SLI
/// futures, whose option grids and per-product closes the operator
/// states separately, and every German-scope closure the sibling
/// [`Eurex`](Self::Eurex) key carries, which the operator's Swiss
/// clause never reaches.
EurexSmi => "eurex_smi",
/// Euronext CAC 40 Index futures (`FCE`, Paris) and AEX Index futures
/// (`FTI`, Amsterdam) on their shared Central Order Book grid:
/// 08:00-22:00 CET/CEST Monday to Friday, one identical row on the
/// operator's own contract-specification pages for both products. The
/// Large-in-Scale Facility beside that grid is an off-book wholesale
/// facility and is not modelled. No banked artifact dates any earlier
/// grid state, so the ledger records the horizon at the 2026-10-11
/// contract-page retrieval and the holiday table ships the operator's
/// shared cash-and-derivatives calendar with the December half days
/// `Unsourced` (the derivatives appendices that state their instants
/// are not banked).
EuronextIndexFutures => "euronext_index_futures",
/// SGX Japan equity-index derivatives (Nikkei 225 suite).
SgxEquityIndexJapan => "sgx_equity_index_japan",
/// SGX China equity-index derivatives (FTSE China A50/H50).
SgxEquityIndexChina => "sgx_equity_index_china",
/// SGX Singapore equity-index derivatives (`SiMSCI`, Straits Times Index).
SgxEquityIndexSingapore => "sgx_equity_index_singapore",
/// SGX Taiwan equity-index derivatives (FTSE Taiwan suite).
SgxEquityIndexTaiwan => "sgx_equity_index_taiwan",
/// SGX NTR (USD) global equity-index futures.
SgxEquityIndexNtrUsd => "sgx_equity_index_ntr_usd",
/// CBOT Rough Rice futures (`ZR`) and options (`OZR`), Rulebook
/// chapters 17 and 17A.
///
/// Rough Rice shared the standard CBOT grain and oilseed grid until
/// CBOT Submission 18-001 cut its extended session to Sunday-Thursday
/// 19:00-21:00 CT on 2018-01-21; from that day it has no
/// midnight-wrapping session and is **not** covered by
/// [`GlobexGrains`](Self::GlobexGrains). Excludes every other CBOT
/// grain and oilseed contract, mini-sized grains, and separately
/// specified session types such as TAS and BTIC. No morning Pre-Open
/// or post-close Pre-Open is modeled after the divergence, because
/// CME's Rough Rice specification publishes neither.
GlobexRoughRice => "globex_rough_rice",
/// CME weather temperature-index **futures** (CME Globex security
/// tag 55 symbol `HW`): the HDD, CDD and CAT monthly, seasonal-strip and
/// quarterly-strip contracts for the US, European and Pacific Rim
/// cities, all quoted in Chicago time. **Excludes options on weather
/// futures**, which are a separate Globex security group and traded
/// on the CME floor for most of the audited history; the day they
/// moved to CME Globex is unsourced, so they stay caller catalog
/// data. Also excludes CME `ClearPort`, which is a clearing-submission
/// window rather than a session, and CME's separate "Wind" products.
///
/// Its current envelope coincides with
/// [`GlobexFx`](Self::GlobexFx) and
/// [`GlobexEnergy`](Self::GlobexEnergy) and its history matches
/// neither: weather closed 15:15 CT from the January-2010 floor until
/// CME SER-9519 expanded it to 16:00 CT on 2025-04-13.
GlobexWeather => "globex_weather",
/// CME/CBOT Spot-Quoted Futures ("SQF"), Rulebook Chapter 24: the
/// eight tradeable roots `QSPX`, `QNDX`, `QDOW` and `QRTY` on the
/// equity indices and `QBTC`, `QETH`, `QSOL` and `QXRP` on the
/// cryptocurrency reference rates. `QDOW` is the CBOT listing and the
/// other seven are CME. Excludes the non-trade clearing legs (`QSF`,
/// `QNF`, `QDF`, `QRF`, `QTF`, `QEF`, `QOF`, `QXF`) and the
/// financing-adjustment marker codes (`QSM`, `QNM`, `QDM`, `QRM`,
/// `QTM`, `QEM`, `QOM`, `QXM`), which are settlement identifiers
/// rather than order books, and CME `ClearPort`.
///
/// The family is neither
/// [`GlobexEquityIndex`](Self::GlobexEquityIndex) — which publishes an
/// 08:30-15:15 CT RTH that no SQF document states — nor
/// [`GlobexCryptocurrency`](Self::GlobexCryptocurrency), which moved
/// to 24/7 trading on 2026-05-29 while CME kept spot-quoted on the
/// five-day grid by name. Its envelope also coincides exactly with
/// [`GlobexWeather`](Self::GlobexWeather) today while the two
/// histories share nothing: weather closed 15:15 CT until 2025-04-13
/// and this family did not exist until 2025-06-29.
///
/// One key covers all eight roots because their normal week and their
/// dated history are identical. Their *holiday* grids are not: CME
/// publishes different half-day closes for the equity roots and the
/// cryptocurrency roots. Holiday and early-close data is caller-owned,
/// so it lies outside this key — but a caller attaching date
/// exceptions to it must build them per subgroup rather than applying
/// one early-close set to all eight.
GlobexSpotQuoted => "globex_spot_quoted",
/// CME Group Event Contracts on futures — daily-expiring,
/// cash-settled, European-style options on futures under CME, CBOT,
/// NYMEX and COMEX Rulebook Chapter 23, together with the hourly
/// contracts under Chapter 23A. The Chapter 23 roots are `ECES`,
/// `ECNQ`, `ECRTY`, `ECYM`, `EC6E`, `ECCL`, `ECNG`, `ECGC`, `ECSI`
/// and `ECHG`; the Chapter 23A roots are the hourly `ECS*`, `ECN*`,
/// `ECR*`, `ECD*`, `ECC*`, `ECH*` and `ECG*` contracts listed from
/// 2025-12-08.
///
/// **A contract's Termination of Trading time is not this family's
/// session close.** CME publishes one hours cell per document with a
/// different termination time per root — 15:00 CT for the equity
/// indices down to 12:00 CT for `ECHG` — and those per-root numbers
/// are stated expiration times, not daily closes. The session is one
/// grid for every root: 17:00→16:00 CT wrapping midnight with a
/// 60-minute maintenance period from 16:00, Pre-Opens Sunday
/// 16:00-17:00 and Monday-Thursday 16:45-17:00 CT, and no
/// Friday-evening reopen.
///
/// **Excludes `ECBTC` in every era.** Its own five-day session closes
/// at 15:00 CT, before its 2026-05-29 move to 24/7 trading. Select
/// [`GlobexEventContractsBtc`](Self::GlobexEventContractsBtc) for that
/// root throughout its history. Also
/// excludes the Chapter 22 swap-based economic and cryptocurrency
/// event contracts, which run a 24/7 grid with a one-minute daily
/// halt, and the sports and political event contracts on the CME
/// `FutureSports` Performance Indexes.
///
/// The envelope coincides exactly with
/// [`GlobexSpotQuoted`](Self::GlobexSpotQuoted) and
/// [`GlobexWeather`](Self::GlobexWeather) today and the three
/// histories share nothing: weather closed 15:15 CT until 2025-04-13,
/// spot-quoted did not exist until 2025-06-29, and this family has run
/// its one grid since 2022-09-18.
GlobexEventContracts => "globex_event_contracts",
/// CME Event Contracts on Bitcoin Futures (`ECBTC`), Rulebook Chapter
/// 23 — the one event-contract root CME moved to 24/7 trading on
/// 2026-05-29. The key carries the root's whole life: sessionless
/// before its 2023-03-12 listing, its own 17:00-15:00 CT five-day
/// grid to 2026-05-28, and a 24/7 grid from 2026-05-29.
///
/// **The 24/7 weekday close is the sourced intersection of two CME
/// primaries that disagree by an hour.** SER-9740R states a 16:00-16:02
/// CT maintenance window; CME's client-systems wiki, written five weeks
/// earlier for this root alone and never revised, states 15:00-16:01
/// CT. Both give the 16:01-16:02 Pre-Open, the 16:02 open, and the
/// Saturday 02:00-04:00 window with its 03:45 Pre-Open. The key serves
/// what both support — open 16:02→15:00 CT — and withholds the disputed
/// hour, erring toward closed. CME's Globex notices since the cutover
/// confirm the Saturday window for this root's channel and also state
/// six one-day Saturday extensions, which are modelled.
///
/// The fixed profile uses adjacent rules for exact open/closed state;
/// [`calendar_for_market_hours_key`](super::calendar_for_market_hours_key)
/// joins the storage pieces into the continuous weekend block and
/// carries the following open business date, as for
/// [`GlobexCryptocurrency`](Self::GlobexCryptocurrency). Unlike that
/// key, this root's Pre-Opens stay `order_entry`.
GlobexEventContractsBtc => "globex_event_contracts_btc",
/// COMEX Gold Trading at Settlement (`GCT`, CME Globex security group
/// TG), listed 2010-04-11 for trade date 2010-04-12.
///
/// Sunday-Thursday 17:00 CT wrapping to 12:30 CT, with **no
/// Friday-evening reopen** and no regular session: the TAS book is
/// Globex-only, and CME's 2009-2015 pit route ran in the underlying's
/// pit on the underlying's hours. `regular` is therefore empty in
/// every era. The Pre-Open is `order_entry`, because Rule 524 permits
/// a TAS order only after its group's pre-open state begins.
///
/// Members `MGT`, `QOT` and `1OT` joined later groups-side and are
/// caller catalog data. Every dated observation from 2010 to today
/// states the 12:30 CT close, and the crate carries it across the
/// 2015-03-22 to 2019-11-18 gap in archived statements rather than
/// asserting a verified continuity; the two dated revisions are
/// queue-onset changes in 2011 and 2012. The
/// Sunday queue serves the sourced 16:15-17:00 CT intersection and
/// withholds 16:00-16:15, as
/// [`GlobexEquityIndex`](Self::GlobexEquityIndex) does.
GlobexGoldTas => "globex_gold_tas",
/// COMEX Silver Trading at Settlement (`SIT`, security group MT),
/// listed 2010-04-11 on the same COMEX self-certification as
/// [`GlobexGoldTas`](Self::GlobexGoldTas).
///
/// Identical shape, closing 12:25 CT instead of 12:30, with the same
/// empty `regular`, the same absent Friday-evening reopen, the same
/// two queue revisions, the same carried 2015-2019 observation gap and
/// the same withheld Sunday quarter-hour. It
/// is a separate key because the close differs; `MST` joined in 2025
/// and is caller catalog data.
GlobexSilverTas => "globex_silver_tas",
/// COMEX Copper Trading at Settlement (`HGT`, security group HT),
/// listed 2011-01-23 for trade date 2011-01-24, nine months after gold
/// and silver and on CME Globex only.
///
/// Sunday-Thursday 17:00 CT wrapping to 12:00 CT, empty `regular`, no
/// Friday-evening reopen, the same two queue revisions and the same
/// carried 2015-2019 observation gap. Copper TAS
/// was **never** a pit product, which both COMEX SER-5542 and MRAN
/// RA1107-4 state in terms.
///
/// Do not substitute
/// [`GlobexPalladiumTas`](Self::GlobexPalladiumTas) on the coincident
/// 12:00 CT close: different exchange, different security group and
/// launches seven years apart. Members `MHT` and `HG0` are caller
/// catalog data.
GlobexCopperTas => "globex_copper_tas",
/// NYMEX Trading at Settlement on Platinum Futures (`PLT`, security
/// group PE), listed 2017-05-21 for trade date 2017-05-22.
///
/// One era: Sunday-Thursday 17:00 CT wrapping to 12:05 CT, empty
/// `regular`, no Friday-evening reopen, and no sourced revision since
/// launch; the close is carried across the 2021-04-11 to 2026-03-10
/// gap in archived statements. Because the root launched after CME's
/// undated 2012
/// move of the Sunday TAS pause, its earliest sourced Sunday queue
/// onset is 16:00 CT and nothing is withheld: Sunday 16:00-17:00 and
/// Monday-Thursday 16:45-17:00 CT are both served.
GlobexPlatinumTas => "globex_platinum_tas",
/// NYMEX Palladium Trading at Settlement (`PAT`, security group PX),
/// listed 2018-11-18 for trade date 2018-11-19.
///
/// One era: Sunday-Thursday 17:00 CT wrapping to 12:00 CT, with the
/// same empty `regular` and the same unwithheld queue as
/// [`GlobexPlatinumTas`](Self::GlobexPlatinumTas); the close is
/// carried across the 2021-05-13 to 2026-05-27 gap in archived
/// statements.
///
/// **There is no 16:00-17:00 CT daily break.** The clause CME's 2019
/// specification printed on the TAS line is inherited boilerplate from
/// the outright row — a book closed at 12:00 CT cannot break at 16:00
/// — and CME deleted it in 2020 while leaving the instants unchanged.
GlobexPalladiumTas => "globex_palladium_tas",
/// OANDA's own FX book, all FX products except TRY pairs: Sunday
/// 17:05 to Friday 16:59 New York time with the six-minute
/// 16:59-17:05 daily break and no other maintenance — the book
/// trades straight through the daily halts of every futures clock
/// an FX hedge might route to. TRY pairs have their own
/// [`OandaTryFx`](Self::OandaTryFx) grid. NZD pairs carry an
/// additional 06:59-07:05 Auckland break that is caller catalog
/// data: no rule in this grid states it.
OandaFx => "oanda_fx",
/// OANDA's own TRY-pair book, a daily Monday-Friday 08:00-17:00
/// Central European session with an overnight gap and no stated
/// maintenance.
OandaTryFx => "oanda_try_fx",
/// OANDA's own spot-metals book (`XAU`/`XAG` and their crosses):
/// Sunday 18:05 to Friday 16:59 New York time, with the printed
/// 16:59-18:05 daily gap and no other maintenance. NZD pairs carry
/// an additional 06:59-07:05 Auckland break that is caller catalog
/// data: no rule in this grid states it.
OandaMetals => "oanda_metals",
/// OANDA's US-anchored index book — US SPX 500, US Nas 100,
/// US Russ 2000 and US Wall St 30 —
/// on one continuous Sunday-to-Friday clock:
/// Chicago 17:01 to 15:59, the same instants as New York 18:01 to
/// 16:59, with the printed 16:59-18:01 daily gap and no other
/// maintenance. US Treasury CFDs use
/// [`OandaUsBondCfd`](Self::OandaUsBondCfd), whose holidays can differ.
OandaUsIndexCfd => "oanda_us_index_cfd",
/// OANDA's four US Treasury CFD listings on the same normal-week
/// clock as [`OandaUsIndexCfd`](Self::OandaUsIndexCfd), with their
/// own holiday closes (including Good Friday 2026 at 11:14 ET).
OandaUsBondCfd => "oanda_us_bond_cfd",
/// OANDA's US-anchored energy and commodity-metals book — Natural
/// Gas, West Texas Oil, Platinum, Palladium and Copper — on the same
/// continuous clock as [`OandaUsIndexCfd`](Self::OandaUsIndexCfd):
/// New York 18:01 to 16:59 Sunday-to-Friday, with the printed
/// 16:59-18:01 daily gap and no other maintenance. A separate key
/// because the operator's holiday page gives this group its own
/// early-close instants ("US energies and metals").
OandaUsCommodityCfd => "oanda_us_commodity_cfd",
/// OANDA's own Brent book, anchored to London by the page's own
/// dagger note: opens Sunday 23:01 and closes Friday 21:59 London
/// time, with the six-minute 21:59-22:05 break and the two-hour
/// 22:59-01:01 break Monday-Thursday. The page's timezone column
/// names New York, but the note states the London clock and the
/// evidence file records that reading.
OandaBrent => "oanda_brent",
/// OANDA China A50 CFD day and overnight trading in Singapore time.
/// This is the broker calendar, distinct from SGX futures.
OandaChina50Cfd => "oanda_china50_cfd",
/// OANDA Singapore 30 CFD day and overnight trading in Singapore time.
/// This is the broker calendar, distinct from SGX futures.
OandaSingapore30Cfd => "oanda_singapore30_cfd",
/// ASX SPI 200 index futures (and options) on the Sydney ASX 24 grid:
/// day session 09:50-16:30 Monday to Friday, night session opening
/// 17:10 Sunday to Friday evenings, and a ten-minute pre-open before
/// each open. The night close follows the operator's own two-column
/// US-daylight selector — 07:00 Sydney from the second Sunday in March
/// to the first Sunday in November, 08:00 otherwise — and the week ends
/// with the Friday-evening leg on the Saturday morning.
AsxSpi200 => "asx_spi_200",
/// MEFF IBEX 35 index futures — with the Mini IBEX 35 and Micro IBEX
/// 35 futures, which the operator's own notices have always printed
/// on the same electronic-order-system row — in Europe/Madrid.
///
/// The family runs one same-day Monday-Friday session: 09:00-17:35
/// with an 08:30-09:00 opening auction at the January-2010 floor,
/// 08:00-20:00 with a 07:55-08:00 auction from the operator's
/// 2017-01-23 press release, and 08:00-22:00 from the dated
/// 2025-06-23 close extension of notice MEFF 16/2025. The auction is
/// `order_entry` in every era. Notice 7/2024's conditional
/// 2024-07-01 date — "se confirmará una vez la Comisión Nacional del
/// Mercado de Valores haya procedido a la valoración" — never keyed a
/// row; the operator postponed the change in notice 13/2024 and
/// dated it unconditionally in notice 16/2025. Excludes Bono 10,
/// xRolling FX, stock futures and every other MEFF product, whose
/// rows the same notices print at different hours, and the
/// Christmas-eve 13:54 VWAP settlement window, which is a fixing
/// instant, not a session boundary (LAW-SESSION-NOT-EXPIRY).
BmeIbex => "bme_ibex",
/// HKEX index futures (Hang Seng Index and the H-shares suite): the
/// HKFE day session in two parts with pre-opening order-entry periods,
/// plus (from 2013-04-08) the After-Hours Futures Trading T+1 session.
/// The T+1 session's trades are "registered as the following day's
/// trades" (the AHFT information paper), so in the current 17:00-03:00
/// era its trade date is the following day. Excludes Mini and other
/// contracts whose own specification closes earlier
/// (last-trading-day shapes are caller catalog data).
HkexIndexFutures => "hkex_index_futures",
/// ICE Futures Europe gilt futures — Long Gilt and Medium Gilt — in
/// Europe/London.
///
/// The family shares one clock through 2026-07-05: Monday-Friday
/// 08:00-18:00 with a 06:03-08:00 pre-open, the grid the operator's
/// own product pages print for every four gilt contracts. Circular
/// 26/063 of 23 April 2026 then extends Long and Medium Gilt alone
/// to a 00:45 pre-open and 01:00-21:00 trading from Monday
/// 2026-07-06, while Short and Ultra Long Gilt explicitly stay on
/// 08:00-18:00 — so from that day this key carries the Long and
/// Medium scope and the unchanged Short/Ultra grid is a different
/// clock outside it. The circular leaves the settlement windows and
/// the Last-Trading-Day cessation unchanged; both are fixing or
/// expiry instants, never session boundaries
/// (LAW-SESSION-NOT-EXPIRY). Excludes SONIA and MPC Dated SONIA,
/// which the same circular moved to the same 01:00-21:00 grid and
/// which earn their own key only when a consumer maps one.
IceEuropeGilts => "ice_europe_gilts",
/// SGX Three-Month SORA Futures current profile.
Sgx => "sgx",
/// Continuous 24x7 UTC profile.
///
/// It has no final daily close, so date-aware trade-date queries return
/// `None` at every instant.
AlwaysOpen => "always_open",
}
}
/// Resolves the fixed [`MarketHours`] snapshot in effect for `key` at `as_of`.
///
/// This is the key-side's only profile-selection path: every request carries
/// the caller's instant (LAW-DETERMINISM), so a backtest and a live query run
/// identical code. Sourced histories are selected independently for each
/// product family, including CME Group equity-index, energy/metals, grains,
/// FX, interest-rate, livestock, and cryptocurrency grids. A key with no
/// in-scope recorded change and **no seasonal grid** resolves to its one grid
/// at every instant; `Eurex` and `EurexFixedIncome` are the two keys that carry
/// two grids with no dated change between them, and this function selects the
/// one in force at `as_of` by the venue's own offset — a seasonal switch, not a
/// revision ([#77](https://github.com/SharurTrading/exchange-hours-rs/issues/77)).
/// Dates
/// before the January-2010 audit floor receive the oldest audited profile. For
/// launch-dated families — CME cryptocurrency, CME/CBOT spot-quoted, CME Group
/// event contracts, ICE U.S.
/// NYSE FANG+, and SGX Three-Month SORA — a pre-launch date returns an
/// explicit sessionless profile. A member listed after its family began does
/// not create a key-level
/// revision; callers enforce product launch dates in their catalog. Some CME
/// histories have a verified-current Pre-Open or PCP queue with no primary day
/// for its onset; each of those timelines carries the queue only from its own
/// knowledge-bound review row onward — 2026-08-22 for the equity-index,
/// energy, FX and interest-rate families and 2026-09-05 for weather — rather
/// than fabricating a cutover.
///
/// This returns one snapshot. Use
/// [`calendar_for_market_hours_key`](super::calendar_for_market_hours_key) for
/// date-aware scans that cross a family revision.
#[must_use]
pub fn hours_for_market_hours_key(key: MarketHoursKey, as_of: DateTime<Utc>) -> MarketHours {
let profile = match key {
MarketHoursKey::GlobexEquityIndex => cme_profile_at(as_of),
MarketHoursKey::GlobexEnergy => energy_metals_profile_at(as_of),
MarketHoursKey::GlobexSilver100Oz => silver_100oz_profile_at(as_of),
MarketHoursKey::GlobexGrains => cbot_profile_at(as_of),
MarketHoursKey::GlobexMiniGrains => mini_grains_profile_at(as_of),
MarketHoursKey::GlobexFx => fx_profile_at(as_of),
MarketHoursKey::GlobexInterestRates => interest_rates_profile_at(as_of),
MarketHoursKey::GlobexLivestock => livestock_profile_at(as_of),
MarketHoursKey::GlobexCryptocurrency => cryptocurrency_profile_at(as_of),
MarketHoursKey::CfeVix => cfe_profile_at(as_of),
MarketHoursKey::Eurex => eurex_profile_at(as_of),
MarketHoursKey::IceUs => ice_us_fang_profile_at(as_of),
MarketHoursKey::IceUsSugar => sugar_profile_at(as_of),
MarketHoursKey::IceUsCoffee => coffee_profile_at(as_of),
MarketHoursKey::IceUsCocoa => cocoa_profile_at(as_of),
MarketHoursKey::IceUsCotton => cotton_profile_at(as_of),
MarketHoursKey::IceUsOrangeJuice => fcoj_profile_at(as_of),
MarketHoursKey::IceUsDollarIndex => ice_usdx_profile_at(as_of),
MarketHoursKey::GlobexNikkei225Dollar => nkd_profile_at(as_of),
MarketHoursKey::EurexFixedIncome => eurex_fixed_income_profile_at(as_of),
MarketHoursKey::EurexSmi => eurex_smi_profile_at(as_of),
MarketHoursKey::EuronextIndexFutures => euronext_index_futures_profile_at(as_of),
MarketHoursKey::SgxEquityIndexJapan => sgx_equity_index_japan_profile_at(as_of),
MarketHoursKey::SgxEquityIndexChina => sgx_equity_index_china_profile_at(as_of),
MarketHoursKey::SgxEquityIndexSingapore => sgx_equity_index_singapore_profile_at(as_of),
MarketHoursKey::SgxEquityIndexTaiwan => sgx_equity_index_taiwan_profile_at(as_of),
MarketHoursKey::SgxEquityIndexNtrUsd => sgx_equity_index_ntr_usd_profile_at(as_of),
MarketHoursKey::GlobexRoughRice => rough_rice_profile_at(as_of),
MarketHoursKey::GlobexWeather => weather_profile_at(as_of),
MarketHoursKey::GlobexSpotQuoted => spot_quoted_profile_at(as_of),
MarketHoursKey::GlobexEventContracts => event_contracts_profile_at(as_of),
MarketHoursKey::GlobexEventContractsBtc => bitcoin_event_contracts_profile_at(as_of),
MarketHoursKey::GlobexGoldTas => gold_tas_profile_at(as_of),
MarketHoursKey::GlobexSilverTas => silver_tas_profile_at(as_of),
MarketHoursKey::GlobexCopperTas => copper_tas_profile_at(as_of),
MarketHoursKey::GlobexPlatinumTas => platinum_tas_profile_at(as_of),
MarketHoursKey::GlobexPalladiumTas => palladium_tas_profile_at(as_of),
MarketHoursKey::OandaFx => oanda_fx_profile_at(as_of),
MarketHoursKey::OandaTryFx => oanda_try_fx_profile_at(as_of),
MarketHoursKey::OandaMetals => oanda_metals_profile_at(as_of),
MarketHoursKey::OandaUsIndexCfd | MarketHoursKey::OandaUsBondCfd => {
oanda_us_index_profile_at(as_of)
}
MarketHoursKey::OandaUsCommodityCfd => oanda_us_commodity_profile_at(as_of),
MarketHoursKey::OandaBrent => oanda_brent_profile_at(as_of),
MarketHoursKey::OandaChina50Cfd => oanda_china50_profile_at(as_of),
MarketHoursKey::OandaSingapore30Cfd => oanda_singapore30_profile_at(as_of),
MarketHoursKey::AsxSpi200 => asx_spi_200_profile_at(as_of),
MarketHoursKey::BmeIbex => bme_ibex_profile_at(as_of),
MarketHoursKey::HkexIndexFutures => hkex_index_futures_profile_at(as_of),
MarketHoursKey::IceEuropeGilts => ice_europe_gilts_profile_at(as_of),
MarketHoursKey::Sgx => sgx_profile_at(as_of),
MarketHoursKey::AlwaysOpen => &ALWAYS_OPEN_PROFILE,
};
from_profile(CalendarSource::MarketHoursKey(key), profile)
}