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 @@