pythoncoinbase-api

coinbase api client.get_accounts() not returning all wallets


Currently the coinbase api will not get my atom wallet. with other testing code i was able to see that it was return 94 wallets however none them are my atom wallet and the accounts data doesn't even seem like it has 94 elements.

Any ideas on how to get my atom wallet to show? i tried the client.get_accounts(limit=200) trick with no success.

#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)

Sample Data returned:

{
  "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"
    }
  ]
}

Solution

  • the better way is to use coinbase api pagination parameteres:

    #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
    

    IF you like your script print your wallets with none zero balance, try this:

    #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