Skip to content

Instantly share code, notes, and snippets.

@whatl3y
Last active September 6, 2022 15:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whatl3y/711d1ce78e57d3a8124959998cce0399 to your computer and use it in GitHub Desktop.
Save whatl3y/711d1ce78e57d3a8124959998cce0399 to your computer and use it in GitHub Desktop.
# Get the price of an ERC20 token based on it's ticker symbol
# Dependencies: curl, jq
# Desired usage:
# $ price hyve
# $ price cnfi
# $ price cudos
# $ price albt
function price() {
id=$(curl -s "https://api.coingecko.com/api/v3/coins/list" -H "accept: application/json" | jq --arg sym "$1" '.[] | select(.symbol==$sym)' | jq .id)
id_no_quotes=${id//$'"'/}
curl -s "https://api.coingecko.com/api/v3/simple/price?ids=$id_no_quotes&vs_currencies=usd" -H "accept: application/json"
}
@whatl3y
Copy link
Author

whatl3y commented Jan 19, 2021

Copy link

ghost commented Jan 19, 2021

Update line 8 to:
id=$(curl -s "https://api.coingecko.com/api/v3/coins/list" -H "accept: application/json" | jq --arg arg1 "$1" '.[] | select(.symbol==$arg1)' | jq .id)

To correctly take position argument and make last API call based on value of ID instead of symbol

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment