区间打分根据用户选择日期自动判断主力合约,放宽前端日期限制支持历史区间

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
fish
2026-05-07 21:48:20 +08:00
parent c54ba5a470
commit cdf793608d
2 changed files with 5 additions and 5 deletions

View File

@@ -47,7 +47,8 @@ def health():
@app.post("/api/v1/run", response_model=RunResponse) @app.post("/api/v1/run", response_model=RunResponse)
def run_pipeline(req: RunRequest): def run_pipeline(req: RunRequest):
ts_code = req.ts_code or contracts.active_contract(req.symbol) ref_date = datetime.strptime(req.trade_date, "%Y%m%d").date() if req.trade_date else None
ts_code = req.ts_code or contracts.active_contract(req.symbol, ref_date)
if not req.ts_code: if not req.ts_code:
print(f"[AUTO] {req.symbol} 当月主力 -> {ts_code}") print(f"[AUTO] {req.symbol} 当月主力 -> {ts_code}")
@@ -97,10 +98,10 @@ def run_batch():
@app.post("/api/v1/run/range") @app.post("/api/v1/run/range")
def run_range(req: RunRangeRequest): def run_range(req: RunRangeRequest):
"""对指定日期区间内的每一天分别打分。""" """对指定日期区间内的每一天分别打分。"""
ts_code = contracts.active_contract(req.symbol) start_dt = datetime.strptime(req.start_date, "%Y%m%d").date()
ts_code = contracts.active_contract(req.symbol, start_dt)
# 为确保区间开始日有足够前置数据,拉取时 start_date 前推 60 天 # 为确保区间开始日有足够前置数据,拉取时 start_date 前推 60 天
start_dt = datetime.strptime(req.start_date, "%Y%m%d")
fetch_start = (start_dt - timedelta(days=60)).strftime("%Y%m%d") fetch_start = (start_dt - timedelta(days=60)).strftime("%Y%m%d")
df = fetcher.fetch_contract(ts_code, start_date=fetch_start, end_date=req.end_date) df = fetcher.fetch_contract(ts_code, start_date=fetch_start, end_date=req.end_date)

View File

@@ -67,10 +67,9 @@ function toDate(s: string) {
function isDateAllowed(d: Date): boolean { function isDateAllowed(d: Date): boolean {
if (!active.value) return true if (!active.value) return true
const min = toDate(active.value.min_date).getTime()
const max = toDate(active.value.max_date).getTime() const max = toDate(active.value.max_date).getTime()
const t = d.getTime() const t = d.getTime()
return t >= min && t <= max return t <= max
} }
function disabledDate(d: Date) { function disabledDate(d: Date) {