Zeaun.com
  • Support
Zeaun.com
  • Support
Information Technology Mastery,

Tutorial: Getting the current price of Bitcoin using Powershell (USD, EUR, & GBP)

by zupreme7 months agono comment
0
Shares
Share on FacebookShare on Twitter
coin10

I began my Bitcoin journey in 2012, with CPU mining, back when that was still profitable. Some of you are just now joining the cryptocurrency wave, and that’s fine. Like all waves it will feel great while rising and will feel horrible while falling.

But, since we are working in the “Now”, let’s get some work done.

We want the price of bitcoin, in 3 currencies, from our PowerShell console window. Let’s get it.

Assign the now-familiar (if you have been following the series) $zurl variable

We begin, as we often do in these tutorials, with assigning the $zurl variable to identify our data source within PowerShell.

Make sure to enable TLS 1.2 within PowerShell

Above we enabled TLS 1.2, to ensure compatibility with our data source’s SSL configuration.

Now we set the all-too-familiar (if you have been following the series) $zdata variable

Above we download our dataset as the variable $zdata, using “Invoke-RestMethod” and our previously set $zurl variable.

Extracting the pricing from the dataset

Above we extract the pricing section of our dataset, leaving the rest for exploration & use at another time. If you were curious about what other data was there, here you go:

Other data contained in our dataset

Now let’s separate out our data into formats that we can display for human beings in a format they will easily understand.

The Bitcoin pricing data for each currency

And then lets display that data, complete with proper naming of the currency (taken from our current dataset)

That looks jumbled, so we probably want to wrap the entire thing in a function. You can do that by placing this on the first line of your script, by itself, “function coinprice(){“, and then by placing this on the last line of your script, again by itself, “}”.

Note: The last item works when on the last line of your actual “code” but this way is cleaner, is more readable, and syntax errors are less likely.

The results of our Coinprice function

And there you have it. Once you store the script in a function, and run the function, you are left with an easy-to-use command which returns the current pricing of Bitcoin in 3 currencies (The United States Dollar, The Euro, and The British Pound), as reported by Coindesk.

I am sure your wheels are already turning, fellow scripters.

Now go use this knowledge (i.e. Power) for Good instead of Evil.

Also: If you found this article valuable, drop a tip here: https://cash.app/$Zeaun

Previous

Tutorial: Public IP Address Identification with PowerShell

7 months ago
Next

PowerShell Tutorial: Programmatically Retrieving the Population of each US State

7 months ago

Leave a Reply Cancel reply

Related posts

pop1
Information Technology Mastery,

PowerShell Tutorial: Programmatically Retrieving the Population of each US State

by zupreme7 months agono comment
image-12
Information Technology Mastery,

Tutorial: Public IP Address Identification with PowerShell

by zupreme7 months agono comment
image-3
Information Technology Mastery,

Browsing NASA’s Image of The Day Archive using PowerShell

by zupreme7 months agono comment
ps9
Information Technology Mastery,

Getting Latitude and Longitude for a given Zip Code with PowerShell

by zupreme7 months agono comment

© 2020 Zeaun Zarrieff. All rights reserved.