Get Crypto Coins Wallet Worth PowerShell

Get Crypto Coins Wallet Worth PowerShell

Hello,

Today a quick followup post of my previous one about BitCoin and its price. I improved it to get a overview of your wallet worth if you have multiple of them on different platforms.

Get Crypto Coins Wallet Worth PowerShell

Some trading platform provide an overview of the wallet you own there, but not global overview of all of your wallets. I wrote a simple function that allows you to keep track of your “investments” in cryptocoins:

Function Get-WalletWorth{
    Param(
        [ValidateSet('USD','EUR')]
        [String]$RefCurency = 'EUR' #USD,EUR
    )
    $ApiUrl = 'https://api.coinmarketcap.com/v1/ticker/'
    $Wallet= @'
Name;Amount;Invested
bitcoin;7;2000
monero;12.5;1000
ethereum;5;840
dash;3;333
litecoin;2;150
'@ | ConvertFrom-Csv -Delimiter ';'
    
    $PreContent = @'
    <style>
    table {
        border-collapse: collapse;
    }
    h2 {text-align:center}
    th, td {
        padding: 8px;
        text-align: left;
        border-bottom: 1px solid #ddd;
    }
    tr:hover{background-color:#f5f5f5}
    </style>
    <h1>Crypto Coin Dashboard</h1>
'@
    if($RefCurency -eq 'USD'){
        $CurrencyFormat = New-Object System.Globalization.CultureInfo('en-US')
        $ExpandProperty = 'price_usd'
    }
    elseif($RefCurency -eq 'EUR'){
        $CurrencyFormat = New-Object System.Globalization.CultureInfo('fr-FR')
        $ExpandProperty = 'price_eur'
    }
    
    $WalletWorthTable = $Wallet | ForEach-Object -Begin {$TotalValue=0;$TotalInvested=0} -Process {
        $CurrentValue = ((Invoke-WebRequest -Uri "$($ApiUrl)$($_.Name)/?convert=$RefCurency" | Select-Object -ExpandProperty Content | ConvertFrom-Json) | Select-Object -ExpandProperty $ExpandProperty) -as [double]
        New-Object -TypeName PSObject -Property @{
            Currency             = $_.Name
            "PriceIn$RefCurency" = $CurrentValue.ToString('c',$CurrencyFormat)
            ValueInWallet        = ($CurrentValue * $_.Amount).ToString('c',$CurrencyFormat)
            Amount               = $_.Amount
            Performance          = "{0:P}" -f ((($CurrentValue * $_.Amount)-$_.Invested)/$_.Invested)
            Invested             = ([double]$_.Invested).ToString('c',$CurrencyFormat)
        }

        $TotalValue += ($CurrentValue * $_.Amount)
        $TotalInvested += $_.Invested

        $CurrentValue = $null
    }
    $PostContent = @"
<br>
<h3>
Total Invested: $($TotalInvested.ToString('c',$CurrencyFormat))
<br>
Total Value: $($TotalValue.ToString('c',$CurrencyFormat))
<br>
Total Performance: $("{0:P}" -f (($TotalValue-$TotalInvested)/$TotalInvested))
</h3>
<br>
Last Refresh: $(Get-Date)
"@
    $WalletWorthTable | ConvertTo-Html -PreContent $PreContent -PostContent $PostContent -Title 'Crypto Coin Dashboard' | Out-File -FilePath $env:temp\wallet.htm
    
    #Open the report
    Invoke-Item -Path $env:temp\wallet.htm
}

Once you run it, it will open the html report with your default web browser:

Get Crypto Coins Wallet Worth PowerShell - Example

Get Crypto Coins Wallet Worth PowerShell – Example

All the performances and value calculation are based on the herestring $Wallet defined at the beginning of the function.

You need to feed it with the name of the crypto currency you own, the amount you have, and the price you paid to acquire it. Based on this, the function will ask CoinMarketCap to get the current value and calculate your benefits. When you call the function, you need to specify if you paid in € or $ (defaulted to €), and it will adapt the calculation.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.