目前,coinbase api 无法获取我的 Atom 钱包。通过其他测试代码,我可以看到它返回了 94 个钱包,但它们都不是我的 Atom 钱包,而且帐户数据甚至看起来都没有 94 个元素。
关于如何显示我的原子钱包有什么想法吗?我尝试了 client.get_accounts(limit=200) 技巧但没有成功。
#import coinbase api
from coinbase.wallet.client import Client
# Coinbase Credentials
api_key = 'xxx'
api_secret = 'xxx'
# create a coinbase client
cb_client = Client(api_key, api_secret)
cb_accounts = cb_client.get_accounts()
# coin setting
coin = 'ATOM'
#print accounts
print(cb_accounts)
#get coin balance
for i in cb_accounts['data']:
if i['currency'] == coin:
coin_balance = float(i['native_balance']['amount'])
#print coin balance
print(coin_balance)
返回样本数据:
{
"data": [
{
"allow_deposits": true,
"allow_withdrawals": true,
"balance": {
"amount": "0.00000000",
"currency": "FET"
},
"created_at": "xxx",
"currency": "FET",
"id": "xxx",
"name": "FET Wallet",
"native_balance": {
"amount": "0.00",
"currency": "USD"
},
"primary": false,
"resource": "account",
"resource_path": "xxx",
"type": "wallet",
"updated_at": "xxx"
}
]
}
更好的方法是使用 coinbase api 分页参数:
#iniliase next wallet id
next = None
# this loop will run until the next_uri parameter is none ( it means that there is no other page to show)
while True:
accounts = client.get_accounts(starting_after=next)
next = accounts.pagination.next_starting_after
print(accounts.data)
if accounts.pagination.next_uri == None :
print("end")
break
如果您喜欢脚本打印零余额的钱包,请尝试以下操作:
#iniliase next wallet id
next=None
# this loop wil run until next_uri parameter is none ( it means that there is no other page to show)
while True:
accounts=client.get_accounts(starting_after=next)
next=accounts.pagination.next_starting_after
for wallet in accounts.data:
if wallet['native_balance']['amount'] != '0.00':
print(str(wallet['name']) + ' ' + str(wallet['native_balance']))
if accounts.pagination.next_uri==None :
print("end")
break
有人知道为什么我无法使用这种获取帐户的确切方式获得
native_balance
密钥吗?