Created
February 6, 2022 01:36
-
-
Save Frank-Buss/fbbae903765767430cac32d092b9bba4 to your computer and use it in GitHub Desktop.
get the quote for a crypto currency from coinmarketcap in USD
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
#!/bin/bash | |
# first create an API key at coinmarketcap.com. It is free for personal use. Set it in a variable: | |
export API_KEY="11111111-1111-1111-1111-111111111111" | |
# now you can call the API with curl, and extract the result with jq | |
# for example to get the quote for a crypto currency in USD: | |
coinquote() { | |
curl -s -H "X-CMC_PRO_API_KEY:$API_KEY" -H "Accept:application/json" \ | |
-d "symbol=$1&convert=USD" \ | |
-G https://pro-api.coinmarketcap.com/v1/cryptocurrency/quotes/latest \ | |
| jq -r .data.$1.quote.USD.price | |
} | |
# usage examples: | |
# frank@hal9000:~$ coinquote BTC | |
# 41565.26702354934 | |
# frank@hal9000:~$ coinquote WPKT | |
# 0.03267430133033706 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment