def update_exchange(exchange): """ 更新交易所的账号信息 """ accounts = list(Account.query({'exchange': exchange})) e = Exchange.query_one({'_id': exchange}) for key, value in accounts_summary(accounts).items(): setattr(e, key, value) e.num_users = len(set(a.user for a in accounts)) e.num_accounts = len(accounts) e.upsert()