Last active
September 6, 2022 15:58
-
-
Save whatl3y/711d1ce78e57d3a8124959998cce0399 to your computer and use it in GitHub Desktop.
This file contains 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
# 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" | |
} |
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
Updated to use @r3s-ash fork: https://gist.github.com/r3s-ash/fe6d7a93e4f540c670ccb81ddf34516d