From feb7291c8358390abfcf851ceca4926aba0d81e7 Mon Sep 17 00:00:00 2001 From: sophon Date: Tue, 12 Aug 2025 11:28:42 +0800 Subject: [PATCH] modify scripts --- src/static/daily_snap_em.py | 9 +++++---- src/static/trading_day.py | 17 +++++++++++++++++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/static/daily_snap_em.py b/src/static/daily_snap_em.py index 3897dfe..9915f14 100644 --- a/src/static/daily_snap_em.py +++ b/src/static/daily_snap_em.py @@ -241,13 +241,14 @@ def main(list, args_debug, notify): for market_id in market_list: # 获取交易日期 trading_day_checker = TradingDayChecker() + if not trading_day_checker.is_trading_day_today(market_id.upper()) and not debug: + logging.info(f"非交易日,不处理 {market_id} 市场,当前交易日期: {trading_date}, 当前日期: {current_date}") + continue + trading_date = trading_day_checker.get_trading_date(market_id.upper()) if not trading_date: logging.error(f"无法获取 {market_id} 市场的交易日期") continue - if trading_date != current_date and not debug: - logging.info(f"非交易日,不处理 {market_id} 市场,当前交易日期: {trading_date}, 当前日期: {current_date}") - continue # 获取快照数据 snap_data = fetch_snap_all(market_id, trading_date) @@ -261,7 +262,7 @@ def main(list, args_debug, notify): logging.info(f"成功获取 {market_id} 市场的快照数据,记录数: {len(snap_data)}") if notify: - send_to_wecom(f"成功获取 {market_id} 市场的快照数据,记录数: {len(snap_data)}") + send_to_wecom(f"fetched {market_id} snap data, counts: {len(snap_data)}") em_code_map.update({row['代码']: row['代码前缀'] for _, row in snap_data.iterrows()}) time.sleep(5) diff --git a/src/static/trading_day.py b/src/static/trading_day.py index c0feedc..d1357cb 100644 --- a/src/static/trading_day.py +++ b/src/static/trading_day.py @@ -73,6 +73,23 @@ class TradingDayChecker: FutuTradingDayModel.trade_date == check_date ).first() is not None + def is_trading_day_today(self, market: str) -> bool: + """ + 检查今天是否为该市场的交易日 + :param market: 市场标识(CN=A股, HK=港股, US=美股) + :return: 是否为交易日 + """ + # 获取东八区当前时间和日期 + tz_sh = ZoneInfo("Asia/Shanghai") + if market == self.MARKET_US: + # 美股需要使用纽约时区来判断夏令时 + tz_sh = ZoneInfo("America/New_York") + now = datetime.now(tz_sh) + current_date: date = now.date() + + return self.is_trading_day(market, current_date) + + def get_trading_date(self, market: str) -> str: """ 根据当前时间判断并返回目标交易日期