简体   繁体   English

如何使用 python fetch_balance() CCXT 打印单个符号?

[英]How do I print a single symbol with python fetch_balance() CCXT?

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.这是我已经在使用的代码,只是不确定如何让 USDT 打印余额。

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.我正在尝试打印 USDT 只是不确定所需的语法。 Thanks!谢谢!

Basically, the code in the question works or at least i could get it to work with the binance website.基本上,问题中的代码有效,或者至少我可以让它与binance网站一起使用。 (i dont have binanceus but the cctx library seems to offer more than just one vendor). (我没有binanceus ,但 cctx 库似乎提供的不仅仅是一家供应商)。

Also, note that you don't need curly braces on the return statement in python.另请注意,在 python 中,您不需要在 return 语句上使用大括号。

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.上面返回一个 python 字典。

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?看起来您使用这个堆栈问题作为答案: 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...如果你被困在那里,你需要发布 dict 以便有人明确帮助......

here is a useful python book for a newb: https://www.amazon.co.uk/dp/B0BHL2XKCR这是一本对新手有用的 Python 书: https ://www.amazon.co.uk/dp/B0BHL2XKCR

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM