Created
December 29, 2017 17:42
-
-
Save 1RedOne/028e5a90cb34f698df3a5b6502be887b to your computer and use it in GitHub Desktop.
Querying 30 day historical pricing of BTC, XMR and XRP using CryptoCompare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #The PriceHistorical Endpoint of cryptoCompare requires you pass in a Unix Time Stamp value. | |
| #the unix TimeStamp works by setting the time of January 1st, 1970 as time 0. To this, seconds are added to resolve to the current date | |
| #for instance, the date of November 29th, 2017 adds 1.5 Billion seconds to the origin time | |
| #First, do some time math to get a Unix TimeStamp equal to 30 days ago | |
| $30DayAgo = (get-date).AddDays(-30) | |
| [datetime]$origin = '1970-01-01 00:00:00' | |
| $ts = ($30DayAgo - $origin).TotalSeconds -as [int] | |
| Write-host "Querying historical pricing for coins on date `n`t" | |
| $origin.AddSeconds($ts.TotalSeconds) | |
| $price = New-Object System.Collections.ArrayList | |
| #Next, for each symbol (Eth, Ripple and Monero), get a comparison of 30 days ago and compare to USD and BTC | |
| ForEach ($coin in @('ETH','XRP','XMR')){ | |
| $uri = "https://min-api.cryptocompare.com/data/pricehistorical?fsym=$coin&tsyms=BTC,USD&ts=$ts&extraParams=Stephen" | |
| $request = invoke-restmethod $uri | |
| [void]$price.Add([pscustomobject]@{ | |
| 'CoinName' = $coin | |
| 'BitCoinValue' = $request.$coin.BTC | |
| 'USDCoinValue' = $request.$coin.USD | |
| }) | |
| } | |
| $price | Format-Table | |
| ##returns | |
| #Querying historical pricing for coins on date Thursday, January 1, 1970 12:00:00 AM | |
| # | |
| #CoinName BitCoinValue USDCoinValue | |
| #-------- ------------ ------------ | |
| #ETH 0.04339 427.42 | |
| #XRP 0.00002419 0.2353 | |
| #XMR 0.01711 167.71 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment