Look up Cryptocurreny Prices with PowerShell

Image Description

Daily PowerShell #55

Daily PowerShell Cryptocurreny REST API

December 9, 2021

quote Discuss this Article

In this post, we’ll look at how to use the CoinMarketCap API to look up prices of cryptocurrencies.

Get an API Key

First, you’ll need a CoinMarketCap API key to access the API.

They offer a free plan that allows for up to 333 credits a day and 10,000 credits a month. Credits are used by executing API calls, and depending on the call, it may use more credits than another call.

Once you have registered, you’ll be able to access your API key and view your credit usage.

Accessing the API

To access the API, you’ll need to include your API key in the headers.

List All Cryptocurrencies

The following example will list the top 5000 symbols and convert the price to US Dollars.

$data = Invoke-RestMethod 'https://pro-api.coinmarketcap.com/v1/cryptocurrency/listings/latest?start=1&limit=5000&convert=USD' -Headers @{ "X-CMC_PRO_API_KEY" = $ApiKey } 

The output from this command will include some info about the execution, including the number of credits used.

PS > $data.status

timestamp     : 12/8/2021 11:27:47 PM
error_code    : 0
error_message :
elapsed       : 450
credit_count  : 25
notice        :
total_count   : 8074

The data for the quote looks like this and include the quote for the US Dollars price.

PS > $data.data[0]

id                 : 1
name               : Bitcoin
symbol             : BTC
slug               : bitcoin
num_market_pairs   : 8243
date_added         : 4/28/2013 12:00:00 AM
tags               : {mineable, pow, sha-256, store-of-value}
max_supply         : 21000000
circulating_supply : 18895481
total_supply       : 18895481
platform           :
cmc_rank           : 1
last_updated       : 12/8/2021 11:26:02 PM
quote              : @{USD=}


PS > $data.data[0].Quote.USD

price                    : 50554.4168704186
volume_24h               : 28609179884.7988
volume_change_24h        : -14.8088
percent_change_1h        : -0.23439262
percent_change_24h       : 0.06753706
percent_change_7d        : -11.55974007
percent_change_30d       : -25.24844906
percent_change_60d       : -8.12738585
percent_change_90d       : 8.43894348
market_cap               : 955250023441.075
market_cap_dominance     : 39.9753
fully_diluted_market_cap : 1061642754278.79
last_updated             : 12/8/2021 11:26:02 PM

List an Individual Quote

Unlike the the /listings endpoint, you can use the /quotes endpoint to look up an individual quote. This only uses one credit so is more efficient use of credits than the /listings endpoint.

The following example looks up the current price of Loopring (LRC).

$data = Invoke-RestMethod 'https://pro-api.coinmarketcap.com/v1/cryptocurrency/quotes/latest?symbol=LRC&&convert=USD' -Headers @{ "X-CMC_PRO_API_KEY" = $ApiKey } 

The output from this endpoint will look like this. It will include the status information as well as the current quote.

PS > $data.status

timestamp     : 12/8/2021 11:32:13 PM
error_code    : 0
error_message :
elapsed       : 28
credit_count  : 1
notice        :



PS > $data.data.LRC

id                 : 1934
name               : Loopring
symbol             : LRC
slug               : loopring
num_market_pairs   : 146
date_added         : 8/30/2017 12:00:00 AM
tags               : {marketplace, decentralized-exchange, defi}
max_supply         : 1374513896
circulating_supply : 1328333700.03787
total_supply       : 1373873440.44246
platform           : @{id=1027; name=Ethereum; symbol=ETH; slug=ethereum; token_address=0xbbbbca6a901c926f240b89eacb641d8aec7aeafd}
is_active          : 1
cmc_rank           : 50
is_fiat            : 0
last_updated       : 12/8/2021 11:30:19 PM
quote              : @{USD=}


PS > $data.data.LRC.quote.USD

price                    : 2.5435699551585
volume_24h               : 931057185.500951
volume_change_24h        : 14.7785
percent_change_1h        : -3.18291119
percent_change_24h       : 3.59351836
percent_change_7d        : -7.9662315
percent_change_30d       : 22.27395321
percent_change_60d       : 519.39594787
percent_change_90d       : 463.56627111
market_cap               : 3378709689.84084
market_cap_dominance     : 0.1415
fully_diluted_market_cap : 3496172248.81
last_updated             : 12/8/2021 11:30:19 PM