Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0613· OpenAIAi2 WildChat-4.8M (AI2)

I used this code: def balance(self, kwargs): """ Futures Account Balance V2…

  1. User

    I used this code: def balance(self, **kwargs): """ | | Futures Account Balance V2 (USER_DATA) | Get current account balance

    :API endpoint: ``GET /fapi/v2/balance``
    :API doc: https://binance-docs.github.io/apidocs/futures/en/#futures-account-balance-v2-user_data
    
    :parameter recvWindow: optional int
    |
    """
    
    url_path = "/fapi/v2/balance"
    return self.sign_request("GET", url_path, {**kwargs})
    

    and this code:

    balance = client.balance() print(balance) balance_usdt = float(balance['asset']) if 'asset' in balance else 0.0 print(balance_usdt)

    But it doesn't print me only my USDT balance , give me code which will give me only my USDT balance

  2. Assistant

    To get only your USDT balance from the balance response, you can modify the code as follows:

    balance = client.balance()
    balance_usdt = 0.0
    
    for asset in balance:
        if asset['asset'] == 'USDT':
            balance_usdt = float(asset['balance'])
            break
    
    print(balance_usdt)
    

    This code iterates over the balance response and checks if the asset is equal to "USDT". If it is, the corresponding balance is extracted and assigned to the balance_usdt variable. The loop breaks after finding the USDT balance. Then, the USDT balance is printed.