3030
3131
3232class 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+
3536 if asset_type == "Equity" :
36- day , date , time = dt .weekday (), dt .date (), dt .time ()
3737 if date in EQUITY_HOLIDAYS or date in EQUITY_EARLY_HOLIDAYS :
3838 if (
3939 date in EQUITY_EARLY_HOLIDAYS
@@ -45,5 +45,22 @@ def is_market_open(self, asset_type, dt):
4545 if day < 5 and time >= EQUITY_OPEN and time <= EQUITY_CLOSE :
4646 return True
4747 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)
4966 return True
0 commit comments