【发布时间】:2017-11-05 04:04:41
【问题描述】:
我正在尝试获取 Coinbase 帐户上的所有交易,这需要分页。 documentation 很少介绍如何在 Python 中执行此操作,但我已经设法使其工作:
client = Client(keys['apiKey'], keys['apiSecret'])
accounts = client.get_accounts()
for account in accounts.data:
txns = client.get_transactions(account.id, limit=25)
while True:
for tx in txns.data:
print(tx.id)
if txns.pagination.next_uri != None:
starting_after_guid = re.search('starting_after=([0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12})', txns.pagination.next_uri, re.I)[1]
txns = client.get_transactions(account.id, limit=25, starting_after=starting_after_guid)
else:
break
分页对象仅包含 next_uri 其他所有内容均为 null/None——它应该包含一个包含 starting_after 以及其他有用数据的字典。正则表达式搜索看起来很傻,但确实有效。
有没有更好的方法?
【问题讨论】:
标签: python python-3.x coinbase-api