Get trading info from Binance API PowerShell

In this article, I will explain how to use the API and get the information and rules for each pair available on Binance with PowerShell.

Before executing orders, we need to know the rules on a pair that we want to interact with. In order to gather information for a symbol, we request the endpoint /api/v3/exchangeInfo. The main utility is to obtain an exhaustive list of available pairs, obtain their status, what filters are used and what type of order is available.

As explained in my first post blog on this topic, all functions are written in PowerShell, my native language as I come from IT.

Function Get-ExchangeInfo

function Get-ExchangeInfo{
    <#
		.SYNOPSIS
		Get current exchange trading rules and symbol information

        .EXAMPLE
        Get-ExchangeInfo

        .EXAMPLE
        Get-ExchangeInfo | ?{$_.symbol -eq "BTCUSDT"} | select -ExpandProperty quoteAssetPrecision

        .EXAMPLE
        Get-ExchangeInfo | ?{$_.symbol -like "*USDT*"} | sort symbol | Out-GridView

        .EXAMPLE
        (Get-ExchangeInfo | ?{$_.symbol -eq "BTCUSDT"}).filters | fl
	#>

    [cmdletbinding()]
    param(

    )

    BEGIN{
        $URL = "https://api.binance.com/api/v3/exchangeInfo"
        $ArraySymobols = @()
    }
    
    PROCESS{
	    $ExchangeInfo = curl $URL -Method get 
        $ExchangeInfo = $ExchangeInfo.Content | ConvertFrom-Json
        $ExchangeSymbols = $ExchangeInfo.symbols

        # for unknown reason, the $web object is case sensitive
        foreach($Symbol in $ExchangeSymbols){
            $ObjSymbols = [PSCustomObject]@{
                symbol     = $Symbol.symbol
                filters = $Symbol.filters
                quoteAsset = $Symbol.quoteAsset
                status     = $Symbol.status
                orderTypes = $Symbol.orderTypes
            }
            $ArraySymobols += $ObjSymbols 
        }
    }

    END{
        return $ArraySymobols 
    }
}

About this function

  • EndPoint /api/v3/exchangeInfo
    An endpoint is simply an end of a communication channel. This one is part of the “General endpoints” and in comparison with the “Account endpoints”, it doesn’t require any authentication.

  • Curl is an alias of Invoke-WebRequest
    This is the command used to request an API. The $Ticker variable is an HtmlWebResponsObject which contains a property Content, and this content is in JSON format. This is why | ConvertFrom-Json is used.

  • $ObjSymbols = [PSCustomObject]@{}
    We create a PSCustomObject with a selected of properties. Add the property you want in the result returned in $ArraySymobols.

Examples

Example 1 Get-ExchangeInfo Using API Binance PowerShell

In the next post, we will see how to use the API with PowerShell to see how to authenticate ourselves on Binance and get ready to make our first transaction.

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

Leave a Comment

*

code