-
Notifications
You must be signed in to change notification settings - Fork 173
/
cme_globex_crypto.py
147 lines (137 loc) · 4.99 KB
/
cme_globex_crypto.py
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
import datetime as dt
from pandas.tseries.holiday import AbstractHolidayCalendar
import pytz
from .cme_globex_base import CMEGlobexBaseExchangeCalendar
from pandas_market_calendars.holidays.cme import (
GoodFriday2021,
GoodFridayAfter2021,
GoodFridayBefore2021,
USIndependenceDayBefore2022PreviousDay,
)
from pandas_market_calendars.holidays.cme_globex import (
ChristmasCME,
USMartinLutherKingJrFrom2022,
USMartinLutherKingJrPre2022,
USPresidentsDayFrom2022,
USPresidentsDayPre2022,
USMemorialDayFrom2022,
USMemorialDayPre2022,
USJuneteenthFrom2022,
USIndependenceDayFrom2022,
USIndependenceDayPre2022,
USLaborDayFrom2022,
USLaborDayPre2022,
USThanksgivingDayFrom2022,
USThanksgivingDayPre2022,
USThanksgivingFridayFrom2021,
USThanksgivingFridayPre2021,
)
from pandas_market_calendars.holidays.us import (
ChristmasEveInOrAfter1993,
USNewYearsDay,
)
# https://github.com/rsheftel/pandas_market_calendars/blob/master/docs/new_market.rst
class CMEGlobexCryptoExchangeCalendar(CMEGlobexBaseExchangeCalendar):
# The label you fetch the exchange with in mcal.get_calendar('CME Globex ...')
aliases = ["CME Globex Cryptocurrencies", "CME Globex Crypto"]
# https://www.cmegroup.com/markets/cryptocurrencies/bitcoin/bitcoin.contractSpecs.html
regular_market_times = {
# Tuple[Tuple[first date used, time, offset], ...]
# -1 offset indicates that the open is on the previous day
# None for first date used marks the start, subsequent market times must have an actual timestamp
"market_open": (
(None, dt.time(17, tzinfo=pytz.timezone("America/Chicago")), -1),
),
"market_close": (
(
None,
dt.time(16, tzinfo=pytz.timezone("America/Chicago")),
),
),
"break_start": (
(
None,
dt.time(16, tzinfo=pytz.timezone("America/Chicago")),
),
),
"break_end": (
(
None,
dt.time(17, tzinfo=pytz.timezone("America/Chicago")),
),
),
}
@property
def tz(self):
# Central Time
return pytz.timezone("America/Chicago")
@property
def name(self):
return "CME Globex Crypto"
# Check the .zip files at the bottom of this page
# https://www.cmegroup.com/tools-information/holiday-calendar.html?redirect=/tools-information/holiday-calendar/#cmeGlobex
# Note: many of the holiday objects (ie. GoodFridayBefore2021) were originally made for equities and other markets
# and hence have a start_date starting before crypto is actually available
@property
def regular_holidays(self):
# Days where the market is fully closed
return AbstractHolidayCalendar(
rules=[
GoodFridayBefore2021,
GoodFridayAfter2021,
ChristmasCME,
USNewYearsDay,
]
)
@property
def special_closes(self):
# Days where the market closes early
# list[Tuple[time, AbstractHolidayCalendar]]
return [
(
dt.time(8, 15, tzinfo=pytz.timezone("America/Chicago")),
AbstractHolidayCalendar(rules=[GoodFriday2021]),
),
(
dt.time(12, tzinfo=pytz.timezone("America/Chicago")),
AbstractHolidayCalendar(
rules=[
USMartinLutherKingJrPre2022,
USPresidentsDayPre2022,
USMemorialDayPre2022,
USIndependenceDayPre2022,
USLaborDayPre2022,
USThanksgivingDayPre2022,
]
),
),
(
dt.time(12, 15, tzinfo=pytz.timezone("America/Chicago")),
AbstractHolidayCalendar(
rules=[
ChristmasEveInOrAfter1993,
USIndependenceDayBefore2022PreviousDay,
USThanksgivingFridayPre2021,
]
),
),
(
dt.time(12, 45, tzinfo=pytz.timezone("America/Chicago")),
AbstractHolidayCalendar(rules=[USThanksgivingFridayFrom2021]),
),
# TODO: this market already closes at 1600 normally, do we need these holidays?
(
dt.time(16, tzinfo=pytz.timezone("America/Chicago")),
AbstractHolidayCalendar(
rules=[
USMartinLutherKingJrFrom2022,
USPresidentsDayFrom2022,
USMemorialDayFrom2022,
USJuneteenthFrom2022,
USIndependenceDayFrom2022,
USLaborDayFrom2022,
USThanksgivingDayFrom2022,
]
),
),
]