From 1e478c84288d501987592508dff9a60f51f9f4c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=96=87=E8=96=87=E5=AE=89?= Date: Sun, 22 Feb 2026 11:07:54 +0800 Subject: [PATCH] =?UTF-8?q?feat(sync=5Fbinance=5Forders):=20=E5=A2=9E?= =?UTF-8?q?=E5=BC=BA=E8=B4=A6=E5=8F=B7=E5=90=8C=E6=AD=A5=E9=80=BB=E8=BE=91?= =?UTF-8?q?=EF=BC=8C=E8=BF=87=E6=BB=A4=E6=97=A0API=E5=AF=86=E9=92=A5?= =?UTF-8?q?=E8=B4=A6=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 更新 `sync_binance_orders.py` 脚本,新增对未配置 API 密钥账号的过滤,确保仅同步有效账号。优化输出信息,明确显示同步的账号数量和跳过的账号名称,提升用户体验与系统稳定性。 --- scripts/sync_binance_orders.py | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) 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__":