feat(sync_binance_orders): 增强账号同步逻辑,过滤无API密钥账号
更新 `sync_binance_orders.py` 脚本,新增对未配置 API 密钥账号的过滤,确保仅同步有效账号。优化输出信息,明确显示同步的账号数量和跳过的账号名称,提升用户体验与系统稳定性。
This commit is contained in:
parent
fc81a8d5d6
commit
1e478c8428
|
|
@ -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__":
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user