diff --git a/scripts/sync_binance_orders.py b/scripts/sync_binance_orders.py index 5564e70..fa1687c 100644 --- a/scripts/sync_binance_orders.py +++ b/scripts/sync_binance_orders.py @@ -222,14 +222,30 @@ def main(): accounts = [r for r in (rows or []) if (r.get("status") or "active").lower() == "active" and r.get("id")] if args.account: accounts = [a for a in accounts if a["id"] == args.account] - if not accounts: - print("无有效账号") + + # 过滤掉未配置 API 密钥的账号 + to_sync = [] + skipped = [] + for acc in accounts: + aid = acc["id"] + api_key, api_secret, _, _ = Account.get_credentials(aid) + if api_key and api_secret: + to_sync.append(acc) + else: + skipped.append(acc.get("name") or f"账号{aid}") + + if skipped: + print(f"跳过无 API 密钥的账号: {', '.join(skipped)}") + + if not to_sync: + print("无可同步账号(需已配置 API 密钥)") sys.exit(0) - print(f"同步 {len(accounts)} 个账号,最近 {hours} 小时,开始时间 {datetime.now(BEIJING_TZ).isoformat()}") + print(f"同步 {len(to_sync)} 个账号,最近 {hours} 小时,开始时间 {datetime.now(BEIJING_TZ).isoformat()}") + sys.stdout.flush() async def run_all(): - for acc in accounts: + for acc in to_sync: aid = acc["id"] name = acc.get("name") or f"账号{aid}" tr, ord_cnt, err = await sync_account(aid, hours) @@ -239,7 +255,8 @@ def main(): print(f" {name} (id={aid}): trades {tr} 条, orders {ord_cnt} 条") asyncio.run(run_all()) - print("同步完成") + print(f"同步完成 {datetime.now(BEIJING_TZ).strftime('%Y-%m-%d %H:%M:%S')}") + sys.stdout.flush() if __name__ == "__main__":