Skip to content

Instantly share code, notes, and snippets.

@whatl3y
Last active September 6, 2022 15:58
Show Gist options
  • Select an option

  • Save whatl3y/711d1ce78e57d3a8124959998cce0399 to your computer and use it in GitHub Desktop.

Select an option

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"
}
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