Fun with powershell. Show the current coin price with a single command.
Like some of you I own more cryptocoins and I check out the website coinmarketcap often. But sometimes I just want to check out the price fast. I use a Telegram Bot for that.
The Telegram Bot is able to kick off scripts (after I give the command /cryptocoinprice) and give me the results back on my phone. In my case I made a Powershell function that uses the API from coinmarketcap to give the info to my Telegram bot.
Ofcourse you do not have to run a Telegram bot to use this script(function). You can run it just from your windows pc.
If you do supply a specific coin it will just give you the current top 10 coins with the price in US dollar.
PS C:\Users\You\Desktop> .\CryptoCoinPrice
$0.456817
Bitcoin $611.677
Ethereum $13.3372
Ripple $0.00818912
Litecoin $3.83656
Monero $7.87139
Ethereum Classic $1.1691
Dash $12.1663
Steem $0.456817
MaidSafeCoin $0.0854529
And if you want to know the price of Steem for example, you do
PS C:\Users\You\Desktop>.\CryptoCoinPrice steem
$0.456817
Below the script(function).
Just put it in notepad and save it with the extension .ps1
# 2016 Disofdis
Function CryptoCoinPrice
{
Param(
[parameter(Mandatory=$false)]
[string]
$variable
)
$coins = Invoke-RestMethod -Method Get -Uri “https://api.coinmarketcap.com/v1/ticker/”
If ($variable -eq "")
{
ForEach ($coin in $coins)
{
[int]$rank = $coin.rank
If ($rank -lt "10")
{
$coin.name + " $" + $coin.price_usd
}
}
}
else
{
ForEach ($coin in $coins)
{
If ($coin.id -eq "$variable")
{
"$" + $coin.price_usd
}
}
}
}
CryptoCoinPrice
There is a piece of code left that you can use to make giving a coin name mandatory before running the script.
[parameter(Mandatory=$false)]
You can put this on true to enable it. Of delete the complete line if you do not want to use ever. Or well just let it stand there :P
Have fun with it :-)
ps you can also make it a psm1 file, so you can run the command all the time. https://msdn.microsoft.com/en-us/library/dd878350(v=vs.85).aspx
Pretty useful, thank you. I might use this code
gotta love powershell , one of the most important tools that i use every day.