If, like me, you have thrown some money into the crypto currency gamble it can be quite addictive to constantly refresh the price and watch it shoot up and then come crashing down hard. I have a tendency to sit and hit refresh on https://coinmarketcap.com/ every 30 seconds, however to make things a little easier I created a tiny PowerShell script to check for me.

The Crypto of choice I went with is Tron. I think down the track this will be a pretty good coin but in reality who the hell knows what will happen?

CoinMarketCap has an “API Ticker” we can query with the PowerShell cmdlet Invoke-RestMethod.

This looks like:

Invoke-RestMethod -Uri https://api.coinmarketcap.com/v1/ticker/tron/

And it will provide an output something like:

id                 : tron
name               : TRON
symbol             : TRX
rank               : 14
price_usd          : 0.0489247
price_btc          : 0.00000592
24h_volume_usd     : 445281000.0
market_cap_usd     : 3216706638.0
available_supply   : 65748111645.0
total_supply       : 100000000000
max_supply         :
percent_change_1h  : -3.34
percent_change_24h : -1.62
percent_change_7d  : 24.79
last_updated       : 1524199755

I don’t really care about most of that info. I just want to know how much the coin is worth at the time I run the script. The price of one Tron coin in US Dollars is provided under price_usd. I actually want to know what one coin is worth and then how much that makes all my Tron coins worth.

Here is what the script looks like if you want to try it out.

As you can see it is pretty simple and only contains 3 variables:

$TRX which contains all the info obtained using Invoke-RestMethod on the Tron API ticker.

$TRXTotal which is the amount of Tron coins I own.

$TRXValue which is the amount of Tron coins I own multiplied by the value of one coin, giving my total portfolio value.

Finally to display the relevent info I want in my PowerShell window the script runs the following:

Write-Host $TRX.id is currently trading at $TRX.price_usd USD. Your portfolio is worth $TRXValue USD.

This displays the id field out of the $TRX variable and the price_usd field also out of the $TRX variable. Finaly it used the $TRXValue variable to display the value of all my Tron coins. The output of the complete script looks something like this:

tron is currently trading at 0.0506463 USD. Your portfolio is worth 50.6463 USD

I have the script saved as Crypto-Tracker.ps1 so everytime I want to know what my Tron is worth I simply run the script:

PS C:\Scripts\Github\PowerShell\Crypto> .\Crypto-Tracker.ps1
tron is currently trading at 0.0506463 USD. Your portfolio is worth 50.6463 USD
PS C:\Scripts\Github\PowerShell\Crypto>

Thanks for playing.