pandas-market-calendars 5.1.0__py3-none-any.whl → 5.1.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pandas_market_calendars/__init__.py +39 -39
- pandas_market_calendars/calendar_registry.py +57 -57
- pandas_market_calendars/calendar_utils.py +1151 -1151
- pandas_market_calendars/calendars/asx.py +77 -70
- pandas_market_calendars/calendars/bmf.py +226 -219
- pandas_market_calendars/calendars/bse.py +432 -425
- pandas_market_calendars/calendars/cboe.py +156 -149
- pandas_market_calendars/calendars/cme.py +412 -405
- pandas_market_calendars/calendars/cme_globex_agriculture.py +172 -172
- pandas_market_calendars/calendars/cme_globex_base.py +126 -119
- pandas_market_calendars/calendars/cme_globex_crypto.py +165 -158
- pandas_market_calendars/calendars/cme_globex_energy_and_metals.py +223 -216
- pandas_market_calendars/calendars/cme_globex_equities.py +130 -123
- pandas_market_calendars/calendars/cme_globex_fixed_income.py +136 -136
- pandas_market_calendars/calendars/cme_globex_fx.py +101 -101
- pandas_market_calendars/calendars/eurex.py +138 -131
- pandas_market_calendars/calendars/eurex_fixed_income.py +105 -98
- pandas_market_calendars/calendars/hkex.py +438 -431
- pandas_market_calendars/calendars/ice.py +88 -81
- pandas_market_calendars/calendars/iex.py +162 -155
- pandas_market_calendars/calendars/jpx.py +124 -117
- pandas_market_calendars/calendars/lse.py +125 -118
- pandas_market_calendars/calendars/mirror.py +144 -144
- pandas_market_calendars/calendars/nyse.py +1472 -1466
- pandas_market_calendars/calendars/ose.py +125 -118
- pandas_market_calendars/calendars/sifma.py +390 -383
- pandas_market_calendars/calendars/six.py +143 -136
- pandas_market_calendars/calendars/sse.py +322 -315
- pandas_market_calendars/calendars/tase.py +231 -224
- pandas_market_calendars/calendars/tsx.py +192 -185
- pandas_market_calendars/class_registry.py +115 -115
- pandas_market_calendars/holidays/cme.py +385 -385
- pandas_market_calendars/holidays/cme_globex.py +214 -214
- pandas_market_calendars/holidays/cn.py +1476 -1476
- pandas_market_calendars/holidays/jp.py +401 -401
- pandas_market_calendars/holidays/jpx_equinox.py +506 -506
- pandas_market_calendars/holidays/nyse.py +1536 -1536
- pandas_market_calendars/holidays/oz.py +63 -63
- pandas_market_calendars/holidays/sifma.py +350 -350
- pandas_market_calendars/holidays/us.py +376 -376
- pandas_market_calendars/market_calendar.py +1008 -1008
- {pandas_market_calendars-5.1.0.dist-info → pandas_market_calendars-5.1.1.dist-info}/METADATA +3 -1
- pandas_market_calendars-5.1.1.dist-info/RECORD +50 -0
- {pandas_market_calendars-5.1.0.dist-info → pandas_market_calendars-5.1.1.dist-info}/WHEEL +1 -1
- pandas_market_calendars-5.1.0.dist-info/RECORD +0 -50
- {pandas_market_calendars-5.1.0.dist-info → pandas_market_calendars-5.1.1.dist-info}/licenses/LICENSE +0 -0
- {pandas_market_calendars-5.1.0.dist-info → pandas_market_calendars-5.1.1.dist-info}/licenses/NOTICE +0 -0
- {pandas_market_calendars-5.1.0.dist-info → pandas_market_calendars-5.1.1.dist-info}/top_level.txt +0 -0
@@ -1,185 +1,192 @@
|
|
1
|
-
from datetime import time
|
2
|
-
from itertools import chain
|
3
|
-
|
4
|
-
import pandas as pd
|
5
|
-
from pandas.tseries.holiday import (
|
6
|
-
AbstractHolidayCalendar,
|
7
|
-
DateOffset,
|
8
|
-
GoodFriday,
|
9
|
-
Holiday,
|
10
|
-
MO,
|
11
|
-
weekend_to_monday,
|
12
|
-
)
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
from
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
#
|
37
|
-
|
38
|
-
"
|
39
|
-
month=
|
40
|
-
day=1,
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
#
|
53
|
-
|
54
|
-
"
|
55
|
-
month=
|
56
|
-
day=
|
57
|
-
|
58
|
-
)
|
59
|
-
#
|
60
|
-
|
61
|
-
"
|
62
|
-
month=
|
63
|
-
day=1,
|
64
|
-
|
65
|
-
)
|
66
|
-
#
|
67
|
-
|
68
|
-
"
|
69
|
-
month=
|
70
|
-
day=1,
|
71
|
-
offset=DateOffset(weekday=MO(1)),
|
72
|
-
)
|
73
|
-
#
|
74
|
-
|
75
|
-
"
|
76
|
-
month=
|
77
|
-
day=1,
|
78
|
-
offset=DateOffset(weekday=MO(
|
79
|
-
)
|
80
|
-
|
81
|
-
|
82
|
-
"
|
83
|
-
month=
|
84
|
-
day=
|
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
|
-
|
1
|
+
from datetime import time
|
2
|
+
from itertools import chain
|
3
|
+
|
4
|
+
import pandas as pd
|
5
|
+
from pandas.tseries.holiday import (
|
6
|
+
AbstractHolidayCalendar,
|
7
|
+
DateOffset,
|
8
|
+
GoodFriday,
|
9
|
+
Holiday,
|
10
|
+
MO,
|
11
|
+
weekend_to_monday,
|
12
|
+
)
|
13
|
+
import sys
|
14
|
+
# check python versiOn aNd import accordingly
|
15
|
+
if sys.version_info >= (3, 9):
|
16
|
+
# For Python 3.9 and later, import directly
|
17
|
+
from zoneinfo import ZoneInfo
|
18
|
+
else:
|
19
|
+
# For Python 3.8 and earlier, import from backports
|
20
|
+
from backports.zoneinfo import ZoneInfo
|
21
|
+
|
22
|
+
from pandas_market_calendars.holidays.uk import (
|
23
|
+
BoxingDay,
|
24
|
+
WeekendBoxingDay,
|
25
|
+
WeekendChristmas,
|
26
|
+
)
|
27
|
+
from pandas_market_calendars.market_calendar import (
|
28
|
+
MarketCalendar,
|
29
|
+
MONDAY,
|
30
|
+
TUESDAY,
|
31
|
+
WEDNESDAY,
|
32
|
+
THURSDAY,
|
33
|
+
FRIDAY,
|
34
|
+
)
|
35
|
+
|
36
|
+
# New Year's Day
|
37
|
+
TSXNewYearsDay = Holiday(
|
38
|
+
"New Year's Day",
|
39
|
+
month=1,
|
40
|
+
day=1,
|
41
|
+
observance=weekend_to_monday,
|
42
|
+
)
|
43
|
+
# Ontario Family Day
|
44
|
+
FamilyDay = Holiday(
|
45
|
+
"Family Day",
|
46
|
+
month=2,
|
47
|
+
day=1,
|
48
|
+
offset=DateOffset(weekday=MO(3)),
|
49
|
+
start_date="2008-01-01",
|
50
|
+
)
|
51
|
+
# Victoria Day
|
52
|
+
# https://www.timeanddate.com/holidays/canada/victoria-day
|
53
|
+
VictoriaDay = Holiday(
|
54
|
+
"Victoria Day",
|
55
|
+
month=5,
|
56
|
+
day=24,
|
57
|
+
offset=DateOffset(weekday=MO(-1)),
|
58
|
+
)
|
59
|
+
# Canada Day
|
60
|
+
CanadaDay = Holiday(
|
61
|
+
"Canada Day",
|
62
|
+
month=7,
|
63
|
+
day=1,
|
64
|
+
observance=weekend_to_monday,
|
65
|
+
)
|
66
|
+
# Civic Holiday
|
67
|
+
CivicHoliday = Holiday(
|
68
|
+
"Civic Holiday",
|
69
|
+
month=8,
|
70
|
+
day=1,
|
71
|
+
offset=DateOffset(weekday=MO(1)),
|
72
|
+
)
|
73
|
+
# Labor Day
|
74
|
+
LaborDay = Holiday(
|
75
|
+
"Labor Day",
|
76
|
+
month=9,
|
77
|
+
day=1,
|
78
|
+
offset=DateOffset(weekday=MO(1)),
|
79
|
+
)
|
80
|
+
# Thanksgiving
|
81
|
+
Thanksgiving = Holiday(
|
82
|
+
"Thanksgiving",
|
83
|
+
month=10,
|
84
|
+
day=1,
|
85
|
+
offset=DateOffset(weekday=MO(2)),
|
86
|
+
)
|
87
|
+
|
88
|
+
Christmas = Holiday(
|
89
|
+
"Christmas",
|
90
|
+
month=12,
|
91
|
+
day=25,
|
92
|
+
)
|
93
|
+
|
94
|
+
ChristmasEveEarlyClose2010Onwards = Holiday(
|
95
|
+
"Christmas Eve Early Close",
|
96
|
+
month=12,
|
97
|
+
day=24,
|
98
|
+
days_of_week=(MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY),
|
99
|
+
start_date=pd.Timestamp("2010-01-01"),
|
100
|
+
)
|
101
|
+
|
102
|
+
September11Closings2001 = [
|
103
|
+
pd.Timestamp("2001-09-11", tz="UTC"),
|
104
|
+
pd.Timestamp("2001-09-12", tz="UTC"),
|
105
|
+
]
|
106
|
+
|
107
|
+
|
108
|
+
class TSXExchangeCalendar(MarketCalendar):
|
109
|
+
"""
|
110
|
+
Exchange calendar for the Toronto Stock Exchange
|
111
|
+
|
112
|
+
Open Time: 9:30 AM, EST
|
113
|
+
Close Time: 4:00 PM, EST
|
114
|
+
|
115
|
+
Regularly-Observed Holidays:
|
116
|
+
- New Years Day (observed on first business day on/after)
|
117
|
+
- Family Day (Third Monday in February, starting in 2008)
|
118
|
+
- Good Friday
|
119
|
+
- Victoria Day (Monday before May 25th)
|
120
|
+
- Canada Day (July 1st, observed first business day after)
|
121
|
+
- Civic Holiday (First Monday in August)
|
122
|
+
- Labor Day (First Monday in September)
|
123
|
+
- Thanksgiving (Second Monday in October)
|
124
|
+
- Christmas Day
|
125
|
+
- Dec. 26th if Christmas is on a Sunday
|
126
|
+
- Dec. 27th if Christmas is on a weekend
|
127
|
+
- Boxing Day
|
128
|
+
- Dec. 27th if Christmas is on a Sunday
|
129
|
+
- Dec. 28th if Boxing Day is on a weekend
|
130
|
+
|
131
|
+
Early closes:
|
132
|
+
- Starting in 2010, if Christmas Eve falls on a weekday, the market
|
133
|
+
closes at 1:00 pm that day. If it falls on a weekend, there is no
|
134
|
+
early close.
|
135
|
+
"""
|
136
|
+
|
137
|
+
aliases = ["TSX", "TSXV"]
|
138
|
+
|
139
|
+
regular_market_times = {
|
140
|
+
"market_open": ((None, time(9, 30)),),
|
141
|
+
"market_close": ((None, time(16)),),
|
142
|
+
}
|
143
|
+
|
144
|
+
@property
|
145
|
+
def name(self):
|
146
|
+
return "TSX"
|
147
|
+
|
148
|
+
@property
|
149
|
+
def full_name(self):
|
150
|
+
return "Toronto Stock Exchange"
|
151
|
+
|
152
|
+
@property
|
153
|
+
def tz(self):
|
154
|
+
return ZoneInfo("Canada/Eastern")
|
155
|
+
|
156
|
+
regular_early_close = time(13)
|
157
|
+
|
158
|
+
@property
|
159
|
+
def regular_holidays(self):
|
160
|
+
return AbstractHolidayCalendar(
|
161
|
+
rules=[
|
162
|
+
TSXNewYearsDay,
|
163
|
+
FamilyDay,
|
164
|
+
GoodFriday,
|
165
|
+
VictoriaDay,
|
166
|
+
CanadaDay,
|
167
|
+
CivicHoliday,
|
168
|
+
LaborDay,
|
169
|
+
Thanksgiving,
|
170
|
+
Christmas,
|
171
|
+
WeekendChristmas,
|
172
|
+
BoxingDay,
|
173
|
+
WeekendBoxingDay,
|
174
|
+
]
|
175
|
+
)
|
176
|
+
|
177
|
+
@property
|
178
|
+
def adhoc_holidays(self):
|
179
|
+
return list(
|
180
|
+
chain(
|
181
|
+
September11Closings2001,
|
182
|
+
)
|
183
|
+
)
|
184
|
+
|
185
|
+
@property
|
186
|
+
def special_closes(self):
|
187
|
+
return [
|
188
|
+
(
|
189
|
+
self.regular_early_close,
|
190
|
+
AbstractHolidayCalendar([ChristmasEveEarlyClose2010Onwards]),
|
191
|
+
)
|
192
|
+
]
|
@@ -1,115 +1,115 @@
|
|
1
|
-
import inspect
|
2
|
-
from pprint import pformat
|
3
|
-
|
4
|
-
|
5
|
-
def _regmeta_instance_factory(cls, name, *args, **kwargs):
|
6
|
-
"""
|
7
|
-
:param cls(RegisteryMeta): registration meta class
|
8
|
-
:param name(str): name of class that needs to be instantiated
|
9
|
-
:param args(Optional(tuple)): instance positional arguments
|
10
|
-
:param kwargs(Optional(dict)): instance named arguments
|
11
|
-
:return: class instance
|
12
|
-
"""
|
13
|
-
try:
|
14
|
-
class_ = cls._regmeta_class_registry[name]
|
15
|
-
except KeyError:
|
16
|
-
raise RuntimeError(
|
17
|
-
"Class {} is not one of the registered classes: {}".format(
|
18
|
-
name, cls._regmeta_class_registry.keys()
|
19
|
-
)
|
20
|
-
)
|
21
|
-
return class_(*args, **kwargs)
|
22
|
-
|
23
|
-
|
24
|
-
def _regmeta_register_class(cls, regcls, name):
|
25
|
-
"""
|
26
|
-
:param cls(RegisteryMeta): registration base class
|
27
|
-
:param regcls(class): class to be registered
|
28
|
-
:param name(str): name of the class to be registered
|
29
|
-
"""
|
30
|
-
if hasattr(regcls, "aliases"):
|
31
|
-
if regcls.aliases:
|
32
|
-
for alias in regcls.aliases:
|
33
|
-
cls._regmeta_class_registry[alias] = regcls
|
34
|
-
else:
|
35
|
-
cls._regmeta_class_registry[name] = regcls
|
36
|
-
else:
|
37
|
-
cls._regmeta_class_registry[name] = regcls
|
38
|
-
|
39
|
-
|
40
|
-
class RegisteryMeta(type):
|
41
|
-
"""
|
42
|
-
Metaclass used to register all classes inheriting from RegisteryMeta
|
43
|
-
"""
|
44
|
-
|
45
|
-
def __new__(mcs, name, bases, attr):
|
46
|
-
cls = super(RegisteryMeta, mcs).__new__(mcs, name, bases, attr)
|
47
|
-
if not hasattr(cls, "_regmeta_class_registry"):
|
48
|
-
cls._regmeta_class_registry = {}
|
49
|
-
cls.factory = classmethod(_regmeta_instance_factory)
|
50
|
-
|
51
|
-
return cls
|
52
|
-
|
53
|
-
def __init__(cls, name, bases, attr):
|
54
|
-
if not inspect.isabstract(cls):
|
55
|
-
_regmeta_register_class(cls, cls, name)
|
56
|
-
for b in bases:
|
57
|
-
if hasattr(b, "_regmeta_class_registry"):
|
58
|
-
_regmeta_register_class(b, cls, name)
|
59
|
-
|
60
|
-
super(RegisteryMeta, cls).__init__(name, bases, attr)
|
61
|
-
|
62
|
-
cls.regular_market_times = ProtectedDict(cls.regular_market_times)
|
63
|
-
cls.open_close_map = ProtectedDict(cls.open_close_map)
|
64
|
-
|
65
|
-
cls.special_market_open = cls.special_opens
|
66
|
-
cls.special_market_open_adhoc = cls.special_opens_adhoc
|
67
|
-
|
68
|
-
cls.special_market_close = cls.special_closes
|
69
|
-
cls.special_market_close_adhoc = cls.special_closes_adhoc
|
70
|
-
|
71
|
-
|
72
|
-
class ProtectedDict(dict):
|
73
|
-
def __init__(self, *args, **kwargs):
|
74
|
-
super().__init__(*args, **kwargs)
|
75
|
-
# __init__ is bypassed when unpickling, which causes __setitem__ to fail
|
76
|
-
# without the _INIT_RAN_NORMALLY flag
|
77
|
-
self._INIT_RAN_NORMALLY = True
|
78
|
-
|
79
|
-
def _set(self, key, value):
|
80
|
-
return super().__setitem__(key, value)
|
81
|
-
|
82
|
-
def _del(self, key):
|
83
|
-
return super().__delitem__(key)
|
84
|
-
|
85
|
-
def __setitem__(self, key, value):
|
86
|
-
if not hasattr(self, "_INIT_RAN_NORMALLY"):
|
87
|
-
return self._set(key, value)
|
88
|
-
|
89
|
-
raise TypeError(
|
90
|
-
"You cannot set a value directly, you can change regular_market_times "
|
91
|
-
"using .change_time, .add_time or .remove_time."
|
92
|
-
)
|
93
|
-
|
94
|
-
def __delitem__(self, key):
|
95
|
-
if not hasattr(self, "_INIT_RAN_NORMALLY"):
|
96
|
-
return self._del(key)
|
97
|
-
|
98
|
-
raise TypeError(
|
99
|
-
"You cannot delete an item directly. You can change regular_market_times "
|
100
|
-
"using .change_time, .add_time or .remove_time"
|
101
|
-
)
|
102
|
-
|
103
|
-
def __repr__(self):
|
104
|
-
return self.__class__.__name__ + "(" + super().__repr__() + ")"
|
105
|
-
|
106
|
-
def __str__(self):
|
107
|
-
try:
|
108
|
-
formatted = pformat(dict(self), sort_dicts=False) # sort_dicts apparently not available < python3.8
|
109
|
-
except TypeError:
|
110
|
-
formatted = pformat(dict(self))
|
111
|
-
|
112
|
-
return self.__class__.__name__ + "(\n" + formatted + "\n)"
|
113
|
-
|
114
|
-
def copy(self):
|
115
|
-
return self.__class__(super().copy())
|
1
|
+
import inspect
|
2
|
+
from pprint import pformat
|
3
|
+
|
4
|
+
|
5
|
+
def _regmeta_instance_factory(cls, name, *args, **kwargs):
|
6
|
+
"""
|
7
|
+
:param cls(RegisteryMeta): registration meta class
|
8
|
+
:param name(str): name of class that needs to be instantiated
|
9
|
+
:param args(Optional(tuple)): instance positional arguments
|
10
|
+
:param kwargs(Optional(dict)): instance named arguments
|
11
|
+
:return: class instance
|
12
|
+
"""
|
13
|
+
try:
|
14
|
+
class_ = cls._regmeta_class_registry[name]
|
15
|
+
except KeyError:
|
16
|
+
raise RuntimeError(
|
17
|
+
"Class {} is not one of the registered classes: {}".format(
|
18
|
+
name, cls._regmeta_class_registry.keys()
|
19
|
+
)
|
20
|
+
)
|
21
|
+
return class_(*args, **kwargs)
|
22
|
+
|
23
|
+
|
24
|
+
def _regmeta_register_class(cls, regcls, name):
|
25
|
+
"""
|
26
|
+
:param cls(RegisteryMeta): registration base class
|
27
|
+
:param regcls(class): class to be registered
|
28
|
+
:param name(str): name of the class to be registered
|
29
|
+
"""
|
30
|
+
if hasattr(regcls, "aliases"):
|
31
|
+
if regcls.aliases:
|
32
|
+
for alias in regcls.aliases:
|
33
|
+
cls._regmeta_class_registry[alias] = regcls
|
34
|
+
else:
|
35
|
+
cls._regmeta_class_registry[name] = regcls
|
36
|
+
else:
|
37
|
+
cls._regmeta_class_registry[name] = regcls
|
38
|
+
|
39
|
+
|
40
|
+
class RegisteryMeta(type):
|
41
|
+
"""
|
42
|
+
Metaclass used to register all classes inheriting from RegisteryMeta
|
43
|
+
"""
|
44
|
+
|
45
|
+
def __new__(mcs, name, bases, attr):
|
46
|
+
cls = super(RegisteryMeta, mcs).__new__(mcs, name, bases, attr)
|
47
|
+
if not hasattr(cls, "_regmeta_class_registry"):
|
48
|
+
cls._regmeta_class_registry = {}
|
49
|
+
cls.factory = classmethod(_regmeta_instance_factory)
|
50
|
+
|
51
|
+
return cls
|
52
|
+
|
53
|
+
def __init__(cls, name, bases, attr):
|
54
|
+
if not inspect.isabstract(cls):
|
55
|
+
_regmeta_register_class(cls, cls, name)
|
56
|
+
for b in bases:
|
57
|
+
if hasattr(b, "_regmeta_class_registry"):
|
58
|
+
_regmeta_register_class(b, cls, name)
|
59
|
+
|
60
|
+
super(RegisteryMeta, cls).__init__(name, bases, attr)
|
61
|
+
|
62
|
+
cls.regular_market_times = ProtectedDict(cls.regular_market_times)
|
63
|
+
cls.open_close_map = ProtectedDict(cls.open_close_map)
|
64
|
+
|
65
|
+
cls.special_market_open = cls.special_opens
|
66
|
+
cls.special_market_open_adhoc = cls.special_opens_adhoc
|
67
|
+
|
68
|
+
cls.special_market_close = cls.special_closes
|
69
|
+
cls.special_market_close_adhoc = cls.special_closes_adhoc
|
70
|
+
|
71
|
+
|
72
|
+
class ProtectedDict(dict):
|
73
|
+
def __init__(self, *args, **kwargs):
|
74
|
+
super().__init__(*args, **kwargs)
|
75
|
+
# __init__ is bypassed when unpickling, which causes __setitem__ to fail
|
76
|
+
# without the _INIT_RAN_NORMALLY flag
|
77
|
+
self._INIT_RAN_NORMALLY = True
|
78
|
+
|
79
|
+
def _set(self, key, value):
|
80
|
+
return super().__setitem__(key, value)
|
81
|
+
|
82
|
+
def _del(self, key):
|
83
|
+
return super().__delitem__(key)
|
84
|
+
|
85
|
+
def __setitem__(self, key, value):
|
86
|
+
if not hasattr(self, "_INIT_RAN_NORMALLY"):
|
87
|
+
return self._set(key, value)
|
88
|
+
|
89
|
+
raise TypeError(
|
90
|
+
"You cannot set a value directly, you can change regular_market_times "
|
91
|
+
"using .change_time, .add_time or .remove_time."
|
92
|
+
)
|
93
|
+
|
94
|
+
def __delitem__(self, key):
|
95
|
+
if not hasattr(self, "_INIT_RAN_NORMALLY"):
|
96
|
+
return self._del(key)
|
97
|
+
|
98
|
+
raise TypeError(
|
99
|
+
"You cannot delete an item directly. You can change regular_market_times "
|
100
|
+
"using .change_time, .add_time or .remove_time"
|
101
|
+
)
|
102
|
+
|
103
|
+
def __repr__(self):
|
104
|
+
return self.__class__.__name__ + "(" + super().__repr__() + ")"
|
105
|
+
|
106
|
+
def __str__(self):
|
107
|
+
try:
|
108
|
+
formatted = pformat(dict(self), sort_dicts=False) # sort_dicts apparently not available < python3.8
|
109
|
+
except TypeError:
|
110
|
+
formatted = pformat(dict(self))
|
111
|
+
|
112
|
+
return self.__class__.__name__ + "(\n" + formatted + "\n)"
|
113
|
+
|
114
|
+
def copy(self):
|
115
|
+
return self.__class__(super().copy())
|