0

I am able to pull a balance of all symbols but how do I print just a single symbol balance? Here is the code I already have working just not sure how to get say USDT to print a balance.

import ccxt
import config

binanceus = ccxt.binanceus({
'apiKey': config.API_KEY,
'secret': config.API_SECRET

})

def trade_crypto(request):
    balance = binanceus.fetch_balance()
    
    print(balance)

    return {
        "balance": list(balance.keys())
    }

I am trying to print USDT just not sure of the syntax needed. Thanks!

  • this return a `dict`, you you just need to access the correct key from the dict. Post the example dict that you have and any user can tell you how to do this.... – D.L Dec 25 '22 at 01:00
  • I am such a newb. What is dict? If you mean dictionary then it should be the CCXT library? – dogecoinguy101 Dec 25 '22 at 04:00
  • no, the CCTX is broadly implemented well (i have posted an answer which works for me). You need to get a grasp of basic python (which is the part letting you down). I posted and example too and also a good started book (https://www.amazon.co.uk/dp/B0BHL2XKCR) that will help you. – D.L Dec 25 '22 at 09:32
  • 1
    You are so awesome thank you so much for your help. I am going to get this book right away. – dogecoinguy101 Dec 30 '22 at 19:01

1 Answers1

0

Basically, the code in the question works or at least i could get it to work with the binance website. (i dont have binanceus but the cctx library seems to offer more than just one vendor).

Also, note that you don't need curly braces on the return statement in python.

So i did this to verify:

import ccxt

import sys
sys.path.append('G:\\path\\to\\creds\\python\\binance')
import creds

binance = ccxt.binance({
'apiKey': creds.API_Key,
'secret': creds.Secret_Key

})

def trade_crypto():
    balance = binance.fetch_balance()
    
    # print(balance)

    return balance

x = trade_crypto()
print(x)

The above returns a python dictionary.

From this, you can get the values that you seek.

It looks like you used this stack question for the answer: How can I get list of values from dict?

But the dictionary has nested dictionaries and lists, so you need to understand the structure to achieve what you want.

Whilst i dont know the exact structure, the answer will generically look like this:

nested_dict = {
    'key1': {
        'key2': 'value'
    }
}

# Get the value from the nested dictionary
value = nested_dict['key1']['key2']
print(value)  # Output: "value"

You need to post the dict for someone to clearly help if you are stuck there...

here is a useful python book for a newb: https://www.amazon.co.uk/dp/B0BHL2XKCR

D.L
  • 4,339
  • 5
  • 22
  • 45