2424CRYPTO_OPEN_WED_2023_6_21_12 = datetime .datetime (2023 , 6 , 21 , 12 , 0 , 0 , tzinfo = NY_TZ )
2525CRYPTO_OPEN_SUN_2023_6_18_12 = datetime .datetime (2023 , 6 , 18 , 12 , 0 , 0 , tzinfo = NY_TZ )
2626
27- def format_datetime_to_utc_iso_string (dt : datetime .datetime ):
28- return dt .astimezone (UTC_TZ ).strftime ("%Y-%m-%dT%H:%M:%S" ) + "Z"
27+
28+ def format_datetime_to_unix_timestamp (dt : datetime .datetime ):
29+ # Convert the datetime object to a Unix timestamp in UTC
30+ timestamp = dt .astimezone (UTC_TZ ).timestamp ()
31+ unix_timestamp_utc = int (timestamp )
32+ return unix_timestamp_utc
2933
3034def test_is_market_open ():
3135 # equity
@@ -67,65 +71,65 @@ def test_get_next_market_open():
6771 # equity within market hours
6872 assert (
6973 get_next_market_open ("equity" , EQUITY_OPEN_WED_2023_6_21_12 )
70- == format_datetime_to_utc_iso_string (datetime .datetime (2023 , 6 , 22 , 9 , 30 , 0 , tzinfo = NY_TZ ))
74+ == format_datetime_to_unix_timestamp (datetime .datetime (2023 , 6 , 22 , 9 , 30 , 0 , tzinfo = NY_TZ ))
7175 )
7276
7377 # equity out of market hours
7478 assert (
7579 get_next_market_open ("equity" , EQUITY_CLOSE_WED_2023_6_21_17 )
76- == format_datetime_to_utc_iso_string (datetime .datetime (2023 , 6 , 22 , 9 , 30 , 0 , tzinfo = NY_TZ ))
80+ == format_datetime_to_unix_timestamp (datetime .datetime (2023 , 6 , 22 , 9 , 30 , 0 , tzinfo = NY_TZ ))
7781 )
7882
7983 # equity weekend
8084 assert (
8185 get_next_market_open ("equity" , EQUITY_CLOSE_SAT_2023_6_10_17 )
82- == format_datetime_to_utc_iso_string (datetime .datetime (2023 , 6 , 12 , 9 , 30 , 0 , tzinfo = NY_TZ ))
86+ == format_datetime_to_unix_timestamp (datetime .datetime (2023 , 6 , 12 , 9 , 30 , 0 , tzinfo = NY_TZ ))
8387 )
8488
8589 # equity holiday
8690 assert (
8791 get_next_market_open ("equity" , EQUITY_HOLIDAY_MON_2023_6_19 )
88- == format_datetime_to_utc_iso_string (datetime .datetime (2023 , 6 , 20 , 9 , 30 , 0 , tzinfo = NY_TZ ))
92+ == format_datetime_to_unix_timestamp (datetime .datetime (2023 , 6 , 20 , 9 , 30 , 0 , tzinfo = NY_TZ ))
8993 )
9094
9195 # equity early close holiday
9296 assert (
9397 get_next_market_open ("equity" , EQUITY_EARLY_CLOSE_OPEN_FRI_2023_11_24_14 )
94- == format_datetime_to_utc_iso_string (datetime .datetime (2023 , 11 , 27 , 9 , 30 , 0 , tzinfo = NY_TZ ))
98+ == format_datetime_to_unix_timestamp (datetime .datetime (2023 , 11 , 27 , 9 , 30 , 0 , tzinfo = NY_TZ ))
9599 )
96100 assert (
97101 get_next_market_open ("equity" , EQUITY_EARLY_CLOSE_CLOSE_FRI_2023_11_24_14 )
98- == format_datetime_to_utc_iso_string (datetime .datetime (2023 , 11 , 27 , 9 , 30 , 0 , tzinfo = NY_TZ ))
102+ == format_datetime_to_unix_timestamp (datetime .datetime (2023 , 11 , 27 , 9 , 30 , 0 , tzinfo = NY_TZ ))
99103 )
100104
101105 # fx & metal within market hours
102106 assert (
103107 get_next_market_open ("fx" , FX_METAL_OPEN_WED_2023_6_21_22 )
104- == format_datetime_to_utc_iso_string (datetime .datetime (2023 , 6 , 25 , 17 , 0 , 0 , tzinfo = NY_TZ ))
108+ == format_datetime_to_unix_timestamp (datetime .datetime (2023 , 6 , 25 , 17 , 0 , 0 , tzinfo = NY_TZ ))
105109 )
106110 assert (
107111 get_next_market_open ("metal" , FX_METAL_OPEN_WED_2023_6_21_22 )
108- == format_datetime_to_utc_iso_string (datetime .datetime (2023 , 6 , 25 , 17 , 0 , 0 , tzinfo = NY_TZ ))
112+ == format_datetime_to_unix_timestamp (datetime .datetime (2023 , 6 , 25 , 17 , 0 , 0 , tzinfo = NY_TZ ))
109113 )
110114
111115 # fx & metal out of market hours
112116 assert (
113117 get_next_market_open ("fx" , FX_METAL_CLOSE_SUN_2023_6_18_16 )
114- == format_datetime_to_utc_iso_string (datetime .datetime (2023 , 6 , 18 , 17 , 0 , 0 , tzinfo = NY_TZ ))
118+ == format_datetime_to_unix_timestamp (datetime .datetime (2023 , 6 , 18 , 17 , 0 , 0 , tzinfo = NY_TZ ))
115119 )
116120 assert (
117121 get_next_market_open ("metal" , FX_METAL_CLOSE_SUN_2023_6_18_16 )
118- == format_datetime_to_utc_iso_string (datetime .datetime (2023 , 6 , 18 , 17 , 0 , 0 , tzinfo = NY_TZ ))
122+ == format_datetime_to_unix_timestamp (datetime .datetime (2023 , 6 , 18 , 17 , 0 , 0 , tzinfo = NY_TZ ))
119123 )
120124
121125 # fx & metal holiday
122126 assert (
123127 get_next_market_open ("fx" , FX_METAL_HOLIDAY_SUN_2023_1_1 )
124- == format_datetime_to_utc_iso_string (datetime .datetime (2023 , 1 , 2 , 17 , 0 , 0 , tzinfo = NY_TZ ))
128+ == format_datetime_to_unix_timestamp (datetime .datetime (2023 , 1 , 2 , 17 , 0 , 0 , tzinfo = NY_TZ ))
125129 )
126130 assert (
127131 get_next_market_open ("metal" , FX_METAL_HOLIDAY_SUN_2023_1_1 )
128- == format_datetime_to_utc_iso_string (datetime .datetime (2023 , 1 , 2 , 17 , 0 , 0 , tzinfo = NY_TZ ))
132+ == format_datetime_to_unix_timestamp (datetime .datetime (2023 , 1 , 2 , 17 , 0 , 0 , tzinfo = NY_TZ ))
129133 )
130134
131135 # crypto
@@ -137,65 +141,65 @@ def test_get_next_market_close():
137141 # equity within market hours
138142 assert (
139143 get_next_market_close ("equity" , EQUITY_OPEN_WED_2023_6_21_12 )
140- == format_datetime_to_utc_iso_string (datetime .datetime (2023 , 6 , 21 , 16 , 0 , 0 , tzinfo = NY_TZ ))
144+ == format_datetime_to_unix_timestamp (datetime .datetime (2023 , 6 , 21 , 16 , 0 , 0 , tzinfo = NY_TZ ))
141145 )
142146
143147 # equity out of market hours
144148 assert (
145149 get_next_market_close ("equity" , EQUITY_CLOSE_WED_2023_6_21_17 )
146- == format_datetime_to_utc_iso_string (datetime .datetime (2023 , 6 , 22 , 16 , 0 , 0 , tzinfo = NY_TZ ))
150+ == format_datetime_to_unix_timestamp (datetime .datetime (2023 , 6 , 22 , 16 , 0 , 0 , tzinfo = NY_TZ ))
147151 )
148152
149153 # equity weekend
150154 assert (
151155 get_next_market_close ("equity" , EQUITY_CLOSE_SAT_2023_6_10_17 )
152- == format_datetime_to_utc_iso_string (datetime .datetime (2023 , 6 , 12 , 16 , 0 , 0 , tzinfo = NY_TZ ))
156+ == format_datetime_to_unix_timestamp (datetime .datetime (2023 , 6 , 12 , 16 , 0 , 0 , tzinfo = NY_TZ ))
153157 )
154158
155159 # equity holiday
156160 assert (
157161 get_next_market_close ("equity" , EQUITY_HOLIDAY_MON_2023_6_19 )
158- == format_datetime_to_utc_iso_string (datetime .datetime (2023 , 6 , 20 , 16 , 0 , 0 , tzinfo = NY_TZ ))
162+ == format_datetime_to_unix_timestamp (datetime .datetime (2023 , 6 , 20 , 16 , 0 , 0 , tzinfo = NY_TZ ))
159163 )
160164
161165 # equity early close holiday
162166 assert (
163167 get_next_market_close ("equity" , EQUITY_EARLY_CLOSE_OPEN_FRI_2023_11_24_14 )
164- == format_datetime_to_utc_iso_string (datetime .datetime (2023 , 11 , 24 , 13 , 0 , 0 , tzinfo = NY_TZ ))
168+ == format_datetime_to_unix_timestamp (datetime .datetime (2023 , 11 , 24 , 13 , 0 , 0 , tzinfo = NY_TZ ))
165169 )
166170 assert (
167171 get_next_market_close ("equity" , EQUITY_EARLY_CLOSE_CLOSE_FRI_2023_11_24_14 )
168- == format_datetime_to_utc_iso_string (datetime .datetime (2023 , 11 , 27 , 16 , 0 , 0 , tzinfo = NY_TZ ))
172+ == format_datetime_to_unix_timestamp (datetime .datetime (2023 , 11 , 27 , 16 , 0 , 0 , tzinfo = NY_TZ ))
169173 )
170174
171175 # fx & metal within market hours
172176 assert (
173177 get_next_market_close ("fx" , FX_METAL_OPEN_WED_2023_6_21_22 )
174- == format_datetime_to_utc_iso_string (datetime .datetime (2023 , 6 , 23 , 17 , 0 , 0 , tzinfo = NY_TZ ))
178+ == format_datetime_to_unix_timestamp (datetime .datetime (2023 , 6 , 23 , 17 , 0 , 0 , tzinfo = NY_TZ ))
175179 )
176180 assert (
177181 get_next_market_close ("metal" , FX_METAL_OPEN_WED_2023_6_21_22 )
178- == format_datetime_to_utc_iso_string (datetime .datetime (2023 , 6 , 23 , 17 , 0 , 0 , tzinfo = NY_TZ ))
182+ == format_datetime_to_unix_timestamp (datetime .datetime (2023 , 6 , 23 , 17 , 0 , 0 , tzinfo = NY_TZ ))
179183 )
180184
181185 # fx & metal out of market hours
182186 assert (
183187 get_next_market_close ("fx" , FX_METAL_CLOSE_SUN_2023_6_18_16 )
184- == format_datetime_to_utc_iso_string (datetime .datetime (2023 , 6 , 23 , 17 , 0 , 0 , tzinfo = NY_TZ ))
188+ == format_datetime_to_unix_timestamp (datetime .datetime (2023 , 6 , 23 , 17 , 0 , 0 , tzinfo = NY_TZ ))
185189 )
186190 assert (
187191 get_next_market_close ("metal" , FX_METAL_CLOSE_SUN_2023_6_18_16 )
188- == format_datetime_to_utc_iso_string (datetime .datetime (2023 , 6 , 23 , 17 , 0 , 0 , tzinfo = NY_TZ ))
192+ == format_datetime_to_unix_timestamp (datetime .datetime (2023 , 6 , 23 , 17 , 0 , 0 , tzinfo = NY_TZ ))
189193 )
190194
191195 # fx & metal holiday
192196 assert (
193197 get_next_market_close ("fx" , FX_METAL_HOLIDAY_SUN_2023_1_1 )
194- == format_datetime_to_utc_iso_string (datetime .datetime (2023 , 1 , 6 , 17 , 0 , 0 , tzinfo = NY_TZ ))
198+ == format_datetime_to_unix_timestamp (datetime .datetime (2023 , 1 , 6 , 17 , 0 , 0 , tzinfo = NY_TZ ))
195199 )
196200 assert (
197201 get_next_market_close ("metal" , FX_METAL_HOLIDAY_SUN_2023_1_1 )
198- == format_datetime_to_utc_iso_string (datetime .datetime (2023 , 1 , 6 , 17 , 0 , 0 , tzinfo = NY_TZ ))
202+ == format_datetime_to_unix_timestamp (datetime .datetime (2023 , 1 , 6 , 17 , 0 , 0 , tzinfo = NY_TZ ))
199203 )
200204
201205 # crypto
0 commit comments