This commit is contained in:
曾志威
2026-05-10 20:07:16 +08:00
parent e2c3b41b27
commit 55de951959
2 changed files with 11 additions and 4 deletions
+1 -1
View File
@@ -88,7 +88,7 @@ python -m src.main --dividend
python -m src.main --dividend --symbol 000001
# 抓取分钟K线(默认5分钟)
python -m src.main --intraday
python -m src.main --intraday --start-date 20260101
# 抓取全部频率分钟K线
python -m src.main --intraday --freq all --start-date 20260508
+10 -3
View File
@@ -61,13 +61,20 @@ def _parse_datetime(date_str: str, time_str: str) -> str | None:
def _get_fetched_codes(model, sd: str, ed: str) -> set[str]:
"""查询已有数据的股票代码(在日期范围内有记录的)"""
"""查询数据已覆盖起始日期的股票代码
只有当股票在起始日期附近(前5个自然日)有数据时,才认为已抓取。
这样扩展日期范围时,缺失的早期数据不会被跳过。
"""
session = get_session()
try:
sd_date = datetime.strptime(sd, "%Y-%m-%d").date()
check_start = str(sd_date - timedelta(days=5))
check_end = str(sd_date + timedelta(days=5))
result = session.execute(
select(distinct(model.code))
.where(model.datetime >= sd)
.where(model.datetime <= ed + " 23:59:59")
.where(model.datetime >= check_start)
.where(model.datetime <= check_end + " 23:59:59")
)
return {row[0] for row in result}
finally: