modify scripts
This commit is contained in:
@ -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)
|
||||
|
||||
@ -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:
|
||||
"""
|
||||
根据当前时间判断并返回目标交易日期
|
||||
|
||||
Reference in New Issue
Block a user