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
// SPDX-License-Identifier: MIT-0
//! Date-aware candle adapters over the shared query engine.
use chrono::{DateTime, Utc};
use super::ExchangeCalendar;
use crate::calendar::query::{QueryContext, candles};
use crate::calendar::{CalendarQueryError, CalendarResolution, SessionKind};
impl ExchangeCalendar {
/// Returns the date-aware bar close after `instant`.
///
/// A key-backed CME cryptocurrency calendar retains Friday 16:00 CT as
/// the weekly close even though its current profile has no long weekend
/// shutdown. An identity-erased fixed snapshot cannot apply that
/// product-family convention.
///
/// # Errors
///
/// Returns [`CalendarQueryError::BeforeSupportFloor`] when the venue-local
/// day this query is addressed to precedes
/// [`SUPPORT_FLOOR`](crate::SUPPORT_FLOOR),
/// [`CalendarQueryError::OutsideCoveredRange`] when the identity has no
/// sourced answer for a day the query depends on,
/// [`CalendarQueryError::UnresolvedGap`] when that day is one the identity
/// withholds as `Unsourced`, and
/// [`CalendarQueryError::SearchExhausted`] when a bounded forward search
/// runs out of window on a day it cannot establish. An error is never
/// reported as `false`, `None`, or a default schedule (LAW-COVERAGE).
pub fn candle_end(
self,
instant: DateTime<Utc>,
resolution: CalendarResolution,
) -> Result<Option<DateTime<Utc>>, CalendarQueryError> {
self.candle_end_with(instant, resolution, SessionKind::Both)
}
/// Returns the date-aware bar close after `instant` for `kind`.
///
/// The CME cryptocurrency weekly-boundary convention described by
/// [`Self::candle_end`] applies here as well.
///
/// # Errors
///
/// Returns [`CalendarQueryError::BeforeSupportFloor`] when the venue-local
/// day this query is addressed to precedes
/// [`SUPPORT_FLOOR`](crate::SUPPORT_FLOOR),
/// [`CalendarQueryError::OutsideCoveredRange`] when the identity has no
/// sourced answer for a day the query depends on,
/// [`CalendarQueryError::UnresolvedGap`] when that day is one the identity
/// withholds as `Unsourced`, and
/// [`CalendarQueryError::SearchExhausted`] when a bounded forward search
/// runs out of window on a day it cannot establish. An error is never
/// reported as `false`, `None`, or a default schedule (LAW-COVERAGE).
pub fn candle_end_with(
self,
instant: DateTime<Utc>,
resolution: CalendarResolution,
kind: SessionKind,
) -> Result<Option<DateTime<Utc>>, CalendarQueryError> {
let context = QueryContext::date_aware(self);
context.require_floor_at(instant)?;
candles::candle_end_with(&context, instant, resolution, kind)
}
/// Returns the date-aware bar start paired with [`candle_end`](Self::candle_end).
///
/// # Errors
///
/// Returns [`CalendarQueryError::BeforeSupportFloor`] when the venue-local
/// day this query is addressed to precedes
/// [`SUPPORT_FLOOR`](crate::SUPPORT_FLOOR),
/// [`CalendarQueryError::OutsideCoveredRange`] when the identity has no
/// sourced answer for a day the query depends on,
/// [`CalendarQueryError::UnresolvedGap`] when that day is one the identity
/// withholds as `Unsourced`, and
/// [`CalendarQueryError::SearchExhausted`] when a bounded forward search
/// runs out of window on a day it cannot establish. An error is never
/// reported as `false`, `None`, or a default schedule (LAW-COVERAGE).
pub fn candle_start(
self,
instant: DateTime<Utc>,
resolution: CalendarResolution,
) -> Result<Option<DateTime<Utc>>, CalendarQueryError> {
self.candle_start_with(instant, resolution, SessionKind::Both)
}
/// Returns the date-aware bar start paired with
/// [`candle_end_with`](Self::candle_end_with) for `kind`.
///
/// # Errors
///
/// Returns [`CalendarQueryError::BeforeSupportFloor`] when the venue-local
/// day this query is addressed to precedes
/// [`SUPPORT_FLOOR`](crate::SUPPORT_FLOOR),
/// [`CalendarQueryError::OutsideCoveredRange`] when the identity has no
/// sourced answer for a day the query depends on,
/// [`CalendarQueryError::UnresolvedGap`] when that day is one the identity
/// withholds as `Unsourced`, and
/// [`CalendarQueryError::SearchExhausted`] when a bounded forward search
/// runs out of window on a day it cannot establish. An error is never
/// reported as `false`, `None`, or a default schedule (LAW-COVERAGE).
pub fn candle_start_with(
self,
instant: DateTime<Utc>,
resolution: CalendarResolution,
kind: SessionKind,
) -> Result<Option<DateTime<Utc>>, CalendarQueryError> {
let context = QueryContext::date_aware(self);
context.require_floor_at(instant)?;
candles::candle_start_with(&context, instant, resolution, kind)
}
/// Returns the next date-aware trading-day close after `instant`.
///
/// # Errors
///
/// Returns [`CalendarQueryError::BeforeSupportFloor`] when the venue-local
/// day this query is addressed to precedes
/// [`SUPPORT_FLOOR`](crate::SUPPORT_FLOOR),
/// [`CalendarQueryError::OutsideCoveredRange`] when the identity has no
/// sourced answer for a day the query depends on,
/// [`CalendarQueryError::UnresolvedGap`] when that day is one the identity
/// withholds as `Unsourced`, and
/// [`CalendarQueryError::SearchExhausted`] when a bounded forward search
/// runs out of window on a day it cannot establish. An error is never
/// reported as `false`, `None`, or a default schedule (LAW-COVERAGE).
pub fn time_end_of_day(
self,
instant: DateTime<Utc>,
) -> Result<Option<DateTime<Utc>>, CalendarQueryError> {
self.candle_end(instant, CalendarResolution::Daily)
}
}