From 58327a9a66ced34ecb21fdf1d1a21ca697b1131e Mon Sep 17 00:00:00 2001 From: fish Date: Sat, 25 Jul 2026 14:03:33 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E8=BF=9B=E5=BA=A6=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E8=AF=A6=E7=BB=86=E5=A4=A9=E6=95=B0=E5=8F=8D=E9=A6=88?= =?UTF-8?q?=EF=BC=8C=E4=BC=98=E5=8C=96=E6=97=A5=E6=9C=9F=E8=8C=83=E5=9B=B4?= =?UTF-8?q?=E9=81=BF=E5=85=8D=E9=87=8D=E5=A4=8D=E8=AF=B7=E6=B1=82=E6=97=A0?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E7=9A=84=E5=8E=86=E5=8F=B2=E6=97=A5=E6=9C=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 4.7 --- ft-app/app/collector.py | 18 ++++++++++++++---- ft-app/app/templates/admin.html | 21 ++++++++++++++------- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/ft-app/app/collector.py b/ft-app/app/collector.py index 500de38..242cc80 100644 --- a/ft-app/app/collector.py +++ b/ft-app/app/collector.py @@ -52,6 +52,7 @@ def sync_contract_bars_bg(contract_code: str) -> bool: with _lock: _progress["total"] = len(bars) + total_bars = len(bars) inserted = 0 min_date = None for i, bar in enumerate(bars): @@ -71,6 +72,7 @@ def sync_contract_bars_bg(contract_code: str) -> bool: min_date = bar["date"] with _lock: _progress["done"] = i + 1 + _progress["label"] = f"同步行情 {code} · {i + 1}/{total_bars} 条" if inserted > 0: db.flush() @@ -102,10 +104,19 @@ def sync_positions_bg(contract_code: str) -> bool: .filter(DailyBar.contract == code) .order_by(DailyBar.date).all() ] - missing = [d for d in bar_dates if d not in existing_dates] + # Only sync dates within or after existing position date range; + # akshare may not have data for very old dates + if existing_dates: + min_pos = min(existing_dates) + missing = [d for d in bar_dates if d not in existing_dates and d >= min_pos] + else: + missing = [d for d in bar_dates if d not in existing_dates] + total_missing = len(missing) with _lock: - _progress["total"] = len(missing) + _progress["total"] = total_missing + if total_missing == 0: + _progress["label"] = f"同步持仓 {code} · 已是最新" inserted = 0 for i, d in enumerate(missing): @@ -120,8 +131,7 @@ def sync_positions_bg(contract_code: str) -> bool: db.flush() with _lock: _progress["done"] = i + 1 - - db.commit() + _progress["label"] = f"同步持仓 {code} · {i + 1}/{total_missing} 天" finally: db.close() diff --git a/ft-app/app/templates/admin.html b/ft-app/app/templates/admin.html index 1b17d92..8d05962 100644 --- a/ft-app/app/templates/admin.html +++ b/ft-app/app/templates/admin.html @@ -193,8 +193,10 @@