{"id":76,"date":"2020-09-01T16:28:50","date_gmt":"2020-09-01T14:28:50","guid":{"rendered":"http:\/\/alittlecrumbs.com\/?p=51"},"modified":"2020-09-01T16:28:50","modified_gmt":"2020-09-01T14:28:50","slug":"check-cryptocurrencies-price-and-amount-coinbase-wallet-with-powershell","status":"publish","type":"post","link":"https:\/\/notbotnotes.com\/?p=76","title":{"rendered":"Check Cryptocurrencies Price and Amount Coinbase Wallet with Powershell"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Powershell script to check cryptocurrencies current prices and wallet amounts of Coinbase account wallet through Coinbase API.<br>Save the script and before run fill mandatory parameters (api key and secret key generated from Coinbase account) and change base currency to account default currency.<\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">.\\cryptobalance.ps1 -api_key 1234567890abcdef -secret_key 1234567890abcdefghijklmnopqrstuv -basecurrency EUR -cryptos \"BTC\", \"ETH\", \"LTC\", \"BCH\"<\/pre>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">&lt;#\n.SYNOPSIS \nRetrieve current price and wallet amount of cryptocurrencies from Coinbase account and coinbase API.\nSee Coinbase API documentation here: https:\/\/developers.coinbase.com\/api\/v2.\nREQUIREMENTS: Powershell and Windows 7 at least.\nSimply change api_key, secret_key and basecurrency (to the default currency of your account) before running cryptobalance.ps1.\nTo create API and SECRET key go to your account preferences in Coinbase and follow the procedure.\n\n.EXAMPLE\nRun .\\cryptobalance.ps1 -api_key 1234567890abcdef -secret_key 1234567890abcdefghijklmnopqrstuv -basecurrency EUR -cryptos \"BTC\", \"ETH\", \"LTC\", \"BCH\"\n\n.NOTES \nName: bitbalance.ps1\nAuthor: Marika Braidotti \nVersion History \n    3.0 - 21\/02\/2018\n#&gt;\n\n    Param(\n        [Parameter(Mandatory=$true)][String] $api_key = '',  #change with your api key generated on your Coinbase account settings API section\n        [Parameter(Mandatory=$true)][String] $secret_key = '', #change with your secret key generated on your Coinbase account settings API section\n        [String] $basecurrency = 'EUR', #change with your desired fiat currency\n        [String[]] $cryptos = @(\"BTC\", \"ETH\", \"LTC\", \"BCH\") #change with your desired criptos\n        )\n\ntry {\n    \n$totalbalance = 0\n\nforeach ($crypto in $cryptos) {\n\n    $urlAPICryptoPrice = 'https:\/\/api.coinbase.com\/v2\/prices\/' + $crypto + '-' + $basecurrency + '\/spot'\n    $CryptoPrice = ((Invoke-WebRequest $urlAPICryptoPrice | ConvertFrom-Json).data).amount\n\n    $accounts = 'https:\/\/api.coinbase.com\/v2\/accounts'\n    $time = 'https:\/\/api.coinbase.com\/v2\/time'\n    $epochtime = [string]((Invoke-WebRequest $time | ConvertFrom-Json).data).epoch\n\n    $method = 'GET'\n    $requestpath = '\/v2\/accounts'\n\n    $sign = $epochtime + $method + $requestpath\n    $hmacsha = New-Object System.Security.Cryptography.HMACSHA256\n    $hmacsha.key = [Text.Encoding]::UTF8.GetBytes($secret_key)\n    $computeSha = $hmacsha.ComputeHash([Text.Encoding]::UTF8.GetBytes($sign))\n\n    $signature = ([System.BitConverter]::ToString($computeSha) -replace \"-\").ToLower()\n\n    $header = @{\n        \"CB-ACCESS-SIGN\"      = $signature\n        \"CB-ACCESS-TIMESTAMP\" = $epochtime\n        \"CB-ACCESS-KEY\"       = $api_key\n    }\n\n    $result = Invoke-WebRequest $accounts -Headers $header -Method Get -ContentType \"application\/json\"\n    $wallets = $result.Content | ConvertFrom-Json\n\n\n    foreach ($wallet in $wallets.data.balance) {\n        if ($wallet.currency -eq $crypto) {\n            $total = [math]::Round([Double]$wallet.amount * $CryptoPrice, 2)\n        }\n    }\n\n    $totalbalance += $total\n    Write-Host $crypto \"Current Price:\" $CryptoPrice $basecurrency \"- Wallet Amount:\" $total $basecurrency -ForegroundColor Yellow\n\n}\n$totalfiat = (((Invoke-WebRequest $accounts -Headers $header -Method Get -ContentType \"application\/json\").Content | ConvertFrom-Json).data | Where-Object {$_.type -match 'fiat'  } | Select-Object balance).balance.amount\nwrite-host \"Fiat Total Amount:\" $totalfiat $basecurrency -ForegroundColor Yellow\n\n$amount = $totalbalance + $totalfiat\nwrite-host \"Wallet Total Amount:\" $amount $basecurrency -ForegroundColor Green\n\n}\ncatch [Exception] {\n    Write-Host $_.Exception.Message\n  exit\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Powershell script to check cryptocurrencies current prices and wallet amounts of Coinbase account wallet through Coinbase API.Save the script and before run fill mandatory parameters (api key and secret key generated from Coinbase account) and change base currency to account default currency.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"jetpack_seo_schema_type":"","_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[15],"tags":[13,14,3],"class_list":["post-76","post","type-post","status-publish","format-standard","hentry","category-notes","tag-bitcoin","tag-crypto","tag-powershell"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack-related-posts":[],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/notbotnotes.com\/index.php?rest_route=\/wp\/v2\/posts\/76","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/notbotnotes.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/notbotnotes.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/notbotnotes.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/notbotnotes.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=76"}],"version-history":[{"count":0,"href":"https:\/\/notbotnotes.com\/index.php?rest_route=\/wp\/v2\/posts\/76\/revisions"}],"wp:attachment":[{"href":"https:\/\/notbotnotes.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=76"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/notbotnotes.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=76"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/notbotnotes.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=76"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}