30
30
31
31
32
32
class HolidayCalendar :
33
- def is_market_open (self , asset_type , dt ):
34
- # equity market
33
+ def is_market_open (self , asset_type : str , dt : datetime .datetime ):
34
+ day , date , time = dt .weekday (), dt .date (), dt .time ()
35
+
35
36
if asset_type == "Equity" :
36
- day , date , time = dt .weekday (), dt .date (), dt .time ()
37
37
if date in EQUITY_HOLIDAYS or date in EQUITY_EARLY_HOLIDAYS :
38
38
if (
39
39
date in EQUITY_EARLY_HOLIDAYS
@@ -45,5 +45,22 @@ def is_market_open(self, asset_type, dt):
45
45
if day < 5 and time >= EQUITY_OPEN and time <= EQUITY_CLOSE :
46
46
return True
47
47
return False
48
- # all other markets (crypto, fx, metal)
48
+
49
+ if asset_type in ["FX" , "Metal" ]:
50
+ # The market for FX and Metal is closed from Friday 5pm to Sunday 5pm
51
+ close_or_open_time = datetime .time (17 , 0 , 0 , tzinfo = TZ )
52
+
53
+ # Friday the market is close after 5pm
54
+ if day == 4 and time > close_or_open_time :
55
+ return False
56
+ # Saturday the market is closed all the time
57
+ if day == 5 :
58
+ return False
59
+ # Sunday the market is closed before 5pm
60
+ if day == 6 and time < close_or_open_time :
61
+ return False
62
+
63
+ return True
64
+
65
+ # all other markets (crypto)
49
66
return True
0 commit comments