Retrieve Binance Balance API PowerShell

Because this is something useful and I’ve been asked, in this article, I introduce you to my Get-Balance function which retrieves the holdings of all the cryptos you have in your Binance spot wallet using the API and PowerShell.

This post is one of a series about how to query the Binance API. Thus if you don’t completely understand how it works, please see the Interact with Binance using API PowerShell.

This function corresponds to my needs, you can modify it according to yours. In order to determine if the amount is greater than the -MinAmount parameter, I also use the Get-Price function. However, to considerably improve the performance, you may want to remove this part.

function Get-Balance{
		Get all your asset

        .PARAMETER MinUSDTAmount
        Specifies the minimum amount in USDT to filter out small amounts
        $Balances = Get-Balance

        Get-Balance -MinUSDTAmount 100

        Get-Balance -MinUSDTAmount 100 -Verbose

        [int]$MinUSDTAmount = 0

        Get-Command -Name Get-Price -ErrorAction Stop | out-null
        Get-Command -name Get-UnixTimeStamp -ErrorAction Stop | Out-Null
        Get-Command -Name Get-BinanceAPIHeader -ErrorAction Stop | Out-Null
        Get-Command -Name Get-BinanceAPISignature -ErrorAction Stop | Out-Null
        Get-Command -Name Request-API -ErrorAction Stop | Out-Null

        $Balances = @()
        $TimeStamp = Get-UnixTimeStamp
        $QueryString = "recvWindow=5000&timestamp=$TimeStamp"
        $URI = Get-BinanceAPISignature -QueryString $QueryString -EndPoint "/api/v3/account"
        $Headers = Get-BinanceAPIHeader
        $ObjResults = Request-API -Method GET -URI $URI -Headers $Headers

        $Assets = $ObjResults.balances
        foreach($Asset in $Assets){
             # filter void assets
             if($ -match ".*[1-9].*" -or $Asset.locked -match ".*[1-9].*"){
                # filter small amount according to param MinimumAmount
                # if not USDT or add any fiat currency
                if($Asset.asset -eq "USDT"){
                    $CurrentAssetValueFreeInUSDT = $
                    $CurrentAssetValueLockedInUSDT = $Asset.locked
                    $CurrentAssetPrice = Get-Price -Symbol "$($Asset.asset)USDT" -Decimal 7
                    $CurrentAssetValueFreeInUSDT = $CurrentAssetPrice * $
                    $CurrentAssetValueLockedInUSDT = $CurrentAssetPrice * $Asset.locked
                Write-Verbose "`n`n`n"
                Write-Verbose "Asset:             $($Asset.asset)"
                write-Verbose "Free:              $($"
                write-Verbose "Locked:            $($Asset.locked)"
                write-Verbose "CurrentAssetPrice: $CurrentAssetPrice"
                write-Verbose "FreeInUSDT:        $CurrentAssetValueFreeInUSDT"
                write-Verbose "LockedInUSDT:      $CurrentAssetValueLockedInUSDT"

                if($CurrentAssetValueFreeInUSDT -lt $MinUSDTAmount -and $CurrentAssetValueLockedInUSDT -lt $MinUSDTAmount){
                    Write-Verbose "Below the minimum value of USDT"
                    $Balances += $Asset
                    Write-Verbose "Above the minimum value of USDT"

       return $Balances | sort asset

About this function

  • EndPoint /api/v3/account
    Part of the Account Endpoint which requires authentification.

  • Where are the functions Get-BinanceAPISignature, Get-BinanceAPIHeader?
    See post blog number 3

  • [math]::Round($Ticker.Price, $Decimal)
    Round off to a decimal number according to the variable “number”.


Example the function Get Balance with the API and PowerShell
Binance Balance Powershell API

Serie of post blog Crypto Binance API PowerShell

  1. Retrieve prices from Binance API PowerShell
  2. Get trading info from Binance API PowerShell
  3. Interact with Binance using API PowerShell
  4. New-Order API Binance PowerShell
  5. Retrieve Binance Balance API PowerShell
  6. Open Order Binance PowerShell API

Leave a Comment